[standalone.py] NameError: name 'RULE' is not defined
See original GitHub issueI am using:
pip3 show lark-parser
Name: lark-parser
Version: 0.6.3
Python 3.6.4
When I generate the standalone parser and try to run it, it throws:
Traceback (most recent call last):
File "lexer.py", line 601, in <module>
1: Rule(NonTerminal('language_syntax'), [NonTerminal(Token(RULE, '__anon_star_0')), NonTerminal('preamble_statements')], None, RuleOptions(False, False, None)),
NameError: name 'RULE' is not defined
The generated parse is this: lexer.zip
The line 601 is this:
File: lexer.py
599: RULES = {
600: 0: Rule(NonTerminal('language_syntax'), [NonTerminal('preamble_statements')], None, RuleOptions(False, False, None)),
601: 1: Rule(NonTerminal('language_syntax'), [NonTerminal(Token(RULE, '__anon_star_0')), NonTerminal('preamble_statements')], None, RuleOptions(False, False, None)),
The problem is this RULE constant on the python code which is not defined anywhere by the standalone.py
tool.
This is the input grammar used:
language_syntax: _NEWLINE* preamble_statements
preamble_statements: target_language_name_statement | master_scope_name_statement
target_language_name_statement: "name" ":" free_input_string
master_scope_name_statement: "scope" ":" free_input_string
// General terminal constructs
CR: "/r"
LF: "/n"
SPACES: /[\t \f]+/
// General non terminal constructs
free_input_string: /[^\n]/
SINGLE_LINE_COMMENT: /(#|\/\/)[^\n]*/
// _NEWLINE: (CR? LF)+
_NEWLINE: ( /\r?\n[\t ]*/ | SINGLE_LINE_COMMENT )+
INTEGER: "0".."9"
%ignore SPACES
%ignore SINGLE_LINE_COMMENT
This was the command line used to build the standalone parser:
python -m lark.tools.standalone ../simple.lark > lexer.py
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
python - NameError: name 'Rule' is not defined but i did import ...
I am making a crawler with scrapy, and I cant use the word Rule, but I did import this. stack_crawler.py
Read more >Python Errors: Nameerror name is not defined and more
Hi there! My name is Marta. I am a software engineer with 10 years of experience. I am highly experienced in Java and...
Read more >6. Modules — Python 3.11.1 documentation
This does not introduce the module name from which the imports are taken in the local namespace (so in the example, fibo is...
Read more >Building Python function-based components - Kubeflow
Define your component's code as a standalone Python function. In this example, the function adds two floats and returns the sum of the...
Read more >Delta Live Tables cookbook - Azure Databricks | Microsoft Learn
The following example uses a CSV file named rules.csv stored in DBFS to ... The following Python example defines data quality expectations ...
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
Pushed some code to
master
that should fix this. Let me know if it works (or if it doesn’t)Sorry for not replying sooner. The reason that the generated parser doesn’t work, is that right now it only supports the “standard” lexer, while your grammar requires the “contextual” lexer.
It shouldn’t be too difficult to add, but it will take a few hours of work. Hopefully I’ll get to it soon.