lark
                                
                                 lark copied to clipboard
                                
                                    lark copied to clipboard
                            
                            
                            
                        Parsing context-free grammar with smart interplay between lexer and parser
I'd like to parse inputs like
equations 3
a=7
b=a*c
c=exp(-1)
which are generated by a context-sensitive grammar (because of the 3 giving the number of equations to follow).
Is there a way to parse such a grammar using an interplay between lexer and parser in Lark, preferably in a "fast" way, e.g. using LARL.
Early kind of works but is painfully - and understandibly - slow and needs to be painstakingly tweaked to most of the time yield the desired parse tree from the ambiguous grammar.
Well, I'm not sure why the 3 matters here.. Just parse everything and verify the count after it's done.
But if you really need this much control, look into the interactive parser with Lark.parse_interactive().
The example might not have been the best but there are instances where without knowing the number of ... (this extends to other "blocks" than equations) you cannot reliably determine where the next block starts.