"
COPYRIGHT (c) 2006 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
"{ Package: 'stx:libbasic' }"
Object subclass:#ReadEvalPrintLoop
instanceVariableNames:'inputStream outputStream errorStream compiler prompt chunkFormat'
classVariableNames:''
poolDictionaries:''
category:'* uncategorized *'
!
!ReadEvalPrintLoop class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 2006 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
! !
!ReadEvalPrintLoop methodsFor:'accessing'!
chunkFormat:something
chunkFormat := something.
!
compiler:something
compiler := something.
!
error:something
errorStream := something.
"Created: / 07-12-2006 / 17:33:39 / cg"
!
input:something
inputStream := something.
"Modified: / 07-12-2006 / 17:33:31 / cg"
!
output:something
outputStream := something.
"Created: / 07-12-2006 / 17:27:48 / cg"
!
prompt:something
prompt := something.
! !
!ReadEvalPrintLoop methodsFor:'evaluation'!
readEvalPrintLoop
"{ Pragma: +optSpace }"
"simple read-eval-print loop for non-graphical Minitalk.
If the chunkFormat-argument is true, chunks are read.
Otherwise, lines up to an empty line (or EOF) are read."
[
|input output error lines chunk|
input := inputStream ? Stdin.
output := outputStream ? Stdout.
error := errorStream ? Stderr.
prompt notNil ifTrue:[
output nextPutAll:prompt.
].
input atEnd ifTrue:[
^ self.
].
(chunkFormat ? true) ifTrue:[
input skipSeparators.
chunk := input nextChunk.
] ifFalse:[
lines := OrderedCollection new.
[
|line|
line := input nextLine.
line notEmptyOrNil ifTrue:[
(line startsWith:'#') ifFalse:[
lines add:line.
]
].
line notEmptyOrNil.
] whileTrue.
chunk := lines asStringWith:Character cr.
].
chunk notEmptyOrNil ifTrue:[
AbortAllOperationRequest handle:[:ex |
error nextPutLine:('Evaluation aborted: ', ex description)
] do:[
|value|
value := (compiler new requestor:self) evaluate:chunk.
value printOn:output
].
].
] loop.
"Created: / 07-12-2006 / 17:27:21 / cg"
! !
!ReadEvalPrintLoop class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.2 2006-12-07 16:52:33 cg Exp $'
! !