author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 07 Nov 2014 02:14:26 +0000 | |
changeset 417 | 3c0a91182e65 |
parent 405 | 0470a5e6e712 |
child 421 | 7e08b31e0dae |
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 |
||
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
11 |
|
0 | 12 |
!PPStream methodsFor:'accessing'! |
13 |
||
159 | 14 |
collection |
15 |
"Answer the underlying collection." |
|
16 |
||
17 |
^ collection |
|
18 |
! |
|
19 |
||
42 | 20 |
next: anInteger |
0 | 21 |
"Answer up to anInteger elements of my collection. Overridden for efficiency." |
22 |
||
23 |
| answer endPosition | |
|
24 |
endPosition := position + anInteger min: readLimit. |
|
25 |
answer := collection copyFrom: position + 1 to: endPosition. |
|
26 |
position := endPosition. |
|
27 |
^ answer |
|
28 |
! |
|
29 |
||
30 |
peek |
|
31 |
"An improved version of peek, that is slightly faster than the built in version." |
|
32 |
||
33 |
^ self atEnd ifFalse: [ collection at: position + 1 ] |
|
34 |
! |
|
35 |
||
36 |
position: anInteger |
|
37 |
"The receiver does not check for invalid arguments passed to this method, as it is solely used with valid indexes for backtracking." |
|
38 |
||
39 |
position := anInteger |
|
40 |
! |
|
41 |
||
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
42 |
size |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
43 |
" |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
44 |
The same implementation as a ReadStream. Implemented here for compatibility with Smalltalk/X |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
45 |
that has different implementation in a ReadStream |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
46 |
" |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
47 |
^readLimit |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
48 |
! |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
49 |
|
0 | 50 |
uncheckedPeek |
51 |
"An unchecked version of peek that throws an error if we try to peek over the end of the stream, even faster than #peek." |
|
52 |
||
53 |
^ collection at: position + 1 |
|
54 |
! ! |
|
55 |
||
56 |
!PPStream methodsFor:'converting'! |
|
57 |
||
58 |
asPetitStream |
|
59 |
^ self |
|
60 |
! ! |
|
61 |
||
62 |
!PPStream methodsFor:'printing'! |
|
63 |
||
64 |
printOn: aStream |
|
65 |
collection isString |
|
66 |
ifFalse: [ ^ super printOn: aStream ]. |
|
67 |
aStream |
|
68 |
nextPutAll: (collection copyFrom: 1 to: position); |
|
69 |
nextPutAll: '·'; |
|
70 |
nextPutAll: (collection copyFrom: position + 1 to: readLimit) |
|
71 |
! ! |
|
72 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
73 |
!PPStream methodsFor:'queries'! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
74 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
75 |
insideCRLF |
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
76 |
(position < 1) ifTrue: [ ^ false ]. |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
77 |
|
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
78 |
^ (self peek = (Character codePoint: 10)) and: [ self peekBack = (Character codePoint: 13) ] |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
79 |
! |
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
|
80 |
|
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
81 |
isEndOfLine |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
82 |
self atEnd ifTrue: [ ^ true ]. |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
83 |
self insideCRLF ifTrue: [ ^ false ]. |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
84 |
^ (self peek = (Character codePoint: 13) or: [ self peek = (Character codePoint: 10)]). |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
85 |
! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
86 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
87 |
isStartOfLine |
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
88 |
(position = 0) ifTrue: [ ^ true ]. |
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
|
89 |
|
405
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
90 |
self insideCRLF ifTrue: [ ^ false ]. |
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
91 |
|
0470a5e6e712
Merged PetitParser and PetitTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
388
diff
changeset
|
92 |
^ (self peekBack = (Character codePoint: 13)) or: [ self peekBack = (Character codePoint: 10)]. |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
93 |
! ! |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
159
diff
changeset
|
94 |
|
0 | 95 |
!PPStream class methodsFor:'documentation'! |
96 |
||
42 | 97 |
version |
159 | 98 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $' |
42 | 99 |
! |
100 |
||
101 |
version_CVS |
|
159 | 102 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $' |
42 | 103 |
! |
104 |
||
388
74c9c229033b
Workaround to fix PPComposedTest>>testLeftRecursion - make PPStream>>size returning size of the input.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
105 |
version_HG |
74c9c229033b
Workaround to fix PPComposedTest>>testLeftRecursion - make PPStream>>size returning size of the input.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
106 |
|
74c9c229033b
Workaround to fix PPComposedTest>>testLeftRecursion - make PPStream>>size returning size of the input.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
107 |
^ '$Changeset: <not expanded> $' |
74c9c229033b
Workaround to fix PPComposedTest>>testLeftRecursion - make PPStream>>size returning size of the input.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
108 |
! |
74c9c229033b
Workaround to fix PPComposedTest>>testLeftRecursion - make PPStream>>size returning size of the input.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
380
diff
changeset
|
109 |
|
0 | 110 |
version_SVN |
159 | 111 |
^ '$Id: PPStream.st,v 1.4 2014-03-04 14:32:00 cg Exp $' |
0 | 112 |
! ! |
159 | 113 |