3841
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
3782
|
12 |
"{ Package: 'stx:libcomp' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
ParseNodeVisitor subclass:#PluggableParseNodeVisitor
|
|
17 |
instanceVariableNames:'actionsPerNodeType'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'System-Compiler-Support'
|
|
21 |
!
|
|
22 |
|
|
23 |
!PluggableParseNodeVisitor class methodsFor:'documentation'!
|
|
24 |
|
3841
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
3782
|
39 |
documentation
|
|
40 |
"
|
|
41 |
a pluggable node visitor.
|
|
42 |
setup with:
|
|
43 |
actionForNodeClass:aClass put:aBlock
|
|
44 |
|
|
45 |
for example, if you are only interested in assignments,
|
|
46 |
use the following code:
|
|
47 |
|v|
|
|
48 |
v := PluggableParseNodeVisitor new.
|
|
49 |
v actionForNodeClass:AssignmentNode put:[:node | Transcript showCR:node. true].
|
|
50 |
v visit:(Parser parse:code in:someClass.
|
|
51 |
"
|
|
52 |
! !
|
|
53 |
|
|
54 |
!PluggableParseNodeVisitor methodsFor:'setup'!
|
|
55 |
|
|
56 |
actionForNodeClass:aNodeClass put:aBlock
|
|
57 |
"setup so that for nodes of type aNodeClass, aBlock is invoked.
|
|
58 |
If the block returns true, subnodes (eg. right side of assignments, etc.)
|
|
59 |
will be enumerated as well.
|
|
60 |
Otherwise, no subnodes are visited."
|
|
61 |
|
|
62 |
actionsPerNodeType isNil ifTrue:[
|
|
63 |
actionsPerNodeType := Dictionary new.
|
|
64 |
].
|
|
65 |
actionsPerNodeType at:aNodeClass put:aBlock
|
|
66 |
! !
|
|
67 |
|
|
68 |
!PluggableParseNodeVisitor methodsFor:'visiting'!
|
|
69 |
|
|
70 |
visit:aNodeObject
|
|
71 |
"redefined to look for an action for this node's class.
|
|
72 |
If there is one, it can specify if subnodes are to be visited too"
|
|
73 |
|
|
74 |
|action|
|
|
75 |
|
3794
|
76 |
action := actionsPerNodeType at:aNodeObject class ifAbsent:[nil].
|
3782
|
77 |
action notNil ifTrue:[
|
|
78 |
(action value:aNodeObject) ifFalse:[^ self].
|
|
79 |
].
|
|
80 |
super visit:aNodeObject
|
|
81 |
! !
|
|
82 |
|
|
83 |
!PluggableParseNodeVisitor class methodsFor:'documentation'!
|
|
84 |
|
|
85 |
version
|
|
86 |
^ '$Header$'
|
|
87 |
!
|
|
88 |
|
|
89 |
version_CVS
|
|
90 |
^ '$Header$'
|
|
91 |
! !
|
|
92 |
|