PPStream.st
author Claus Gittinger <cg@exept.de>
Thu, 18 Aug 2011 20:59:32 +0200
changeset 1 019230f9432c
parent 0 739fe9b7253e
child 4 90de244a7fa2
permissions -rw-r--r--
*** empty log message ***

"{ Package: 'squeak:petitparser' }"

ReadStream subclass:#PPStream
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitParser-Core'
!

PPStream comment:'A positional stream implementation used for parsing. It overrides some methods for optimization reasons.'
!


!PPStream methodsFor:'accessing'!

next: anInteger 
	"Answer up to anInteger elements of my collection. Overridden for efficiency."

	| answer endPosition |
	endPosition := position + anInteger min: readLimit.
	answer := collection copyFrom: position + 1 to: endPosition.
	position := endPosition.
	^ answer
!

peek
	"An improved version of peek, that is slightly faster than the built in version."

	^ self atEnd ifFalse: [ collection at: position + 1 ]
!

position: anInteger
	"The receiver does not check for invalid arguments passed to this method, as it is solely used with valid indexes for backtracking."

	position := anInteger
!

uncheckedPeek
	"An unchecked version of peek that throws an error if we try to peek over the end of the stream, even faster than #peek."

	^ collection at: position + 1
! !

!PPStream methodsFor:'converting'!

asPetitStream
	^ self
! !

!PPStream methodsFor:'printing'!

printOn: aStream
	collection isString
		ifFalse: [ ^ super printOn: aStream ].
	aStream
		nextPutAll: (collection copyFrom: 1 to: position);
		nextPutAll: '·';
		nextPutAll: (collection copyFrom: position + 1 to: readLimit)
! !

!PPStream class methodsFor:'documentation'!

version_SVN
    ^ '$Id: PPStream.st,v 1.1 2011-08-18 18:56:17 cg Exp $'
! !