oranoran / antlr4-autosuggest-js

JavaScript auto-suggest engine for ANTLR4 grammars
MIT License
42 stars 17 forks source link

Infinite loop in case of long input text #15

Open vdeygas opened 1 year ago

vdeygas commented 1 year ago

I am getting an infinite loop for next grammar:

grammar Query;

/* Parser rules */
orexpression
    : andexpression ( OR andexpression )*
    ;

andexpression
    : notexpression ( notexpression | AND notexpression )*
    ;

notexpression
    : (NOT)? searchterm
    ;

searchterm
    : TERM
    | QUOTEDTERM
    | LEFT_PAREN orexpression RIGHT_PAREN
    | linkexpression
    ;

linkexpression
    : LINK LEFT_BRACE linkinfo RIGHT_BRACE LEFT_PAREN orexpression RIGHT_PAREN
    ;

linkinfo
    : QUOTEDTERM ':' TERM
    ;

query:
  orexpression EOF;

/* Lexer rules */
AND : 'AND' ;
OR  : 'OR' ;
NOT : 'NOT' ;
LINK: 'LINK' ;
LEFT_PAREN   : '(' ;
RIGHT_PAREN  : ')' ;
LEFT_BRACE   : '{' ;
RIGHT_BRACE  : '}' ;
QUOTEDTERM   : '"' ~('"')* '"' ;
UNTERMINATED_QUOTEDTERM : '"' ~('"')* ;
NONSPECIALCHAR : ~(' '|'\t'|'"' | '\u00A0' | '(' | ')') ;
TERM : (NONSPECIALCHAR|QUOTEDTERM) (NONSPECIALCHAR|QUOTEDTERM)+ ;
WS  : [ \t\u00A0] -> skip;
ErrorChar : . ;

and with 'LINK { \"Is Version Of\" : ARTICLE } ( title:test ) OR LINK { \"Is Version Of\" : ARTICLE } ( title:test ) OR LINK { \"Is Version Of\" : ARTICLE } ( title:test ) OR LINK input.

Note that with a shorten input, 'LINK { \"Is Version Of\" : ARTICLE } ( title:test ) OR LINK { \"Is Version Of\" : ARTICLE } ( title:test ) OR LINK, token suggestion works.

Thanks