Closed evandrocoan closed 6 years ago
Thanks for the bug report! I pushed a fix to master
which should solve this issue.
Also pushed a new version to pypi. Upgrading to lark-parser==0.6.4
should do the trick.
Thanks! But I got this error: NameError: name 'UnexpectedToken' is not defined
I added a print when using the tokens: https://github.com/evandroforks/lark/commit/b9cf98427d0f7ff103340804eabe5be24faf8f8a You see the 2 first tokens where get:
"[@0,0:23='\n\n\n// Example program:\n\n'<_NEWLINE>,1:1]"
"[@1,24:54='name: Abstract Machine Language'<__ANON_2>,6:1]"
Traceback (most recent call last):
File "lexer.py", line 678, in get_action
return states[state][key]
KeyError: '__ANON_2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main_lexer.py", line 38, in <module>
test()
File "main_lexer.py", line 33, in test
tree = parser.parse(file.read())
File "lexer.py", line 1097, in parse
return self.parser.parse(tokens)
File "lexer.py", line 705, in parse
action, arg = get_action(token.type)
File "lexer.py", line 681, in get_action
raise UnexpectedToken(token, expected, state=state) # TODO filter out rules from expected
NameError: name 'UnexpectedToken' is not defined
When I run the grammar without generating the parser, it runs correctly.
This is the generated parser, input grammar and the test programs: ...
If you run the file python3 main.py
you will import lark and run the example program without problems. But if you call python3 main_lexer.py
, it will use the generated parser and you will see the error.
This bellow is the output of running python3 main.py
, it runs correctly without any errors. The extra print you see on the beginning are just the tokens information: https://github.com/evandroforks/lark/commit/b9cf98427d0f7ff103340804eabe5be24faf8f8a After all tokens being outputted, you see the full tree generated correctly.
```
$ python3 main.py
"[@0,0:1='\n\n'<_NL>,1:1]"
"[@1,2:16='language_syntax'
I am using:
When I generate the standalone parser and try to run it, it throws:
The generated parse is this: lexer.zip
The line 601 is this:
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:
This was the command line used to build the standalone parser: