[antlr-interest] Infinite loop after upgrade to 3.3

Ben Dotte ben.dotte at gmail.com
Thu Oct 13 12:31:59 PDT 2011


Finally figured it out! Incase anyone else hits this, I was using a
SwitchingCommonTokenStream in the Java code that I had found out on the net
years ago. The grammar actually stopped using it at some point, but it never
got removed on the Java side. Replacing that with the standard
CommonTokenStream made everything work again.

So, word to the wise, do NOT use SwitchingCommonTokenStream on the Java
antlr-runtime versions 3.3 and above.

On Wed, Oct 12, 2011 at 3:14 PM, Ben Dotte <ben.dotte at gmail.com> wrote:

> I was able to get things running again by removing the "implicitAndSearch"
> parser rule from the chain. Unfortunately I still need a way to consider
> multiple consecutive terms as "and" searches. I tried combining the
> "andSearch" and "implicitAndSearch" rules to look like this:
>
>
> http://stackoverflow.com/questions/3392377/antlr-implicit-and-tokens-in-tree/3396517#3396517
>
> But ended up with the same infinite loop. Setting k=1, backtrack=true, and
> greedy=false on that rule also do not help. Are there any other options or
> alternate ways of doing an implicit "and" search that might help this?
>
> Thanks again.. upgrading a different dependency on our app forced the
> upgrade of antlr-runtime to 3.3; I may try to force it back to 3.1.2 if I
> can't find an alternative that works with newer versions.
>
> On Tue, Oct 11, 2011 at 4:11 PM, Ben Dotte <ben.dotte at gmail.com> wrote:
>
>> 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