equal
deleted
inserted
replaced
|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCompiledParser subclass:#PPTokenizingCompiledParser |
|
6 instanceVariableNames:'currentTokenValue currentTokenType' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Parsers' |
|
10 ! |
|
11 |
|
12 !PPTokenizingCompiledParser methodsFor:'tokenizing'! |
|
13 |
|
14 consume: tokenType |
|
15 (self currentTokenTypeIs: tokenType) ifTrue: [ |
|
16 | retval | |
|
17 retval := currentTokenValue. |
|
18 currentTokenType := nil. |
|
19 ^ retval |
|
20 ] ifFalse: [ |
|
21 "self error: 'expected: ', tokenType storeString, ' got ', currentTokenType storeString." |
|
22 self error. |
|
23 ] |
|
24 ! |
|
25 |
|
26 currentTokenType |
|
27 currentTokenType isNil ifTrue: [ self nextToken ]. |
|
28 ^ currentTokenType |
|
29 ! |
|
30 |
|
31 currentTokenTypeIs: tokenType |
|
32 "if the type is read" |
|
33 currentTokenType isNil ifFalse: [ ^ currentTokenType = tokenType ]. |
|
34 |
|
35 "if not, try to read the token" |
|
36 self perform: tokenType. |
|
37 error ifTrue: [ |
|
38 ^ error := false. |
|
39 ]. |
|
40 ^ true |
|
41 ! |
|
42 |
|
43 currentTokenValue |
|
44 currentTokenType isNil ifTrue: [ self nextToken ]. |
|
45 ^ currentTokenType |
|
46 ! |
|
47 |
|
48 nextToken |
|
49 self shouldBeImplemented |
|
50 ! |
|
51 |
|
52 parseOn: input |
|
53 currentTokenType := nil. |
|
54 ^ super parseOn: input. |
|
55 ! ! |
|
56 |