question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[standalone.py] NameError: name 'RULE' is not defined

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Sep 6, 2018

Pushed some code to master that should fix this. Let me know if it works (or if it doesn’t)

1reaction
erezshcommented, Aug 27, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found