antlr / intellij-plugin-v4

An IntelliJ plugin for ANTLR v4
https://plugins.jetbrains.com/plugin/7358-antlr-v4
BSD 3-Clause "New" or "Revised" License
461 stars 103 forks source link

ANTLR Preview should let users configure which start rule to use #707

Closed autonomousapps closed 1 month ago

autonomousapps commented 2 months ago

Given a grammar with multiple start rules (for example, Kotlin), the ANTRL Preview window can show an error when the input doesn't match the default start rule (how is that even determined?). In the screencap below, the Preview window is trying to parse my input as if it were a kotlinFile, but actually it should match from another start rule, a gradleScript (see below for my currently internal customizations of the official grammar). The only way I have discovered to get the preview to work is to comment out the other start rules, let the preview work, and then uncomment them again; at that point, the window "remembers" (?) the correct start rule. It would be really great if I could tell it from where to start parsing.

Screenshot 2024-06-24 at 11 35 53 AM
// These are the only changes to the official grammar
// NEW
gradleScript
    : NL* fileAnnotation* importList (statement semi?)* EOF
    ;

// NEW
namedBlock
    : name LCURL NL* statements NL* RCURL
    ;

// NEW
name
    : Identifier
    ;

// MODIFIED
statement
    : namedBlock // this part is NEW
    | (label | annotation)* (declaration | assignment | loopStatement | expression)
    ;
minesunny commented 1 month ago

first you should right click the rule name you want to start, then you click test rule, it should be work;

autonomousapps commented 1 month ago

A-ha! That worked. Thanks! <3

Screenshot 2024-06-28 at 11 23 15 AM

Closing as resolved (not sure how this might be better documented 🤷 ).