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
|
|
19 |
! !
|
|
20 |
|
|
21 |
!PPPredicateObjectParser class methodsFor:'factory-chars'!
|
|
22 |
|
|
23 |
blank
|
|
24 |
^ self chars: (String with: Character space with: Character tab) message: 'blank expected'
|
|
25 |
!
|
|
26 |
|
|
27 |
char: aCharacter
|
|
28 |
^ self expect: aCharacter message: (String with: $" with: aCharacter with: $") , ' expected'
|
|
29 |
!
|
|
30 |
|
|
31 |
char: aCharacter message: aString
|
|
32 |
^ self expect: aCharacter message: aString
|
|
33 |
!
|
|
34 |
|
|
35 |
chars: aCollection message: aString
|
|
36 |
^ self on: (PPCharSetPredicate on: [ :char | aCollection includes: char ]) message: aString
|
|
37 |
!
|
|
38 |
|
|
39 |
cr
|
|
40 |
^ self char: Character cr message: 'carriage return expected'
|
|
41 |
!
|
|
42 |
|
|
43 |
digit
|
|
44 |
^ self on: (PPCharSetPredicate on: [ :char | char isDigit ]) message: 'digit expected'
|
|
45 |
!
|
|
46 |
|
|
47 |
hex
|
40
|
48 |
^ self
|
|
49 |
on: (PPCharSetPredicate on: [ :char |
|
|
50 |
(char between: $0 and: $9)
|
|
51 |
or: [ (char between: $a and: $f)
|
0
|
52 |
or: [ (char between: $A and: $F) ] ] ])
|
|
53 |
message: 'hex digit expected'
|
|
54 |
!
|
|
55 |
|
|
56 |
letter
|
|
57 |
^ self on: (PPCharSetPredicate on: [ :char | char isLetter ]) message: 'letter expected'
|
|
58 |
!
|
|
59 |
|
|
60 |
lf
|
|
61 |
^ self char: Character lf
|
|
62 |
!
|
|
63 |
|
|
64 |
lowercase
|
|
65 |
^ self on: (PPCharSetPredicate on: [ :char | char isLowercase ]) message: 'lowercase letter expected'
|
|
66 |
!
|
|
67 |
|
|
68 |
newline
|
|
69 |
^ self chars: (String with: Character cr with: Character lf) message: 'newline expected'
|
|
70 |
!
|
|
71 |
|
|
72 |
punctuation
|
|
73 |
^ self chars: '.,"''?!!;:#$%&()*+-/<>=@[]\^_{}|~' message: 'punctuation expected'
|
|
74 |
!
|
|
75 |
|
|
76 |
space
|
|
77 |
^ self on: (PPCharSetPredicate on: [ :char | char isSeparator ]) message: 'separator expected'
|
|
78 |
!
|
|
79 |
|
|
80 |
tab
|
|
81 |
^ self char: Character tab message: 'tab expected'
|
|
82 |
!
|
|
83 |
|
|
84 |
uppercase
|
|
85 |
^ self on: (PPCharSetPredicate on: [ :char | char isUppercase ]) message: 'uppercase letter expected'
|
|
86 |
!
|
|
87 |
|
|
88 |
word
|
|
89 |
^ self on: (PPCharSetPredicate on: [ :char | char isAlphaNumeric ]) message: 'letter or digit expected'
|
|
90 |
! !
|
|
91 |
|
|
92 |
!PPPredicateObjectParser class methodsFor:'factory-objects'!
|
|
93 |
|
|
94 |
any
|
|
95 |
^ self
|
|
96 |
on: [ :each | true ] message: 'input expected'
|
|
97 |
negated: [ :each | false ] message: 'no input expected'
|
|
98 |
!
|
|
99 |
|
|
100 |
anyExceptAnyOf: aCollectionOfChars
|
|
101 |
^ self
|
|
102 |
on: [ :each | (aCollectionOfChars includes: each) not ] message: 'any except ' , aCollectionOfChars printString , ' expected'
|
|
103 |
negated: [ :each | aCollectionOfChars includes: each ] message: aCollectionOfChars printString , ' not expected'
|
|
104 |
!
|
|
105 |
|
|
106 |
anyOf: anArray
|
|
107 |
^ self
|
|
108 |
on: [ :each | anArray includes: each ] message: 'any of ' , anArray printString , ' expected'
|
|
109 |
negated: [ :each | (anArray includes: each) not ] message: 'none of ' , anArray printString , 'expected'
|
|
110 |
!
|
|
111 |
|
|
112 |
between: min and: max
|
|
113 |
^ self
|
|
114 |
on: [ :each | each >= min and: [ each <= max ] ] message: min printString , '..' , max printString , ' expected'
|
|
115 |
negated: [ :each | each < min or: [ each > max ] ] message: min printString , '..' , max printString , ' not expected'
|
|
116 |
!
|
|
117 |
|
|
118 |
expect: anObject
|
|
119 |
^ self expect: anObject message: anObject printString , ' expected'
|
|
120 |
!
|
|
121 |
|
|
122 |
expect: anObject message: aString
|
40
|
123 |
^ self
|
0
|
124 |
on: [ :each | each = anObject ] message: aString
|
|
125 |
negated: [ :each | each ~= anObject ] message: 'no ' , aString
|
|
126 |
! !
|
|
127 |
|
|
128 |
!PPPredicateObjectParser methodsFor:'initialization'!
|
|
129 |
|
|
130 |
initializeOn: aBlock message: aString negated: aNegatedBlock message: aNegatedString
|
|
131 |
predicate := aBlock.
|
|
132 |
predicateMessage := aString.
|
|
133 |
negated := aNegatedBlock.
|
|
134 |
negatedMessage := aNegatedString
|
|
135 |
! !
|
|
136 |
|
|
137 |
!PPPredicateObjectParser methodsFor:'operators'!
|
|
138 |
|
|
139 |
negate
|
|
140 |
"Answer a parser that is the negation of the receiving predicate parser."
|
40
|
141 |
|
|
142 |
^ self class
|
|
143 |
on: negated message: negatedMessage
|
0
|
144 |
negated: predicate message: predicateMessage
|
|
145 |
! !
|
|
146 |
|
|
147 |
!PPPredicateObjectParser methodsFor:'parsing'!
|
|
148 |
|
|
149 |
parseOn: aStream
|
|
150 |
^ (aStream atEnd not and: [ predicate value: aStream uncheckedPeek ])
|
|
151 |
ifFalse: [ PPFailure message: predicateMessage at: aStream position ]
|
|
152 |
ifTrue: [ aStream next ]
|
|
153 |
! !
|
|
154 |
|
|
155 |
!PPPredicateObjectParser class methodsFor:'documentation'!
|
|
156 |
|
40
|
157 |
version
|
|
158 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.3 2012-05-04 22:05:48 vrany Exp $'
|
|
159 |
!
|
|
160 |
|
|
161 |
version_CVS
|
|
162 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPPredicateObjectParser.st,v 1.3 2012-05-04 22:05:48 vrany Exp $'
|
|
163 |
!
|
|
164 |
|
0
|
165 |
version_SVN
|
40
|
166 |
^ '§Id: PPPredicateObjectParser.st 2 2010-12-17 18:44:23Z vranyj1 §'
|
0
|
167 |
! !
|