[antlr-interest] Matching the * character

Terence Parr parrt at cs.usfca.edu
Thu Mar 27 18:15:05 PDT 2008


how are you getting the input?  If from command-line arg, it might be  
expanding '*'.
Ter
On Mar 27, 2008, at 5:58 PM, Steve O'Hara wrote:

> Thanks for your help Loring – unfortunately, it hasn’t helped.
> I’ve condensed the example down to something really simple;
>
> subExpressionText :  QuotedString STAR? WS?;
> QuotedString :'\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )* ;
> WS : (' ' | '\t' | '\n' | '\r')+ ;
> STAR : '*' ;
>
> The test string “’test’*” works fine but “’test’*    “ doesn’t.
> It seems bizarre to me because if I substitute STAR for some other  
> character, it works fine.
>
> e.g. STAR : '$' ;
> “’test’$    “ works fine
>
> Thanks,
> Steve
>
> From: Loring Craymer [mailto:lgcraymer at yahoo.com]
> Sent: 27 March 2008 23:59
> To: Steve O'Hara; antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Matching the * character
>
> This looks ok, except for the (STAR | QUESTION*)? idiom (equivalent  
> to (STAR | QUESTION+ | | ).  Try either changing QUESTION* to  
> QUESTION+ or remove the terminal ?.  I would have thought that ANTLR  
> would issue a warning about the two empty alts; maybe it did and you  
> missed it.
>
> --Loring
> ----- Original Message ----
> From: Steve O'Hara <sohara at pivotal-solutions.co.uk>
> To: antlr-interest at antlr.org
> Sent: Thursday, March 27, 2008 4:27:33 PM
> Subject: [antlr-interest] Matching the * character
> I'm new to Antlr so forgive me if this is a stupid question...
> I'm trying to match a database search criteria that looks like the  
> following;
>
> 'some text'*, *'more criteria' & 'more criteria'*
>
> My grammar is;
>
> expression
>     : subExpression (WS? (COMMA | AMPERSAND) WS? subExpression)*
>     ;
>
> subExpression
>     : WS? (Identifier | subExpressionText) WS?
>     ;
>
> subExpressionText
>     :  (STAR | QUESTION*)? QuotedString  (STAR | QUESTION*)? WS?
>     ;
>
> Letter : 'a'..'z' | 'A'..'Z' | '_' | '\u0080'..'\ufffe' ;
> Digit : '0'..'9' ;
> Identifier : Letter (Letter | Digit)* ;
> QuotedString :'\'' (~'\'')* '\'' ;
> WS : (' ' | '\t' | '\n' | '\r')+ ;
>
> COMMA : ',' ;
> AMPERSAND : '&' ;
> QUESTION : '?' ;
> STAR : '*' ;
>
> The parser finds the first quoted string (some text) but fails after  
> that with a NoViableAltException. If I change the * to ? it works  
> fine. I'm waiting for delivery of the reference manual so maybe I'm  
> breaking some sort of golden rule here, but any help would be  
> greatly appreciated.
>
> Steve
>
> Steve O'Hara
> Pivotal Solutions
> ( +44 (0)7802 484227
>     +44 (0)208 660 7288 (Fax)
> *  sohara at pivotal-solutions.co.uk
>
>
>
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  
> Try it now.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080327/8a45bff8/attachment.html 


More information about the antlr-interest mailing list