--- a/PosStream.st Mon Nov 08 03:29:58 1993 +0100
+++ b/PosStream.st Mon Nov 08 03:32:43 1993 +0100
@@ -11,8 +11,8 @@
"
Stream subclass:#PositionableStream
- instanceVariableNames:'collection position readLimit continueBlock abortBlock'
- classVariableNames:''
+ instanceVariableNames:'collection position readLimit'
+ classVariableNames:'ErrorDuringFileInSignal'
poolDictionaries:''
category:'Streams'
!
@@ -22,16 +22,22 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-Instances of myself allow positioning the read pointer.
-I also add methods for source-chunk reading and writing
+Instances of PositionableStream allow positioning the read pointer.
+PositionableStream also adds methods for source-chunk reading and writing
and for filing-in/out of source code.
+This is an abstract class.
+
+$Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.5 1993-11-08 02:31:29 claus Exp $
+'!
-$Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.4 1993-10-13 02:13:11 claus Exp $
+!PositionableStream class methodsFor:'initialization'!
-TODO
- change to use signals for error handling during fileIn
- (get rid of continue/abort blocks)
-'!
+initialize
+ ErrorDuringFileInSignal isNil ifTrue:[
+ ErrorDuringFileInSignal := (Signal new) mayProceed:true.
+ ErrorDuringFileInSignal notifierString:'error during fileIn'.
+ ]
+! !
!PositionableStream class methodsFor:'constants'!
@@ -91,17 +97,18 @@
|peekObject|
peekObject := self next.
- self position:(self position - 1).
+ self backStep.
^ peekObject
!
peekFor:something
- "return true and move past if next == something"
+ "return true and move past if next == something;
+ otherwise stay and let position unchanged"
self next == something ifTrue:[
^ true
].
- self position:(self position - 1).
+ self backStep.
^ false
!
@@ -135,7 +142,11 @@
"return a collection of the elements up-to the end
Return nil if the stream-end is reached before."
- |newColl e|
+ |newColl|
+
+ "this implementation has stupid (o-square) runtime behavior -
+ should I add a query for resizability if collections and use
+ add: instead ?"
newColl := collection species new.
[self atEnd] whileFalse:[
@@ -189,10 +200,17 @@
position:index
"set the read position"
- (index > (readLimit + 1)) ifTrue: [^ self positionError].
+ ((index > (readLimit + 1)) or:[position < 1]) ifTrue: [^ self positionError].
position := index
!
+backStep
+ "move backward read position by one"
+
+ position <= 1 ifTrue: [^ self positionError].
+ position := position - 1
+!
+
reset
"set the read position to the beginning of the collection"
@@ -418,13 +436,37 @@
|lastValue|
self position:1.
- abortBlock := [^ nil].
- continueBlock := [].
Smalltalk at:#ErrorHandler put:self.
- [self atEnd] whileFalse:[
- lastValue := self fileInNextChunkNotifying:someone
- ].
- Smalltalk at:#ErrorHandler put:nil.
+ [
+ ErrorDuringFileInSignal handle:[:ex |
+ |action|
+
+ "handle the case where no GUI has been built in,
+ just abort with a notification"
+
+ Display isNil ifTrue:[
+ self notify:(ex parameter).
+ ex return
+ ].
+
+ "otherwise ask what should be done now and either
+ continue or abort the fileIn"
+
+ action := self askForDebug:(ex parameter).
+ action == #continue ifTrue:[
+ Smalltalk at:#ErrorHandler put:self.
+ ex proceed
+ ].
+ action == #abort ifTrue:[
+ ex return
+ ].
+ ex reject
+ ] do:[
+ [self atEnd] whileFalse:[
+ lastValue := self fileInNextChunkNotifying:someone
+ ].
+ ].
+ ] valueNowOrOnUnwindDo:[Smalltalk at:#ErrorHandler put:nil].
^ lastValue
!
@@ -452,9 +494,11 @@
we dont want a debugger to come up but simply notify
the error (also on the Transcript so you have a trace of it)"
- |message action|
+ |message|
+ "switch back to regular error handling"
Smalltalk at:#ErrorHandler put:nil.
+
(aSymbol == #doesNotUnderstand:) ifTrue:[
anObject isNil ifTrue:[
"try to give a bit more detail on what went wrong"
@@ -480,20 +524,7 @@
].
message := 'Error: ' , message.
Transcript showCr:message.
-
- YesNoBox notNil ifTrue:[
- action := self askForDebug:message.
- action == #debug ifTrue:[
- Debugger enterWithMessage:message
- ].
- action == #continue ifTrue:[
- continueBlock value
- ].
- ] ifFalse:[
- self notify:message
- ].
-
- abortBlock value.
+ ErrorDuringFileInSignal raiseRequestWith:message.
^ nil
!