Skip to content

'tree' as name of a parser rule causes syntax error. #1960

@mateuszpawlik

Description

@mateuszpawlik

A simple grammar ('g.g4'):

grammar g;
tree : 'X';

causes the following error

java -jar antlr-4.7-complete.jar g.g4 
error(50): g.g4::: syntax error: mismatched character ':' expecting 'g'
error(50): g.g4:2:7: syntax error: ''X'' came as a complete surprise to me

Removing the space between 'tree' and ':' or changing 'tree' to other rule name helps.

I've found that 'tree' was a keyword in antlr v3. But the reference book of v4 doesn't list it any more.

If 'tree' is a reserved keyword, the error message is confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions