def parse_source(source): """returns list of parsed tokens""" lexer = Source( P, source.splitlines(True), {}) tokens = [] last_token = Token( P, NULLTOKEN, None) while last_token.codename != ENDMARKER: last_token = lexer.next() tokens.append(last_token) return tokens
def parse_lines(self, lines, goal, builder, flags=0): # builder.keywords = self.keywords.copy() # if flags & CO_FUTURE_WITH_STATEMENT: # builder.enable_with() goalnumber = self.symbols[goal] target = self.root_rules[goalnumber] src = Source(self, lines, flags) if not target.match(src, builder): line, lineno = src.debug() # XXX needs better error messages raise SyntaxError("invalid syntax", lineno, -1, line) # return None return builder
def parse_lines(self, lines, goal, builder, flags=0): goalnumber = self.symbols[goal] target = self.root_rules[goalnumber] keywords = {} # dict.fromkeys(self.keywords) disable_with = not (flags & CO_FUTURE_WITH_STATEMENT) for keyword in self.keywords: if disable_with and keyword in ('with', 'as'): continue keywords[keyword] = None src = Source(self, lines, keywords, flags) if not target.match(src, builder): line, lineno = src.debug() # XXX needs better error messages raise SyntaxError("invalid syntax", lineno, -1, line) # return None return builder
def parse_lines(self, lines, goal, builder, flags=0): goalnumber = self.symbols[goal] target = self.root_rules[goalnumber] keywords = {} # dict.fromkeys(self.keywords) disable_with = not (flags & CO_FUTURE_WITH_STATEMENT) for keyword in self.keywords: if disable_with and keyword in ('with', 'as'): continue keywords[keyword] = None src = Source(self, lines, keywords, flags) if not target.match(src, builder): # clean up errors found_error = self.found_error self.found_error = grammar.NO_ERROR tok, line, lnum, pos = src.most_recent_token() if tok.codename == self.tokens['INDENT']: raise IndentationError("unexpected indent", lnum, pos, line) if tok.codename == self.tokens['DEDENT']: raise IndentationError("unexpected dedent", lnum, pos, line) if found_error == grammar.ERROR_EXPECTED_INDENT: raise IndentationError("expected an indented block", lnum, pos, line) raise SyntaxError("invalid syntax", lnum, pos, line) return builder