-
Notifications
You must be signed in to change notification settings - Fork 194
Is it possible to get an iterator over unbounded variables in the AST? Like iter_literal_variables() for literal variables. #959
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
Comments
There is a similar function to iterate all imported modules. Maybe you can base on that function and write something similar. Shouldn't be difficult.... But you need to take care of variables declared in local blocks. Alternatively you can look at the parser implementation methods. They actually collect lists of unbounded variables as part of parsing closures that capture external variables. That's how the strict variables mode can work. |
Thanks a bunch for your quick reply, @schungx! I did search for the function you mentioned and read a lot of the code, but I’m still not sure which one you’re talking about. Could you please give me the exact name or location of the function that iterates over all imported modules? I’ve also looked into the parser implementation, but I hope I can avoid getting too deep into the logic. By the way, in the ast.statements() output, you can clearly see the variables. But maybe thinking about getting them out easily and confidently is a bit too naive of me, since the current expression is still quite simple. Output: |
If you're only parsing expressions then it gets easier because you don't declare local variables. Therefore any It only gets hairy when you can declare local variables in blocks. You can use the |
Just to check up on how it is going for you. Did you eventually resolve your issue? |
Imagine something like this:
I would like to get something like ast.iter_unbounded_variables() which yields something like ["src_port", "dst_port"] in the end.
Thank you all in advance for any helpful input. :)
The text was updated successfully, but these errors were encountered: