-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for injecting extra rules written in Python into PEG grammars #29
Comments
I'm planing a more general approach for parser composability. Something like this: from lib.external import rule1, rule2
from arpeggio import GrammarPython, GrammarPEG, GrammarCPEG, Parser
...
parser = Parser(GrammarPython(calc), GrammarPEG(calc_override_in_peg),
GrammarPython(rule1, rule2), GrammarCPEG(clean_peg_addition)) Grammar* callables will know how to read grammar written in different styles and In this approach you could mix and match grammars using different styles. E.g., Grammars could be incomplete, i.e. rules could reference unexisting rules thus Additionally, in the list of the grammars you shall be able to use All this stuff require some non-trivial changes to the core though. |
It sounds excelent! Although I like the possibility of refering to rules of Anyway, thanks for writing Arpeggio and making it available for free. It's On Friday, 7 October 2016, Igor Dejanović notifications@github.com wrote:
|
Just FYI, this is how I did it — https://github.com/vuvova/gdb-tools/blob/64a9280/duel/parser.py The main grammar starts from line 52, note the token It'd be cleaner to inherit from |
Thanks. It would indeed be better if new |
May be I used an older version? There was You can try to inherit with a dummy class, like
and see where it won't work. It should be easily fixable, I agree. |
It would be useful to be able to inject rules written as python functions into PEG grammars.
This would accomplish two things:
peg
,cleanpeg
orpython
parsers. Python functions, although more cumbersome to write, are more composable.I'd suggest the following API:
The user could then use
'rule_name1'
and'rule_name2'
in the file, and the rules would be automatically resolve. There might be a problem with name clashes between user defined rules and inner rules defined by the external functions, though. I'm not familiar enough with Arpeggio's internals to be sure.The text was updated successfully, but these errors were encountered: