author | Claus Gittinger <cg@exept.de> |
Tue, 04 Mar 2014 16:53:53 +0100 | |
changeset 213 | b38781d329c5 |
parent 155 | 1109bb0048eb |
child 226 | f88e1127557a |
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 |
|
153 | 35 |
!Interval methodsFor:'*petitparser-converting'! |
0 | 36 |
|
37 |
asParser |
|
153 | 38 |
"Create a range of characters between start and stop." |
152 | 39 |
|
40 |
self assert:start isCharacter. |
|
41 |
self assert:stop isCharacter. |
|
42 |
self assert:step == 1. |
|
43 |
^ PPPredicateObjectParser between: start and: stop |
|
44 |
||
45 |
" |
|
46 |
($a to:$f) asParser parse:'a' |
|
47 |
($a to:$f) asParser parse:'g' |
|
48 |
" |
|
49 |
! ! |
|
50 |
||
153 | 51 |
!Object methodsFor:'*petitparser-core-converting'! |
52 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
53 |
asParser |
213 | 54 |
"Answer a parser accepting the receiving object." |
55 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
56 |
^ PPPredicateObjectParser expect: self |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
57 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
58 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
59 |
!Object methodsFor:'*petitparser-core-testing'! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
60 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
61 |
isPetitFailure |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
62 |
^ false |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
63 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
64 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
65 |
!Object methodsFor:'*petitparser-core-testing'! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
66 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
67 |
isPetitParser |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
68 |
^ false |
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 |
!PositionableStream methodsFor:'*petitparser-core-converting'! |
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 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
74 |
"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
|
75 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
76 |
"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
|
77 |
self breakPoint: #petitparser. |
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 |
^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
153 | 80 |
ifFalse: [ PPStream on: collection from: (position +1) to: readLimit ] |
81 |
ifTrue: [ super asPetitStream ] |
|
82 |
||
83 |
||
84 |
"/ ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
|
85 |
"/ ifFalse: [ PPStream on: collection from: position to: readLimit ] |
|
86 |
"/ ifTrue: [ super asPetitStream ] |
|
87 |
||
88 |
"Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>" |
|
89 |
! ! |
|
90 |
||
91 |
!SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
92 |
||
93 |
asParser |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
94 |
^ PPSequenceParser withAll: (self collect: [ :each | each asParser ]) |
153 | 95 |
! ! |
96 |
||
97 |
!SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
98 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
99 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
100 |
^ PPStream on: self |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
101 |
! ! |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
102 |
|
0 | 103 |
!Set methodsFor:'*petitparser-core-converting'! |
104 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
105 |
asParser |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
106 |
^ PPChoiceParser withAll: (self collect: [ :each | each asParser ]) |
0 | 107 |
! ! |
3 | 108 |
|
0 | 109 |
!Stream 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 |
^ self contents asPetitStream |
0 | 113 |
! ! |
3 | 114 |
|
0 | 115 |
!String methodsFor:'*petitparser-core-converting'! |
116 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
117 |
asParser |
213 | 118 |
"Answer a parser that accepts the receiving string." |
119 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
120 |
^ PPLiteralSequenceParser on: self |
0 | 121 |
! ! |
3 | 122 |
|
0 | 123 |
!Symbol methodsFor:'*petitparser-core-converting'! |
124 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
125 |
asParser |
213 | 126 |
"Answer a predicate parser named after the receiving symbol. Possible symbols are the method selectors on the class-side of PPPredicateObjectParser." |
127 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
128 |
^ PPPredicateObjectParser perform: self |
0 | 129 |
! ! |
3 | 130 |
|
0 | 131 |
!Symbol methodsFor:'Compatibility-Squeak'! |
132 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
133 |
value:anObject |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
134 |
^ anObject perform: self. |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
135 |
|
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
136 |
"Created: / 18-12-2010 / 16:47:22 / Jan Kurs <kurs.jan@post.cz>" |
0 | 137 |
! ! |
3 | 138 |
|
0 | 139 |
!Text methodsFor:'*petitparser-core'! |
140 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
141 |
asPetitStream |
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
142 |
^ string asPetitStream |
0 | 143 |
! ! |
3 | 144 |
|
0 | 145 |
!UndefinedObject methodsFor:'*petitparser-converting'! |
146 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
147 |
asParser |
213 | 148 |
"Answer a parser that succeeds and does not consume anything." |
149 |
||
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
150 |
^ PPEpsilonParser new |
0 | 151 |
! ! |
3 | 152 |
|
4 | 153 |
!stx_goodies_petitparser class methodsFor:'documentation'! |
3 | 154 |
|
154
5c8f5da40d90
manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
155 |
extensionsVersion_CVS |
213 | 156 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/extensions.st,v 1.10 2014-03-04 15:53:53 cg Exp $' |
150
24e8d10ff041
Character>>-not needed here - already in libbasic
Claus Gittinger <cg@exept.de>
parents:
58
diff
changeset
|
157 |
! ! |
213 | 158 |