RBProgramNodeVisitor example
Last updated at 12:14 pm UTC on 5 January 2019
http://marcusdenker.de/talks/06HPI/Meta06_07_Refactoring.pdf Slide 23
Simple example how to subclass RBProgramNodeVisitor to create visitor for a specific purpose.
RBProgramNodeVisitor
subclass: #
TestVisitor
instanceVariableNames: 'literals'
classVariableNames: ''
poolDictionaries : ''
category: 'Compiler-AST-Visitors'
TestVisitor
>>acceptLiteralNode: aLiteralNode
literals add: aLiteralNode value.
TestVisitor>>initialize
literals := Set new.
TestVisitor>>literals
^literals
Use:
tree := RBParser parseExpression: '3 + 4'.
(TestVisitor new visitNode: tree) literals
Result:
a Set(3 4)