PPMemoizedParser.st
author sr
Thu, 05 Jul 2018 09:23:34 +0200
changeset 628 379fc127ba99
parent 10 cbaaa689fab2
child 377 6112a403a52d
permissions -rw-r--r--
order

"{ Package: 'stx:goodies/petitparser' }"

PPDelegateParser subclass:#PPMemoizedParser
	instanceVariableNames:'stream buffer'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitParser-Parsers'
!


!PPMemoizedParser methodsFor:'operations'!

memoized
	"Ther is no point in memoizing more than once."

	^ self
! !

!PPMemoizedParser methodsFor:'parsing'!

parseOn: aStream
	| memento |
	stream == aStream
		ifFalse: [ self reset: aStream ].
	memento := (buffer at: stream position + 1)
		ifNil: [ buffer at: stream position + 1 put: PPMemento new ].
	memento position isNil
		ifTrue: [
			memento result: (stream size - stream position + 2 < memento count
				ifTrue: [ PPFailure message: 'overflow' at: stream position ]
				ifFalse: [ memento increment. parser parseOn: stream ]).
			memento position: stream position ]
		ifFalse: [ stream position: memento position ].
	^ memento result
! !

!PPMemoizedParser methodsFor:'private'!

reset: aStream
	stream := aStream.
	buffer := Array new: aStream size + 1
! !

!PPMemoizedParser class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPMemoizedParser.st,v 1.3 2012-05-04 21:58:48 vrany Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPMemoizedParser.st,v 1.3 2012-05-04 21:58:48 vrany Exp $'
!

version_SVN
    ^ '§Id: PPMemoizedParser.st 2 2010-12-17 18:44:23Z vranyj1 §'
! !