A fast implementation of the Nix expression language
修訂 | 41cf845db913649905de4ce650312754b5a8d301 (tree) |
---|---|
時間 | 2024-06-14 11:59:00 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
parser: Use some sugar.
@@ -404,23 +404,22 @@ opDict = { | ||
404 | 404 | "-": "sub", |
405 | 405 | } |
406 | 406 | |
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()]) | |
424 | 423 | |
425 | 424 | @pg.production("expr_op : expr_op HAS attrpath") |
426 | 425 | def exprHas(p): return HasBox(p[0], p[2]) |
@@ -530,5 +529,9 @@ def checkTable(table): | ||
530 | 529 | # assert not table.sr_conflicts and not table.rr_conflicts |
531 | 530 | checkTable(parser.lr_table) |
532 | 531 | |
532 | +print "Grammar:", parser.lr_table.grammar | |
533 | +for i, production in enumerate(parser.lr_table.grammar.productions): | |
534 | + print i, production | |
535 | + | |
533 | 536 | # Top-level interface: Lex and parse UTF-8 text. |
534 | 537 | def parse(expr): return parser.parse(lexer.lex(expr)) |