Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get parent of the node using antlr4 typescript #4555

Open
Suraiyab opened this issue Mar 13, 2024 · 5 comments
Open

How to get parent of the node using antlr4 typescript #4555

Suraiyab opened this issue Mar 13, 2024 · 5 comments

Comments

@Suraiyab
Copy link

I am generating a parser using below command
image

I am unable to get the parent token for the current token using ParserRuleContext, I can't see getParent() function as mentioned in documentations
(https://github.com/antlr/antlr4/blob/dev/runtime/JavaScript/src/antlr4/context/ParserRuleContext.d.ts)

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Mar 13, 2024 via email

@Suraiyab
Copy link
Author

I have tried but parentCtx is also ParserRuleContext

@ericvergnaud
Copy link
Contributor

Sorry I misread your question.
Not sure what you mean by parent token. This concept does not exist in ANTLR.

@Suraiyab
Copy link
Author

Suraiyab commented Mar 13, 2024

For example, for the below block of code

image

I need to get 'table' as the parent of 'column' token and 'column' as the parent of 'dataType' token

@kaby76
Copy link
Contributor

kaby76 commented Mar 13, 2024

This is a multi-step navigation in the parse tree. We don't know your grammar, but obviously there would need to be a rule that recognizes the entire input from table to string in the last line. To get 'Dim Legal Entity', you would need to navigate up the parse tree to the node that contains the input, then down the parse tree to the leaf node 'Dim Legal Entity', then get the token for the leaf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants