author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 03 Oct 2014 02:33:08 +0100 | |
changeset 377 | 6112a403a52d |
parent 176 | 0c000acd9ad7 |
child 380 | 8fe3cb4e607f |
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 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
23 |
^ PPStartOfLine 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 |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
45 |
^ self char: Character cr 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 |
|
66 |
^ self char: Character lf |
|
67 |
! |
|
68 |
||
69 |
lowercase |
|
70 |
^ self on: (PPCharSetPredicate on: [ :char | char isLowercase ]) message: 'lowercase letter expected' |
|
71 |
! |
|
72 |
||
73 |
newline |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
74 |
^ self chars: (String with: Character cr with: Character lf) 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 |
||
123 |
expect: anObject |
|
124 |
^ self expect: anObject message: anObject printString , ' expected' |
|
125 |
! |
|
126 |
||
127 |
expect: anObject message: aString |
|
40 | 128 |
^ self |
0 | 129 |
on: [ :each | each = anObject ] message: aString |
130 |
negated: [ :each | each ~= anObject ] message: 'no ' , aString |
|
131 |
! ! |
|
132 |
||
133 |
!PPPredicateObjectParser methodsFor:'initialization'! |
|
134 |
||
135 |
initializeOn: aBlock message: aString negated: aNegatedBlock message: aNegatedString |
|
136 |
predicate := aBlock. |
|
137 |
predicateMessage := aString. |
|
138 |
negated := aNegatedBlock. |
|
139 |
negatedMessage := aNegatedString |
|
140 |
! ! |
|
141 |
||
142 |
!PPPredicateObjectParser methodsFor:'operators'! |
|
143 |
||
144 |
negate |
|
145 |
"Answer a parser that is the negation of the receiving predicate parser." |
|
40 | 146 |
|
147 |
^ self class |
|
148 |
on: negated message: negatedMessage |
|
0 | 149 |
negated: predicate message: predicateMessage |
150 |
! ! |
|
151 |
||
152 |
!PPPredicateObjectParser methodsFor:'parsing'! |
|
153 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
154 |
parseOn: aPPContext |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
155 |
^ (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
|
156 |
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
|
157 |
ifTrue: [ aPPContext next ] |
0 | 158 |
! ! |
159 |
||
160 |
!PPPredicateObjectParser class methodsFor:'documentation'! |
|
161 |
||
40 | 162 |
version |
176 | 163 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
40 | 164 |
! |
165 |
||
166 |
version_CVS |
|
176 | 167 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
40 | 168 |
! |
169 |
||
0 | 170 |
version_SVN |
176 | 171 |
^ '$Id: PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
0 | 172 |
! ! |
176 | 173 |