coffee, dart, elixir, elm: detect unclosed strings.
[jackhill/mal.git] / js / step1_read_print.js
index 264b6c6..d712a2f 100644 (file)
@@ -1,8 +1,8 @@
-var types = require('./types');
-var reader = require('./reader');
-var printer = require('./printer');
 if (typeof module !== 'undefined') {
+    var types = require('./types');
     var readline = require('./node_readline');
+    var reader = require('./reader');
+    var printer = require('./printer');
 }
 
 // read
@@ -24,25 +24,18 @@ function PRINT(exp) {
 var re = function(str) { return EVAL(READ(str), {}); };
 var rep = function(str) { return PRINT(EVAL(READ(str), {})); };
 
-if (typeof require === 'undefined') {
-    // Asynchronous browser mode
-    readline.rlwrap(function(line) { return rep(line); },
-                    function(exc) {
-                        if (exc instanceof reader.BlankException) { return; }
-                        if (exc.stack) { console.log(exc.stack); } else { console.log(exc); }
-                    });
-} else if (require.main === module) {
+// repl loop
+if (typeof require !== 'undefined' && require.main === module) {
     // Synchronous node.js commandline mode
     while (true) {
         var line = readline.readline("user> ");
         if (line === null) { break; }
         try {
-            if (line) { console.log(rep(line)); }
+            if (line) { printer.println(rep(line)); }
         } catch (exc) {
-            if (exc instanceof reader.BlankException) { continue; }
-            if (exc.stack) { console.log(exc.stack); } else { console.log(exc); }
+            if (exc instanceof reader.BlankException) { continue }
+            if (exc instanceof Error) { console.warn(exc.stack) }
+            else { console.warn("Error: " + printer._pr_str(exc, true)) }
         }
     }
-} else {
-    exports.rep = rep;
 }