PPRepeatingParser.st
changeset 406 c05417ade8ac
parent 378 53d66ecfeb1b
equal deleted inserted replaced
405:0470a5e6e712 406:c05417ade8ac
    23 !
    23 !
    24 
    24 
    25 on: aParser min: aMinInteger max: aMaxInteger
    25 on: aParser min: aMinInteger max: aMaxInteger
    26 	^ (self on: aParser) setMin: aMinInteger max: aMaxInteger
    26 	^ (self on: aParser) setMin: aMinInteger max: aMaxInteger
    27 ! !
    27 ! !
       
    28 
    28 
    29 
    29 
    30 
    30 
    31 
    31 
    32 
    32 !PPRepeatingParser methodsFor:'accessing'!
    33 !PPRepeatingParser methodsFor:'accessing'!
    61 setMin: aMinInteger max: aMaxInteger
    62 setMin: aMinInteger max: aMaxInteger
    62 	min := aMinInteger.
    63 	min := aMinInteger.
    63 	max := aMaxInteger
    64 	max := aMaxInteger
    64 ! !
    65 ! !
    65 
    66 
    66 !PPRepeatingParser methodsFor:'parsing'!
       
    67 
       
    68 parseOn: aStream
       
    69 	| start element elements |
       
    70 	start := aStream position.
       
    71 	elements := OrderedCollection new.
       
    72 	[ elements size < min ] whileTrue: [
       
    73 		(element := parser parseOn: aStream) isPetitFailure ifTrue: [
       
    74 			aStream position: start.
       
    75 			^ element ].
       
    76 		elements addLast: element ].
       
    77 	[ elements size < max ] whileTrue: [
       
    78 	 	(element := parser parseOn: aStream) isPetitFailure
       
    79 			ifTrue: [ ^ elements asArray ].
       
    80 		elements addLast: element ].
       
    81 	^ elements asArray
       
    82 ! !
       
    83 
       
    84 !PPRepeatingParser methodsFor:'printing'!
    67 !PPRepeatingParser methodsFor:'printing'!
    85 
    68 
    86 printOn: aStream
    69 printOn: aStream
    87 	super printOn: aStream.
    70 	super printOn: aStream.
    88 	aStream nextPutAll: ' ['; print: min; nextPutAll: ', '; nextPutAll: (max = SmallInteger maxVal
    71 	aStream nextPutAll: ' ['; print: min; nextPutAll: ', '; nextPutAll: (max = SmallInteger maxVal