[antlr-interest] Python Parse problem
Michael O'Keeffe
themjwok at gmail.com
Wed Dec 8 21:48:11 PST 2010
Hi all,
I'm fairly new to ANTLR (about half a day of playing). I've been
mucking around with the CSV example test driven development but as a
python version. The generated lexer works fine but the parse just dies
when asked to parse. It produces the following error message:
---------------------------------------------
Traceback (most recent call last):
File "CSVParser.py", line 272, in <module>
main(sys.argv)
File "CSVParser.py", line 268, in main
main.execute(argv)
File "c:\apps\Python27\lib\site-packages\antlr_python_runtime-3.1.3-py2.7.egg\
antlr3\main.py", line 163, in execute
self.parseStream(options, inStream)
File "c:\apps\Python27\lib\site-packages\antlr_python_runtime-3.1.3-py2.7.egg\
antlr3\main.py", line 236, in parseStream
result = getattr(parser, options.parserRule)()
TypeError: getattr(): attribute name must be string
---------------------------------------------
My grammar is short so here it is...
---------------------------------------------
grammar CSV;
options {
language = Python;
}
line returns [result]
scope { fields }
@init { $line::fields = []; }
: ( (NEWLINE) => NEWLINE
| field (SEPARATOR field)* NEWLINE
)
{ $result = $line::fields; }
;
field :
( f=QUOTED
| f=UNQUOTED
| // nothing
)
{ $line::fields.append( $f.getText() ); }
;
QUOTE : '"';
QUOTED : ( QUOTE ( options{ greedy=false; }: . )* QUOTE );
UNQUOTED : NONBREAKING*;
SEPARATOR : ',';
NEWLINE : '\r'? '\n';
fragment NONBREAKING
: ~( '\r' | '\n' | SEPARATOR );
---------------------------------------------
Hope I've just made a n00b mistake. Any advice you can provide will be
greatly appreciated.
Regards,
Michael
More information about the antlr-interest
mailing list