[antlr-interest] Infinite loop after upgrade to 3.3

Ben Dotte ben.dotte at gmail.com
Tue Oct 11 14:11:55 PDT 2011


I don't see anything like that, but I wouldn't be surprised if the grammar
could be improved. I pasted it below incase that is any help. Thanks for
your suggestions.


/*----------------------------------------------------------------
 * PARSER RULES
 *----------------------------------------------------------------*/

search : orSearch
;

orSearch: andSearch (OR^ andSearch)*
;

andSearch
: (implicitAndSearch AND)=> implicitAndSearch (AND^ implicitAndSearch)*
| implicitAndSearch
;

implicitAndSearch
: (f=fieldSearch -> $f)
(f2=fieldSearch -> ^(AND $implicitAndSearch $f2))*
;

fieldSearch
: (TEXT ':'^)? (subSearch | negationSearch)
;

negationSearch
: ('-'^)? (quotedSearch | dateRangeSearch | comparisonSearch | idSearch |
wildcardSearch | term)
;

wildcardSearch
: TEXT_WITH_WILDCARD -> ^(WILDCARD TEXT_WITH_WILDCARD)
;

idSearch
: '#'^ TEXT
;

comparisonSearch
: '>'^ TEXT
| '<'^ TEXT
;

quotedSearch
: QUOTED_STRING -> ^(QUOTED QUOTED_STRING)
;

dateRangeSearch
: '[' DATE TO DATE ']' -> ^(DATE_BETWEEN DATE+)
| '[' AFTER DATE ']' -> ^(DATE_AFTER DATE)
| '[' BEFORE DATE ']' -> ^(DATE_BEFORE DATE)
;

subSearch
: '('! orSearch ')'!
;

term : SEPARATOR* (t=anyText -> $t)
(SEPARATOR t2=anyText -> ^(AND $term $t2))*
SEPARATOR*
;

anyText : (TO | AFTER | BEFORE | DATE | TEXT)
;


/*----------------------------------------------------------------
 * LEXER RULES
 *----------------------------------------------------------------*/

AND : ('a'|'A')('n'|'N')('d'|'D') ;
OR : ('o'|'O')('r'|'R') ;
TO : ('t'|'T')('o'|'O') ;
AFTER : ('a'|'A')('f'|'F')('t'|'T')('e'|'E')('r'|'R') ;
BEFORE : ('b'|'B')('e'|'E')('f'|'F')('o'|'O')('r'|'R')('e'|'E') ;

fragment NUM
: ('0'..'9') ;
DATE : ('0'..'1')? NUM '/' ('0'..'3')? NUM '/' NUM NUM NUM NUM ;

fragment WHITESPACE_CHAR
: (' '|'\t'|'\n'|'\r') ;
fragment SEPARATOR_CHAR
: '_' ;
CONTROL_CHAR // not a fragment so . matches to these as well
: ('#'|'>'|'<'|'['|']'|'/'|'('|')'|':'|'*'|'"') ;

QUOTED_STRING
: '"' .+ '"' { setText(getText().substring(1, getText().length() - 1)); } ;
// strip quotes from output

WHITESPACE
: (WHITESPACE_CHAR)+ {$channel = HIDDEN;} ;
SEPARATOR
: (SEPARATOR_CHAR)+ ;

fragment TEXT_CHAR
: (WHITESPACE_CHAR|SEPARATOR_CHAR|CONTROL_CHAR) ;
TEXT : ~('-'|TEXT_CHAR) (~(TEXT_CHAR))* ;
TEXT_WITH_WILDCARD
: (('*' TEXT)|(TEXT '*')) ;


On Tue, Oct 11, 2011 at 3:54 PM, Terence Parr <parrt at cs.usfca.edu> wrote:

> maybe an empty lexer rule or one that could match nothign?
> Ter
> On Oct 11, 2011, at 1:16 PM, Ben Dotte wrote:
>
> > Sorry, it has been a while since I worked with Antlr!
> >
> > In that case, no I do not see any.
> >
> > On Tue, Oct 11, 2011 at 3:11 PM, Terence Parr <parrt at cs.usfca.edu>
> wrote:
> > hi. semantic preds look like {..}? :)
> > Ter
> > On Oct 11, 2011, at 1:08 PM, Ben Dotte wrote:
> >
> > > Yes, there are a couple rules with semantic predicates:
> > >
> > > fieldSearch
> > > : (TEXT ':'^)? (subSearch | negationSearch)
> > > ;
> > >
> > > negationSearch
> > > : ('-'^)? (quotedSearch | dateRangeSearch | comparisonSearch | idSearch
> |
> > > wildcardSearch | term)
> > > ;
> >
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
>
>


More information about the antlr-interest mailing list