author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 03 Nov 2014 11:30:59 +0000 | |
changeset 407 | a0e6299c7337 |
parent 405 | 0470a5e6e712 |
child 427 | a7f5e6de19d2 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/petitparser' }" |
0 | 2 |
|
3 |
PPPredicateParser subclass:#PPPredicateObjectParser |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitParser-Parsers' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPPredicateObjectParser class methodsFor:'instance creation'! |
|
12 |
||
13 |
on: aBlock message: aString |
|
14 |
^ self on: aBlock message: aString negated: [ :each | (aBlock value: each) not ] message: 'no ' , aString |
|
15 |
! |
|
16 |
||
17 |
on: aBlock message: aString negated: aNegatedBlock message: aNegatedString |
|
18 |
^ self new initializeOn: aBlock message: aString negated: aNegatedBlock message: aNegatedString |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
19 |
! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
20 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
21 |
startOfLine |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
22 |
|
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
23 |
^ PPStartOfLineParser new. |
0 | 24 |
! ! |
25 |
||
26 |
!PPPredicateObjectParser class methodsFor:'factory-chars'! |
|
27 |
||
28 |
blank |
|
29 |
^ self chars: (String with: Character space with: Character tab) message: 'blank expected' |
|
30 |
! |
|
31 |
||
32 |
char: aCharacter |
|
33 |
^ self expect: aCharacter message: (String with: $" with: aCharacter with: $") , ' expected' |
|
34 |
! |
|
35 |
||
36 |
char: aCharacter message: aString |
|
37 |
^ self expect: aCharacter message: aString |
|
38 |
! |
|
39 |
||
40 |
chars: aCollection message: aString |
|
41 |
^ self on: (PPCharSetPredicate on: [ :char | aCollection includes: char ]) message: aString |
|
42 |
! |
|
43 |
||
44 |
cr |
|
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
45 |
^ self char: (Character codePoint: 13) message: 'carriage return expected' |
0 | 46 |
! |
47 |
||
48 |
digit |
|
49 |
^ self on: (PPCharSetPredicate on: [ :char | char isDigit ]) message: 'digit expected' |
|
50 |
! |
|
51 |
||
52 |
hex |
|
40 | 53 |
^ self |
54 |
on: (PPCharSetPredicate on: [ :char | |
|
55 |
(char between: $0 and: $9) |
|
56 |
or: [ (char between: $a and: $f) |
|
0 | 57 |
or: [ (char between: $A and: $F) ] ] ]) |
58 |
message: 'hex digit expected' |
|
59 |
! |
|
60 |
||
61 |
letter |
|
62 |
^ self on: (PPCharSetPredicate on: [ :char | char isLetter ]) message: 'letter expected' |
|
63 |
! |
|
64 |
||
65 |
lf |
|
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
66 |
^ self char: (Character codePoint: 10) |
0 | 67 |
! |
68 |
||
69 |
lowercase |
|
70 |
^ self on: (PPCharSetPredicate on: [ :char | char isLowercase ]) message: 'lowercase letter expected' |
|
71 |
! |
|
72 |
||
73 |
newline |
|
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
74 |
^ self chars: (String with: (Character codePoint: 13) with: (Character codePoint: 10)) message: 'newline expected' |
0 | 75 |
! |
76 |
||
77 |
punctuation |
|
78 |
^ self chars: '.,"''?!!;:#$%&()*+-/<>=@[]\^_{}|~' message: 'punctuation expected' |
|
79 |
! |
|
80 |
||
81 |
space |
|
82 |
^ self on: (PPCharSetPredicate on: [ :char | char isSeparator ]) message: 'separator expected' |
|
83 |
! |
|
84 |
||
85 |
tab |
|
86 |
^ self char: Character tab message: 'tab expected' |
|
87 |
! |
|
88 |
||
89 |
uppercase |
|
90 |
^ self on: (PPCharSetPredicate on: [ :char | char isUppercase ]) message: 'uppercase letter expected' |
|
91 |
! |
|
92 |
||
93 |
word |
|
94 |
^ self on: (PPCharSetPredicate on: [ :char | char isAlphaNumeric ]) message: 'letter or digit expected' |
|
95 |
! ! |
|
96 |
||
97 |
!PPPredicateObjectParser class methodsFor:'factory-objects'! |
|
98 |
||
99 |
any |
|
100 |
^ self |
|
101 |
on: [ :each | true ] message: 'input expected' |
|
102 |
negated: [ :each | false ] message: 'no input expected' |
|
103 |
! |
|
104 |
||
176 | 105 |
anyExceptAnyOf: aCollection |
0 | 106 |
^ self |
176 | 107 |
on: [ :each | (aCollection includes: each) not ] message: 'any except ' , aCollection printString , ' expected' |
108 |
negated: [ :each | aCollection includes: each ] message: aCollection printString , ' not expected' |
|
0 | 109 |
! |
110 |
||
176 | 111 |
anyOf: aCollection |
0 | 112 |
^ self |
176 | 113 |
on: [ :each | aCollection includes: each ] message: 'any of ' , aCollection printString , ' expected' |
114 |
negated: [ :each | (aCollection includes: each) not ] message: 'none of ' , aCollection printString , 'expected' |
|
0 | 115 |
! |
116 |
||
117 |
between: min and: max |
|
118 |
^ self |
|
119 |
on: [ :each | each >= min and: [ each <= max ] ] message: min printString , '..' , max printString , ' expected' |
|
120 |
negated: [ :each | each < min or: [ each > max ] ] message: min printString , '..' , max printString , ' not expected' |
|
121 |
! |
|
122 |
||
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
123 |
endOfLine |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
124 |
|
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
125 |
^ PPEndOfLineParser new. |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
126 |
! |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
127 |
|
0 | 128 |
expect: anObject |
129 |
^ self expect: anObject message: anObject printString , ' expected' |
|
130 |
! |
|
131 |
||
132 |
expect: anObject message: aString |
|
40 | 133 |
^ self |
0 | 134 |
on: [ :each | each = anObject ] message: aString |
135 |
negated: [ :each | each ~= anObject ] message: 'no ' , aString |
|
136 |
! ! |
|
137 |
||
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
387
diff
changeset
|
138 |
|
0 | 139 |
!PPPredicateObjectParser methodsFor:'initialization'! |
140 |
||
141 |
initializeOn: aBlock message: aString negated: aNegatedBlock message: aNegatedString |
|
142 |
predicate := aBlock. |
|
143 |
predicateMessage := aString. |
|
144 |
negated := aNegatedBlock. |
|
145 |
negatedMessage := aNegatedString |
|
146 |
! ! |
|
147 |
||
148 |
!PPPredicateObjectParser methodsFor:'operators'! |
|
149 |
||
150 |
negate |
|
151 |
"Answer a parser that is the negation of the receiving predicate parser." |
|
40 | 152 |
|
153 |
^ self class |
|
154 |
on: negated message: negatedMessage |
|
0 | 155 |
negated: predicate message: predicateMessage |
156 |
! ! |
|
157 |
||
158 |
!PPPredicateObjectParser methodsFor:'parsing'! |
|
159 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
160 |
parseOn: aPPContext |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
161 |
^ (aPPContext atEnd not and: [ predicate value: aPPContext uncheckedPeek ]) |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
162 |
ifFalse: [ PPFailure message: predicateMessage context: aPPContext ] |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
163 |
ifTrue: [ aPPContext next ] |
0 | 164 |
! ! |
165 |
||
166 |
!PPPredicateObjectParser class methodsFor:'documentation'! |
|
167 |
||
40 | 168 |
version |
176 | 169 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
40 | 170 |
! |
171 |
||
172 |
version_CVS |
|
176 | 173 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
40 | 174 |
! |
175 |
||
387
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
176 |
version_HG |
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
177 |
|
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
178 |
^ '$Changeset: <not expanded> $' |
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
179 |
! |
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
180 |
|
0 | 181 |
version_SVN |
176 | 182 |
^ '$Id: PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
0 | 183 |
! ! |
176 | 184 |