author | Claus Gittinger <cg@exept.de> |
Mon, 27 May 2019 16:53:37 +0200 | |
changeset 24192 | 18512bf68422 |
parent 23063 | 5a1e00943c56 |
child 24596 | 2ef21466b617 |
permissions | -rw-r--r-- |
22416 | 1 |
"{ Encoding: utf8 }" |
2 |
||
58 | 3 |
" |
4 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
379 | 5 |
All Rights Reserved |
58 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5394 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17560 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
58 | 18 |
Stream subclass:#PeekableStream |
1295 | 19 |
instanceVariableNames:'' |
10002
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
20 |
classVariableNames:'ErrorDuringFileInSignal CurrentFileInDirectoryQuerySignal |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
21 |
CurrentSourceContainerQuery' |
1295 | 22 |
poolDictionaries:'' |
23 |
category:'Streams' |
|
58 | 24 |
! |
25 |
||
88 | 26 |
!PeekableStream class methodsFor:'documentation'! |
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
379 | 31 |
All Rights Reserved |
58 | 32 |
|
88 | 33 |
This software is furnished under a license and may be used |
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
58 | 41 |
|
88 | 42 |
documentation |
43 |
" |
|
44 |
abstract superclass for all Stream which support read-ahead |
|
45 |
(i.e. peeking) of one element. |
|
46 |
Concrete subclasses must implement a peek method. |
|
1295 | 47 |
|
17560 | 48 |
[caveat:] |
49 |
Basing capabilities like readability/writability/positionability/peekability on inheritance makes |
|
50 |
the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream |
|
51 |
below PositionableStream or ExternalReadStream under WriteStream) |
|
52 |
||
1295 | 53 |
[author:] |
54 |
Claus Gittinger |
|
88 | 55 |
" |
56 |
! ! |
|
58 | 57 |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
58 |
!PeekableStream class methodsFor:'initialization'! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
59 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
60 |
initialize |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
61 |
"setup the signal used to handle errors during fileIn" |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
62 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
63 |
ErrorDuringFileInSignal isNil ifTrue:[ |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
64 |
ErrorDuringFileInSignal := Error newSignalMayProceed:true. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
65 |
ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
66 |
ErrorDuringFileInSignal notifierString:'error during fileIn'. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
67 |
] |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
68 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
69 |
" |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
70 |
self initialize |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
71 |
" |
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
72 |
|
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
73 |
"Modified: / 23-10-2006 / 16:34:41 / cg" |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
74 |
! ! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
75 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
76 |
!PeekableStream class methodsFor:'Signal constants'! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
77 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
78 |
currentFileInDirectoryQuerySignal |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
79 |
"return the querySignal, which can be used to ask for the current directory |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
80 |
during a fileIn (that is the directory where the filed-in file resides), |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
81 |
and in a fileBrowsers doIt. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
82 |
Using this, allows for the loaded code or doIts to ask for the fileBrowsers |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
83 |
current directory, by asking this querySignal (which is nice sometimes)." |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
84 |
|
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
85 |
CurrentFileInDirectoryQuerySignal isNil ifTrue:[ |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
86 |
CurrentFileInDirectoryQuerySignal := QuerySignal new. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
87 |
CurrentFileInDirectoryQuerySignal nameClass:self message:#currentFileInDirectoryQuerySignal. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
88 |
CurrentFileInDirectoryQuerySignal notifierString:'query for current directory when filing in'. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
89 |
CurrentFileInDirectoryQuerySignal handlerBlock:[:ex | ex proceedWith:Filename currentDirectory]. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
90 |
]. |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
91 |
^ CurrentFileInDirectoryQuerySignal |
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
92 |
|
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
93 |
"Modified: / 23-10-2006 / 16:34:37 / cg" |
10002
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
94 |
! |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
95 |
|
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
96 |
currentSourceContainerQuery |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
97 |
"return the querySignal, which can be used to ask for the current source container filename |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
98 |
during a fileIn |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
99 |
Using this, allows for the loaded code to remember the classes file name." |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
100 |
|
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
101 |
CurrentSourceContainerQuery isNil ifTrue:[ |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
102 |
CurrentSourceContainerQuery := QuerySignal new. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
103 |
CurrentSourceContainerQuery nameClass:self message:#currentClassFilenameQuery. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
104 |
CurrentSourceContainerQuery notifierString:'query for current sorce container name when filing in'. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
105 |
CurrentSourceContainerQuery handlerBlock:[:ex | ex proceedWith:nil]. |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
106 |
]. |
10002
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
107 |
^ CurrentSourceContainerQuery |
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
108 |
|
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
109 |
"Modified: / 23-10-2006 / 16:32:49 / cg" |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
110 |
! ! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
111 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
112 |
!PeekableStream class methodsFor:'queries'! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
113 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
114 |
currentFileInDirectory |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
115 |
"during a fileIn (if a script), the script can ask for the current directory" |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
116 |
|
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
117 |
^ self currentFileInDirectoryQuerySignal query |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
118 |
|
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
119 |
"Modified: / 23-10-2006 / 16:34:47 / cg" |
10002
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
120 |
! |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
121 |
|
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
122 |
currentSourceContainer |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
123 |
"during a fileIn (if a script), the script can ask for the current filename" |
3a70c4f5afe0
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9356
diff
changeset
|
124 |
|
10120
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
125 |
^ self currentSourceContainerQuery query |
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
126 |
|
cc81848112f4
allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents:
10002
diff
changeset
|
127 |
"Modified: / 23-10-2006 / 16:33:40 / cg" |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
128 |
! ! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
129 |
|
21033 | 130 |
!PeekableStream class methodsFor:'testing'! |
131 |
||
132 |
isAbstract |
|
133 |
^ self == PeekableStream |
|
134 |
! ! |
|
135 |
||
23063 | 136 |
!PeekableStream methodsFor:'accessing'! |
137 |
||
138 |
contents |
|
139 |
^ self upToEnd. |
|
140 |
||
141 |
"Created: / 11-06-2018 / 13:47:53 / Stefan Vogel" |
|
142 |
! ! |
|
143 |
||
5394 | 144 |
!PeekableStream methodsFor:'chunk input/output'! |
145 |
||
146 |
nextChunk |
|
147 |
"return the next chunk, i.e. all characters up to the next |
|
148 |
exclamation mark. Within the chunk, exclamation marks have to be doubled, |
|
149 |
they are undoubled here. |
|
150 |
Except for primitive code, in which doubling is not needed (allowed). |
|
151 |
This exception was added to make it easier to edit primitive code with |
|
152 |
external editors. However, this means, that other Smalltalks cannot always |
|
153 |
read chunks containing primitive code |
|
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
154 |
- but that doesn't really matter, since C-primitives are an ST/X feature anyway." |
5394 | 155 |
|
18213 | 156 |
|buffer theString chunkSeparator newString done thisChar nextChar |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
157 |
atBeginOfLine inPrimitive hasCR hasLF |
5394 | 158 |
index "{ Class:SmallInteger }" |
159 |
currSize "{ Class:SmallInteger }" | |
|
160 |
||
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
161 |
chunkSeparator := ChunkSeparator. |
18213 | 162 |
buffer := CharacterWriteStream on:(String new:100). |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
163 |
self skipSeparators. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
164 |
thisChar := self nextOrNil. |
5394 | 165 |
done := false. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
166 |
atBeginOfLine := true. |
5394 | 167 |
inPrimitive := false. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
168 |
hasCR := hasLF := false. |
5394 | 169 |
|
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
170 |
[done not and:[thisChar notNil]] whileTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
171 |
"match primitive only at beginning of line |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
172 |
(ExternalStream>>#nextChunk did this, although stc allows primitive to start anywhere)" |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
173 |
|
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
174 |
(atBeginOfLine and:[thisChar == $%]) ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
175 |
nextChar := self peekOrNil. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
176 |
(nextChar == ${ ) ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
177 |
inPrimitive := true. |
18213 | 178 |
buffer nextPut:thisChar. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
179 |
thisChar := self next |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
180 |
] ifFalse:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
181 |
(nextChar == $} ) ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
182 |
inPrimitive := false. |
18213 | 183 |
buffer nextPut:thisChar. |
8192 | 184 |
thisChar := self next |
185 |
] |
|
186 |
] |
|
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
187 |
] ifFalse:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
188 |
"chunk can not end in primitive code" |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
189 |
(inPrimitive not and:[thisChar == chunkSeparator]) ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
190 |
(self peekOrNil == chunkSeparator) ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
191 |
"double chunkSeparator, make single" |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
192 |
self next. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
193 |
] ifFalse:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
194 |
"single chunkSeparator: end of chunk" |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
195 |
done := true. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
196 |
]. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
197 |
]. |
8192 | 198 |
]. |
199 |
done ifFalse:[ |
|
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
200 |
"now map CR LF to LF (ExternalStream>>#nextChunk did this)" |
10351
132061a1ad3f
Fix %{ detection in #nextChunk
Stefan Vogel <sv@exept.de>
parents:
10347
diff
changeset
|
201 |
atBeginOfLine := false. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
202 |
thisChar == Character return ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
203 |
self peekOrNil == Character lf ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
204 |
self next. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
205 |
thisChar := Character lf. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
206 |
hasLF := true. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
207 |
] ifFalse:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
208 |
"CR without LF" |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
209 |
hasCR := true. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
210 |
]. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
211 |
atBeginOfLine := true. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
212 |
] ifFalse:[thisChar == Character lf ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
213 |
hasLF := true. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
214 |
atBeginOfLine := true. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
215 |
]]. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
216 |
|
18213 | 217 |
buffer nextPut:thisChar. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
218 |
thisChar := self nextOrNil. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
219 |
]. |
5394 | 220 |
]. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
221 |
|
18213 | 222 |
theString := buffer contents. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
223 |
(hasCR and:[hasLF not]) ifTrue:[ |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
224 |
"map all CR in a CR only file to NL (ExternalStream>>#nextChunk did this)" |
19642 | 225 |
theString replaceAll:Character return with:Character nl. |
10347
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
226 |
]. |
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
227 |
|
0d5ca408160f
#nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents:
10120
diff
changeset
|
228 |
^ theString |
5394 | 229 |
! ! |
230 |
||
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
231 |
!PeekableStream methodsFor:'fileIn'! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
232 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
233 |
fileIn |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
234 |
"file in from the receiver, i.e. read chunks and evaluate them - |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
235 |
return the value of the last chunk." |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
236 |
|
21470 | 237 |
|notifiedLoader| |
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
238 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
239 |
SourceFileLoader notNil ifTrue:[ |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
240 |
notifiedLoader := SourceFileLoader on:self. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
241 |
]. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
242 |
|
21470 | 243 |
^ Class nameSpaceQuerySignal answer:Smalltalk do:[ |
244 |
self fileInNotifying:notifiedLoader passChunk:true. |
|
12783 | 245 |
]. |
21470 | 246 |
|
247 |
"Modified: / 16-02-2017 / 10:01:43 / stefan" |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
248 |
! |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
249 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
250 |
fileInBinary |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
251 |
"file in from the receiver, i.e. read binary stored classes and/or objects. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
252 |
Return the last object." |
21470 | 253 |
|
254 |
|bos| |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
255 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
256 |
bos := BinaryObjectStorage onOld:self. |
21470 | 257 |
^ [ |
258 |
|obj| |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
259 |
|
21470 | 260 |
[ self atEnd ] whileFalse:[ |
261 |
obj := bos next. |
|
262 |
]. |
|
263 |
obj. |
|
264 |
] on:Class nameSpaceQuerySignal |
|
265 |
do:[:ex | ex proceedWith:Smalltalk ] |
|
266 |
ensure:[ bos close ]. |
|
267 |
||
268 |
"Created: / 13-11-2001 / 10:12:30 / cg" |
|
269 |
"Modified (format): / 16-02-2017 / 14:30:27 / stefan" |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
270 |
! ! |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
271 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
272 |
!PeekableStream methodsFor:'positioning'! |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
273 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
274 |
skipAny:skipCollection |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
275 |
"skip all characters included in the argument-set. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
276 |
returns the next peeked element or nil, if the end-of-stream was reached." |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
277 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
278 |
|nextOne| |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
279 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
280 |
nextOne := self peekOrNil. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
281 |
[nextOne notNil and:[skipCollection includes:nextOne]] whileTrue:[ |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
282 |
self next. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
283 |
nextOne := self peekOrNil |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
284 |
]. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
285 |
^ nextOne |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
286 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
287 |
" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
288 |
|s skipChars| |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
289 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
290 |
s := ReadStream on:'some numbers1234with\in other99 stuff' withCRs. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
291 |
skipChars := 'abcdefghijklmnopqrstuvwxyz\ ' withCRs. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
292 |
s skipAny:skipChars. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
293 |
Transcript showCR:(Integer readFrom:s). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
294 |
s skipAny:skipChars. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
295 |
Transcript showCR:(Integer readFrom:s). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
296 |
" |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
297 |
! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
298 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
299 |
skipSeparators |
16502 | 300 |
"skip all whitespace; |
301 |
return the next peeked element or nil, if the end-of-stream was reached. |
|
302 |
The stream's elements should be characters. |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
303 |
Notice: compare this method to skipSpaces" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
304 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
305 |
|nextOne| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
306 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
307 |
nextOne := self peekOrNil. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
308 |
[nextOne notNil and:[nextOne isSeparator]] whileTrue:[ |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
309 |
self next. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
310 |
nextOne := self peekOrNil |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
311 |
]. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
312 |
^ nextOne |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
313 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
314 |
" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
315 |
|s| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
316 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
317 |
s := ReadStream on:'one two\three' withCRs. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
318 |
s skipSeparators. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
319 |
Transcript showCR:(s nextWord). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
320 |
s skipSeparators. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
321 |
Transcript showCR:(s nextWord). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
322 |
s skipSeparators. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
323 |
Transcript showCR:(s next displayString). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
324 |
" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
325 |
! |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
326 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
327 |
skipSeparatorsExceptCR |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
328 |
"skip all whitespace except carriage return; returns the |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
329 |
next peeked element or nil, if the end-of-stream was reached. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
330 |
The streams elements should be characters. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
331 |
Notice: compare this method to skipSpaces and skipSeparators" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
332 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
333 |
|nextOne| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
334 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
335 |
nextOne := self peekOrNil. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
336 |
[nextOne notNil |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
337 |
and:[nextOne isSeparator |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
338 |
and:[nextOne ~~ Character cr]]] whileTrue:[ |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
339 |
self next. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
340 |
nextOne := self peekOrNil |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
341 |
]. |
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
342 |
^ nextOne |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
343 |
! |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
344 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
345 |
skipSpaces |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
346 |
"skip all spaces; returns the next peeked element or |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
347 |
nil, if the end-of-stream was reached. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
348 |
The streams elements should be characters. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
349 |
Notice: this one skips only spaces (i.e. no cr, tabs etc) |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
350 |
usually, skipSeparators is what you want." |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
351 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
352 |
|nextOne| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
353 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
354 |
nextOne := self peekOrNil. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
355 |
[nextOne notNil and:[nextOne == Character space]] whileTrue:[ |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
356 |
self next. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
357 |
nextOne := self peekOrNil |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
358 |
]. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
359 |
^ nextOne |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
360 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
361 |
" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
362 |
|s| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
363 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
364 |
s := ReadStream on:'one two\three' withCRs. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
365 |
s skipSpaces. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
366 |
Transcript showCR:(s nextWord). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
367 |
s skipSpaces. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
368 |
Transcript showCR:(s nextWord). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
369 |
s skipSpaces. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
370 |
Transcript showCR:(s next displayString). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
371 |
" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
372 |
! ! |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
373 |
|
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
374 |
!PeekableStream methodsFor:'private fileIn'! |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
375 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
376 |
basicFileInNotifying:someone passChunk:passChunk |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
377 |
"central method to file in from the receiver, i.e. read chunks and evaluate them - |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
378 |
return the value of the last chunk. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
379 |
Someone (which is usually some codeView) is notified of errors." |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
380 |
|
21470 | 381 |
|lastValue pkg nameSpace usedNameSpaces |
382 |
packageQuerySignal nameSpaceQuerySignal usedNameSpaceQuerySignal |
|
383 |
changeDefaultApplicationNotificationSignal |
|
384 |
defaultApplicationQuerySignal defaultApplication |
|
385 |
confirmationQuerySignal handledSignals passedSignals askSomeoneForPackage outerContext askForVariableTypeOfUndeclaredQuery| |
|
386 |
||
387 |
self isEncodedStream ifFalse:[ |
|
388 |
"keep the fileIn stuff in this class and not in EncodedStream" |
|
389 |
^ (EncodedStream decodedStreamFor:self) basicFileInNotifying:someone passChunk:passChunk. |
|
390 |
]. |
|
391 |
||
392 |
self skipSeparators. |
|
393 |
lastValue := self peek. |
|
394 |
lastValue == $< ifTrue:[ |
|
395 |
"/ assume, it's an xml file |
|
396 |
^ self fileInXMLNotifying:someone passChunk:passChunk. |
|
397 |
]. |
|
398 |
lastValue == $# ifTrue:[ |
|
399 |
"assume unix interpreter name: |
|
400 |
'#!!stx -e' or something like this" |
|
401 |
self nextPeek == $!! ifTrue:[ |
|
402 |
"skip the unix command line" |
|
403 |
self nextLine |
|
404 |
] ifFalse:[ |
|
405 |
self error:'Invalid chunk start' |
|
406 |
] |
|
407 |
]. |
|
408 |
||
409 |
(Smalltalk at:#Compiler) isNil ifTrue:[ |
|
410 |
self isFileStream ifTrue:[ |
|
411 |
Transcript show:('[' , self pathName , '] '). |
|
412 |
]. |
|
413 |
Transcript showCR:'cannot fileIn (no compiler).'. |
|
414 |
^ nil. |
|
415 |
]. |
|
416 |
||
417 |
"/ support for V'Age applications |
|
418 |
defaultApplicationQuerySignal := Class defaultApplicationQuerySignal. |
|
419 |
changeDefaultApplicationNotificationSignal := Class changeDefaultApplicationNotificationSignal. |
|
420 |
||
421 |
"/ support for ST/X's nameSpaces & packages |
|
422 |
packageQuerySignal := Class packageQuerySignal. |
|
423 |
nameSpaceQuerySignal := Class nameSpaceQuerySignal. |
|
424 |
usedNameSpaceQuerySignal := Class usedNameSpaceQuerySignal. |
|
425 |
||
426 |
askSomeoneForPackage := someone respondsTo:#packageToInstall. |
|
427 |
askSomeoneForPackage ifTrue:[ |
|
428 |
pkg := someone packageToInstall. |
|
429 |
] ifFalse:[ |
|
430 |
pkg := packageQuerySignal query. |
|
431 |
]. |
|
432 |
(someone respondsTo:#currentNameSpace) ifTrue:[ |
|
433 |
nameSpace := someone currentNameSpace |
|
434 |
] ifFalse:[ |
|
435 |
nameSpace := nameSpaceQuerySignal query. |
|
436 |
]. |
|
437 |
(someone respondsTo:#usedNameSpaces) ifTrue:[ |
|
438 |
usedNameSpaces := someone usedNameSpaces |
|
439 |
] ifFalse:[ |
|
440 |
usedNameSpaces := usedNameSpaceQuerySignal query. |
|
441 |
]. |
|
442 |
(someone respondsTo:#defaultApplication) ifTrue:[ |
|
443 |
defaultApplication := someone defaultApplication |
|
444 |
] ifFalse:[ |
|
445 |
defaultApplication := defaultApplicationQuerySignal query. |
|
446 |
]. |
|
447 |
||
448 |
confirmationQuerySignal := Metaclass confirmationQuerySignal. |
|
449 |
||
450 |
handledSignals := SignalSet new. |
|
451 |
passedSignals := IdentitySet new. |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
452 |
|
21470 | 453 |
handledSignals add:changeDefaultApplicationNotificationSignal. |
454 |
passedSignals add:changeDefaultApplicationNotificationSignal. |
|
455 |
handledSignals add:defaultApplicationQuerySignal. |
|
456 |
passedSignals add:defaultApplicationQuerySignal. |
|
457 |
||
458 |
handledSignals add:packageQuerySignal. |
|
459 |
handledSignals add:usedNameSpaceQuerySignal. |
|
460 |
handledSignals add:nameSpaceQuerySignal. |
|
461 |
handledSignals add:confirmationQuerySignal. |
|
462 |
passedSignals add:confirmationQuerySignal. |
|
463 |
Parser notNil ifTrue:[ |
|
464 |
"only if libcomp is present" |
|
465 |
"Also catch a 'Parser askForVariableTypeOfUndeclaredQuery' and proceed with nil. |
|
466 |
Imagine somebody has autodefine workspace variables on and then |
|
467 |
evaluate Smalltalk loadPackage:'xyz' that loads code from source (using file-in), |
|
468 |
certainly we don't want to compile workspace variable access for every |
|
469 |
not-yet-loaded class in some namespace. |
|
470 |
This is demonstrated by Regression::CompilerTests2>>test_01 |
|
471 |
and this change actually fixes this test." |
|
472 |
askForVariableTypeOfUndeclaredQuery := Parser askForVariableTypeOfUndeclaredQuery. |
|
473 |
handledSignals add:askForVariableTypeOfUndeclaredQuery. |
|
474 |
]. |
|
475 |
||
476 |
||
477 |
outerContext := thisContext. |
|
478 |
||
479 |
handledSignals handle:[:ex | |
|
480 |
|sig| |
|
481 |
||
482 |
sig := ex creator. |
|
483 |
((passedSignals includes:sig) and:[sig isHandledIn:outerContext]) ifTrue:[ |
|
484 |
ex reject |
|
485 |
]. |
|
486 |
||
487 |
sig == changeDefaultApplicationNotificationSignal ifTrue:[ |
|
488 |
"/ invoked via #becomeDefault to set the defaultApp and the package. |
|
489 |
"/ (only when filing in V'Age code) |
|
490 |
defaultApplication := ex parameter. |
|
491 |
pkg := defaultApplication name asSymbol. |
|
492 |
ex proceedWith:nil |
|
493 |
]. |
|
494 |
sig == defaultApplicationQuerySignal ifTrue:[ |
|
495 |
"/ query for the application to add classes & methods into |
|
496 |
"/ (only when filing in V'Age code) |
|
497 |
ex proceedWith:defaultApplication |
|
498 |
]. |
|
499 |
sig == packageQuerySignal ifTrue:[ |
|
500 |
"answer the package to use for classes & methods" |
|
501 |
askSomeoneForPackage ifTrue:[ |
|
502 |
ex proceedWith:someone packageToInstall |
|
503 |
] ifFalse:[ |
|
504 |
ex proceedWith:pkg |
|
505 |
] |
|
506 |
]. |
|
507 |
sig == usedNameSpaceQuerySignal ifTrue:[ |
|
508 |
"answer the nameSpaces to be searched when encountering globals" |
|
509 |
ex proceedWith:usedNameSpaces |
|
510 |
]. |
|
511 |
sig == nameSpaceQuerySignal ifTrue:[ |
|
512 |
"answer the nameSpace to install new classes in" |
|
513 |
ex proceedWith:nameSpace |
|
514 |
]. |
|
515 |
sig == confirmationQuerySignal ifTrue:[ |
|
516 |
"don't pop up dialogs" |
|
517 |
ex proceedWith:false |
|
518 |
]. |
|
519 |
sig == askForVariableTypeOfUndeclaredQuery ifTrue:[ |
|
520 |
"no autodefined variables or so" |
|
521 |
ex proceedWith:nil. |
|
522 |
]. |
|
523 |
] do:[ |
|
524 |
[self atEnd] whileFalse:[ |
|
525 |
lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk silent:nil. |
|
526 |
] |
|
527 |
]. |
|
528 |
^ lastValue |
|
529 |
||
15965 | 530 |
"Modified: / 16-11-2001 / 16:21:28 / cg" |
531 |
"Modified: / 25-03-2013 / 22:57:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
21470 | 532 |
"Modified: / 16-02-2017 / 15:20:02 / stefan" |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
533 |
! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
534 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
535 |
fileInNextChunkNotifying:someone |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
536 |
"read next chunk, evaluate it and return the result; |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
537 |
someone (which is usually some codeView) is notified of errors. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
538 |
Filein is done as follows: |
21470 | 539 |
read a chunk |
540 |
if it started with an excla, evaluate it, and let the resulting object |
|
541 |
fileIn more chunks. |
|
542 |
This is a nice trick, since the methodsFor: expression evaluates to |
|
543 |
a ClassCategoryReader which reads and compiles chunks for its class. |
|
544 |
However, other than methodsFor expressions are possible - you can |
|
545 |
(in theory) create readers for any syntax. |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
546 |
" |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
547 |
|
21470 | 548 |
^ self fileInNextChunkNotifying:someone passChunk:false silent:nil. |
549 |
||
550 |
"Modified: / 16-02-2017 / 15:17:22 / stefan" |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
551 |
! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
552 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
553 |
fileInNextChunkNotifying:someone passChunk:passChunk |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
554 |
"read next chunk, evaluate it and return the result; |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
555 |
someone (which is usually some codeView) is notified of errors. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
556 |
Filein is done as follows: |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
557 |
read a chunk |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
558 |
if it started with an excla, evaluate it, and let the resulting object |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
559 |
fileIn more chunks. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
560 |
This is a nice trick, since the methodsFor: expression evaluates to |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
561 |
a ClassCategoryReader which reads and compiles chunks for its class. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
562 |
However, other than methodsFor expressions are possible - you can |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
563 |
(in theory) create readers for any syntax. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
564 |
" |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
565 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
566 |
^ self fileInNextChunkNotifying:someone passChunk:passChunk silent:nil |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
567 |
! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
568 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
569 |
fileInNextChunkNotifying:someone passChunk:passChunk silent:beSilent |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
570 |
"read next chunk, evaluate it and return the result; |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
571 |
someone (which is usually some codeView) is notified of errors. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
572 |
Filein is done as follows: |
11497
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
573 |
read a chunk |
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
574 |
if it started with an excla, evaluate it, and let the resulting object |
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
575 |
fileIn more chunks. |
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
576 |
This is a nice trick, since the methodsFor: expression evaluates to |
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
577 |
a ClassCategoryReader which reads and compiles chunks for its class. |
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
578 |
However, other than methodsFor expressions are possible - you can |
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
579 |
(in theory) create readers for any syntax. |
21470 | 580 |
The beSilent argument controls output to the transcript, if it's true or |
581 |
false. If it's nil, output is controlled by the Smalltalk>>silenLoading setting." |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
582 |
|
21470 | 583 |
|aString sawExcla rslt compiler lastClass| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
584 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
585 |
self skipSeparators. |
21470 | 586 |
self atEnd ifTrue:[ |
587 |
^ nil. |
|
588 |
]. |
|
589 |
||
590 |
sawExcla := self peekFor:(self class chunkSeparator). |
|
591 |
aString := self nextChunk. |
|
592 |
"/ |
|
593 |
"/ handle empty chunks; |
|
594 |
"/ this allows for Squeak code to be filedIn |
|
595 |
"/ |
|
596 |
[aString isEmpty and:[self atEnd not]] whileTrue:[ |
|
11497
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
597 |
aString := self nextChunk. |
21470 | 598 |
]. |
599 |
aString isEmpty ifTrue:[ |
|
600 |
^ nil. |
|
601 |
]. |
|
602 |
||
603 |
(passChunk and:[someone notNil]) ifTrue:[ |
|
604 |
someone source:aString. |
|
605 |
]. |
|
606 |
someone perform:#reader: with:(SourceFileLoader::SourceFileReader new) ifNotUnderstood:[]. |
|
607 |
compiler := (Smalltalk at:#Compiler) new. |
|
608 |
compiler allowUndeclaredVariables:false. |
|
609 |
||
610 |
sawExcla ifFalse:[ |
|
611 |
"/ class definition chunks, etc., which are simply evaluated |
|
612 |
rslt := compiler evaluate:aString receiver:someone notifying:someone compile:false. |
|
613 |
rslt isBehavior ifTrue:[ |
|
614 |
lastClass := rslt |
|
615 |
] ifFalse:[ |
|
616 |
lastClass := nil |
|
11497
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
617 |
]. |
21470 | 618 |
] ifTrue:[ |
619 |
"/ methodsFor chunks, etc., which generate a reader |
|
22704 | 620 |
compiler class emptySourceNotificationSignal handle:[:ex | |
21470 | 621 |
^ nil |
622 |
] do:[ |
|
623 |
rslt := compiler |
|
624 |
evaluate:aString |
|
625 |
notifying:someone |
|
626 |
compile:false. |
|
627 |
]. |
|
13282
9b8542c8439e
changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents:
12785
diff
changeset
|
628 |
|
21470 | 629 |
" |
630 |
usually, the above chunk consists of some methodsFor:-expression |
|
631 |
in this case, the returned value is a ClassCategoryReader, |
|
632 |
which is used to load & compile the methods ... |
|
633 |
" |
|
634 |
(rslt isNil or:[rslt == #Error]) ifTrue:[ |
|
635 |
" |
|
636 |
however, if that was nil (i.e. some error), we skip chunks |
|
637 |
up to the next empty chunk. |
|
638 |
" |
|
639 |
Transcript showCR:'skipping chunks ...'. |
|
640 |
[ |
|
641 |
aString := self nextChunk. |
|
642 |
] doWhile:[aString notEmpty]. |
|
643 |
] ifFalse:[ |
|
644 |
Class packageQuerySignal handle:[:ex | |
|
645 |
lastClass notNil ifTrue:[ |
|
646 |
ex proceedWith:lastClass package |
|
19122 | 647 |
] ifFalse:[ |
21470 | 648 |
ex reject |
649 |
]. |
|
650 |
] do:[ |
|
651 |
rslt := rslt |
|
652 |
fileInFrom:self |
|
653 |
notifying:someone |
|
654 |
passChunk:passChunk |
|
655 |
single:false |
|
656 |
silent:beSilent |
|
657 |
]. |
|
11497
ac8024ede0ff
changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents:
11139
diff
changeset
|
658 |
] |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
659 |
]. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
660 |
^ rslt |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
661 |
|
13282
9b8542c8439e
changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents:
12785
diff
changeset
|
662 |
"Modified: / 05-02-2011 / 10:06:57 / cg" |
22704 | 663 |
"Modified: / 24-04-2018 / 22:46:36 / stefan" |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
664 |
! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
665 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
666 |
fileInNotifying:notifiedLoader passChunk:passChunk |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
667 |
"central method to file in from the receiver, i.e. read chunks and evaluate them - |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
668 |
return the value of the last chunk. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
669 |
Someone (which is usually some codeView) is notified of errors." |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
670 |
|
10394
485f6c2d8db0
Do not refer to non-existant aspect
Stefan Vogel <sv@exept.de>
parents:
10356
diff
changeset
|
671 |
^ self basicFileInNotifying:notifiedLoader passChunk:passChunk. |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
672 |
! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
673 |
|
21470 | 674 |
fileInNotifying:notifiedLoader passChunk:passChunk inDirectory:aDirectory |
675 |
"central method to file in from the receiver, i.e. read chunks and evaluate them - |
|
676 |
return the value of the last chunk. |
|
677 |
Someone (which is usually some codeView) is notified of errors. |
|
678 |
Add aDirectory to the search path for classes, while performing the fileIn." |
|
679 |
||
680 |
|oldPath thisDirectory thisDirectoryPathName| |
|
681 |
||
682 |
thisDirectory := aDirectory asFilename. |
|
683 |
thisDirectoryPathName := thisDirectory pathName. |
|
684 |
oldPath := Smalltalk systemPath. |
|
685 |
||
686 |
^ [ |
|
687 |
Smalltalk systemPath:(oldPath copyWithFirst:thisDirectoryPathName). |
|
688 |
self class currentFileInDirectoryQuerySignal answer:thisDirectory do:[ |
|
689 |
self class currentSourceContainerQuery answer:self do:[ |
|
690 |
self basicFileInNotifying:notifiedLoader passChunk:passChunk. |
|
691 |
]. |
|
692 |
] |
|
693 |
] ensure:[ |
|
694 |
"take care, someone could have changed SystemPath during fileIn!!" |
|
695 |
(Smalltalk systemPath copyFrom:2) = oldPath ifTrue:[ |
|
696 |
Smalltalk systemPath:oldPath. |
|
697 |
] ifFalse:[ |
|
698 |
(oldPath includes:thisDirectoryPathName) ifFalse:[ |
|
699 |
Smalltalk systemPath remove:thisDirectoryPathName ifAbsent:[]. |
|
700 |
Smalltalk flushPathCaches. |
|
701 |
]. |
|
702 |
]. |
|
703 |
]. |
|
704 |
||
705 |
"Modified: / 23-10-2006 / 16:35:10 / cg" |
|
706 |
"Modified: / 16-02-2017 / 14:51:48 / stefan" |
|
707 |
! |
|
708 |
||
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
709 |
fileInXMLNotifying:someone passChunk:passChunk |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
710 |
"filein an XML source file (format as in campSmalltalk DTD)" |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
711 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
712 |
| builder parser| |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
713 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
714 |
(XML isNil or:[XML::SourceNodeBuilder isNil or:[XML::XMLParser isNil]]) ifTrue:[ |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
715 |
Smalltalk loadPackage:'stx:goodies/xml/vw'. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
716 |
(XML isNil or:[XML::SourceNodeBuilder isNil or:[XML::XMLParser isNil]]) ifTrue:[ |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
717 |
self error:'Could not load XML package(s) from ''stx:goodies/xml/vw'''. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
718 |
] |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
719 |
]. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
720 |
|
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
721 |
builder := XML::SourceNodeBuilder new. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
722 |
parser := XML::XMLParser on:self. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
723 |
parser builder:builder. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
724 |
parser validate:false. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
725 |
parser scanDocument. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
726 |
"/ self halt. |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
727 |
! ! |
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
728 |
|
4404 | 729 |
!PeekableStream methodsFor:'reading'! |
730 |
||
731 |
nextPeek |
|
732 |
"advance to next element and return the peeked element" |
|
733 |
||
734 |
self next. |
|
735 |
^ self peek |
|
736 |
! |
|
737 |
||
20128 | 738 |
nextPeekOrNil |
739 |
"advance to next element and return the peeked element" |
|
740 |
||
741 |
self nextOrNil. |
|
742 |
^ self peekOrNil |
|
743 |
! |
|
744 |
||
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
745 |
nextUpTo:anObject |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
746 |
"read a collection of all objects up-to anObject and return these |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
747 |
elements, but excluding anObject. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
748 |
The next read operation will return anObject. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
749 |
If anObject is not encountered, all elements up to the end are read |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
750 |
and returned, and the stream is positioned at the end. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
751 |
Compare this with #upTo: which positions behind anObject" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
752 |
|
22416 | 753 |
|answerStream| |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
754 |
|
22416 | 755 |
answerStream := self contentsSpecies writeStream. |
756 |
[self atEnd or:[anObject = self peek]] whileFalse:[ |
|
757 |
answerStream nextPut:self next. |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
758 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
759 |
^ answerStream contents |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
760 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
761 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
762 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
763 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
764 |
Transcript showCR:(s nextUpTo:4). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
765 |
Transcript showCR:s next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
766 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
767 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
768 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
769 |
Transcript showCR:(s upTo:4). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
770 |
Transcript showCR:s next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
771 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
772 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
773 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
774 |
Transcript showCR:(s nextUpTo:9). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
775 |
Transcript showCR:s next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
776 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
777 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
778 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
779 |
Transcript showCR:(s upTo:9). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
780 |
Transcript showCR:s next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
781 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
782 |
|
22416 | 783 |
"Created: / 24-01-1997 / 14:08:35 / cg" |
784 |
"Modified: / 10-01-2018 / 18:29:47 / stefan" |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
785 |
! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
786 |
|
4404 | 787 |
peek |
788 |
"return the next element of the stream without advancing (i.e. |
|
789 |
the following send of next will return this element again.) |
|
790 |
- we do not know here how to do it, it must be redefined in subclass" |
|
791 |
||
792 |
^ self subclassResponsibility |
|
793 |
! |
|
794 |
||
795 |
peekFor:anObject |
|
796 |
"if the next-to-be-read object is equal to the argument, anObject, read it |
|
797 |
and return true. Otherwise, leave the receiver unaffected and return false." |
|
798 |
||
799 |
self peek = anObject ifTrue:[ |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
800 |
self nextOrNil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
801 |
^ true |
4404 | 802 |
]. |
803 |
^ false |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
804 |
|
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
805 |
" |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
806 |
#() readStream peekFor:nil |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
807 |
#() readStream signalAtEnd:true; peekFor:nil |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
808 |
#(nil) readStream peekFor:nil |
18479 | 809 |
'abc' readStream next; peekFor:$b. |
810 |
'abc' readStream next; peekFor:$c. |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
811 |
" |
68 | 812 |
! |
813 |
||
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
814 |
peekOrNil |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
815 |
"like #peek, this returns the next readAhead element, if available. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
816 |
However, unlike #peek, this does not raise an atEnd-query signal - even |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
817 |
if handled. Instead, nil is returned immediately." |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
818 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
819 |
self atEnd ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
820 |
^ self peek |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
821 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
822 |
"Created: / 5.3.1998 / 02:56:49 / cg" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
823 |
"Modified: / 5.3.1998 / 13:45:07 / cg" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
824 |
! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
825 |
|
21135 | 826 |
skipUntil:aBlock |
827 |
"skip all elements for which aBlock returns false. |
|
828 |
Return true if more elements can be read, false if eof has been reached." |
|
829 |
||
830 |
[self atEnd] whileFalse:[ |
|
831 |
(aBlock value: self peek) ifTrue:[^ true]. |
|
832 |
self next |
|
833 |
]. |
|
834 |
^ false |
|
835 |
||
836 |
" |
|
837 |
#(1 2 3 4 5 6 7 8 9 10) readStream |
|
838 |
skipUntil:[:el | el >= 5]; |
|
839 |
next |
|
840 |
" |
|
841 |
! |
|
842 |
||
843 |
skipWhile:aBlock |
|
844 |
"skip all elements for which aBlock returns true. Return true if more elements can be read, |
|
845 |
false if eof has been reached." |
|
846 |
||
847 |
[self atEnd] whileFalse:[ |
|
848 |
(aBlock value: self peek) ifFalse:[^ true]. |
|
849 |
self next |
|
850 |
]. |
|
851 |
^ false |
|
852 |
||
853 |
" |
|
854 |
#(1 2 3 4 5 6 7 8 9 10) readStream |
|
855 |
skipWhile:[:el | el <= 5]; |
|
856 |
next |
|
857 |
" |
|
858 |
||
859 |
"Created: / 23-09-2011 / 13:32:40 / cg" |
|
860 |
! |
|
861 |
||
11139 | 862 |
throughAnyForWhich:checkBlock |
863 |
"read & return a collection of all objects up-to and including |
|
864 |
the elements for which checkBlock returns true. |
|
865 |
(i.e. read until checkBlock returns false on an element) |
|
866 |
If no such element is encountered, all elements up to the end are read |
|
867 |
and returned." |
|
868 |
||
22416 | 869 |
|answerStream| |
11139 | 870 |
|
22416 | 871 |
answerStream := self contentsSpecies writeStream. |
872 |
[self atEnd or:[(checkBlock value:self peek) not]] whileFalse:[ |
|
873 |
answerStream nextPut:self next. |
|
11139 | 874 |
]. |
875 |
^ answerStream contents |
|
876 |
||
877 |
" |
|
878 |
|s| |
|
879 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
22416 | 880 |
Transcript showCR:(s throughAnyForWhich:[:e| e <= 4]). |
11139 | 881 |
Transcript showCR:s next |
882 |
||
883 |
|s| |
|
884 |
s := ReadStream on:'hello world, this is some text'. |
|
885 |
Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]). |
|
886 |
Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]). |
|
887 |
Transcript showCR:s upToEnd. |
|
888 |
" |
|
889 |
||
22416 | 890 |
"Modified: / 11-01-1998 / 15:28:04 / cg" |
891 |
"Modified: / 10-01-2018 / 18:29:51 / stefan" |
|
892 |
"Modified (comment): / 10-01-2018 / 23:18:08 / stefan" |
|
21135 | 893 |
! |
894 |
||
895 |
upToAny:aCollectionOfObjects |
|
22631 | 896 |
"read a collection of all objects up to an element that is contained in |
21135 | 897 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
898 |
The next read operation will return the element AFTER anObject. |
|
899 |
If no such element is encountered, all elements up to the end are read |
|
900 |
and returned. |
|
901 |
Compare this with #throughAll: which also reads up to some object |
|
902 |
and also positions behind it, but DOES include it in the returned |
|
903 |
value." |
|
904 |
||
905 |
|result| |
|
906 |
||
907 |
result := self upToBeforeAny:aCollectionOfObjects. |
|
908 |
self atEnd ifFalse:[ |
|
909 |
self next. |
|
910 |
]. |
|
911 |
^ result |
|
912 |
||
913 |
" |
|
914 |
|s| |
|
915 |
s := ReadStream on:'hello world'. |
|
916 |
Transcript showCR:(s upToAny:(Array with:Character space)). |
|
917 |
Transcript showCR:(s upToEnd) |
|
918 |
||
919 |
'Makefile' asFilename readStream upToAny:($A to:$Z) |
|
920 |
" |
|
921 |
||
922 |
"Created: / 30.8.1997 / 03:02:05 / cg" |
|
923 |
"Modified: / 11.1.1998 / 15:19:18 / cg" |
|
924 |
! |
|
925 |
||
926 |
upToBeforeAny:aCollectionOfObjects |
|
22631 | 927 |
"read a collection of all objects up to an element that is contained in |
21135 | 928 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
929 |
The next read operation will return the matching element. |
|
930 |
If no such element is encountered, all elements up to the end are read |
|
931 |
and returned. |
|
932 |
This returns the exact same as upToAny: would, but leaves the stream's position so that |
|
933 |
the next read returns the matching delimiter instead of skipping it. |
|
934 |
Caveat: this is the one which should have been called upTo: in the first place; |
|
935 |
however, it seems now too late for a change." |
|
936 |
||
22416 | 937 |
|answerStream| |
21135 | 938 |
|
22416 | 939 |
answerStream := self contentsSpecies writeStream. |
940 |
[self atEnd or:[aCollectionOfObjects includes:self peek]] whileFalse:[ |
|
941 |
answerStream nextPut:self next. |
|
21135 | 942 |
]. |
943 |
^ answerStream contents |
|
944 |
||
945 |
" |
|
946 |
|s| |
|
947 |
s := ReadStream on:'hello world'. |
|
948 |
Transcript showCR:(s upToBeforeAny:(Array with:Character space)). |
|
949 |
Transcript showCR:(s upToEnd) |
|
950 |
||
951 |
'Make.proto' asFilename readStream upToBeforeAny:($A to:$Z) |
|
952 |
" |
|
953 |
||
22416 | 954 |
"Created: / 30-08-1997 / 03:02:05 / cg" |
955 |
"Modified: / 11-01-1998 / 15:19:18 / cg" |
|
956 |
"Modified: / 10-01-2018 / 18:29:57 / stefan" |
|
21135 | 957 |
! |
958 |
||
959 |
upToElementForWhich:aBlock |
|
960 |
"read elements until aBlock returns true for an element. |
|
961 |
Return the collected elements excluding that element. |
|
962 |
Leave the stream positioned for the next read to return that element. |
|
963 |
If no element matches, all elements up to the end are returned" |
|
964 |
||
22416 | 965 |
|answerStream| |
21135 | 966 |
|
22416 | 967 |
answerStream := self contentsSpecies writeStream. |
968 |
[self atEnd or:[aBlock value:self peek]] whileFalse:[ |
|
969 |
answerStream nextPut:self next. |
|
21135 | 970 |
]. |
971 |
^ answerStream contents |
|
972 |
||
973 |
" |
|
974 |
#(1 2 3 4 5 6 7 8 9 10) readStream |
|
975 |
upToElementForWhich:[:el | el > 5] |
|
976 |
" |
|
22416 | 977 |
|
978 |
"Modified: / 10-01-2018 / 18:30:03 / stefan" |
|
979 |
! |
|
980 |
||
981 |
upToMatching:aBlock |
|
982 |
"Return the next elements up to but not including the next element |
|
983 |
for which aBlock returns true. |
|
984 |
The next read will return that matching element. |
|
985 |
If none matches, the remaining elements up to the end are returned." |
|
986 |
||
987 |
^ self upToElementForWhich:aBlock |
|
988 |
||
989 |
" |
|
990 |
'hello world' readStream upToMatching:[:c | c isSeparator]. |
|
991 |
" |
|
992 |
" |
|
993 |
'helloworld' readStream upToMatching:[:c | c isSeparator]. |
|
994 |
" |
|
995 |
" |
|
996 |
|s| |
|
997 |
||
998 |
s := 'hello world' readStream. |
|
999 |
s upToMatching:[:c | c isSeparator]. |
|
1000 |
s upToEnd |
|
1001 |
" |
|
1002 |
||
1003 |
"Modified: / 26-02-1997 / 12:20:57 / cg" |
|
1004 |
"Modified (comment): / 10-01-2018 / 23:20:32 / stefan" |
|
1005 |
! |
|
1006 |
||
1007 |
upToSeparator |
|
1008 |
"Return the next elements up to but not including the next separator. |
|
1009 |
The next read will return the separator. |
|
1010 |
If no separator is encountered, the contents up to the end is returned. |
|
1011 |
The elements are supposed to understand #isSeparator |
|
1012 |
(i.e. the receiver is supposed to be a character-stream)." |
|
1013 |
||
1014 |
^ self upToElementForWhich:[:ch | ch isSeparator] |
|
1015 |
||
1016 |
" |
|
1017 |
'hello world' readStream upToSeparator |
|
1018 |
'helloworld' readStream upToSeparator |
|
1019 |
'helloworld' readStream upToSeparator |
|
1020 |
'' readStream upToSeparator |
|
1021 |
||
1022 |
|s| |
|
1023 |
s := 'hello world' readStream. |
|
1024 |
s upToSeparator. |
|
1025 |
s upToEnd |
|
1026 |
" |
|
1027 |
||
1028 |
"Modified: 4.1.1997 / 23:38:05 / cg" |
|
21135 | 1029 |
! ! |
1030 |
||
1031 |
!PeekableStream methodsFor:'reading-numbers'! |
|
1032 |
||
1033 |
nextDecimalInteger |
|
21754 | 1034 |
"read the next integer in radix 10. |
21135 | 1035 |
Does NOT skip initial whitespace. |
1036 |
The streams elements should be characters. |
|
1037 |
||
21754 | 1038 |
Be careful - this method returns 0 if not positioned on a digit initially |
21135 | 1039 |
or if the end of the stream is encountered." |
1040 |
||
1041 |
|nextOne value| |
|
1042 |
||
1043 |
nextOne := self peekOrNil. |
|
1044 |
value := 0. |
|
1045 |
[nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[ |
|
1046 |
value := (value * 10) + nextOne digitValue. |
|
1047 |
self next. |
|
1048 |
nextOne := self peekOrNil |
|
1049 |
]. |
|
1050 |
^ value |
|
1051 |
||
1052 |
" |
|
1053 |
|s| |
|
1054 |
||
1055 |
s := '1234 5678' readStream. |
|
21754 | 1056 |
s nextDecimalInteger. |
21135 | 1057 |
" |
1058 |
||
1059 |
" |
|
1060 |
|s| |
|
1061 |
||
1062 |
s := '1234 5678' readStream. |
|
1063 |
s nextDecimalInteger. |
|
1064 |
s skipSpaces. |
|
21754 | 1065 |
s nextDecimalInteger. |
21135 | 1066 |
" |
21754 | 1067 |
|
1068 |
"Modified (comment): / 17-05-2017 / 15:13:04 / mawalch" |
|
611 | 1069 |
! ! |
58 | 1070 |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1071 |
!PeekableStream methodsFor:'reading-strings'! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1072 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1073 |
nextAlphaNumericWord |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1074 |
"read the next word (i.e. up to non letter-or-digit). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1075 |
Return a string containing those characters. |
18273 | 1076 |
Any leading non-alphaNumeric chars are skipped. |
1077 |
||
1078 |
National letters or digits in unicode are not treated as letters." |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1079 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1080 |
|s c| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1081 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1082 |
"first: skip white space and other garbage, leave first character in c" |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1083 |
[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1084 |
c := self nextOrNil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1085 |
c isNil ifTrue:[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1086 |
"end of stream" |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1087 |
^ nil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1088 |
]. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1089 |
c isLetterOrDigit |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1090 |
] whileFalse. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1091 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1092 |
"second: get the alphanumeric word" |
22416 | 1093 |
s := self contentsSpecies writeStream:100. |
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1094 |
[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1095 |
s nextPut:c. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1096 |
c := self peekOrNil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1097 |
(c notNil and:[c isLetterOrDigit]) ifTrue:[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1098 |
self next. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1099 |
true. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1100 |
] ifFalse:[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1101 |
false. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1102 |
] |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1103 |
] whileTrue. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1104 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1105 |
^ s contents. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1106 |
|
18273 | 1107 |
"Use UnicodeString in the examples, to avoid the optimization in ReadStream for Strings" |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1108 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1109 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1110 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1111 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1112 |
s := 'hello world 1234 foo1 foo2' asUnicodeString readStream. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1113 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1114 |
Transcript showCR:(s nextAlphaNumericWord). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1115 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1116 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1117 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1118 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1119 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1120 |
|
22416 | 1121 |
s := 'hello +++ #world привiт ###123###abc### 1234 foo1 foo2++++' asUnicodeString readStream. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1122 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1123 |
Transcript showCR:(s nextAlphaNumericWord). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1124 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1125 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1126 |
|
22416 | 1127 |
"Modified: / 15-05-1996 / 17:51:42 / cg" |
1128 |
"Modified: / 10-01-2018 / 18:34:42 / stefan" |
|
1129 |
! |
|
1130 |
||
1131 |
nextDelimited:terminator |
|
1132 |
"return the contents of the receiver, up to the next terminator element. |
|
1133 |
Doubled terminators indicate an embedded terminator element. |
|
1134 |
For example: 'this '' was a quote'. |
|
1135 |
Start positioned before the initial terminator." |
|
1136 |
||
1137 |
| out element | |
|
1138 |
||
1139 |
self atEnd ifTrue: [^ '']. |
|
1140 |
self peek = terminator ifTrue: [self next]. "absorb initial terminator" |
|
1141 |
out := self contentsSpecies writeStream. |
|
1142 |
[(element := self nextOrNil) isNil and:[self atEnd]] whileFalse:[ |
|
1143 |
element = terminator ifTrue: [ |
|
1144 |
self peek ~= terminator ifTrue: [ |
|
1145 |
^ out contents "terminator is not doubled; we're done!!" |
|
1146 |
]. |
|
1147 |
self next. "skip doubled terminator" |
|
1148 |
]. |
|
1149 |
out nextPut:element. |
|
1150 |
]. |
|
1151 |
^ out contents |
|
1152 |
||
1153 |
" |
|
1154 |
('*foo bar baz* more foo' readStream nextDelimited:$*) |
|
1155 |
('*foo bar **baz***' readStream nextDelimited:$*) |
|
1156 |
" |
|
1157 |
||
1158 |
"Modified: / 10-01-2018 / 18:29:42 / stefan" |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1159 |
! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1160 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1161 |
nextMatching:matchBlock1 thenMatching:matchBlock2 |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1162 |
"read the next word. The first character must match matchBlock1, |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1163 |
remaining characters must match matchBlock2. |
16376 | 1164 |
Return a string containing those characters. |
1165 |
Useful to read identifiers, where the first char is from a different |
|
1166 |
set than the remaining (letter vs. letterOrDigit)" |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1167 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1168 |
|s c| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1169 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1170 |
self atEnd ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1171 |
(matchBlock1 value:self peek) ifFalse:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1172 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1173 |
s := self next asString. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1174 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1175 |
[self atEnd not |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1176 |
and:[matchBlock2 value:(c := self peek)]] whileTrue:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1177 |
s := s copyWith:c. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1178 |
self next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1179 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1180 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1181 |
s size == 0 ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1182 |
^ s. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1183 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1184 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1185 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1186 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1187 |
s := 'hello_world_1234 foo1 foo2' readStream. |
16375 | 1188 |
s nextMatching:[:c | c isLetter] |
1189 |
thenMatching:[:c | c isLetterOrDigit or:[c == $_]]. |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1190 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1191 |
! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1192 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1193 |
nextSymbol |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1194 |
"read the next selector-symbol (i.e. up to non letter-or-digit). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1195 |
Return a string containing those characters. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1196 |
Any leading non-alphaNumeric chars are skipped." |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1197 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1198 |
|symbol c symbolStream| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1199 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1200 |
[self atEnd |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1201 |
or:[(c := self peek) isLetterOrDigit]] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1202 |
self next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1203 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1204 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1205 |
self atEnd ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1206 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1207 |
symbolStream := '' writeStream. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1208 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1209 |
[self atEnd not |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1210 |
and:[(c := self peek) isLetterOrDigit or:[c == $:]]] whileTrue:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1211 |
symbolStream nextPut:c. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1212 |
self next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1213 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1214 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1215 |
symbol := symbolStream contents. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1216 |
symbol size == 0 ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1217 |
^ symbol. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1218 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1219 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1220 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1221 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1222 |
s := 'hello: world 1234 foo1 foo2:' readStream. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1223 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1224 |
Transcript showCR:(s nextSymbol). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1225 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1226 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1227 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1228 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1229 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1230 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1231 |
s := 'hello +++ #world ###123###abc### 1234 foo1 foo2' readStream. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1232 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1233 |
Transcript showCR:(s nextAlphaNumericWord). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1234 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1235 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1236 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1237 |
"Modified: 15.5.1996 / 17:51:42 / cg" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1238 |
! ! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1239 |
|
701 | 1240 |
!PeekableStream class methodsFor:'documentation'! |
1241 |
||
1242 |
version |
|
18479 | 1243 |
^ '$Header$' |
12783 | 1244 |
! |
1245 |
||
1246 |
version_CVS |
|
18479 | 1247 |
^ '$Header$' |
701 | 1248 |
! ! |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
1249 |
|
14900 | 1250 |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
1251 |
PeekableStream initialize! |