|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 PPCDelegateNode subclass:#PPCTokenNode |
|
4 instanceVariableNames:'tokenClass' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'PetitCompiler-Nodes' |
|
8 ! |
|
9 |
|
10 PPCTokenNode comment:'' |
|
11 ! |
|
12 |
|
13 !PPCTokenNode methodsFor:'accessing'! |
|
14 |
|
15 initialize |
|
16 super initialize. |
|
17 |
|
18 "Modified: / 26-10-2014 / 01:34:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
19 ! |
|
20 |
|
21 rewrite: changeStatus |
|
22 | | |
|
23 super rewrite: changeStatus. |
|
24 |
|
25 (self allNodes anySatisfy: [ :node | node asFast ~= node ]) ifTrue: [ |
|
26 changeStatus change. |
|
27 self replace: child with: (child transform: [:node | node asFast]). |
|
28 ] |
|
29 ! |
|
30 |
|
31 tokenClass |
|
32 |
|
33 ^ tokenClass |
|
34 ! |
|
35 |
|
36 tokenClass: anObject |
|
37 |
|
38 tokenClass := anObject |
|
39 ! ! |
|
40 |
|
41 !PPCTokenNode methodsFor:'as yet unclassified'! |
|
42 |
|
43 compileWith: compiler effect: effect id: id |
|
44 | | |
|
45 |
|
46 compiler startMethod: id. |
|
47 compiler startTokenMode. |
|
48 compiler addVariable: 'start'. |
|
49 compiler addVariable: 'end'. |
|
50 |
|
51 " |
|
52 (compiler guards and: [ (guardSet := compiler guardCharSet: self) isNil not ]) ifTrue: [ |
|
53 guardSetId := (compiler idFor: guardSet prefixed: #guard). |
|
54 compiler addConstant: guardSet as: guardSetId. |
|
55 compiler add: 'context atEnd ifTrue: [ ^ self error ].'. |
|
56 compiler add: '(', guardSetId, ' value: context peek) ifFalse: [ ^ self error ].'. |
|
57 ]. |
|
58 " |
|
59 compiler add: 'start := context position + 1.'. |
|
60 compiler call: (self child compileWith: compiler). |
|
61 compiler add: 'error ifTrue: [ ^ self ].'. |
|
62 compiler add: 'end := context position.'. |
|
63 |
|
64 compiler add: '^ ', tokenClass asString, ' on: (context collection) |
|
65 start: start |
|
66 stop: end |
|
67 value: nil'. |
|
68 compiler stopTokenMode. |
|
69 ^ compiler stopMethod. |
|
70 ! |
|
71 |
|
72 prefix |
|
73 ^ #token |
|
74 ! ! |
|
75 |