You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using ~x + ... seems to disallow whitespace skip with left recursion. Is this intended behavior? If so, what's the idiomatic way of doing it in left recursive grammars?
An example:
importpyparsingaspppp.ParserElement.inline_literals_using(pp.Suppress)
pp.ParserElement.enable_left_recursion()
Top=pp.Forward()
# an xyz word that doesn't start with xxxAtom=~pp.Literal('xxx') +pp.Word('xyz')
# ^--------- this negative lookahead seems # to mess with whitespace handling# in recursive grammars?## This workaround works:# Atom = pp.White()[0,1] + ~pp.Literal('xxx') + pp.Word('xyz')# (Minibug: pp.White(min=0) cannot match 0 whitespace)Expr0=pp.Forward()
Expr0<<=Expr0+'['+Top+']'|Atom# ... in my case there's many levels of expressions,# and they're constructed dynamically ...Expr1=TopExpr1<<=Top+'*'+Expr0|Expr0
The thought is that this would match anything like x[ x * x[y] ][y] * y with optional whitespaces anywhere, but whitespace is only skipped inside expressions, not at the start:
>>> Top.run_tests(['x[y*x]', 'x [y * xx ]', ' x', 'x[ y*xx]', ' x*y'])
x[y*x]
['x', 'y', 'x']
x [y * xx ]
['x', 'y', 'xx']
x
['x']
x[ y*xx]
x[ y*xx]
^
ParseException: Expected end of text, found '[' (at char 1), (line:1, col:2)
FAIL: Expected end of text, found '[' (at char 1), (line:1, col:2)
x*y
x*y
^
ParseException: Expected end of text, found '*' (at char 3), (line:1, col:4)
FAIL: Expected end of text, found '*' (at char 3), (line:1, col:4)
The text was updated successfully, but these errors were encountered:
Using
~x + ...
seems to disallow whitespace skip with left recursion. Is this intended behavior? If so, what's the idiomatic way of doing it in left recursive grammars?An example:
The thought is that this would match anything like
x[ x * x[y] ][y] * y
with optional whitespaces anywhere, but whitespace is only skipped inside expressions, not at the start:The text was updated successfully, but these errors were encountered: