10249
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
10248
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
|
14 |
Object subclass:#ReadEvalPrintLoop
|
|
15 |
instanceVariableNames:'inputStream outputStream errorStream compiler prompt chunkFormat'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'* uncategorized *'
|
|
19 |
!
|
|
20 |
|
10249
|
21 |
!ReadEvalPrintLoop class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
! !
|
10248
|
36 |
|
|
37 |
!ReadEvalPrintLoop methodsFor:'accessing'!
|
|
38 |
|
|
39 |
chunkFormat:something
|
|
40 |
chunkFormat := something.
|
|
41 |
!
|
|
42 |
|
|
43 |
compiler:something
|
|
44 |
compiler := something.
|
|
45 |
!
|
|
46 |
|
|
47 |
error:something
|
|
48 |
errorStream := something.
|
|
49 |
|
|
50 |
"Created: / 07-12-2006 / 17:33:39 / cg"
|
|
51 |
!
|
|
52 |
|
|
53 |
input:something
|
|
54 |
inputStream := something.
|
|
55 |
|
|
56 |
"Modified: / 07-12-2006 / 17:33:31 / cg"
|
|
57 |
!
|
|
58 |
|
|
59 |
output:something
|
|
60 |
outputStream := something.
|
|
61 |
|
|
62 |
"Created: / 07-12-2006 / 17:27:48 / cg"
|
|
63 |
!
|
|
64 |
|
|
65 |
prompt:something
|
|
66 |
prompt := something.
|
|
67 |
! !
|
|
68 |
|
|
69 |
!ReadEvalPrintLoop methodsFor:'evaluation'!
|
|
70 |
|
|
71 |
readEvalPrintLoop
|
|
72 |
"{ Pragma: +optSpace }"
|
|
73 |
|
|
74 |
"simple read-eval-print loop for non-graphical Minitalk.
|
|
75 |
If the chunkFormat-argument is true, chunks are read.
|
|
76 |
Otherwise, lines up to an empty line (or EOF) are read."
|
|
77 |
|
|
78 |
[
|
10252
|
79 |
|input output error lines chunk compilerClass|
|
10248
|
80 |
|
|
81 |
input := inputStream ? Stdin.
|
|
82 |
output := outputStream ? Stdout.
|
|
83 |
error := errorStream ? Stderr.
|
10252
|
84 |
compilerClass := compiler ? Compiler.
|
10248
|
85 |
|
|
86 |
prompt notNil ifTrue:[
|
|
87 |
output nextPutAll:prompt.
|
|
88 |
].
|
|
89 |
|
|
90 |
input atEnd ifTrue:[
|
|
91 |
^ self.
|
|
92 |
].
|
|
93 |
|
|
94 |
(chunkFormat ? true) ifTrue:[
|
|
95 |
input skipSeparators.
|
|
96 |
chunk := input nextChunk.
|
|
97 |
] ifFalse:[
|
|
98 |
lines := OrderedCollection new.
|
|
99 |
[
|
|
100 |
|line|
|
|
101 |
|
|
102 |
line := input nextLine.
|
|
103 |
line notEmptyOrNil ifTrue:[
|
|
104 |
(line startsWith:'#') ifFalse:[
|
|
105 |
lines add:line.
|
|
106 |
]
|
|
107 |
].
|
|
108 |
line notEmptyOrNil.
|
|
109 |
] whileTrue.
|
|
110 |
chunk := lines asStringWith:Character cr.
|
|
111 |
].
|
|
112 |
|
|
113 |
chunk notEmptyOrNil ifTrue:[
|
|
114 |
AbortAllOperationRequest handle:[:ex |
|
|
115 |
error nextPutLine:('Evaluation aborted: ', ex description)
|
|
116 |
] do:[
|
|
117 |
|value|
|
|
118 |
|
10252
|
119 |
value := (compilerClass new requestor:self) evaluate:chunk.
|
10253
|
120 |
value printOn:output.
|
|
121 |
output cr.
|
10248
|
122 |
].
|
|
123 |
].
|
|
124 |
] loop.
|
|
125 |
|
10252
|
126 |
"
|
|
127 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop
|
|
128 |
"
|
|
129 |
|
10248
|
130 |
"Created: / 07-12-2006 / 17:27:21 / cg"
|
|
131 |
! !
|
|
132 |
|
|
133 |
!ReadEvalPrintLoop class methodsFor:'documentation'!
|
|
134 |
|
|
135 |
version
|
10253
|
136 |
^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.4 2006-12-07 17:14:34 cg Exp $'
|
10248
|
137 |
! !
|