[antlr-interest] SQL string literals
Balvinder Singh
bals1978 at hotmail.com
Fri May 31 02:11:00 PDT 2002
Hi...
This is due to greedy apporach of lexer, it consumes " in loop.
use the following :
STRING
: '"'! ( options { greedy=false; } (~('"')|'"''"'!)* ) '"'!
;
>From: Pete Forman <pete.forman at westerngeco.com>
>Reply-To: antlr-interest at yahoogroups.com
>To: antlr-interest <antlr-interest at yahoogroups.com>
>Subject: [antlr-interest] SQL string literals
>Date: Fri, 31 May 2002 09:11:19 +0100
>
>How might I handle the SQL style of quoting in string literals?
>This allows the delimiter (' or ") to stand for itself in the string
>if it is doubled. Examples of a simplification of this are
>
> "foo" => foo
> "using ""quotes""" => using "quotes"
> """" => "
> "" => [empty string]
>
>My naive solution is this:
>
>class SqlLexer extends Lexer;
>
>STRING
> : '"'! (~('"')|'"''"'!)* '"'!
> ;
>
>Which results in:
>
>ANTLR Parser Generator Version 2.7.2a2 (20020112-1) 1989-2002 jGuru.com
>sql.g:4: warning: lexical nondeterminism upon
>sql.g:4: k==1:'"'
>sql.g:4: between alt 2 and exit branch of block
>
>
>How might I get that to work?
>
>My best workaround at the moment is to get the parser to concatenate
>adjacent STRINGs inserting a quote. For correctness the lexer should
>be emitting whitespace tokens but that will clutter all the grammar.
>
>--
>Pete Forman -./\.- Disclaimer: This post is originated
>WesternGeco -./\.- by myself and does not represent
>pete.forman at westerngeco.com -./\.- opinion of Schlumberger, Baker
>http://petef.port5.com -./\.- Hughes or their divisions.
>
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
_________________________________________________________________
Join the worlds largest e-mail service with MSN Hotmail.
http://www.hotmail.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list