Basil Bourque
Basil Bourque

Reputation: 338181

How to select a "start rule" for ANTLR 4 when using "ANTLR v4" plugin for IntelliJ

When using ANTLR 4 to process a grammar against input text, we must specify the starting rule within that grammar.

I have forgotten how to specify the start rule when using the ANTLR v4 plugin for IntelliJ IDE. So when I type in some input, the plugin displays in the Parse tree pane the error message No-start-rule-is-selected. Another error message in red is displayed on the left pane for Input / File options.

screenshot of ANTLR v4 plugin for IntelliJ displaying error message No-start-rule-is-selected.

Upvotes: 1

Views: 1185

Answers (1)

Basil Bourque
Basil Bourque

Reputation: 338181

  1. Context-click on your desired rule within the grammar source file.
  2. Choose Test Rule menu item.

The plugin’s panes then interactively reacts to your input text. As you type or paste in text, the selected rule and further rules are instantly updated to generate the Parse tree & Hierarchy panes’ content.

Let's click on that rule r : "hello" ID ; shown in your Question’s screen shot. Select the item Test Rule r. See the red message Hello.g4 start rule: <select from navigator or grammar> disappear. And see the Parse tree appear.

screenshot

This behavior is mentioned briefly on the plugin’s home page. But you must click the tiny more… blue link text to reveal this verbiage.

Right click on rule and say "Test ANTLR Rule".

Also noted briefly on the ReadMe page on GitHub site for the open-source project.

has live grammar interpreter for grammar preview. Right click on rule and say "Test ANTLR Rule".

Upvotes: 3

Related Questions