lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.62k stars 395 forks source link

Stand-alone program cannot be run #1412

Closed Doormatty closed 2 months ago

Doormatty commented 2 months ago

Given the following grammar (and to be clear, I don't think this has anything to do with the grammar itself):

ANY: "n"
dist: NUMBER | ANY
basic_move: dist
start: basic_move

%import common.NUMBER
%import common.WS
%ignore WS

running python -m lark.tools.standalone .\grammar.txt > standalone.py

Produces the following attached python program (renamed to standalone.txt to allow uploading)

standalone.txt

With either Python 3.12 and Python 3.11 on Windows 10, any attempt to even include the created file: from standalone import Lark_StandAlone throws the exception: SyntaxError: source code string cannot contain null bytes

Thanks so much!

erezsh commented 2 months ago

That sounds like an issue with Windows encoding. Try to open the resulting Python file with a code editor and updating the encoding to utf8 or latin-1.

Doormatty commented 2 months ago

I was under the impression that Python 3.X was by default unicode - is that not the case?

MegaIng commented 2 months ago

python is, but windows cmd is stupid. It defaults to UTF-16, which is not going to work correctly.

Doormatty commented 2 months ago

Ahh! Thanks! Appreciate the info!