ANTLR V4 plugin in intellij provides an option to test the Parser rules in your grammar using the 'Test Rule' option available in the right click window. However this option is greyed out for Lexer rules. How can I test Lexer rules using this plugin ?
If you hold down the Ctrl key and hover over your input in the source view of the preview panel, you can get a pop-up preview of the token under the pointer. You can pull up the Intellij Plugin read.me on github and search for "ctrl key" for an example. You’ll still need to select a parse rule to debug to get this output.
It's useful but a bit tedious to hover over everything to get the full picture.
You may find it more useful to use the grun alias with the -tokens option or the grun <GrammarName> tokens alternative (using tokens instead of a start rule will just run the lexer and dump the tokenStream to sysout). It's not part of the plugin but is generally a very useful way to validate your lexer rules from the command line (even the terminal tab in IntelliJ). You'll need to run the antlr command to generate your source, and compile the java sources to run the grun alias.
(The Quick start on the ANTLR home page shows you how to set up the grun alias.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With