1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/lua/step1_read_print.lua
2015-02-28 15:58:35 -06:00

47 lines
869 B
Lua
Executable File

#!/usr/bin/env lua
local readline = require('readline')
local utils = require('utils')
local reader = require('reader')
local printer = require('printer')
-- read
function READ(str)
return reader.read_str(str)
end
-- eval
function EVAL(ast, env)
return ast
end
-- print
function PRINT(exp)
return printer._pr_str(exp, true)
end
-- repl
function rep(str)
return PRINT(EVAL(READ(str),""))
end
if #arg > 0 and arg[1] == "--raw" then
readline.raw = true
end
while true do
line = readline.readline("user> ")
if not line then break end
xpcall(function()
print(rep(line))
end, function(exc)
if exc then
if types._malexception_Q(exc) then
exc = printer._pr_str(exc.val, true)
end
print("Error: " .. exc)
print(debug.traceback())
end
end)
end