equal
deleted
inserted
replaced
|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCRewritingVisitor subclass:#PPCTokenDetector |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Visitors' |
|
10 ! |
|
11 |
|
12 !PPCTokenDetector methodsFor:'visiting'! |
|
13 |
|
14 visitActionNode: node |
|
15 (node hasProperty: #trimmingToken) ifTrue: [ |
|
16 | newWs newChild | |
|
17 self change. |
|
18 |
|
19 newChild := self visitWithTokenVisitor: node child children second child. "Oups, what a chain" |
|
20 newWs := self visitWithTokenVisitor: node child children first. |
|
21 |
|
22 ^ PPCTrimmingTokenNode new |
|
23 name: node name; |
|
24 child: newChild; |
|
25 tokenClass: node child children second tokenClass; |
|
26 whitespace: newWs; |
|
27 yourself. |
|
28 ]. |
|
29 |
|
30 ^ super visitActionNode: node |
|
31 ! |
|
32 |
|
33 visitNotNode: node |
|
34 "We don't need result of the not,..." |
|
35 | child newChild | |
|
36 self change. |
|
37 child := node child. |
|
38 newChild := self visitWithTokenVisitor: child. |
|
39 node replace: child with: newChild. |
|
40 ^ node |
|
41 ! |
|
42 |
|
43 visitTokenNode: node |
|
44 | child newChild | |
|
45 |
|
46 self change. |
|
47 child := node child. |
|
48 newChild := self visitWithTokenVisitor: child. |
|
49 node replace: child with: newChild. |
|
50 |
|
51 ^ node |
|
52 ! |
|
53 |
|
54 visitWithTokenVisitor: node |
|
55 | retval forbiddenNodes copyVisitor tokenVisitor | |
|
56 |
|
57 copyVisitor := PPCCopyVisitor new. |
|
58 tokenVisitor := PPCTokenVisitor new. |
|
59 |
|
60 forbiddenNodes := openSet copy. |
|
61 tokenVisitor forbiddenNodes: forbiddenNodes. |
|
62 |
|
63 retval := copyVisitor visit: node. |
|
64 retval := tokenVisitor visit: retval. |
|
65 ^ retval |
|
66 ! ! |
|
67 |