-
-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline rules expand ambiguities unnecessarily #1221
Comments
@chanicpanic The saga continues! |
Sorry, messed up the original examples, corrected now. |
The example provided is actually a special case that may be open to optimization. Consider the general case in which expansions of start: field+
field: f1 ws | f2 ws2
f1: INT
f2: INT
ws: WS
ws2: WS
%import common.WS
%import common.INT Parsing the text
If we inline
which is not correct. In this case, I see no more compact way to represent the ambiguities than to expand them all. We may be able to optimize the special case in which all instances of @yurymann Conditional inlining may be your friend for highly ambiguous rules: start: field+
?field: f1 | f2
f1: INT
f2: INT
%ignore WS
%import common.WS
%import common.INT gives:
You may also want to look at lark-ambig-tools which can help you process highly ambiguous trees more efficiently. |
@chanicpanic, wow, conditional inlining looks indeed like THE solution for my case. |
Thanks for fixing #1214 earlier. It now seems to return all ambiguities, but ambiguities inside inline rules are expanded within the parser rather than leaving it to
CollapseAmbiguities
transformer.I have some input strings that explode very quickly when expanding ambiguities. I parse them with
ambiguity=explicit
, then count the expected number of expanded ambiguities. If it's within a reasonable threshold, I put the tree throughCollapseAmbituities
. Otherwise, the processing stops (until I find a better way to deal with such strings). As the result, I still can't use inline rules because parsing of some inputs explodes before I can even count the number of ambiguities.To reproduce, parse this string:
with this grammar
Result:
Now, inline
field
:The parser now expands the nested ambiguities prematurely:
The text was updated successfully, but these errors were encountered: