np-hard
np-hard

Reputation: 5815

getting token type in Antlr listener

I am using Antlr4 with C# Target. There is a simple lexer rule in my grammar as follows

SearchIdentifier : QTE (WILDCARD | Identifier) QTE  
           | (Digit)+                               
           ;

I use this rule in one of the parser rules as follows

conditionExpr: Identifier LT SearchIdentifier

in my listener, i will like to know which lexer subrule was parsed. For example currently the only thing i get is

 context.SearchIdentifier().GetText();

this will give me the SearchIdentifier text, is there a way to know which subrule (QT Identifier QT or Digit) was matched ?

Thanks

Upvotes: 1

Views: 1566

Answers (1)

Sam Harwell
Sam Harwell

Reputation: 99949

No, ANTLR 4 lexers are state machines that do not track any information aside from where the token stops (so it can execute the correct action and assign the correct token type).

This is very different from ANTLR 3 lexers, but also tremendously faster.

Upvotes: 3

Related Questions