mike-lischke / vscode-antlr4

ANTLR4 language support for Visual Studio Code
http://www.soft-gems.net
MIT License
421 stars 58 forks source link

Changing token.type is invalid #265

Closed mageniao2 closed 2 weeks ago

mageniao2 commented 4 months ago

I added action for LETTERS in the lexer file, which adjusts the token type to VALUE_FUNCTION_NAME (1), but it doesn't take effect, and the output in antlr4-debug is still LETTERS, not VALUE_FUNCTION_NAME.

Tokens:
[@0,0:3='show',<3>,1:0]
[@1,4:4='1',<4>,1:4]
[@2,5:4='<EOF>',<-1>,1:5]

But the syntax tree I get through antlr4-listener outputs the token as VALUE_FUNCTION_NAME Maybe I got something wrong? My code is as follows:

mike-lischke commented 4 months ago

Is the resetBuiltInToken function actually called? And the this binding is wrong. That's not the token, but the lexer. If all you want is to change the token type use the type lexer command:

LETTERS : [a-zA-Z]+ -> type(VALUE_FUNCTION_NAME);