[antlr-interest] Solution to " How to have strings enclosed in " and/or ""
matthew ford
Matthew.Ford at forward.com.au
Sun Dec 12 00:34:55 PST 2004
No greedy=false did no do it
It generated the test
// nongreedy exit test
if ((LA(1)=='"'||LA(1)=='&') && (true)) break _loop11;
but I need to match '&' 'q' 'u' 'o' 't' ';' in order to exit not just &
lexer is
STRING
options {
paraphrase="STRING";
}
:STRING_PART
(STRING_PART)*
;
protected
STRING_PART
: { ( (LA(1) == '"')
|| ( (LA(1) == '&')
&& (LA(2) == 'q')
&& (LA(3) == 'u')
&& (LA(4) == 'o')
&& (LA(5) == 't')
&& (LA(6) == ';'))
) }?
('"'
| ('&' 'q' 'u' 'o' 't' ';')
) (
options {
generateAmbigWarnings=false;
greedy=false;
}
: '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('\n'|'\r')
)*
('"' !
| ('&' ! 'q' ! 'u' ! 'o' ! 't' ! ';' !)
)
;
matthew
----- Original Message -----
From: "Terence Parr" <parrt at cs.usfca.edu>
To: <antlr-interest at yahoogroups.com>
Sent: Sunday, December 12, 2004 5:14 PM
Subject: Re: [antlr-interest] Solution to " How to have strings enclosed in
" and/or ""
>
>
> On Dec 11, 2004, at 10:08 PM, matthew ford wrote:
> > This is what I came up with which seems to work
> >
> > The interesting bit is
> > | ~('\n'|'\r')
> > { if ( (LA(1) == '"') || ( (LA(1) == '&')
> > && (LA(2) == 'q')
> > && (LA(3) == 'u')
> > && (LA(4) == 'o')
> > && (LA(5) == 't')
> > && (LA(6) == ';'))
> > ) {break;} }
> > where the break; is used to break out of antlr' ( )* block
>
> Won't a greedy=false loop do the same thing?
>
> Ter
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
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/
More information about the antlr-interest
mailing list