Labeled elements in lexer #4714
Answered
by
kaby76
MihaMarkic
asked this question in
Q&A
-
How does one get access to an element in lexer rule?
TIA |
Beta Was this translation helpful? Give feedback.
Answered by
kaby76
Oct 13, 2024
Replies: 1 comment 3 replies
-
You can’t do this in the lever. It isn’t the right place anyway. Make the
lever as simple as possible, no actions in the parser. Produce the parse
tree, and walk it. You can walk the tree multiple times with different
walkers. Perhaps you need your first walk to build symbols?
Jim
…On Sat, Oct 12, 2024 at 13:34 Miha Markič ***@***.***> wrote:
How does one get access to an element in lexer rule?
Here is an example where I'd like to use only UNQUOTED_STRING part to pass
to my method (I'm trying to reference it using 'filePath' name) - together
with this token information (I'd like to store token position within file
plus the reference path. Looking amateurish at ANTLR4 grammar such
construct (filePath=UNQUOTED_STRING should be allowed, but I'm not an
expert).
REFERENCED_FILEPATH
: DOUBLE_QUOTE filePath=UNQUOTED_STRING DOUBLE_QUOTE
{
AddReferencedFileInfo(_localctx, filePath);
}
TIA
—
Reply to this email directly, view it on GitHub
<#4714>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMDWKMOG6NFTFQZWLM3Z3F2UTAVCNFSM6AAAAABP2V2LD2VHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXGMYTCMBYGU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The syntax between lexer and parser rules were identical for Antlr2 and Antlr3 (i.e., a
rule_
referenced analtList
in Antlr2 and Antlr3), but that changed for Antlr4 with ruleBlock for parser rules and lexerRuleBlock for lexer rules. element has a labeled element reference, lexerElement doesn't.