author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 04 Oct 2014 23:34:14 +0100 | |
changeset 383 | e9919f8e47de |
parent 379 | 451b5ae38b72 |
child 405 | 0470a5e6e712 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/petitparser' }"! |
0 | 2 |
|
3 |
!Block methodsFor:'*petitparser-core-converting'! |
|
4 |
||
5 |
asParser |
|
213 | 6 |
"Answer a parser implemented in the receiving one-argument block." |
7 |
||
0 | 8 |
^ PPPluggableParser on: self |
9 |
! ! |
|
3 | 10 |
|
0 | 11 |
!BlockContext methodsFor:'*petitparser-core-converting'! |
12 |
||
13 |
asParser |
|
14 |
^ PPPluggableParser on: self |
|
15 |
! ! |
|
3 | 16 |
|
213 | 17 |
!Character methodsFor:'*petitparser-core-converting'! |
0 | 18 |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
19 |
asParser |
213 | 20 |
"Answer a parser that accepts the receiving character." |
21 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
22 |
^ PPLiteralObjectParser on: self |
0 | 23 |
! ! |
3 | 24 |
|
0 | 25 |
!Character methodsFor:'arithmetic'! |
26 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
27 |
ppMinus: aCharacter |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
28 |
"Create a range of characters between the receiver and the argument." |
0 | 29 |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
30 |
^ PPPredicateObjectParser between: self and: aCharacter |
0 | 31 |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
32 |
"Created: / 19-12-2010 / 18:13:19 / Jan Kurs <kurs.jan@post.cz>" |
0 | 33 |
! ! |
3 | 34 |
|
226 | 35 |
!Collection methodsFor:'*petitparser-core-converting'! |
36 |
||
37 |
asChoiceParser |
|
38 |
^ PPChoiceParser withAll: (self collect: [ :each | each asParser ]) |
|
39 |
! ! |
|
40 |
||
41 |
!Collection methodsFor:'*petitparser-core-converting'! |
|
42 |
||
43 |
asSequenceParser |
|
44 |
^ PPSequenceParser withAll: (self collect: [ :each | each asParser ]) |
|
45 |
! ! |
|
46 |
||
153 | 47 |
!Interval methodsFor:'*petitparser-converting'! |
0 | 48 |
|
49 |
asParser |
|
153 | 50 |
"Create a range of characters between start and stop." |
152 | 51 |
|
52 |
self assert:start isCharacter. |
|
53 |
self assert:stop isCharacter. |
|
54 |
self assert:step == 1. |
|
55 |
^ PPPredicateObjectParser between: start and: stop |
|
56 |
||
57 |
" |
|
58 |
($a to:$f) asParser parse:'a' |
|
59 |
($a to:$f) asParser parse:'g' |
|
60 |
" |
|
61 |
! ! |
|
62 |
||
153 | 63 |
!Object methodsFor:'*petitparser-core-converting'! |
64 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
65 |
asParser |
213 | 66 |
"Answer a parser accepting the receiving object." |
67 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
68 |
^ PPPredicateObjectParser expect: self |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
69 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
70 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
71 |
!Object methodsFor:'*petitparser-core-testing'! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
72 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
73 |
isPetitFailure |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
74 |
^ false |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
75 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
76 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
77 |
!Object methodsFor:'*petitparser-core-testing'! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
78 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
79 |
isPetitParser |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
80 |
^ false |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
81 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
82 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
83 |
!PositionableStream methodsFor:'*petitparser-core-converting'! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
84 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
85 |
asPetitStream |
383
e9919f8e47de
Removed leftover Smalltalk/X-ism: end-of-line comments.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
379
diff
changeset
|
86 |
"Some of my subclasses do not use the instance-variables collection, position and readLimit but instead have a completely different internal representation. In these cases just use the super implementation that is inefficient but should work in all cases." |
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
87 |
|
383
e9919f8e47de
Removed leftover Smalltalk/X-ism: end-of-line comments.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
379
diff
changeset
|
88 |
^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
e9919f8e47de
Removed leftover Smalltalk/X-ism: end-of-line comments.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
379
diff
changeset
|
89 |
ifFalse: [ PPStream on: collection from: ( position + 1 ) to: readLimit ] |
e9919f8e47de
Removed leftover Smalltalk/X-ism: end-of-line comments.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
379
diff
changeset
|
90 |
ifTrue: [ super asPetitStream ] |
153 | 91 |
|
92 |
"Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>" |
|
383
e9919f8e47de
Removed leftover Smalltalk/X-ism: end-of-line comments.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
379
diff
changeset
|
93 |
"Modified: / 04-10-2014 / 23:27:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
153 | 94 |
! ! |
95 |
||
379 | 96 |
!PositionableStream methodsFor:'*petitparser-core'! |
97 |
||
98 |
peekTwice |
|
99 |
"Answer what would be returned if the message next were sent to the |
|
100 |
receiver. If the receiver is at the end, answer nil." |
|
101 |
||
102 |
| array | |
|
103 |
self atEnd |
|
104 |
ifTrue: [^Array with: nil with: nil]. |
|
105 |
array := Array with: (self next) with: (self peek). |
|
106 |
position := position - 1. |
|
107 |
^array |
|
108 |
! ! |
|
109 |
||
153 | 110 |
!SequenceableCollection methodsFor:'*petitparser-core-converting'! |
111 |
||
112 |
asParser |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
113 |
^ PPSequenceParser withAll: (self collect: [ :each | each asParser ]) |
153 | 114 |
! ! |
115 |
||
116 |
!SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
117 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
118 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
119 |
^ PPStream on: self |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
120 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
121 |
|
0 | 122 |
!Set methodsFor:'*petitparser-core-converting'! |
123 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
124 |
asParser |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
125 |
^ PPChoiceParser withAll: (self collect: [ :each | each asParser ]) |
0 | 126 |
! ! |
3 | 127 |
|
0 | 128 |
!Stream methodsFor:'*petitparser-core-converting'! |
129 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
130 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
131 |
^ self contents asPetitStream |
0 | 132 |
! ! |
3 | 133 |
|
0 | 134 |
!String methodsFor:'*petitparser-core-converting'! |
135 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
136 |
asParser |
213 | 137 |
"Answer a parser that accepts the receiving string." |
138 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
139 |
^ PPLiteralSequenceParser on: self |
0 | 140 |
! ! |
3 | 141 |
|
0 | 142 |
!Symbol methodsFor:'*petitparser-core-converting'! |
143 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
144 |
asParser |
213 | 145 |
"Answer a predicate parser named after the receiving symbol. Possible symbols are the method selectors on the class-side of PPPredicateObjectParser." |
146 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
147 |
^ PPPredicateObjectParser perform: self |
0 | 148 |
! ! |
3 | 149 |
|
0 | 150 |
!Symbol methodsFor:'Compatibility-Squeak'! |
151 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
152 |
value:anObject |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
153 |
^ anObject perform: self. |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
154 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
155 |
"Created: / 18-12-2010 / 16:47:22 / Jan Kurs <kurs.jan@post.cz>" |
0 | 156 |
! ! |
3 | 157 |
|
0 | 158 |
!Text methodsFor:'*petitparser-core'! |
159 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
160 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
161 |
^ string asPetitStream |
0 | 162 |
! ! |
3 | 163 |
|
0 | 164 |
!UndefinedObject methodsFor:'*petitparser-converting'! |
165 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
166 |
asParser |
213 | 167 |
"Answer a parser that succeeds and does not consume anything." |
168 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
169 |
^ PPEpsilonParser new |
0 | 170 |
! ! |
3 | 171 |
|
4 | 172 |
!stx_goodies_petitparser class methodsFor:'documentation'! |
3 | 173 |
|
376
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
309
diff
changeset
|
174 |
extensionsVersion_HG |
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
309
diff
changeset
|
175 |
|
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
309
diff
changeset
|
176 |
^ '$Changeset: <not expanded> $' |
150
24e8d10ff041
Character>>-not needed here - already in libbasic
Claus Gittinger <cg@exept.de>
parents:
58
diff
changeset
|
177 |
! ! |