def _parsefile (self, filename): if filename[-2:] != "py": filename = filename[:-1] tree1 = convert_pypgen_tree(self.parser1, self.parser1.parseFile(filename)) token_stream = PythonicTokenStream( mktokenizer(open(filename).readline)) tree2 = convert_trampoline_tree(trampoline.trampoline_parse( self.handlers, token_stream).tree[1][0]) if __debug__: print(" ".join((str(elem) for elem in [tree1[0], tree2[0]]))) problem_report = find_problem_child(tree1, tree2) self.assertEquals(problem_report, None, problem_report)
def parse_lineiter (self, lineiter, env = None): if env is None: env = {} line_offset = env.get("lineno", 1) - 1 column_offset = env.get("column_offset", 0) filename = env.get("filename", "<string>") readliner = mylexer.MythonReadliner(lineiter) token_stream = mylexer.MythonTokenStream(readliner, lnum = line_offset, column_offset = column_offset) tree_builder = trampoline.TreeBuilder() try: tree_builder = trampoline.trampoline_parse( self.handlers, token_stream, tree_builder) except SyntaxError, syntax_err: if __DEBUG__: pprint.pprint(tree_builder.__dict__) if syntax_err.args[0].startswith("Line"): err_str = "File '%s', l%s" % (filename, syntax_err.args[0][1:]) else: err_str = "File '%s', %s" % (filename, syntax_err.args[0]) raise MyFrontSyntaxError(err_str)
def parse_start (self, instream, outtree=None): return trampoline.trampoline_parse(self.handlers, instream, outtree)