You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a grammar with multiple top-level non-terminals that I want to use at different points in my program. Currently I have to specify ONE root rule when loading a grammar with ParserPEG. That means I need to parse the same grammar multiple times with different root rule names if I want to use different root rules throughout my program.
Could Arpeggio add support for specifying the root rule name when calling parse(), instead of once and for all for the parser when instantiating it? Or is there another way of achieving this?
E.g. currently I have to do this:
fromarpeggio.cleanpegimportParserPEGgrammar=r"""assignment = name "=" expr EOFexpression = expr EOFname = r"\b[a-z]+\b"expr = name (("+" / "-") name)*"""parser_e=ParserPEG(grammar, root_rule_name="expression")
parser_a=ParserPEG(grammar, root_rule_name="assignment") # <-- BAD! Parsing the same grammar twicedefrun(condition, action):
parser_e.parse(condition)
parser_a.parse(action)
run("a + b", "c = a + a + b")
I think it should be relatively straight forward to support this although it would require first implementing the same feature in ParserPython. I don't see any conceptual difficulty as the recursive descend parsers can naturally start from any rule.
I have a grammar with multiple top-level non-terminals that I want to use at different points in my program. Currently I have to specify ONE root rule when loading a grammar with ParserPEG. That means I need to parse the same grammar multiple times with different root rule names if I want to use different root rules throughout my program.
Could Arpeggio add support for specifying the root rule name when calling
parse()
, instead of once and for all for the parser when instantiating it? Or is there another way of achieving this?E.g. currently I have to do this:
I would like to be able to do this instead:
The text was updated successfully, but these errors were encountered: