LALR templates not expanding
See original GitHub issueDescribe the bug
Basically, templates don’t work as well on the LALR parser. I have to manually expand the template in order for my grammar to work on LALR. This kind of defeats the purpose of templates.
To Reproduce
Grammar “A”:
%import common.WORD
%import common.NEWLINE -> _NL
%ignore " "
start: _list{WORD}
_COMMA: "," _NL?
_list{x}: _sep{x, _COMMA} _COMMA?
_sep{x, sep}: x (sep x)*
Grammar “B” (this is equivalent to grammar A but I manually expanded one of the templates):
%import common.WORD
%import common.NEWLINE -> _NL
%ignore " "
start: _list{WORD}
_COMMA: "," _NL?
_list{x}: x (_COMMA x)* _COMMA?
Problem
Earley can parse the following examples with either grammars
Hello, world
Hello, world,
LALR can only parse both inputs using grammar B (grammar A fails when trying to parse the second input)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Resolving a shift/reduce conflict in an LALR parser
Yacc parsers are not particularly powerful and attempting a context-free parse may be asking too much of it. I suggest using some kind...
Read more >Is LALR(1) or LL(k) parser better for C++ - Google Groups
The LALR(1) grammar does not deal with templates at all. My LL(2) grammar is weak in a number of ways (although I'm working...
Read more >Example-Driven Error Reporting - Lark documentation
A demonstration of example-driven error reporting with the LALR parser (See ... label = 'Missing Opening' class JsonMissingClosing(JsonSyntaxError): label ...
Read more >Elkhound: A fast, practical GLR parser generator
Abstract. The Generalized LR (GLR) parsing algorithm is attractive for use in parsing programming languages because it is asymptotically.
Read more >cwbaker/lalr: Modern LALR(1) parser for C++ - GitHub
If the symbol and the production have the same precedence and the symbol explicitly has no associativity (i.e. it is listed in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Each template is currently expanded into its own rule. Which is why you get a shift/reduce conflict.
Btw, I already opened an issue for this a year ago, but it didn’t get any attention: https://github.com/lark-parser/lark/issues/822
Templates generate trees where
data
is the template name. It’s very predictable.Of course, you won’t see those starting with underscore, because they get inlined during parsing.