author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 05 Oct 2014 00:05:20 +0100 | |
changeset 380 | 8fe3cb4e607f |
parent 377 | 6112a403a52d |
child 388 | 74c9c229033b |
permissions | -rw-r--r-- |
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 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
64 |
!PPStream methodsFor:'queries'! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
65 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
66 |
insideCRLF |
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
67 |
(position < 1) ifTrue: [ ^ false ]. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
68 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
69 |
^ (self peek = (Character codePoint: 10)) and: [ self peekBack = (Character codePoint: 13) ] |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
70 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
71 |
"Modified: / 03-10-2014 / 23:52:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
72 |
! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
73 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
74 |
isStartOfLine |
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
75 |
(position = 0) ifTrue: [ ^ true ]. |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
76 |
|
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
77 |
self insideCRLF ifTrue: [ ^ false ]. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
78 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
79 |
^ (self peekBack = (Character codePoint: 13)) or: [ self peekBack = (Character codePoint: 10)]. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
80 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
81 |
"Modified: / 03-10-2014 / 23:52:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
82 |
! ! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
83 |
|
0 | 84 |
!PPStream class methodsFor:'documentation'! |
85 |
||
42 | 86 |
version |
159 | 87 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $' |
42 | 88 |
! |
89 |
||
90 |
version_CVS |
|
159 | 91 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $' |
42 | 92 |
! |
93 |
||
0 | 94 |
version_SVN |
159 | 95 |
^ '$Id: PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $' |
0 | 96 |
! ! |
159 | 97 |