rrevenantt / antlr4rust

ANTLR4 parser generator runtime for Rust programming laguage
Other
398 stars 70 forks source link

`foo_all()` getters output children that are not of the kind `foo` #56

Open dmitrii-ubskii opened 2 years ago

dmitrii-ubskii commented 2 years ago

I encountered this issue while implementing grammarVisitorCompat using antlr-rust v0.3.0-beta.

Consider the following grammar:

grammar all_test;

list: GET VAR_ ( ',' VAR_ )* ;
GET: 'get';
VAR_: '$' [a-zA-Z0-9][a-zA-Z0-9_-]* ;

WS : [ \t\r\n]+ -> channel(HIDDEN) ;

When parsing the input, we would like to collect all the variables into a list. I.e,, when parsing the string "get $abc, $def", we expect to parse that into ["$abc", "$def"].

Using ctx.VAR__all() (where ctx is the &ListContext argument of visit_list()) results in the following output: "get", "$abc", ",", "$def"

Note that, at the same time, ctx.VAR_(i) produces the expected result:

ctx.VAR_(0) == Some($abc);
ctx.VAR_(1) == Some($def);
ctx.VAR_(2) == None;

The entire MRE can be found at https://github.com/dmitrii-ubskii/antlr-rust-all-issue