oranoran / antlr4-autosuggest-js

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

Massive loop on autosuggest #13

Closed albanx closed 2 years ago

albanx commented 2 years ago

EDIT: It is not a infinite loop, actually it is a massive loop suggesting all possible combination of upper cases/lower cases

First of all thanks for this, it is an amazing work (anltr4 it is hard).

I am trying to integrate the autosuggest in the Ace Editor, to allow autosuggest a SQL language base grammar (a small subset).

The issue I am getting in a basic POC, is that it is going in massive loop on the call of autosuggest function:

POC code

        const suggester = autosuggester.autosuggester(HatsLexer, HatsParser);
        let suggestions = suggester.autosuggest('SELE');
        console.log(suggestions);

Loop caused between these functions:

TokenSuggester.prototype._suggestViaLexerTransition
if (trans.isEpsilon) {
        this._suggest(tokenSoFar, trans.target, remainingText);
    }

and

TokenSuggester.prototype._suggest

Logs:

SUGGEST: tokenSoFar=GROmaScHe remainingText= lexerState=140
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHe remainingText= lexerState=16
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHe remainingText= lexerState=158
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHe remainingText= lexerState=89
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHe remainingText= lexerState=172
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHe remainingText= lexerState=91
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScH remainingText= lexerState=137
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScH remainingText= lexerState=63
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScH remainingText= lexerState=240
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHE remainingText= lexerState=241
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHE remainingText= lexerState=64
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHE remainingText= lexerState=118
tokenSuggester.js?8de6:26 SUGGEST: tokenSoFar=GROmaScHE remainingText= lexerState=77

I am pretty newbie in the ANTLR4 and I trying to decode what is going on in this case. Any help would be great. Thanks