equal
deleted
inserted
replaced
|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 PPCNode subclass:#PPCAbstractCharacterNode |
|
4 instanceVariableNames:'character' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'PetitCompiler-Nodes' |
|
8 ! |
|
9 |
|
10 PPCAbstractCharacterNode comment:'' |
|
11 ! |
|
12 |
|
13 !PPCAbstractCharacterNode methodsFor:'accessing'! |
|
14 |
|
15 acceptsEpsilon |
|
16 ^ false |
|
17 ! |
|
18 |
|
19 character |
|
20 ^ character |
|
21 ! |
|
22 |
|
23 character: char |
|
24 character := char |
|
25 ! |
|
26 |
|
27 prefix |
|
28 ^ #char |
|
29 ! ! |
|
30 |
|
31 !PPCAbstractCharacterNode methodsFor:'analysis'! |
|
32 |
|
33 firstCharParser |
|
34 ^ character asParser |
|
35 ! ! |
|
36 |
|
37 !PPCAbstractCharacterNode methodsFor:'compiling'! |
|
38 |
|
39 body: compiler |
|
40 | id | |
|
41 |
|
42 character ppcPrintable ifTrue: [ |
|
43 id := character printString |
|
44 ] ifFalse: [ |
|
45 id := compiler idFor: character prefixed: #char. |
|
46 compiler addConstant: (Character value: character asInteger) as: id . |
|
47 ]. |
|
48 |
|
49 compiler add: '(context peek == ', id, ')'. |
|
50 compiler indent. |
|
51 compiler add: 'ifFalse: [ self error: ''', character asInteger asString, ' expected'' at: context position ] '. |
|
52 compiler add: 'ifTrue: [ context next ].'. |
|
53 compiler dedent. |
|
54 ! |
|
55 |
|
56 compileWith: compiler effect: effect id: id |
|
57 self start: compiler id: id. |
|
58 self body: compiler. |
|
59 ^ self stop: compiler. |
|
60 ! |
|
61 |
|
62 compileWith: compiler id: id |
|
63 self start: compiler. |
|
64 self body: compiler. |
|
65 ^ compiler stopMethod. |
|
66 ! ! |
|
67 |