1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/cs/step1_read_print.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2014-04-07 07:13:14 +04:00
using System;
using System.IO;
using Mal;
using MalVal = Mal.types.MalVal;
namespace Mal {
2014-04-07 09:17:13 +04:00
class step1_read_print {
2014-04-07 07:13:14 +04:00
// read
static MalVal READ(string str) {
return reader.read_str(str);
}
// eval
static MalVal EVAL(MalVal ast, string env) {
return ast;
}
// print
static string PRINT(MalVal exp) {
return printer._pr_str(exp, true);
}
// repl
2014-04-07 07:13:14 +04:00
static void Main(string[] args) {
Func<string, MalVal> RE = (string str) => EVAL(READ(str), "");
2014-04-07 07:13:14 +04:00
if (args.Length > 0 && args[0] == "--raw") {
Mal.readline.mode = Mal.readline.Mode.Raw;
}
// repl loop
2014-04-07 07:13:14 +04:00
while (true) {
string line;
try {
line = Mal.readline.Readline("user> ");
2014-04-07 07:13:14 +04:00
if (line == null) { break; }
if (line == "") { continue; }
2014-04-07 07:13:14 +04:00
} catch (IOException e) {
Console.WriteLine("IOException: " + e.Message);
break;
}
try {
Console.WriteLine(PRINT(RE(line)));
2014-04-07 07:13:14 +04:00
} catch (Mal.types.MalContinue) {
continue;
} catch (Exception e) {
2014-04-07 07:13:14 +04:00
Console.WriteLine("Error: " + e.Message);
Console.WriteLine(e.StackTrace);
2014-04-07 07:13:14 +04:00
continue;
}
}
}
}
}