[antlr-interest] Set encoding for python target

Rene Liebscher R.Liebscher at gmx.de
Wed Nov 26 01:36:21 PST 2008


Hi,

I just use antlr for writing a parser for a small expression language.

In this language I have a function called 'LÄNGE' (the german word for length).
This also shows up in the resulting code for the lexer. However this is not ascii so python complains about it.
------
$ python Lexer.py
  File "Lexer.py", line 1414
SyntaxError: Non-ASCII character '\xc4' in file Lexer.py on line 1414, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
------
The solution is to add a line like 
-----
# coding: latin1
-----
as first or second line in the generated file.

Is there a way to set this from the grammar file?


Kind regards

René Liebscher


PS: One could think encoding it as 'L\u00c4NGE' in the grammar file, but this results in "L\u00c4NGE" in the python file, where it had to be u"L\u00c4NGE" to accept the \u.

-- 
Sensationsangebot nur bis 30.11: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a


More information about the antlr-interest mailing list