PPStream.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 11 Jan 2013 13:31:10 +0100
changeset 126 558e35a13ce8
parent 42 9b021405b8a5
child 159 0a53379a1214
permissions -rw-r--r--
class: PPParser

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

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


!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
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.3 2012-05-04 22:06:11 vrany Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.3 2012-05-04 22:06:11 vrany Exp $'
!

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