Antlr4: Make grammar work with two identical lexer rules

I have grammar:

grammar qwe;

query
    : COLUMN OPERATOR value EOF
    ;

COLUMN
    : [a-z_]+
    ;

OPERATOR
    : ('='|'>'|'<')
    ;

STRING_LITERAL
    : [a-zA-Z_]+
    ;

value
    : STRING_LITERAL
    ;

WS : [ \t\r\n]+ -> skip ;

Example query: total_sales>qwe.

The problem with that is that COLUMN and value lexer rules are identical. This causes errors:

enter image description here

How could I rewrite the grammar to make it work without error messages?

Upvotes: 0

Views: 38

Answers (1)

bwdm
bwdm

Reputation: 853

You can't have two equal lexer rules, of course. In this case it seems that you should remove the COLUMN rule and treat it as a value, if there's really nothing that distinguishes them.

Another option would be to consider a rule for COLUMN with a number of reserved words, if that's applicable.

Upvotes: 1

Related Questions