author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 01 Nov 2014 00:34:30 +0000 | |
changeset 404 | 8da796db7f95 |
parent 387 | e2b2ccaa4de6 |
child 405 | 0470a5e6e712 |
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 |
|
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
45 |
^ self char: (Character codePoint: 13) message: 'carriage return expected' |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
46 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
47 |
"Modified: / 03-10-2014 / 23:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 48 |
! |
49 |
||
50 |
digit |
|
51 |
^ self on: (PPCharSetPredicate on: [ :char | char isDigit ]) message: 'digit expected' |
|
52 |
! |
|
53 |
||
54 |
hex |
|
40 | 55 |
^ self |
56 |
on: (PPCharSetPredicate on: [ :char | |
|
57 |
(char between: $0 and: $9) |
|
58 |
or: [ (char between: $a and: $f) |
|
0 | 59 |
or: [ (char between: $A and: $F) ] ] ]) |
60 |
message: 'hex digit expected' |
|
61 |
! |
|
62 |
||
63 |
letter |
|
64 |
^ self on: (PPCharSetPredicate on: [ :char | char isLetter ]) message: 'letter expected' |
|
65 |
! |
|
66 |
||
67 |
lf |
|
68 |
^ self char: Character lf |
|
69 |
! |
|
70 |
||
71 |
lowercase |
|
72 |
^ self on: (PPCharSetPredicate on: [ :char | char isLowercase ]) message: 'lowercase letter expected' |
|
73 |
! |
|
74 |
||
75 |
newline |
|
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
76 |
^ self chars: (String with: (Character codePoint: 13) with: (Character codePoint: 10)) message: 'newline expected' |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
77 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
78 |
"Modified: / 03-10-2014 / 23:56:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 79 |
! |
80 |
||
81 |
punctuation |
|
82 |
^ self chars: '.,"''?!!;:#$%&()*+-/<>=@[]\^_{}|~' message: 'punctuation expected' |
|
83 |
! |
|
84 |
||
85 |
space |
|
86 |
^ self on: (PPCharSetPredicate on: [ :char | char isSeparator ]) message: 'separator expected' |
|
87 |
! |
|
88 |
||
89 |
tab |
|
90 |
^ self char: Character tab message: 'tab expected' |
|
91 |
! |
|
92 |
||
93 |
uppercase |
|
94 |
^ self on: (PPCharSetPredicate on: [ :char | char isUppercase ]) message: 'uppercase letter expected' |
|
95 |
! |
|
96 |
||
97 |
word |
|
98 |
^ self on: (PPCharSetPredicate on: [ :char | char isAlphaNumeric ]) message: 'letter or digit expected' |
|
99 |
! ! |
|
100 |
||
101 |
!PPPredicateObjectParser class methodsFor:'factory-objects'! |
|
102 |
||
103 |
any |
|
104 |
^ self |
|
105 |
on: [ :each | true ] message: 'input expected' |
|
106 |
negated: [ :each | false ] message: 'no input expected' |
|
107 |
! |
|
108 |
||
176 | 109 |
anyExceptAnyOf: aCollection |
0 | 110 |
^ self |
176 | 111 |
on: [ :each | (aCollection includes: each) not ] message: 'any except ' , aCollection printString , ' expected' |
112 |
negated: [ :each | aCollection includes: each ] message: aCollection printString , ' not expected' |
|
0 | 113 |
! |
114 |
||
176 | 115 |
anyOf: aCollection |
0 | 116 |
^ self |
176 | 117 |
on: [ :each | aCollection includes: each ] message: 'any of ' , aCollection printString , ' expected' |
118 |
negated: [ :each | (aCollection includes: each) not ] message: 'none of ' , aCollection printString , 'expected' |
|
0 | 119 |
! |
120 |
||
121 |
between: min and: max |
|
122 |
^ self |
|
123 |
on: [ :each | each >= min and: [ each <= max ] ] message: min printString , '..' , max printString , ' expected' |
|
124 |
negated: [ :each | each < min or: [ each > max ] ] message: min printString , '..' , max printString , ' not expected' |
|
125 |
! |
|
126 |
||
127 |
expect: anObject |
|
128 |
^ self expect: anObject message: anObject printString , ' expected' |
|
129 |
! |
|
130 |
||
131 |
expect: anObject message: aString |
|
40 | 132 |
^ self |
0 | 133 |
on: [ :each | each = anObject ] message: aString |
134 |
negated: [ :each | each ~= anObject ] message: 'no ' , aString |
|
135 |
! ! |
|
136 |
||
137 |
!PPPredicateObjectParser methodsFor:'initialization'! |
|
138 |
||
139 |
initializeOn: aBlock message: aString negated: aNegatedBlock message: aNegatedString |
|
140 |
predicate := aBlock. |
|
141 |
predicateMessage := aString. |
|
142 |
negated := aNegatedBlock. |
|
143 |
negatedMessage := aNegatedString |
|
144 |
! ! |
|
145 |
||
146 |
!PPPredicateObjectParser methodsFor:'operators'! |
|
147 |
||
148 |
negate |
|
149 |
"Answer a parser that is the negation of the receiving predicate parser." |
|
40 | 150 |
|
151 |
^ self class |
|
152 |
on: negated message: negatedMessage |
|
0 | 153 |
negated: predicate message: predicateMessage |
154 |
! ! |
|
155 |
||
156 |
!PPPredicateObjectParser methodsFor:'parsing'! |
|
157 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
158 |
parseOn: aPPContext |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
176
diff
changeset
|
159 |
^ (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
|
160 |
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
|
161 |
ifTrue: [ aPPContext next ] |
0 | 162 |
! ! |
163 |
||
164 |
!PPPredicateObjectParser class methodsFor:'documentation'! |
|
165 |
||
40 | 166 |
version |
176 | 167 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
40 | 168 |
! |
169 |
||
170 |
version_CVS |
|
176 | 171 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
40 | 172 |
! |
173 |
||
387
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
174 |
version_HG |
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
175 |
|
e2b2ccaa4de6
Commited a island parser support (MC package PetitIslands)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
176 |
^ '$Changeset: <not expanded> $' |
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 |
|
0 | 179 |
version_SVN |
176 | 180 |
^ '$Id: PPPredicateObjectParser.st,v 1.5 2014-03-04 14:33:20 cg Exp $' |
0 | 181 |
! ! |
176 | 182 |