1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 PPCompiledParser subclass:#PPTokenizingCompiledParser |
5 PPCompiledParser subclass:#PPTokenizingCompiledParser |
6 instanceVariableNames:'currentTokenValue currentTokenType scanner' |
6 instanceVariableNames:'scanner' |
7 classVariableNames:'' |
7 classVariableNames:'' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Parsers' |
9 category:'PetitCompiler-Parsers' |
10 ! |
10 ! |
11 |
11 |
12 !PPTokenizingCompiledParser class methodsFor:'as yet unclassified'! |
12 !PPTokenizingCompiledParser class methodsFor:'as yet unclassified'! |
13 |
13 |
14 acceptsLoggingOfCompilation |
14 acceptsLoggingOfCompilation |
15 ^ self == PPTokenizingCompiledParser |
15 ^ true |
|
16 " ^ self == PPTokenizingCompiledParser" |
|
17 ! ! |
|
18 |
|
19 !PPTokenizingCompiledParser methodsFor:'accessing'! |
|
20 |
|
21 scanner |
|
22 ^ scanner |
16 ! ! |
23 ! ! |
17 |
24 |
18 !PPTokenizingCompiledParser methodsFor:'initialization'! |
25 !PPTokenizingCompiledParser methodsFor:'initialization'! |
19 |
26 |
20 initialize |
27 initialize |
22 |
29 |
23 ! ! |
30 ! ! |
24 |
31 |
25 !PPTokenizingCompiledParser methodsFor:'tokenizing'! |
32 !PPTokenizingCompiledParser methodsFor:'tokenizing'! |
26 |
33 |
27 consume: tokenType |
|
28 self halt: 'deprecated'. |
|
29 (self perform: tokenType) ifTrue: [ |
|
30 currentTokenType := nil. |
|
31 ^ currentTokenValue. |
|
32 ]. |
|
33 "self error: 'expected: ', tokenType storeString, ' got ', currentTokenType storeString." |
|
34 self error. |
|
35 ! |
|
36 |
|
37 consumeWhitespace |
34 consumeWhitespace |
38 "self shouldBeImplemented " |
35 "self shouldBeImplemented " |
39 ! |
|
40 |
|
41 currentTokenType |
|
42 currentTokenType isNil ifTrue: [ self nextToken ]. |
|
43 ^ currentTokenType |
|
44 ! |
|
45 |
|
46 currentTokenTypeIs: tokenType |
|
47 "if the type is read" |
|
48 self halt: 'deprecated'. |
|
49 currentTokenType isNil ifFalse: [ ^ currentTokenType = tokenType ]. |
|
50 |
|
51 "if not, try to read the token" |
|
52 ^ self perform: tokenType. |
|
53 ! |
|
54 |
|
55 currentTokenValue |
|
56 currentTokenType isNil ifTrue: [ self nextToken ]. |
|
57 ^ currentTokenType |
|
58 ! |
36 ! |
59 |
37 |
60 nextToken |
38 nextToken |
61 self shouldBeImplemented |
39 self shouldBeImplemented |
62 ! |
40 ! |
67 context := aPPContext. |
45 context := aPPContext. |
68 context compiledParser: self. |
46 context compiledParser: self. |
69 failure := PPFailure new message: nil; context: context; position: -1. |
47 failure := PPFailure new message: nil; context: context; position: -1. |
70 context noteFailure: failure. |
48 context noteFailure: failure. |
71 error := false. |
49 error := false. |
72 currentTokenType := nil. |
|
73 scanner := (self class classVarNamed: #scannerClass) new. |
50 scanner := (self class classVarNamed: #scannerClass) new. |
74 scanner stream: aPPContext. |
51 scanner stream: aPPContext. |
75 |
52 |
76 |
53 [ |
77 self consumeWhitespace. |
54 scanner scan_consumeWhitespace. |
78 retval := self perform: startSymbol. |
55 scanner position: context position. |
79 " self consumeWhitespace." |
56 |
|
57 retval := self perform: startSymbol. |
|
58 ] on: PPCScannerError do: [ :e | |
|
59 "TODO JK: fix reporting of position?" |
|
60 retval := PPFailure message: e description at: 0. |
|
61 ]. |
80 |
62 |
81 (retval isPetitFailure) ifTrue: [ aPPContext noteFailure: failure ]. |
63 (retval isPetitFailure) ifTrue: [ aPPContext noteFailure: failure ]. |
82 error ifTrue: [ aPPContext noteFailure: failure. retval := failure ]. |
64 error ifTrue: [ aPPContext noteFailure: failure. retval := failure ]. |
83 |
65 |
84 " aPPContext position: context position." |
66 " aPPContext position: context position." |