PHP-Parsers icon indicating copy to clipboard operation
PHP-Parsers copied to clipboard

More examples of how to use the CustomVisitor class

Open me2nuk opened this issue 2 years ago • 0 comments

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.

me2nuk avatar Feb 16 '23 10:02 me2nuk