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 modify tokens tree programmatically with BaseListener? #25

Open
yasamprom opened this issue Jul 13, 2022 · 4 comments
Open

How to modify tokens tree programmatically with BaseListener? #25

yasamprom opened this issue Jul 13, 2022 · 4 comments
Labels

Comments

@yasamprom
Copy link

In my language I have TAB and UNTAB tokens (it is important like in Python). It is impossible to process TAB and UNTAB in grammar.g4 correctly so I need special class (I guess it is BaseListener) for processing TAB/UNTAB when I enter some rules.
How to make my BaseListener work in background? This class now is highlighted with grey color, it is not used. Where should I create it?

@parrt
Copy link
Member

parrt commented Jul 13, 2022

Do you mean's plugin's parse tree view or arbitrary antlr code altering parse tree? It's typically modified by constructing new parse tree or other from auto-generated tree.

@parrt parrt added the question label Jul 13, 2022
@yasamprom
Copy link
Author

Do you mean's plugin's parse tree view or arbitrary antlr code altering parse tree? It's typically modified by constructing new parse tree or other from auto-generated tree.

I guess I need ParseTreeView. My purpose is to add TAB and UNTUB in my PSI programmatically. And I want to do it in background, while user is typing characters. I didn't find examples how to do that

@parrt
Copy link
Member

parrt commented Jul 15, 2022

Hmm...ok, yeah, I'm afraid I just can't remember how all this works :( Sorry!
Ter

@l-Luna
Copy link

l-Luna commented Dec 11, 2024

In my current project parsing Haskell, I found that actually letting IJ see the synthetic tokens caused issues with the consistency of the token stream (i.e. IJ complains a lot); instead I use a custom token stream that adds tokens just before the parser sees them, and then a modified tree converter that doesn't use up physical tokens on these fake tokens (alongside some other extensions that would be nice to upstream sometime).

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

No branches or pull requests

3 participants