Posted By:
Przemyslaw_Jaskierski
Posted On:
Thursday, June 19, 2003 06:47 AM
Hi, I have two problems with my ANTLR - generated Parser/Lexer (I'm new in this things). Please, help me... I'm stuck. (At the end there is a part of grammar file that this questions are about) 1. How can I set "SEPARATOR" token value from my grammar file in produced CSVLexer/CSVParser? I mean, I wrote class that uses this Parser/Lexer but I want the class' user to have ability to set SEPARATOR to ';' instead of ",". How is it possible to define variable SEPARATOR in Parser/Lexer that will be used to process input without running antlr.Tool again? I wonder why ANTLR hard-code tokens instead of exposing them in easy-to-modify variables... 2. In my grammar I tried to put
More>>
Hi, I have two problems with my ANTLR - generated Parser/Lexer (I'm new in this things). Please, help me... I'm stuck.
(At the end there is a part of grammar file that this questions are about)
1. How can I set "SEPARATOR" token value from my grammar file in produced CSVLexer/CSVParser? I mean, I wrote class that uses this Parser/Lexer but I want the class' user to have ability to set SEPARATOR to ';' instead of ",". How is it possible to define variable SEPARATOR in Parser/Lexer that will be used to process input without running antlr.Tool again?
I wonder why ANTLR hard-code tokens instead of exposing them in easy-to-modify variables...
2. In my grammar I tried to put
RECORD : (~('"'|SEPARATOR|'
'|'
'))+;
instead of
RECORD : (~('"'|','|'
'|'
'))+;
but antlr.Tool throws error:
csv.g:119:13: This subrule cannot be inverted. Only
subrules of the form:
(T1|T2|T3...) or
('c1'|'c2'|'c3'...)
may be inverted (ranges are also allowed).
Exiting due to errors.
How can I do that?
******************************************************
My grammar file:
---------------------------------------
class CSVLexer extends Lexer;
options
{
defaultErrorHandler=false;
k=2;
charVocabulary = '3'..'377';
}
RECORD : (~('"'|','|'
'|'
'))+;
SEPARATOR : ',';
QRECORD : '"'!('"''"'|~('"'))+'"'!;
NEWLINE : '
''
' //DOS
| '
' //MAC
| '
' //UNIX
{ newline(); };
--------------------------------------
<<Less