mike-lischke / antlr4-c3

A grammar agnostic code completion engine for ANTLR4 based parsers
MIT License
397 stars 62 forks source link

Allow specifying a timeout or max call number for processRule #44

Open alessiostalla opened 4 years ago

alessiostalla commented 4 years ago

Our language makes antlr4-c3 take an exponentially long time as we add clauses to a relatively simple expression. It appears that the processRule method enters into a loop of recursive calls that go on for a very long time. Would it be possible to limit processRule with a timeout, or max number of calls?

yangjunhan commented 3 years ago

I am facing a similar situation. My defined grammar is non-trivial, and the core.collectCandidates(index) call seems to take a significantly long time when I attempt to run a relatively large script. What I am doing for a workaround is to break the script into parts and only parse the one which the caret locates.

alessiostalla commented 3 years ago

In our case, scripts were not particularly big – it was a certain kind of recursive expression that caused exponential blowup when adding each new (simple) clause to it. I ended up monkey-patching the processRule method to throw an error when a given timeout is exceeded. It's not the ideal solution, as intermediate results are lost that way.