Trying to parse a soft keyword
See original GitHub issueWhat is your question?
I’m currently making a Python transpiler, using lark/grammars/python.lark
for parsing.
The grammar is almost fine, but it lacks match…case support.
I’ve adapted grammar from official docs, but now I encounter a new problem
If you’re having trouble with your code or grammar Here’s a minimal example, with semicolons and braces added to drop indentation checks
from lark import Lark
grammar = """
%ignore /[\t \f\n]+/x
NAME: /[a-zA-Z_]\w*/
MATCH: "match"
CASE: "case"
NUMBER: ("+" | "-")? "0".."9"
expr: NAME | NUMBER
agmt: NAME "=" expr
match: MATCH expr "{" case+ "}"
case: CASE expr block
block: "{" code "}"
code: stmt+
stmt: (expr | match | agmt) ";"
"""
parser = Lark(grammar, start="code", parser="lalr")
code = """match = 1;
case = 2;
match N {
case Z {
5;
}
};"""
parser.parse(code)
What happens is “match” in first line treated as the beginning of match rule and fails to parse. Is there a way to resolve this while using LALR(1), not Earley?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
difference between soft parse and hard parse - Ask TOM
We want to be SOFT parsing at the system level (that means our applications as a whole make use of shared sql). That...
Read more >Keyword Extraction: A Guide to Finding Keywords in Text
Keyword extraction is used to automatically pull out single keywords, or groups of two or more words to detect key phrases in unstructured...
Read more >Oracle Performance tuning | Oracle hard parse vs soft parse
Oracle Performance tuning | Oracle hard parse vs soft ... tuning | Oracle hard parse vs soft parse https://sivakacademy.blogspot.com/p/o.
Read more >How to parse contextual keywords in a programming language
How to parse contextual keywords in a programming language · Parsing partial directly in the grammar · Having special syntax for a verbatim ......
Read more >A Guide To Parsing: Algorithms And Terminology
So they use them to try to parse everything, even the things they should not. ... example of context-sensitive elements are the so-called...
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
Not in general. There is a reason python3.10 does no longer use a lalr compatible parser/grammar. You can maybe get around this with a postlex that looks at the next token/symbol/end of the line for a colon l and change it according to that, but this is simply not context free.
@erezsh Yeah, you are correct it works.
@evtn #1016 should contain full support for parsing match statements.