4
|
1 |
"{ Package: 'stx:goodies/petitparser' }"
|
0
|
2 |
|
|
3 |
PPDelegateParser subclass:#PPRepeatingParser
|
|
4 |
instanceVariableNames:'min max'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'PetitParser-Parsers'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!PPRepeatingParser class methodsFor:'instance creation'!
|
|
12 |
|
|
13 |
on: aParser
|
|
14 |
^ (super on: aParser) setMin: 0 max: SmallInteger maxVal
|
|
15 |
!
|
|
16 |
|
|
17 |
on: aParser max: aMaxInteger
|
|
18 |
^ (self on: aParser) setMin: 0 max: aMaxInteger
|
|
19 |
!
|
|
20 |
|
|
21 |
on: aParser min: aMinInteger
|
52
|
22 |
^ (self on: aParser) setMin: aMinInteger max: SmallInteger maxVal
|
0
|
23 |
!
|
|
24 |
|
|
25 |
on: aParser min: aMinInteger max: aMaxInteger
|
|
26 |
^ (self on: aParser) setMin: aMinInteger max: aMaxInteger
|
|
27 |
! !
|
|
28 |
|
179
|
29 |
!PPRepeatingParser methodsFor:'*petitanalyzer-matching'!
|
|
30 |
|
|
31 |
match: aParser inContext: aDictionary seen: anIdentitySet
|
|
32 |
^ (super match: aParser inContext: aDictionary seen: anIdentitySet) and: [ self min = aParser min and: [ self max = aParser max ] ]
|
|
33 |
! !
|
|
34 |
|
|
35 |
!PPRepeatingParser methodsFor:'*petitanalyzer-testing'!
|
|
36 |
|
|
37 |
isNullable
|
|
38 |
^ min = 0
|
|
39 |
! !
|
|
40 |
|
0
|
41 |
!PPRepeatingParser methodsFor:'accessing'!
|
|
42 |
|
|
43 |
max
|
|
44 |
"Answer the maximum number of repetitions."
|
|
45 |
|
|
46 |
^ max
|
|
47 |
!
|
|
48 |
|
|
49 |
min
|
|
50 |
"Answer the minimum number of repetitions."
|
52
|
51 |
|
0
|
52 |
^ min
|
|
53 |
! !
|
|
54 |
|
|
55 |
!PPRepeatingParser methodsFor:'initialization'!
|
|
56 |
|
179
|
57 |
initialize
|
|
58 |
super initialize.
|
|
59 |
self setMin: 0; setMax: SmallInteger maxVal
|
|
60 |
!
|
|
61 |
|
|
62 |
setMax: anInteger
|
|
63 |
max := anInteger
|
|
64 |
!
|
|
65 |
|
|
66 |
setMin: anInteger
|
|
67 |
min := anInteger
|
|
68 |
!
|
|
69 |
|
0
|
70 |
setMin: aMinInteger max: aMaxInteger
|
|
71 |
min := aMinInteger.
|
|
72 |
max := aMaxInteger
|
|
73 |
! !
|
|
74 |
|
|
75 |
!PPRepeatingParser methodsFor:'parsing'!
|
|
76 |
|
|
77 |
parseOn: aStream
|
|
78 |
| start element elements |
|
|
79 |
start := aStream position.
|
|
80 |
elements := OrderedCollection new.
|
|
81 |
[ elements size < min ] whileTrue: [
|
|
82 |
(element := parser parseOn: aStream) isPetitFailure ifTrue: [
|
|
83 |
aStream position: start.
|
|
84 |
^ element ].
|
|
85 |
elements addLast: element ].
|
|
86 |
[ elements size < max ] whileTrue: [
|
52
|
87 |
(element := parser parseOn: aStream) isPetitFailure
|
0
|
88 |
ifTrue: [ ^ elements asArray ].
|
|
89 |
elements addLast: element ].
|
|
90 |
^ elements asArray
|
|
91 |
! !
|
|
92 |
|
|
93 |
!PPRepeatingParser methodsFor:'printing'!
|
|
94 |
|
|
95 |
printOn: aStream
|
|
96 |
super printOn: aStream.
|
|
97 |
aStream nextPutAll: ' ['; print: min; nextPutAll: ', '; nextPutAll: (max = SmallInteger maxVal
|
|
98 |
ifTrue: [ '*' ] ifFalse: [ max printString ]); nextPut: $]
|
|
99 |
! !
|
|
100 |
|
|
101 |
!PPRepeatingParser class methodsFor:'documentation'!
|
|
102 |
|
52
|
103 |
version
|
179
|
104 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPRepeatingParser.st,v 1.4 2014-03-04 14:33:24 cg Exp $'
|
52
|
105 |
!
|
|
106 |
|
|
107 |
version_CVS
|
179
|
108 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPRepeatingParser.st,v 1.4 2014-03-04 14:33:24 cg Exp $'
|
52
|
109 |
!
|
|
110 |
|
0
|
111 |
version_SVN
|
179
|
112 |
^ '$Id: PPRepeatingParser.st,v 1.4 2014-03-04 14:33:24 cg Exp $'
|
0
|
113 |
! !
|
179
|
114 |
|