-
-
Notifications
You must be signed in to change notification settings - Fork 276
Zen
Paul McGuire edited this page Feb 4, 2020
·
3 revisions
- Don't clutter up the parser grammar with whitespace, just handle it! (likewise for comments)
- Class names are easier to read and understand than specialized typography
- Use operators to implement an embedded parsing DSL:
-
+
for And -
|
for MatchFirst -
^
for Or -
~
for NotAny -
&
for Each (like And, but accepting out of order) -
-
for And with no backtracking -
<<
and<<=
for Forward -
...
for SkipTo -
[...]
for ZeroOrMore
-
- Simple grammars can return lists; complex grammars need named results
- Parsers can do more than just tokenize
- Grammars should be:
- easy (and quick) to write
- easy to read
- easy to update
- No separate code-generation step (like lex/yacc)
- No forced naming conventions (like PLY)
- Stay Pure Python
- Lightweight packaging – single .py file
- Liberally licensed (MIT license – free for commercial use)