-
Is there a way to create a visitor class without having an instance of the parser ? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hey @dhowe, you can always create a class that implements the |
Beta Was this translation helpful? Give feedback.
-
Hello @dhowe Following up on @msujew's answer: BTW I believe these visitor APIs could be improved, see: |
Beta Was this translation helpful? Give feedback.
-
Do I understand correctly that the If so I think it would be useful to have a sort of default Visitor to subclass that provides a simple implementation of the |
Beta Was this translation helpful? Give feedback.
-
Seems its as simple as this (unless I'm missing something): class BaseVisitor {
visit(cstNode, param) {
if (Array.isArray(cstNode)) {
cstNode = cstNode[0];
}
if (typeof cstNode === 'undefined') {
return undefined;
}
return this[cstNode.name](cstNode.children, param);
}
validateVisitor() {
// no-op
}
} |
Beta Was this translation helpful? Give feedback.
Seems its as simple as this (unless I'm missing something):