author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 08 Oct 2014 00:08:21 +0100 | |
changeset 386 | a409905f7f2d |
parent 291 | 2017fbc4d826 |
permissions | -rw-r--r-- |
202 | 1 |
"{ Package: 'stx:goodies/petitparser/analyzer' }" |
2 |
||
3 |
PPProcessor subclass:#PPRewriter |
|
4 |
instanceVariableNames:'changed' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitAnalyzer-Core' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPRewriter methodsFor:'accessing'! |
|
12 |
||
13 |
replace: aSearchParser with: aReplaceParser |
|
14 |
self replace: aSearchParser with: aReplaceParser when: [ :node | true ] |
|
15 |
! |
|
16 |
||
17 |
replace: aSearchParser with: aReplaceParser when: aValidationBlock |
|
18 |
self addRule: (PPParserReplaceRule searchFor: aSearchParser replaceWith: aReplaceParser when: aValidationBlock) |
|
19 |
! |
|
20 |
||
21 |
replace: aSearchParser withValueFrom: aReplaceBlock |
|
22 |
self replace: aSearchParser withValueFrom: aReplaceBlock when: [ :node | true ] |
|
23 |
! |
|
24 |
||
25 |
replace: aSearchParser withValueFrom: aReplaceBlock when: aValidationBlock |
|
26 |
self addRule: (PPBlockReplaceRule searchFor: aSearchParser replaceWith: aReplaceBlock when: aValidationBlock) |
|
27 |
! ! |
|
28 |
||
29 |
!PPRewriter methodsFor:'initialization'! |
|
30 |
||
31 |
initialize |
|
32 |
super initialize. |
|
33 |
changed := false |
|
34 |
! ! |
|
35 |
||
36 |
!PPRewriter methodsFor:'public'! |
|
37 |
||
38 |
execute: aParser |
|
39 |
"Perform the replace rules of the receiver on aParser, answer the resulting parser." |
|
40 |
||
41 |
| previous result | |
|
42 |
previous := context. |
|
43 |
changed := false. |
|
44 |
context := Dictionary new. |
|
45 |
result := aParser transform: [ :each | |
|
46 |
| transformed | |
|
47 |
transformed := self performRulesOn: each. |
|
48 |
transformed isNil |
|
49 |
ifTrue: [ each ] |
|
50 |
ifFalse: [ changed := true. transformed ] ]. |
|
51 |
context := previous. |
|
52 |
^ result |
|
53 |
! ! |
|
54 |
||
55 |
!PPRewriter methodsFor:'testing'! |
|
56 |
||
57 |
hasChanged |
|
58 |
"Answer if the last operation has changed anything." |
|
59 |
||
60 |
^ changed |
|
61 |
! ! |
|
62 |
||
63 |
!PPRewriter class methodsFor:'documentation'! |
|
64 |
||
65 |
version |
|
291 | 66 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/PPRewriter.st,v 1.2 2014-03-04 20:27:50 cg Exp $' |
202 | 67 |
! |
68 |
||
69 |
version_CVS |
|
291 | 70 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/PPRewriter.st,v 1.2 2014-03-04 20:27:50 cg Exp $' |
386
a409905f7f2d
Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
291
diff
changeset
|
71 |
! |
a409905f7f2d
Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
291
diff
changeset
|
72 |
|
a409905f7f2d
Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
291
diff
changeset
|
73 |
version_HG |
a409905f7f2d
Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
291
diff
changeset
|
74 |
|
a409905f7f2d
Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
291
diff
changeset
|
75 |
^ '$Changeset: <not expanded> $' |
202 | 76 |
! ! |
77 |