Fix unescaping in matlab, miniMAL and rpython.
[jackhill/mal.git] / gst / step1_read_print.st
1 String extend [
2 String >> loadRelative [
3 | scriptPath scriptDirectory |
4 scriptPath := thisContext currentFileName.
5 scriptDirectory := FilePath stripFileNameFor: scriptPath.
6 FileStream fileIn: (FilePath append: self to: scriptDirectory)
7 ]
8 ]
9
10 'readline.st' loadRelative.
11 'util.st' loadRelative.
12 'types.st' loadRelative.
13 'reader.st' loadRelative.
14 'printer.st' loadRelative.
15
16 Object subclass: MAL [
17 MAL class >> READ: input [
18 ^Reader readStr: input
19 ]
20
21 MAL class >> EVAL: sexp [
22 ^sexp
23 ]
24
25 MAL class >> PRINT: sexp [
26 ^Printer prStr: sexp printReadably: true
27 ]
28
29 MAL class >> rep: input [
30 ^self PRINT: (self EVAL: (self READ: input))
31 ]
32 ]
33
34 | input historyFile |
35
36 historyFile := '.mal_history'.
37 ReadLine readHistory: historyFile.
38
39 [ input := ReadLine readLine: 'user> '. input isNil ] whileFalse: [
40 input isEmpty ifFalse: [
41 ReadLine addHistory: input.
42 ReadLine writeHistory: historyFile.
43 [ (MAL rep: input) displayNl ]
44 on: MALEmptyInput do: [ #return ]
45 on: MALError do:
46 [ :err | ('error: ', err messageText) displayNl. #return ].
47 ]
48 ]
49
50 '' displayNl.