1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCNode subclass:#PPCAbstractCharacterNode |
|
6 instanceVariableNames:'character' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Nodes' |
|
10 ! |
|
11 |
|
12 |
|
13 !PPCAbstractCharacterNode methodsFor:'accessing'! |
|
14 |
|
15 character |
|
16 ^ character |
|
17 ! |
|
18 |
|
19 character: char |
|
20 character := char |
|
21 ! |
|
22 |
|
23 prefix |
|
24 ^ #char |
|
25 ! ! |
|
26 |
|
27 !PPCAbstractCharacterNode methodsFor:'analysis'! |
|
28 |
|
29 acceptsEpsilon |
|
30 ^ false |
|
31 ! |
|
32 |
|
33 firstCharSet |
|
34 ^ PPCharSetPredicate on: [:e | e = character ] |
|
35 ! |
|
36 |
|
37 recognizedSentencesPrim |
|
38 ^ Array with: character asString |
|
39 ! ! |
|
40 |
|
41 !PPCAbstractCharacterNode methodsFor:'comparison'! |
|
42 |
|
43 = anotherNode |
|
44 super = anotherNode ifFalse: [ ^ false ]. |
|
45 ^ character = anotherNode character. |
|
46 ! |
|
47 |
|
48 hash |
|
49 ^ super hash bitXor: character hash |
|
50 ! ! |
|
51 |
|
52 !PPCAbstractCharacterNode methodsFor:'compiling'! |
|
53 |
|
54 body: compiler |
|
55 | id | |
|
56 |
|
57 character ppcPrintable ifTrue: [ |
|
58 id := character storeString |
|
59 ] ifFalse: [ |
|
60 id := compiler idFor: character prefixed: #char. |
|
61 compiler addConstant: (Character value: character asInteger) as: id . |
|
62 ]. |
|
63 |
|
64 compiler add: '(context peek == ', id, ')'. |
|
65 compiler indent. |
|
66 compiler add: 'ifFalse: [ self error: ''', character asInteger asString, ' expected'' at: context position ] '. |
|
67 compiler add: 'ifTrue: [ context next ].'. |
|
68 compiler dedent. |
|
69 ! ! |
|
70 |
|
71 !PPCAbstractCharacterNode methodsFor:'printing'! |
|
72 |
|
73 printNameOn: aStream |
|
74 super printNameOn: aStream. |
|
75 |
|
76 character = $" ifTrue: [ |
|
77 "this is hack to allow for printing '' in comments..." |
|
78 aStream nextPutAll: ', '; nextPutAll: '$'''''. |
|
79 ^ self |
|
80 ]. |
|
81 |
|
82 aStream nextPutAll: ', '; print: character |
|
83 ! ! |
|
84 |
|
85 !PPCAbstractCharacterNode class methodsFor:'documentation'! |
|
86 |
|
87 version_HG |
|
88 |
|
89 ^ '$Changeset: <not expanded> $' |
|
90 ! ! |
|
91 |
|