[antlr-interest] Python.g string with triple quote

Fırat Küçük firatkucuk at gmail.com
Tue Jan 1 02:05:15 PST 2008


Hi

These are the Python.g string literal lexer rules:

STRING
    :   ('r'|'u'|'ur')?
        (   '\'\'\'' (options {greedy=false;}:.)* '\'\'\''
        |   '"""' (options {greedy=false;}:.)* '"""'
        |   '"' (ESC|~('\\'|'\n'|'"'))* '"'
        |   '\'' (ESC|~('\\'|'\n'|'\''))* '\''
        )
	;

fragment
ESC
	:	'\\' .
	;

--------------------------

var = """hello"""

this is OK

var = """"hello"""

this is OK

var = """hello""""

this is NOT OK.

and also python shell behaves like that.

Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> var = """hello"""
>>> var = """"hello"""
>>> var = """hello""""
  File "<stdin>", line 1
    var = """hello""""
                     ^
SyntaxError: EOL while scanning single-quoted string


is there a way to fix this? or is this normal?

-- 
Öğr. Gör. Fırat Küçük
ADAMYO Distance Learning
SAKARYA University / TURKEY


More information about the antlr-interest mailing list