3782
|
1 |
"{ Package: 'stx:libcomp' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
ParseNodeVisitor subclass:#PluggableParseNodeVisitor
|
|
6 |
instanceVariableNames:'actionsPerNodeType'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'System-Compiler-Support'
|
|
10 |
!
|
|
11 |
|
|
12 |
!PluggableParseNodeVisitor class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
a pluggable node visitor.
|
|
17 |
setup with:
|
|
18 |
actionForNodeClass:aClass put:aBlock
|
|
19 |
|
|
20 |
for example, if you are only interested in assignments,
|
|
21 |
use the following code:
|
|
22 |
|v|
|
|
23 |
v := PluggableParseNodeVisitor new.
|
|
24 |
v actionForNodeClass:AssignmentNode put:[:node | Transcript showCR:node. true].
|
|
25 |
v visit:(Parser parse:code in:someClass.
|
|
26 |
"
|
|
27 |
! !
|
|
28 |
|
|
29 |
!PluggableParseNodeVisitor methodsFor:'setup'!
|
|
30 |
|
|
31 |
actionForNodeClass:aNodeClass put:aBlock
|
|
32 |
"setup so that for nodes of type aNodeClass, aBlock is invoked.
|
|
33 |
If the block returns true, subnodes (eg. right side of assignments, etc.)
|
|
34 |
will be enumerated as well.
|
|
35 |
Otherwise, no subnodes are visited."
|
|
36 |
|
|
37 |
actionsPerNodeType isNil ifTrue:[
|
|
38 |
actionsPerNodeType := Dictionary new.
|
|
39 |
].
|
|
40 |
actionsPerNodeType at:aNodeClass put:aBlock
|
|
41 |
! !
|
|
42 |
|
|
43 |
!PluggableParseNodeVisitor methodsFor:'visiting'!
|
|
44 |
|
|
45 |
visit:aNodeObject
|
|
46 |
"redefined to look for an action for this node's class.
|
|
47 |
If there is one, it can specify if subnodes are to be visited too"
|
|
48 |
|
|
49 |
|action|
|
|
50 |
|
3794
|
51 |
action := actionsPerNodeType at:aNodeObject class ifAbsent:[nil].
|
3782
|
52 |
action notNil ifTrue:[
|
|
53 |
(action value:aNodeObject) ifFalse:[^ self].
|
|
54 |
].
|
|
55 |
super visit:aNodeObject
|
|
56 |
! !
|
|
57 |
|
|
58 |
!PluggableParseNodeVisitor class methodsFor:'documentation'!
|
|
59 |
|
|
60 |
version
|
|
61 |
^ '$Header$'
|
|
62 |
!
|
|
63 |
|
|
64 |
version_CVS
|
|
65 |
^ '$Header$'
|
|
66 |
! !
|
|
67 |
|