[antlr-interest] Oracle SQL Parser

Brown, Rick RBROWN at allstate.com
Tue Jun 12 15:20:36 PDT 2012


I am trying to generate an Oracle SQL parser, and came across a grammar
at http://www.antlr.org/grammar/1062280680642/MS_SQL_SELECT.html.  This
seems to work well, except that I am having trouble getting it to
properly recognize single-line comments that begin with a double dash
('--') or double-slash ('//').  Comments enclosed in /* */ pairs work
fine.  I am no grammar expert, but the problem seems to be that the
comment is not being ended at the end of a line; instead, it seems to
consider everything that follows, the entire rest of the file, as part
of the comment.  Do you think this may have something to do with the
'greedy' option?  If so, how would I rewrite the definition?

For reference, here is the comment definition:

Comment   : '--' ~('\n'|'\r')* '\r'? '\n' { $channel=HIDDEN; }   | '//'
~('\n'|'\r')* '\r'? '\n' { $channel=HIDDEN; }   | '/*' ( options
{greedy=false;} : . )* '*/' { $channel=HIDDEN; }   ; 

Thanks for your help!




More information about the antlr-interest mailing list