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)
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
def visitRuleAltList(self, ctx: ANTLRv4Parser.ParserRuleSpecContext): return tuple(x.accept(self) for x in ctx.labeledAlt())