def emit_classes (self): code_list = ["#! /usr/bin/env python", "class AST (object):", ["pass"], "", ] class_names = self.classes.keys() class_names.sort() for class_name in class_names: code_list += ["class %s (AST):" % class_name, self.classes[class_name], ""] return "\n".join(pgen2LL1.gen_code_lines(code_list))
def main (*args): # Parse the input pgen file. fe = PgenFrontEnd() fe.handle_args(*args) cpt = fe.get_concrete_parse() rules = process_rules(cpt) # For each nonterminal, create a handler method. methods = {} rule_names = [rule_name for rule_name in rules.keys() if rule_name[0] != "_"] for rule_name in rule_names: methods["handle_%s" % rule_name] = [ "child_results = self.handle_children(node)", "return child_results"] # Anything else? (Overloading needed traversal methods?) klass = make_class(methods, fe.klass_name, fe.start) code_lines = gen_code_lines(klass) fe.output_text("\n".join(code_lines))