#DOCUMENTATION by cg
class: ReadEvalPrintLoop
comment/format in: #basicReadEvalPrintLoopWithInput:output:error:compiler:prompt:print:
changed: #readEvalPrintLoop
--- a/ReadEvalPrintLoop.st Fri Nov 04 10:31:44 2016 +0100
+++ b/ReadEvalPrintLoop.st Fri Nov 04 12:01:06 2016 +0100
@@ -447,7 +447,8 @@
for included scripts.
If chunkFormat is true, chunks are read.
Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read.
- A '#' character appearing in the first column of the first line turns off chunkmode."
+ A '#' character appearing in the first column of the first line turns off chunkmode,
+ which allows for convenient shell scripts containing a #/bin/stx as the first line."
[
|lines chunk|
@@ -574,24 +575,36 @@
exitAction := [^ self].
ControlInterrupt handle:[:ex |
- self errorStream nextPutLine:('Caught: ', ex description).
- ex restart.
+ self errorStream nextPutLine:('Caught: ', ex description).
+ ex restart.
] do:[
- |input output error compilerClass|
+ |input output error compilerClass|
+
+ "/ re-evaluate these in the loop, so they can be changed dynamically
+ input := self inputStream.
+ output := self outputStream.
+ error := self errorStream.
- "/ re-evaluate these in the loop, so they can be changed dynamically
- input := self inputStream.
- output := self outputStream.
- error := self errorStream.
-
- compilerClass := compiler ? Compiler ? Parser.
- compilerClass isNil ifTrue:[
- self errorStream nextPutLine:('oops - no Compiler class found').
- ^ self.
- ].
- self
- basicReadEvalPrintLoopWithInput:input output:output error:error
- compiler:compilerClass prompt:prompt print:(printFlag ? true).
+ compilerClass := compiler ? Compiler ? Parser.
+ compilerClass isNil ifTrue:[
+ self errorStream nextPutLine:('oops - no Compiler class found').
+ ^ self.
+ ].
+ StreamError handle:[:ex |
+ (input isOpen not or:[input atEnd]) ifTrue:[
+ error nextPutLine:'EOF on input'.
+ ].
+ (output isOpen not) ifTrue:[
+ error nextPutLine:'no output'.
+ ].
+ (error isOpen not) ifTrue:[
+ ].
+ ] do:[
+ input signalAtEnd:true.
+ self
+ basicReadEvalPrintLoopWithInput:input output:output error:error
+ compiler:compilerClass prompt:prompt print:(printFlag ? true).
+ ]
]
"