[antlr-interest] How to handle Quoted Strings?

Weiler-Thiessen, David, SASKATOON, Engineering David.Weiler-Thiessen at purina.nestle.com
Mon Sep 7 15:33:40 PDT 2009


> Hi 
> 
> I am having trouble adding Lexer/Parser rules to a grammar that will deal with quoted strings.
> 
> A phrase I would like to parse is:
> 
> create register FAULT_CODE initial value '301'
> 
> I am having trouble with the quoted string '301'.  When I build my AST, I would like to have just the inner value, 301 passed, but when I tried to get the text in my tree grammar, I get the full token with quotes, i.e. '301'.
> 
> This is a portion of my Parser/Lexer grammar where I am trying to define this.
> 
> stringValue
> 	:	SINGLE_QUOTE! (~SINGLE_QUOTE|BACK_SLASH SINGLE_QUOTE)* SINGLE_QUOTE!
> 	;
> 
> SINGLE_QUOTE
> 	:	'\''
> 	;
> 
> BACK_SLASH
> 	:	'\\'
> 	;
> 
> Everything works until I get into my Tree Grammar, and when I request the text of the stringValue rule, I get the leading and trailing quotes, even though there are not passed through to the Tree Grammar.
> 
> What am I doing wrong?  Is there a best practice for dealing with quoted strings, and being able to escaped embedded quotes?
> 
> David Weiler-Thiessen
> Nestlé Purina PetCare
> phone: 306-933-0232
> cell: 306-291-9770
> 
> This e-mail, its electronic document attachments, and the contents of its website linkages may contain confidential information.  This information is intended solely for use by the individual or entity to whom it is addressed.  If you have received this information in error, please notify the sender immediately and promptly destroy the material and any accompanying attachments from your system.
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090907/c49d83ee/attachment.html 


More information about the antlr-interest mailing list