GRUN for Antlr4: How to use?

2k views Asked by At

For grammar:

grammar qwe;

query
    : COLUMN OPERATOR value EOF
    ;

COLUMN
    : [a-z_]+
    ;

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

SCALAR
    : [a-z_]+
    ;

value
    : SCALAR
    ;

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

there are identical rules COLUMN and SCALAR. Here I was advised to use grun aliases.

I installed it for my Ubuntu. And for folders structure:

enter image description here

ran this from project learning_antlr4 level:

grun qwe tokens -tokens < qwe/qwe.tokens

The output was empty.

What do I wrong? Where that aliases are saved?

1

There are 1 answers

0
Mike Cargal On BEST ANSWER

Assuming you have the grun alias set up (if not, see the QuickStart at the tops of this page https://www.antlr.org):

What you want is to view the token stream produced by the Lexer processing your input (not your qwe.tokens file)

qwe.txt:

total_sales>qwe
ANTLR on  master [✘+?] 
➜ antlr4 qwe.g4      

ANTLR on  master [✘+?] 
➜ javac *.java

ANTLR on  master [✘+?] 
➜ grun qwe tokens -tokens < qwe.txt
[@0,0:10='total_sales',<COLUMN>,1:0]
[@1,11:11='>',<OPERATOR>,1:11]
[@2,12:14='qwe',<COLUMN>,1:12]
[@3,15:14='<EOF>',<EOF>,1:15]

AS you can see... both total_sales and qwe are recognized as COLUMN tokens,