aboutsummaryrefslogtreecommitdiff
path: root/coffee/step1_read_print.coffee
blob: 28edd1b2be81cd8d60abc34ca560c16a555a314d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
readline = require "./node_readline.coffee"
reader = require "./reader.coffee"
printer = require "./printer.coffee"

# read
READ = (str) -> reader.read_str str

# eval
EVAL = (ast, env) -> ast

# print
PRINT = (exp) -> printer._pr_str exp, true

# repl
rep = (str) -> PRINT(EVAL(READ(str), {}))

# repl loop
while (line = readline.readline("user> ")) != null
  continue if line == ""
  try
    console.log rep line
  catch exc
    continue if exc instanceof reader.BlankException
    if exc.stack then console.log exc.stack
    else              console.log exc

# vim: ts=2:sw=2