author | Claus Gittinger <cg@exept.de> |
Sun, 05 Jan 2020 17:27:00 +0100 | |
changeset 25177 | 1c618f3d51f5 |
parent 25096 | 9af9383ce171 |
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 |
|
24805 | 307 |
[(nextOne := self peekOrNil) notNil and:[nextOne isSeparator]] whileTrue:[ |
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
308 |
self next. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
309 |
]. |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
310 |
^ nextOne |
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 |
" |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
313 |
|s| |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
314 |
|
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
315 |
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
|
316 |
s skipSeparators. |
24805 | 317 |
Transcript showCR:(s nextAlphaNumericWord). |
8867
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
318 |
s skipSeparators. |
24805 | 319 |
Transcript showCR:(s nextAlphaNumericWord). |
8867
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 next displayString). |
436f86af36df
Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents:
8719
diff
changeset
|
322 |
" |
24805 | 323 |
|
324 |
"Modified (comment): / 28-09-2019 / 15:01:04 / Stefan Vogel" |
|
8867
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 |
||
24596 | 862 |
throughAnyAtMost:limit forWhich:checkBlock |
863 |
"read & return a collection of all objects up-to and including |
|
864 |
the elements for which checkBlock returns true, |
|
865 |
but stop when limit elements have been read. |
|
866 |
(i.e. read until checkBlock returns false on an element or limit is reached) |
|
867 |
If no such element is encountered, all elements up to the end, but not more than limit |
|
868 |
are read and returned." |
|
869 |
||
870 |
|answerStream| |
|
871 |
||
872 |
answerStream := self contentsSpecies writeStream. |
|
873 |
[ |
|
874 |
self atEnd |
|
875 |
or:[ (checkBlock value:self peek) not |
|
876 |
or:[ answerStream size >= limit |
|
877 |
]]] whileFalse:[ |
|
878 |
answerStream nextPut:self next. |
|
879 |
]. |
|
880 |
^ answerStream contents |
|
881 |
||
882 |
" |
|
883 |
|s| |
|
884 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
885 |
Transcript showCR:(s throughAnyAtMost:3 forWhich:[:e| e <= 4]). |
|
886 |
Transcript showCR:s next |
|
887 |
||
888 |
|s| |
|
889 |
s := ReadStream on:'1987-22'. |
|
890 |
Transcript showCR:(s throughAnyAtMost:4 forWhich:[:ch | ch isDigit]). |
|
891 |
Transcript showCR:s upToEnd. |
|
892 |
||
893 |
|s| |
|
894 |
s := ReadStream on:'198722'. |
|
895 |
Transcript showCR:(s throughAnyAtMost:4 forWhich:[:ch | ch isDigit]). |
|
896 |
Transcript showCR:s upToEnd. |
|
897 |
||
898 |
|s| |
|
899 |
s := ReadStream on:'87-22'. |
|
900 |
Transcript showCR:(s throughAnyAtMost:4 forWhich:[:ch | ch isDigit]). |
|
901 |
Transcript showCR:s upToEnd. |
|
902 |
" |
|
903 |
||
904 |
"Modified: / 11-01-1998 / 15:28:04 / cg" |
|
905 |
"Modified: / 10-01-2018 / 18:29:51 / stefan" |
|
906 |
"Modified (comment): / 10-01-2018 / 23:18:08 / stefan" |
|
907 |
! |
|
908 |
||
11139 | 909 |
throughAnyForWhich:checkBlock |
910 |
"read & return a collection of all objects up-to and including |
|
911 |
the elements for which checkBlock returns true. |
|
912 |
(i.e. read until checkBlock returns false on an element) |
|
913 |
If no such element is encountered, all elements up to the end are read |
|
914 |
and returned." |
|
915 |
||
22416 | 916 |
|answerStream| |
11139 | 917 |
|
22416 | 918 |
answerStream := self contentsSpecies writeStream. |
919 |
[self atEnd or:[(checkBlock value:self peek) not]] whileFalse:[ |
|
920 |
answerStream nextPut:self next. |
|
11139 | 921 |
]. |
922 |
^ answerStream contents |
|
923 |
||
924 |
" |
|
925 |
|s| |
|
926 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
22416 | 927 |
Transcript showCR:(s throughAnyForWhich:[:e| e <= 4]). |
11139 | 928 |
Transcript showCR:s next |
929 |
||
930 |
|s| |
|
931 |
s := ReadStream on:'hello world, this is some text'. |
|
932 |
Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]). |
|
933 |
Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]). |
|
934 |
Transcript showCR:s upToEnd. |
|
935 |
" |
|
936 |
||
22416 | 937 |
"Modified: / 11-01-1998 / 15:28:04 / cg" |
938 |
"Modified: / 10-01-2018 / 18:29:51 / stefan" |
|
939 |
"Modified (comment): / 10-01-2018 / 23:18:08 / stefan" |
|
21135 | 940 |
! |
941 |
||
942 |
upToAny:aCollectionOfObjects |
|
22631 | 943 |
"read a collection of all objects up to an element that is contained in |
21135 | 944 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
945 |
The next read operation will return the element AFTER anObject. |
|
946 |
If no such element is encountered, all elements up to the end are read |
|
947 |
and returned. |
|
948 |
Compare this with #throughAll: which also reads up to some object |
|
949 |
and also positions behind it, but DOES include it in the returned |
|
950 |
value." |
|
951 |
||
952 |
|result| |
|
953 |
||
954 |
result := self upToBeforeAny:aCollectionOfObjects. |
|
25096 | 955 |
self nextOrNil. |
21135 | 956 |
^ result |
957 |
||
958 |
" |
|
959 |
|s| |
|
960 |
s := ReadStream on:'hello world'. |
|
961 |
Transcript showCR:(s upToAny:(Array with:Character space)). |
|
962 |
Transcript showCR:(s upToEnd) |
|
963 |
||
964 |
'Makefile' asFilename readStream upToAny:($A to:$Z) |
|
965 |
" |
|
966 |
||
25096 | 967 |
"Created: / 30-08-1997 / 03:02:05 / cg" |
968 |
"Modified: / 11-01-1998 / 15:19:18 / cg" |
|
969 |
"Modified: / 11-12-2019 / 22:08:02 / Stefan Vogel" |
|
21135 | 970 |
! |
971 |
||
972 |
upToBeforeAny:aCollectionOfObjects |
|
22631 | 973 |
"read a collection of all objects up to an element that is contained in |
21135 | 974 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
975 |
The next read operation will return the matching element. |
|
976 |
If no such element is encountered, all elements up to the end are read |
|
977 |
and returned. |
|
978 |
This returns the exact same as upToAny: would, but leaves the stream's position so that |
|
979 |
the next read returns the matching delimiter instead of skipping it. |
|
980 |
Caveat: this is the one which should have been called upTo: in the first place; |
|
981 |
however, it seems now too late for a change." |
|
982 |
||
22416 | 983 |
|answerStream| |
21135 | 984 |
|
22416 | 985 |
answerStream := self contentsSpecies writeStream. |
986 |
[self atEnd or:[aCollectionOfObjects includes:self peek]] whileFalse:[ |
|
987 |
answerStream nextPut:self next. |
|
21135 | 988 |
]. |
989 |
^ answerStream contents |
|
990 |
||
991 |
" |
|
992 |
|s| |
|
993 |
s := ReadStream on:'hello world'. |
|
994 |
Transcript showCR:(s upToBeforeAny:(Array with:Character space)). |
|
995 |
Transcript showCR:(s upToEnd) |
|
996 |
||
997 |
'Make.proto' asFilename readStream upToBeforeAny:($A to:$Z) |
|
998 |
" |
|
999 |
||
22416 | 1000 |
"Created: / 30-08-1997 / 03:02:05 / cg" |
1001 |
"Modified: / 11-01-1998 / 15:19:18 / cg" |
|
1002 |
"Modified: / 10-01-2018 / 18:29:57 / stefan" |
|
21135 | 1003 |
! |
1004 |
||
1005 |
upToElementForWhich:aBlock |
|
1006 |
"read elements until aBlock returns true for an element. |
|
1007 |
Return the collected elements excluding that element. |
|
1008 |
Leave the stream positioned for the next read to return that element. |
|
1009 |
If no element matches, all elements up to the end are returned" |
|
1010 |
||
22416 | 1011 |
|answerStream| |
21135 | 1012 |
|
22416 | 1013 |
answerStream := self contentsSpecies writeStream. |
1014 |
[self atEnd or:[aBlock value:self peek]] whileFalse:[ |
|
1015 |
answerStream nextPut:self next. |
|
21135 | 1016 |
]. |
1017 |
^ answerStream contents |
|
1018 |
||
1019 |
" |
|
1020 |
#(1 2 3 4 5 6 7 8 9 10) readStream |
|
1021 |
upToElementForWhich:[:el | el > 5] |
|
1022 |
" |
|
22416 | 1023 |
|
1024 |
"Modified: / 10-01-2018 / 18:30:03 / stefan" |
|
1025 |
! |
|
1026 |
||
1027 |
upToMatching:aBlock |
|
1028 |
"Return the next elements up to but not including the next element |
|
1029 |
for which aBlock returns true. |
|
1030 |
The next read will return that matching element. |
|
1031 |
If none matches, the remaining elements up to the end are returned." |
|
1032 |
||
1033 |
^ self upToElementForWhich:aBlock |
|
1034 |
||
1035 |
" |
|
1036 |
'hello world' readStream upToMatching:[:c | c isSeparator]. |
|
1037 |
" |
|
1038 |
" |
|
1039 |
'helloworld' readStream upToMatching:[:c | c isSeparator]. |
|
1040 |
" |
|
1041 |
" |
|
1042 |
|s| |
|
1043 |
||
1044 |
s := 'hello world' readStream. |
|
1045 |
s upToMatching:[:c | c isSeparator]. |
|
1046 |
s upToEnd |
|
1047 |
" |
|
1048 |
||
1049 |
"Modified: / 26-02-1997 / 12:20:57 / cg" |
|
1050 |
"Modified (comment): / 10-01-2018 / 23:20:32 / stefan" |
|
1051 |
! |
|
1052 |
||
1053 |
upToSeparator |
|
1054 |
"Return the next elements up to but not including the next separator. |
|
1055 |
The next read will return the separator. |
|
1056 |
If no separator is encountered, the contents up to the end is returned. |
|
1057 |
The elements are supposed to understand #isSeparator |
|
1058 |
(i.e. the receiver is supposed to be a character-stream)." |
|
1059 |
||
1060 |
^ self upToElementForWhich:[:ch | ch isSeparator] |
|
1061 |
||
1062 |
" |
|
1063 |
'hello world' readStream upToSeparator |
|
1064 |
'helloworld' readStream upToSeparator |
|
1065 |
'helloworld' readStream upToSeparator |
|
1066 |
'' readStream upToSeparator |
|
1067 |
||
1068 |
|s| |
|
1069 |
s := 'hello world' readStream. |
|
1070 |
s upToSeparator. |
|
1071 |
s upToEnd |
|
1072 |
" |
|
1073 |
||
1074 |
"Modified: 4.1.1997 / 23:38:05 / cg" |
|
21135 | 1075 |
! ! |
1076 |
||
1077 |
!PeekableStream methodsFor:'reading-numbers'! |
|
1078 |
||
1079 |
nextDecimalInteger |
|
21754 | 1080 |
"read the next integer in radix 10. |
21135 | 1081 |
Does NOT skip initial whitespace. |
1082 |
The streams elements should be characters. |
|
1083 |
||
21754 | 1084 |
Be careful - this method returns 0 if not positioned on a digit initially |
21135 | 1085 |
or if the end of the stream is encountered." |
1086 |
||
1087 |
|nextOne value| |
|
1088 |
||
1089 |
nextOne := self peekOrNil. |
|
1090 |
value := 0. |
|
1091 |
[nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[ |
|
1092 |
value := (value * 10) + nextOne digitValue. |
|
1093 |
self next. |
|
1094 |
nextOne := self peekOrNil |
|
1095 |
]. |
|
1096 |
^ value |
|
1097 |
||
1098 |
" |
|
1099 |
|s| |
|
1100 |
||
1101 |
s := '1234 5678' readStream. |
|
21754 | 1102 |
s nextDecimalInteger. |
21135 | 1103 |
" |
1104 |
||
1105 |
" |
|
1106 |
|s| |
|
1107 |
||
1108 |
s := '1234 5678' readStream. |
|
1109 |
s nextDecimalInteger. |
|
1110 |
s skipSpaces. |
|
21754 | 1111 |
s nextDecimalInteger. |
21135 | 1112 |
" |
21754 | 1113 |
|
1114 |
"Modified (comment): / 17-05-2017 / 15:13:04 / mawalch" |
|
611 | 1115 |
! ! |
58 | 1116 |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1117 |
!PeekableStream methodsFor:'reading-strings'! |
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 |
nextAlphaNumericWord |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1120 |
"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
|
1121 |
Return a string containing those characters. |
18273 | 1122 |
Any leading non-alphaNumeric chars are skipped. |
1123 |
||
1124 |
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
|
1125 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1126 |
|s c| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1127 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1128 |
"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
|
1129 |
[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1130 |
c := self nextOrNil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1131 |
c isNil ifTrue:[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1132 |
"end of stream" |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1133 |
^ nil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1134 |
]. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1135 |
c isLetterOrDigit |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1136 |
] whileFalse. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1137 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1138 |
"second: get the alphanumeric word" |
22416 | 1139 |
s := self contentsSpecies writeStream:100. |
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1140 |
[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1141 |
s nextPut:c. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1142 |
c := self peekOrNil. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1143 |
(c notNil and:[c isLetterOrDigit]) ifTrue:[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1144 |
self next. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1145 |
true. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1146 |
] ifFalse:[ |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1147 |
false. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1148 |
] |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1149 |
] whileTrue. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1150 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1151 |
^ s contents. |
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1152 |
|
18273 | 1153 |
"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
|
1154 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1155 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1156 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1157 |
|
10356
6f32850bdc81
speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents:
10351
diff
changeset
|
1158 |
s := 'hello world 1234 foo1 foo2' asUnicodeString readStream. |
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1159 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1160 |
Transcript showCR:(s nextAlphaNumericWord). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1161 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1162 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1163 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1164 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1165 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1166 |
|
22416 | 1167 |
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
|
1168 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1169 |
Transcript showCR:(s nextAlphaNumericWord). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1170 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1171 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1172 |
|
22416 | 1173 |
"Modified: / 15-05-1996 / 17:51:42 / cg" |
1174 |
"Modified: / 10-01-2018 / 18:34:42 / stefan" |
|
1175 |
! |
|
1176 |
||
1177 |
nextDelimited:terminator |
|
1178 |
"return the contents of the receiver, up to the next terminator element. |
|
1179 |
Doubled terminators indicate an embedded terminator element. |
|
1180 |
For example: 'this '' was a quote'. |
|
1181 |
Start positioned before the initial terminator." |
|
1182 |
||
1183 |
| out element | |
|
1184 |
||
1185 |
self atEnd ifTrue: [^ '']. |
|
1186 |
self peek = terminator ifTrue: [self next]. "absorb initial terminator" |
|
1187 |
out := self contentsSpecies writeStream. |
|
1188 |
[(element := self nextOrNil) isNil and:[self atEnd]] whileFalse:[ |
|
1189 |
element = terminator ifTrue: [ |
|
1190 |
self peek ~= terminator ifTrue: [ |
|
1191 |
^ out contents "terminator is not doubled; we're done!!" |
|
1192 |
]. |
|
1193 |
self next. "skip doubled terminator" |
|
1194 |
]. |
|
1195 |
out nextPut:element. |
|
1196 |
]. |
|
1197 |
^ out contents |
|
1198 |
||
1199 |
" |
|
1200 |
('*foo bar baz* more foo' readStream nextDelimited:$*) |
|
1201 |
('*foo bar **baz***' readStream nextDelimited:$*) |
|
1202 |
" |
|
1203 |
||
1204 |
"Modified: / 10-01-2018 / 18:29:42 / stefan" |
|
9356
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1205 |
! |
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 |
nextMatching:matchBlock1 thenMatching:matchBlock2 |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1208 |
"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
|
1209 |
remaining characters must match matchBlock2. |
16376 | 1210 |
Return a string containing those characters. |
1211 |
Useful to read identifiers, where the first char is from a different |
|
1212 |
set than the remaining (letter vs. letterOrDigit)" |
|
9356
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 |
|s c| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1215 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1216 |
self atEnd ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1217 |
(matchBlock1 value:self peek) ifFalse:[^ nil]. |
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 |
s := self next asString. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1220 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1221 |
[self atEnd not |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1222 |
and:[matchBlock2 value:(c := self peek)]] whileTrue:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1223 |
s := s copyWith:c. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1224 |
self next |
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 |
s size == 0 ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1228 |
^ s. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1229 |
|
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| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1232 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1233 |
s := 'hello_world_1234 foo1 foo2' readStream. |
16375 | 1234 |
s nextMatching:[:c | c isLetter] |
1235 |
thenMatching:[:c | c isLetterOrDigit or:[c == $_]]. |
|
9356
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 |
! |
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 |
nextSymbol |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1240 |
"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
|
1241 |
Return a string containing those characters. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1242 |
Any leading non-alphaNumeric chars are skipped." |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1243 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1244 |
|symbol c symbolStream| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1245 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1246 |
[self atEnd |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1247 |
or:[(c := self peek) isLetterOrDigit]] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1248 |
self next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1249 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1250 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1251 |
self atEnd ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1252 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1253 |
symbolStream := '' writeStream. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1254 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1255 |
[self atEnd not |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1256 |
and:[(c := self peek) isLetterOrDigit or:[c == $:]]] whileTrue:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1257 |
symbolStream nextPut:c. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1258 |
self next |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1259 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1260 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1261 |
symbol := symbolStream contents. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1262 |
symbol size == 0 ifTrue:[^ nil]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1263 |
^ symbol. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1264 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1265 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1266 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1267 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1268 |
s := 'hello: world 1234 foo1 foo2:' readStream. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1269 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1270 |
Transcript showCR:(s nextSymbol). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1271 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1272 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1273 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1274 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1275 |
|s| |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1276 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1277 |
s := 'hello +++ #world ###123###abc### 1234 foo1 foo2' readStream. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1278 |
[s atEnd] whileFalse:[ |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1279 |
Transcript showCR:(s nextAlphaNumericWord). |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1280 |
]. |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1281 |
" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1282 |
|
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1283 |
"Modified: 15.5.1996 / 17:51:42 / cg" |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1284 |
! ! |
dfc36db0f470
Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8867
diff
changeset
|
1285 |
|
24943 | 1286 |
!PeekableStream methodsFor:'testing'! |
1287 |
||
1288 |
isUnicodeEncoded |
|
1289 |
"return true, if the streamed collection is any string (8-, 16- or 32-bit), |
|
1290 |
which definitly is not using UTF-x or JIS or any other encoding. |
|
1291 |
I.e. 'self next' always returns a unicode character. |
|
1292 |
Note: the answer of false sows not mean that it is not unicode, |
|
1293 |
but it does mean that we don't know for sure." |
|
1294 |
||
1295 |
^ (self objectAttributeAt:#isUnicodeEncoded) == true. |
|
1296 |
||
1297 |
"Created: / 21-11-2019 / 18:46:01 / Stefan Vogel" |
|
1298 |
! |
|
1299 |
||
1300 |
isUnicodeEncoded:aBoolean |
|
1301 |
"set to true, if the streamed collection is any string (8-, 16- or 32-bit), |
|
1302 |
which definitly is not using UTF-x or JIS or any other encoding. |
|
1303 |
I.e. 'self next' always returns a unicode character. |
|
1304 |
Note: the answer of false sows not mean that it is not unicode, |
|
1305 |
but it does mean that we don't know for sure." |
|
1306 |
||
1307 |
self objectAttributeAt:#isUnicodeEncoded put:aBoolean. |
|
1308 |
||
1309 |
"Created: / 21-11-2019 / 18:47:36 / Stefan Vogel" |
|
1310 |
! ! |
|
1311 |
||
701 | 1312 |
!PeekableStream class methodsFor:'documentation'! |
1313 |
||
1314 |
version |
|
18479 | 1315 |
^ '$Header$' |
12783 | 1316 |
! |
1317 |
||
1318 |
version_CVS |
|
18479 | 1319 |
^ '$Header$' |
701 | 1320 |
! ! |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
1321 |
|
14900 | 1322 |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8192
diff
changeset
|
1323 |
PeekableStream initialize! |