PPLazyRepeatingParser.st
author sr
Thu, 05 Jul 2018 09:23:34 +0200
changeset 628 379fc127ba99
parent 167 f7d5e10c3fe8
child 377 6112a403a52d
permissions -rw-r--r--
order
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
167
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser' }"
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
PPLimitedRepeatingParser subclass:#PPLazyRepeatingParser
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
	instanceVariableNames:''
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
	classVariableNames:''
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	poolDictionaries:''
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	category:'PetitParser-Parsers'
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
!
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
!PPLazyRepeatingParser methodsFor:'parsing'!
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
parseOn: aStream
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
	| start element elements |
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	start := aStream position.
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	elements := OrderedCollection new.
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	[ elements size < min ] whileTrue: [
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
		(element := parser parseOn: aStream) isPetitFailure ifTrue: [
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
			aStream position: start.
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
			^ element ].
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
		elements addLast: element ].
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	[ self matchesLimitOn: aStream ] whileFalse: [
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
		elements size < max ifFalse: [
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
			aStream position: start.
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
			^ PPFailure message: 'overflow' at: start ].
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
		element := parser parseOn: aStream.
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
		element isPetitFailure ifTrue: [
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
			aStream position: start.
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
			^ element ].
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
		elements addLast: element ].
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	^ elements asArray
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
! !
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
!PPLazyRepeatingParser class methodsFor:'documentation'!
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
version
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLazyRepeatingParser.st,v 1.1 2014-03-04 14:32:47 cg Exp $'
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
version_CVS
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLazyRepeatingParser.st,v 1.1 2014-03-04 14:32:47 cg Exp $'
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
! !
f7d5e10c3fe8 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43