gnu-smalltalk, go, js, lua, php, rust, ts: Detect more unterminated strings.
[jackhill/mal.git] / lua / step1_read_print.lua
1 #!/usr/bin/env lua
2
3 local readline = require('readline')
4 local utils = require('utils')
5 local types = require('types')
6 local reader = require('reader')
7 local printer = require('printer')
8
9 -- read
10 function READ(str)
11 return reader.read_str(str)
12 end
13
14 -- eval
15 function EVAL(ast, env)
16 return ast
17 end
18
19 -- print
20 function PRINT(exp)
21 return printer._pr_str(exp, true)
22 end
23
24 -- repl
25 function rep(str)
26 return PRINT(EVAL(READ(str),""))
27 end
28
29 if #arg > 0 and arg[1] == "--raw" then
30 readline.raw = true
31 end
32
33 while true do
34 line = readline.readline("user> ")
35 if not line then break end
36 xpcall(function()
37 print(rep(line))
38 end, function(exc)
39 if exc then
40 if types._malexception_Q(exc) then
41 exc = printer._pr_str(exc.val, true)
42 end
43 print("Error: " .. exc)
44 print(debug.traceback())
45 end
46 end)
47 end