• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A fast implementation of the Nix expression language


Commit MetaInfo

修訂41cf845db913649905de4ce650312754b5a8d301 (tree)
時間2024-06-14 11:59:00
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

parser: Use some sugar.

Change Summary

差異

--- a/parser.py
+++ b/parser.py
@@ -404,23 +404,22 @@ opDict = {
404404 "-": "sub",
405405 }
406406
407-@pg.production("expr_op : expr_op AND expr_op")
408-@pg.production("expr_op : expr_op CONCAT expr_op")
409-@pg.production("expr_op : expr_op DIV expr_op")
410-@pg.production("expr_op : expr_op EQ expr_op")
411-@pg.production("expr_op : expr_op GE expr_op")
412-@pg.production("expr_op : expr_op GEQ expr_op")
413-@pg.production("expr_op : expr_op IMPL expr_op")
414-@pg.production("expr_op : expr_op LE expr_op")
415-@pg.production("expr_op : expr_op LEQ expr_op")
416-@pg.production("expr_op : expr_op MINUS expr_op")
417-@pg.production("expr_op : expr_op MUL expr_op")
418-@pg.production("expr_op : expr_op NEQ expr_op")
419-@pg.production("expr_op : expr_op OR_OP expr_op")
420-@pg.production("expr_op : expr_op PLUS expr_op")
421-@pg.production("expr_op : expr_op UPDATE expr_op")
422-def exprBinary(p):
423- return ExprBinaryBox(p[0], p[2], opDict[p[1].getstr()])
407+@pg.production("""expr_op : expr_op AND expr_op
408+ | expr_op CONCAT expr_op
409+ | expr_op DIV expr_op
410+ | expr_op EQ expr_op
411+ | expr_op GE expr_op
412+ | expr_op GEQ expr_op
413+ | expr_op IMPL expr_op
414+ | expr_op LE expr_op
415+ | expr_op LEQ expr_op
416+ | expr_op MINUS expr_op
417+ | expr_op MUL expr_op
418+ | expr_op NEQ expr_op
419+ | expr_op OR_OP expr_op
420+ | expr_op PLUS expr_op
421+ | expr_op UPDATE expr_op""")
422+def exprBinary(p): return ExprBinaryBox(p[0], p[2], opDict[p[1].getstr()])
424423
425424 @pg.production("expr_op : expr_op HAS attrpath")
426425 def exprHas(p): return HasBox(p[0], p[2])
@@ -530,5 +529,9 @@ def checkTable(table):
530529 # assert not table.sr_conflicts and not table.rr_conflicts
531530 checkTable(parser.lr_table)
532531
532+print "Grammar:", parser.lr_table.grammar
533+for i, production in enumerate(parser.lr_table.grammar.productions):
534+ print i, production
535+
533536 # Top-level interface: Lex and parse UTF-8 text.
534537 def parse(expr): return parser.parse(lexer.lex(expr))