예제 #1
0
    def visitParserRuleSpec(self, ctx: ANTLRv4Parser.ParserRuleSpecContext):
        # Extract the name and reset subrules before exploring deeper.
        name = str(ctx.RULE_REF())
        self.last_rule = name
        self.subrule_count = 0

        # Recurse into the subtree of this rule.
        rules = ctx.ruleBlock().accept(self)
        self.grammar.add_nonterminal(name, rules)
예제 #2
0
    def enterParserRuleSpec(self, ctx:ANTLRv4Parser.ParserRuleSpecContext):
        global lhs
        name = str(ctx.RULE_REF())
        if ' ' in name:
            raise Exception("Rule name with space not handled: " + name)
        if mark in name:
            raise Exception(("Rule name with '%s' not handled: " % mark) + name)
        lhs = name

        global first_lhs,add_axiom
        if first_lhs and add_axiom:
            print("<" + lhs + "> ;")
        first_lhs = False
        print("# PARSER: " + lhs)

        global parser_or_lexer
        parser_or_lexer = "parser"
        global is_fragment
        is_fragment = False
예제 #3
0
 def visitRuleAltList(self, ctx: ANTLRv4Parser.ParserRuleSpecContext):
     return tuple(x.accept(self) for x in ctx.labeledAlt())