A fast implementation of the Nix expression language
Révision | 376831c93fc2872a6134b52fd5bec158805e195f (tree) |
---|---|
l'heure | 2024-06-10 07:57:27 |
Auteur | Corbin <cds@corb...> |
Commiter | Corbin |
parser: Add weird let-expression and rec-expression.
@@ -295,6 +295,14 @@ class WithBox(BaseBox): | ||
295 | 295 | self.expr = expr |
296 | 296 | def pretty(self): return "with %s; %s" % (self.scope.pretty(), self.expr.pretty()) |
297 | 297 | |
298 | +class WeirdLetBox(BaseBox): | |
299 | + def __init__(self, binds): self.binds = binds | |
300 | + def pretty(self): return "let " + self.binds.pretty() | |
301 | + | |
302 | +class RecBox(BaseBox): | |
303 | + def __init__(self, binds): self.binds = binds | |
304 | + def pretty(self): return "rec " + self.binds.pretty() | |
305 | + | |
298 | 306 | class LambdaBox(BaseBox): |
299 | 307 | def __init__(self, binding, params, body): |
300 | 308 | self.binding = binding |
@@ -444,6 +452,12 @@ def stringQLEnd(p): return IncompleteQL([(p[0], trimBox(p[1], 1, -1))]) | ||
444 | 452 | @pg.production("expr_simple : URI") |
445 | 453 | def exprURI(p): return StrBox(p[0].getstr()) |
446 | 454 | |
455 | +@pg.production("expr_simple : LET OPEN_BRACE binds CLOSE_BRACE") | |
456 | +def exprWeirdLet(p): return WeirdLetBox(p[2]) | |
457 | + | |
458 | +@pg.production("expr_simple : REC OPEN_BRACE binds CLOSE_BRACE") | |
459 | +def exprRec(p): return RecBox(p[2]) | |
460 | + | |
447 | 461 | enclosedRule("expr_simple : OPEN_BRACE binds CLOSE_BRACE", 1) |
448 | 462 | enclosedRule("expr_simple : OPEN_PAREN expr CLOSE_PAREN", 1) |
449 | 463 | enclosedRule("expr_simple : OPEN_BRACK expr_list CLOSE_BRACK", 1) |