mike-lischke / antlr4-c3

A grammar agnostic code completion engine for ANTLR4 based parsers
MIT License
397 stars 62 forks source link

Get token values for a lexer rule #16

Closed ssdimmanuel closed 4 years ago

ssdimmanuel commented 6 years ago

First of all many thanks for making the auto-completion feature available. It saved me lot of work. I am able to use the CodeCompletionCore and get the list of tokens rules and token names (using vocabulary). But is there a way to extract the actual values used in the grammar? For ex: l have the following lexer rule AndorOr: ‘&’ | ‘|’ ; From the CodeCompletionCore I can get AndorOr . How can I get the values & , | ?

mike-lischke commented 6 years ago

There's no built-in support to directly return the values a lexer rule is made of. Keep in mind that can be complex, involving other lexer rules (also fragment rules), predicates etc.

You could use a symbol table to get that info (still not perfect) or do an LL1 walk over the lexer ATN for a given rule (see the LL1Analyzer class, which does this for parser rules).