|
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 |
|
66 ^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/PPRewriter.st,v 1.1 2014-03-04 15:41:58 cg Exp $' |
|
67 ! |
|
68 |
|
69 version_CVS |
|
70 ^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/PPRewriter.st,v 1.1 2014-03-04 15:41:58 cg Exp $' |
|
71 ! ! |
|
72 |