[antlr-interest] Space in values (need more info)

Bryan Ewbank ewbank at synopsys.com
Wed Nov 24 08:57:05 PST 2004


> Thanks for the help, but ... I don't see what you mean...
> Need to parse the following input:
> 
> PRIORITY = "3"
> REQ_USER_ID = "PTS JDA"
> REQ_PROC_ID = "process"
> 
> As you can see, there is a space in second quoted string.
> With the following grammar, I am getting stuck on that space.
> How can I improve the grammar to detect space in this quoted 
> string and get back the value ?

Don't do this in the grammar; have the scanner eat STRING as a unit instead.
What I use is like this:

	protected ESC: '\\' ( 'f' | 'r' | 't' | '"' | '\\' );
	STRING: '"' ( ESC | ~('\\' | '"') )* '"';

Now the parser sees STRING as a single token - and the text of the STRING
will be the entire string - including the leading and trailing " characters,
as well as any white space in the middle.

- Bryan Ewbank
"The best tool for requirements analysis and design is a crayon" 




 
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