[antlr-interest] Problems with " and/or ""

matthew ford Matthew.Ford at forward.com.au
Tue Dec 14 23:16:26 PST 2004


Attached is a corrected version of a lexer that will handle strings
delimited by " or " (actionLexer.g)
Also attached is an alternate version which looks like it should work but
does not due to the way Antlr generates that code. (badactionLexer.g)

the interesting part of the working lexer is
  | ~('"'|'\n'|'\r')
        { if( ( (LA(0) == '&') && (LA(1) == 'q')  && (LA(2) == 'u') &&
(LA(3) == 'o')  && (LA(4) == 't')  && (LA(5) == ';')) ) {
            text.setLength(text.length()-1); // drop the & just matched
            break;
        } }
  )*
 ('"' !
    | ( 'q' ! 'u' ! 'o' ! 't' ! ';' !)  // & already matched above
   )

There should be an easier (and more strightforward) way to do this.
But if there is I have not found it yet.
Ter can you get greedy = false to work for this case?
matthew


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: actionLexer.g
Type: application/octet-stream
Size: 1334 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20041215/c73bce87/actionLexer.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: badactionLexer.g
Type: application/octet-stream
Size: 1311 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20041215/c73bce87/badactionLexer.obj


More information about the antlr-interest mailing list