[antlr-interest] Changing Symbol

Ric Klaren ric.klaren at gmail.com
Tue Aug 9 05:51:19 PDT 2005


Sarayooth Chittratanawat wrote:
> I want to build the CSV parser. The delimiter, text qualifier and row 
> separator must be changable during runtime. Anyway, I was really new to 
> Antlr. I am sure how can I do that.
> 
> class CSVLexer extends Lexer;
> options { k = 1; charVocabulary = '\1'..'\377'; } 
> 
> WITHINQUOTE : ('"'(~'"')* '"')+ ;
> WITHOUTQUOTE : ( ~( ',' | '\r' | '\n' | '"' ) ( ~( ',' | '\r' | '\n' ) )* );
> EOL : ( '\n' | '\r' ) {newline();};
> DELIM : ',' ; 
> 
> After I use antlr.Tool to generate the parser, how can I change the ',' to 
> some thing else such as Tab delimit without to regenerate the parser by the 
> antlr.Tool.

In general you can't do this with antlr, or be prepared for insane
ambiguities. The generated bitsets are all final, and some checks are
done with if's depending on codegeneration settings. So changing bitsets
between runs is also not an option (and if you do you have no way to
know if you'll introduce ambiguities). If the separators are in a
limited set you could maybe adapt your grammar to accomodate it and then
use predicates to force the right delimiter.

Cheers,

Ric


More information about the antlr-interest mailing list