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

More examples of how to use the CustomVisitor class #1

Open
me2nuk opened this issue Feb 16, 2023 · 0 comments
Open

More examples of how to use the CustomVisitor class #1

me2nuk opened this issue Feb 16, 2023 · 0 comments

Comments

@me2nuk
Copy link

me2nuk commented Feb 16, 2023

hello! I am very interested in your project.

It's not different, I have a question about the example code, so I left a question.

In the code below, I created a CustomVisitor, can I only use that visit function?

Or is there a way to have a function called for each token with a visit_Num expression like python's ast module?

from src.modules.php.traversers.bf import BFTraverser
from src.modules.php.base import Visitor
from src.modules.php.syntax_tree import build_syntax_tree

class CustomVisitor(Visitor):
     def visit(self, node):
         print(type(node))

s_tree = build_syntax_tree("/path/to/file")
traverser = BFTraverser(s_tree)
printer_visitor = CustomVisitor()
traverser.register_visitor(printer_visitor)

traverser. traverse()

I would like to know how to inherit the Visitor class and utilize various functions of the CustomVisitor class.

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

1 participant