-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Antlr Preview Freezes Intellij but no crash #393
Comments
Hi, usually this is because the grammar is very inefficient at parsing the input, which causes the IDE to freeze because parsing is currently done on the EDT. See #380 for a similar case and #381 for a future 'fix'. To confirm that it's a perf problem, you could either:
As to how you can make your grammar faster, you should ask StackOverflow or the mailing list I guess. |
I totally forgot to mention that this happens with or without any example code to parse, input and file. I've tried waiting half an hour. The generator visitor and listener work just fine. I have the actual generator code working flawlessly. It's just the previewer |
OK I was able to reproduce the bug. The code is stuck in a loop producing errors like As a workaround, you can modify your start rule like this: toylangFile : lines=line+ | EOF; |
Actually, a better fix would be: toylangFile : lines=line+;
line : statement (NEWLINE* | EOF);
|
This is another infinite loop, but this time it's happening both in the interpreter and the real parser. It's caused by a warning that is reported by the IDE: The parser gets stuck matching an empty string over and over again. To fix this, simply change your rule to: COMMENT_CONTENT : .+? -> channel(COMMENT); |
Related: antlr/antlr4#2444 |
…o process the input text (relates to #393)
…f it is stuck iterating on the same token over and over. This can prevent the IDE from crashing when a token can match the empty string for example. This watchdog is failsafe for issues like #393.
I added a "watchdog" that will detect such cases and kill the interpreter if it's stuck because of empty string issues. In addition, the parser now runs in a separate thread, which means that rogue grammars shouldn't completely freeze the UI anymore. This thread can be killed using a dedicated button: |
…f it is stuck iterating on the same token over and over. This can prevent the IDE from crashing when a token can match the empty string for example. This watchdog is failsafe for issues like #393.
Beautiful, thank you! |
I am getting a weird behavior with this plugin and I have looked everywhere for a solution. Every time I try using the grammar preview tool, it freezes intellij. I don't know why. I have prepared a snippet of the log that shows what intellij was doing when it froze, and the grammar I am using that causes it to crash. Besides that, antlr works just fine. This is the only problem that I have. I've tried alternative means of testing a rule but it's always freezing. This happened in 2019.2 and 2019.3 with the latest antlr plugin.
Toylang Lexer
Toylang Grammar
The text was updated successfully, but these errors were encountered: