4
|
1 |
"{ Package: 'stx:goodies/petitparser' }"
|
0
|
2 |
|
|
3 |
ReadStream subclass:#PPStream
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'PetitParser-Core'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!PPStream methodsFor:'accessing'!
|
|
12 |
|
159
|
13 |
collection
|
|
14 |
"Answer the underlying collection."
|
|
15 |
|
|
16 |
^ collection
|
|
17 |
!
|
|
18 |
|
42
|
19 |
next: anInteger
|
0
|
20 |
"Answer up to anInteger elements of my collection. Overridden for efficiency."
|
|
21 |
|
|
22 |
| answer endPosition |
|
|
23 |
endPosition := position + anInteger min: readLimit.
|
|
24 |
answer := collection copyFrom: position + 1 to: endPosition.
|
|
25 |
position := endPosition.
|
|
26 |
^ answer
|
|
27 |
!
|
|
28 |
|
|
29 |
peek
|
|
30 |
"An improved version of peek, that is slightly faster than the built in version."
|
|
31 |
|
|
32 |
^ self atEnd ifFalse: [ collection at: position + 1 ]
|
|
33 |
!
|
|
34 |
|
|
35 |
position: anInteger
|
|
36 |
"The receiver does not check for invalid arguments passed to this method, as it is solely used with valid indexes for backtracking."
|
|
37 |
|
|
38 |
position := anInteger
|
|
39 |
!
|
|
40 |
|
|
41 |
uncheckedPeek
|
|
42 |
"An unchecked version of peek that throws an error if we try to peek over the end of the stream, even faster than #peek."
|
|
43 |
|
|
44 |
^ collection at: position + 1
|
|
45 |
! !
|
|
46 |
|
|
47 |
!PPStream methodsFor:'converting'!
|
|
48 |
|
|
49 |
asPetitStream
|
|
50 |
^ self
|
|
51 |
! !
|
|
52 |
|
|
53 |
!PPStream methodsFor:'printing'!
|
|
54 |
|
|
55 |
printOn: aStream
|
|
56 |
collection isString
|
|
57 |
ifFalse: [ ^ super printOn: aStream ].
|
|
58 |
aStream
|
|
59 |
nextPutAll: (collection copyFrom: 1 to: position);
|
|
60 |
nextPutAll: '·';
|
|
61 |
nextPutAll: (collection copyFrom: position + 1 to: readLimit)
|
|
62 |
! !
|
|
63 |
|
|
64 |
!PPStream class methodsFor:'documentation'!
|
|
65 |
|
42
|
66 |
version
|
159
|
67 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $'
|
42
|
68 |
!
|
|
69 |
|
|
70 |
version_CVS
|
159
|
71 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $'
|
42
|
72 |
!
|
|
73 |
|
0
|
74 |
version_SVN
|
159
|
75 |
^ '$Id: PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $'
|
0
|
76 |
! !
|
159
|
77 |
|