Merge pull request #358 from bjh21/bjh21-extra-tests
[jackhill/mal.git] / cs / step1_read_print.cs
CommitLineData
53beaa0a
JM
1using System;
2using System.IO;
3using Mal;
4using MalVal = Mal.types.MalVal;
5
6namespace Mal {
afdf531e 7 class step1_read_print {
53beaa0a
JM
8 // read
9 static MalVal READ(string str) {
10 return reader.read_str(str);
11 }
12
13 // eval
14 static MalVal EVAL(MalVal ast, string env) {
15 return ast;
16 }
17
18 // print
19 static string PRINT(MalVal exp) {
20 return printer._pr_str(exp, true);
21 }
22
86b689f3 23 // repl
53beaa0a 24 static void Main(string[] args) {
c3b508af
JM
25 Func<string, MalVal> RE = (string str) => EVAL(READ(str), "");
26
53beaa0a
JM
27 if (args.Length > 0 && args[0] == "--raw") {
28 Mal.readline.mode = Mal.readline.Mode.Raw;
29 }
c3b508af
JM
30
31 // repl loop
53beaa0a
JM
32 while (true) {
33 string line;
34 try {
c3b508af 35 line = Mal.readline.Readline("user> ");
53beaa0a 36 if (line == null) { break; }
c3b508af 37 if (line == "") { continue; }
53beaa0a
JM
38 } catch (IOException e) {
39 Console.WriteLine("IOException: " + e.Message);
40 break;
41 }
42 try {
c3b508af 43 Console.WriteLine(PRINT(RE(line)));
53beaa0a
JM
44 } catch (Mal.types.MalContinue) {
45 continue;
8cb5cda4 46 } catch (Exception e) {
53beaa0a 47 Console.WriteLine("Error: " + e.Message);
8cb5cda4 48 Console.WriteLine(e.StackTrace);
53beaa0a 49 continue;
53beaa0a
JM
50 }
51 }
52 }
53 }
54}