author | Claus Gittinger <cg@exept.de> |
Tue, 01 Jul 2014 11:59:37 +0200 | |
changeset 368 | 8350dbe18762 |
parent 309 | a60bee92ad60 |
child 376 | a2656b27cace |
child 634 | e63445bb2c9a |
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 |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
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." |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
87 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
88 |
"DUNNO WHY, but on: collection from: position to: last set the start to position -1" |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
89 |
self breakPoint: #petitparser. |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
90 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
91 |
^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
153 | 92 |
ifFalse: [ PPStream on: collection from: (position +1) to: readLimit ] |
93 |
ifTrue: [ super asPetitStream ] |
|
94 |
||
95 |
||
96 |
"/ ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
|
97 |
"/ ifFalse: [ PPStream on: collection from: position to: readLimit ] |
|
98 |
"/ ifTrue: [ super asPetitStream ] |
|
99 |
||
100 |
"Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>" |
|
101 |
! ! |
|
102 |
||
103 |
!SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
104 |
||
105 |
asParser |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
106 |
^ PPSequenceParser withAll: (self collect: [ :each | each asParser ]) |
153 | 107 |
! ! |
108 |
||
109 |
!SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
110 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
111 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
112 |
^ PPStream on: self |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
113 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
114 |
|
0 | 115 |
!Set methodsFor:'*petitparser-core-converting'! |
116 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
117 |
asParser |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
118 |
^ PPChoiceParser withAll: (self collect: [ :each | each asParser ]) |
0 | 119 |
! ! |
3 | 120 |
|
0 | 121 |
!Stream methodsFor:'*petitparser-core-converting'! |
122 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
123 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
124 |
^ self contents asPetitStream |
0 | 125 |
! ! |
3 | 126 |
|
0 | 127 |
!String methodsFor:'*petitparser-core-converting'! |
128 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
129 |
asParser |
213 | 130 |
"Answer a parser that accepts the receiving string." |
131 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
132 |
^ PPLiteralSequenceParser on: self |
0 | 133 |
! ! |
3 | 134 |
|
0 | 135 |
!Symbol methodsFor:'*petitparser-core-converting'! |
136 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
137 |
asParser |
213 | 138 |
"Answer a predicate parser named after the receiving symbol. Possible symbols are the method selectors on the class-side of PPPredicateObjectParser." |
139 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
140 |
^ PPPredicateObjectParser perform: self |
0 | 141 |
! ! |
3 | 142 |
|
0 | 143 |
!Symbol methodsFor:'Compatibility-Squeak'! |
144 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
145 |
value:anObject |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
146 |
^ anObject perform: self. |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
147 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
148 |
"Created: / 18-12-2010 / 16:47:22 / Jan Kurs <kurs.jan@post.cz>" |
0 | 149 |
! ! |
3 | 150 |
|
0 | 151 |
!Text methodsFor:'*petitparser-core'! |
152 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
153 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
154 |
^ string asPetitStream |
0 | 155 |
! ! |
3 | 156 |
|
0 | 157 |
!UndefinedObject methodsFor:'*petitparser-converting'! |
158 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
159 |
asParser |
213 | 160 |
"Answer a parser that succeeds and does not consume anything." |
161 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
162 |
^ PPEpsilonParser new |
0 | 163 |
! ! |
3 | 164 |
|
4 | 165 |
!stx_goodies_petitparser class methodsFor:'documentation'! |
3 | 166 |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
167 |
extensionsVersion_CVS |
309 | 168 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/extensions.st,v 1.12 2014-03-04 20:29:55 cg Exp $' |
150
24e8d10ff041
Character>>-not needed here - already in libbasic
Claus Gittinger <cg@exept.de>
parents:
58
diff
changeset
|
169 |
! ! |
213 | 170 |