[antlr-interest] How to have strings enclosed in " and/or "
matthew ford
Matthew.Ford at forward.com.au
Wed Dec 8 12:47:25 PST 2004
Hi all,
I am having trouble in the lexer handling strings that start and end with "
or "
(might start with " and end with ")
Some html editors kindly replace " with " when you load the file.
I would like to be able to handle something like
"str is ""here""""
to return
str is "here"
due to the (STRING_PART)* below and dropping the final quote of each
STRING_PART
"" inside a string just escapes a single "
Any ideas on how to make this work?
I don't want to pre-filter " to " as I assume the user is happy with
what the editor has done.
The following pseudo code does not work
matthew
QUOTE
: '&' 'q' 'u' 'o' 't' ';'
;
STRING
: STRING_PART (STRING_PART)*
{ // remove leading quote here and just return string
}
;
STRING_PART
: ('"' | QUOTE)
(
options { generateAmbigWarnings=false; }
: '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('"' | QUOTE |'\n'|'\r')
)*
('"'! | QUOTE!)
;
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