[antlr-interest] v2->v3 Skip wrapper and inside quotes in LITERAL of SQL // description.

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Mon Apr 18 11:39:49 PDT 2011


On 4/18/11 8:25 PM, "Jim Idle" <jimi at temporal-wave.com> wrote:

> ???


Okay, let me copy paste here SQL standard   :-)

<character string literal> ::=
    <quote> [ <character representation>... ] <quote>

<character representation> ::=
     <nonquote character> | <quote symbol>

<nonquote character> ::= !! See the Syntax Rules.

<quote symbol> ::= <quote><quote>

so:

SQL standard escape in literal must looks as:
    literal:        'som''e literal'

Common escape with backslash \  (e.g. C++ Java)
    literal:        'som\'e literal'


================================
Problem (for me :-) is how  to skip one of quotes INSIDE of literal,
using ANTLR v3 ...

In ANTLR v2 this was veeeeeery easy:

STRING_LITERAL
    :    QUOTE!                        << WRAPPER quote... Easy enough in v3
        (    ESCAPE_SEQUENCE
        |    ~('\'' | '\\')
        |    QUOTE QUOTE!        << can be inside of LITERAL many times
        )* 
        QUOTE!                       << WRAPPER quote... Easy enough in v3


Just  three '!'  and task was solved in v2...

Yes, you (Jim) have to show effective solution for v3 (C) to remove
WRAPPER-quotes. 

But above rule for LITERAL is more hard. Because it can have quotes INSIDE.
You see problem?


================================
Also I have check few SQL grammars from ANTLR site.
E.g. This is mySQL lexer.

TEXT_STRING:
      ('\'' 
          ( 
                options{greedy=true;}: ~('\'' | '\r' | '\n' ) | '\'' '\''
          )* 
      '\'' )

Here author even do not care about QUOTE QUOTE.

So lexer will send to parser  Token ( 'aaa''bbb''ccc' )
But should sent   Token ( aaa'bbb'ccc )


Or I do smoke wrong staff???  :-)


-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the antlr-interest mailing list