Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Name: PetitCompiler-JanVrany.135
Author: JanVrany
Time: 22-07-2015, 06:53:29.127 PM
UUID: 890178b5-275d-46af-a2ad-1738998f07cb
Ancestors: PetitCompiler-JanVrany.134
Name: PetitCompiler-Tests-JanKurs.93
Author: JanKurs
Time: 20-07-2015, 11:30:10.283 PM
UUID: 6473e671-ad70-42ca-b6c3-654b78edc531
Ancestors: PetitCompiler-Tests-JanKurs.92
Name: PetitCompiler-Extras-Tests-JanVrany.16
Author: JanVrany
Time: 22-07-2015, 05:18:22.387 PM
UUID: 8f6f9129-dbba-49b1-9402-038470742f98
Ancestors: PetitCompiler-Extras-Tests-JanKurs.15
Name: PetitCompiler-Benchmarks-JanKurs.12
Author: JanKurs
Time: 06-07-2015, 02:10:06.901 PM
UUID: cb24f1ac-46a4-494d-9780-64576f0f0dba
Ancestors: PetitCompiler-Benchmarks-JanKurs.11, PetitCompiler-Benchmarks-JanVrany.e29bd90f388e.20150619081300
"{ Package: 'stx:goodies/petitparser' }"
"{ NameSpace: Smalltalk }"
ReadStream subclass:#PPStream
instanceVariableNames:'newlines'
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
!
size
"
The same implementation as a ReadStream. Implemented here for compatibility with Smalltalk/X
that has different implementation in a ReadStream
"
^readLimit
!
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:'positioning'!
column: pos
| nl |
(pos = -1) ifTrue: [ ^ 0 ].
(pos > readLimit) ifTrue: [ ^ self error: 'Out of limit' ].
nl := self newlines.
nl keysAndValuesDo: [ :index :value |
(value > pos) ifTrue: [ ^ pos - (nl at: (index - 1)) + 1]
].
^ pos - (nl at: (nl size )) + 1
!
fillNewlines
| tmp line |
newlines := OrderedCollection new.
tmp := position.
line := 0.
(0 to: readLimit) do: [:index |
position := index.
self isStartOfLine ifTrue: [ newlines add: position ]
].
position := tmp.
newlines := newlines asArray.
^ newlines
!
line: pos
| nl |
(pos = -1) ifTrue: [ ^ 0 ].
(pos > readLimit) ifTrue: [ ^ self error: 'Out of limit' ].
nl := self newlines.
nl keysAndValuesDo: [ :index :value |
(value > pos) ifTrue: [ ^ (index - 1)]
].
^ nl size
!
newlines
^ newlines ifNil: [
newlines := self fillNewlines.
]
! !
!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'!
column
^ self column: position.
!
insideCRLF
(position < 1) ifTrue: [ ^ false ].
^ (self peek = (Character codePoint: 10)) and: [ self peekBack = (Character codePoint: 13) ]
!
isEndOfLine
self atEnd ifTrue: [ ^ true ].
self insideCRLF ifTrue: [ ^ false ].
^ (self peek = (Character codePoint: 13) or: [ self peek = (Character codePoint: 10)]).
!
isStartOfLine
(position = 0) ifTrue: [ ^ true ].
self insideCRLF ifTrue: [ ^ false ].
^ (self peekBack = (Character codePoint: 13)) or: [ self peekBack = (Character codePoint: 10)].
!
line
^ self line: position
! !
!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 $'
! !