PPStream.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 01 Nov 2014 00:30:28 +0000
changeset 403 7063d523b064
parent 388 74c9c229033b
child 405 0470a5e6e712
permissions -rw-r--r--
Removed autoload attribut for tests. As all classes are in a test package, when package is loaded likely tests are required, so load them right away.

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

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


!PPStream methodsFor:'accessing'!

collection
	"Answer the underlying collection."
	
	^ collection
!

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 methodsFor:'queries'!

insideCRLF
        (position < 1) ifTrue: [ ^ false ].
        
        ^ (self peek = (Character codePoint: 10)) and: [ self peekBack = (Character codePoint: 13) ]

    "Modified: / 03-10-2014 / 23:52:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isStartOfLine
        (position = 0) ifTrue: [ ^ true ].

        self insideCRLF ifTrue: [ ^ false ].
        
        ^ (self peekBack = (Character codePoint: 13)) or: [ self peekBack = (Character codePoint: 10)].

    "Modified: / 03-10-2014 / 23:52:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

size
    ^ readLimit
    "DO NOT REMOVE this method event though in Pharo it is the same as
     inherited. This is required for Smalltalk/X compatibility"

    "Created: / 08-10-2014 / 12:25:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPStream class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id: PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $'
! !