• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

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

Revisão476522045be45336529417d240954a5b0e91ff66 (tree)
Hora2024-06-14 11:29:28
AutorCorbin <cds@corb...>
CommiterCorbin

Mensagem de Log

parser: Make string QLs left-recursive.

And, with this, there's no longer any good explanation for why we cannot
match formals and binds at the same top-level.

Mudança Sumário

Diff

--- a/parser.py
+++ b/parser.py
@@ -180,16 +180,17 @@ class AppBox(EBox):
180180 compiler.mkApp()
181181
182182 class StrQLBox(EBox):
183- def __init__(self, init, pairs):
184- self.init = init
183+ def __init__(self, pairs, tail):
185184 self.pairs = pairs
185+ self.tail = tail
186186 def pretty(self):
187- rv = [self.init]
188- for expr, piece in self.pairs:
187+ rv = []
188+ for piece, expr in self.pairs:
189+ rv.append(piece)
189190 rv.append("${ ")
190191 rv.append(expr.pretty())
191192 rv.append(" }")
192- rv.append(piece)
193+ rv.append(self.tail)
193194 return '"%s"' % "".join(rv)
194195 # def compile(self, compiler):
195196 # l = [heap.HeapStr(self.init)]
@@ -439,23 +440,22 @@ def exprSimpleInt(p): return IntBox(int(p[0].getstr()))
439440 @pg.production("expr_simple : STRING")
440441 def exprQuoted(p): return StrBox(trimBox(p[0], 1, -1))
441442
442-@pg.production("expr_simple : STRING_INIT string_ql")
443-def stringQL(p):
444- s = trimBox(p[0], 1, -2)
445- incomplete = p[1]
446- assert isinstance(incomplete, IncompleteQL)
447- return StrQLBox(s, incomplete.pairs)
443+@pg.production("string_ql : STRING_INIT expr")
444+def stringQL(p): return IncompleteQL([(trimBox(p[0], 1, -2), p[1])])
448445
449-# XXX should be left-recursive? Requires refactoring all string_ql rules
450-@pg.production("string_ql : expr STRING_PIECE string_ql")
446+@pg.production("string_ql : string_ql STRING_PIECE expr")
451447 def stringQLPiece(p):
452- incomplete = p[2]
448+ incomplete = p[0]
453449 assert isinstance(incomplete, IncompleteQL)
454- pairs = [(p[0], trimBox(p[1], 1, -2))] + incomplete.pairs
450+ pairs = incomplete.pairs + [(trimBox(p[1], 1, -2), p[2])]
455451 return IncompleteQL(pairs)
456452
457-@pg.production("string_ql : expr STRING_END")
458-def stringQLEnd(p): return IncompleteQL([(p[0], trimBox(p[1], 1, -1))])
453+@pg.production("expr_simple : string_ql STRING_END")
454+def stringQLEnd(p):
455+ incomplete = p[0]
456+ assert isinstance(incomplete, IncompleteQL)
457+ s = trimBox(p[1], 1, -1)
458+ return StrQLBox(incomplete.pairs, s)
459459
460460 @pg.production("expr_simple : URI")
461461 def exprURI(p): return StrBox(p[0].getstr())