| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 #import('../lib/node/node.dart'); | |
| 7 #import('../file_system_node.dart'); | |
| 8 #import('../js_evaluator_node.dart'); | |
| 9 #import('../lang.dart'); | |
| 10 #import('../evaluator.dart'); | |
| 11 | |
| 12 String _getPrompt(Token incompleteToken) { | |
| 13 if (incompleteToken == null) return ">>> "; | |
| 14 switch (incompleteToken.kind) { | |
| 15 case TokenKind.INCOMPLETE_MULTILINE_STRING_DQ: return '""" '; | |
| 16 case TokenKind.INCOMPLETE_MULTILINE_STRING_SQ: return "''' "; | |
| 17 default: return "... "; | |
| 18 } | |
| 19 } | |
| 20 | |
| 21 void main() { | |
| 22 var homedir = path.dirname(fs.realpathSync(process.argv[1])); | |
| 23 Evaluator.initWorld(homedir, [], new NodeFileSystem()); | |
| 24 | |
| 25 var eval = new Evaluator(new NodeJsEvaluator()); | |
| 26 var rl = Readline.createInterface(process.stdin, process.stdout); | |
| 27 var incompleteToken = null; | |
| 28 var priorCommand = null; | |
| 29 | |
| 30 rl.setPrompt(">>> "); | |
| 31 rl.on("line", (command) { | |
| 32 if (priorCommand != null) command = priorCommand + "\n" + command; | |
| 33 try { | |
| 34 var result = eval.eval(command); | |
| 35 if (result !== null) print(result); | |
| 36 incompleteToken = null; | |
| 37 priorCommand = null; | |
| 38 } catch (CompilerException e) { | |
| 39 // Do nothing, since a message was already printed | |
| 40 incompleteToken = null; | |
| 41 priorCommand = null; | |
| 42 } catch (IncompleteSourceException e) { | |
| 43 incompleteToken = e.token; | |
| 44 priorCommand = command; | |
| 45 } catch (var e, stack) { | |
| 46 incompleteToken = null; | |
| 47 priorCommand = null; | |
| 48 if (stack != null) { | |
| 49 print(stack); | |
| 50 } else { | |
| 51 print(e); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 rl.setPrompt(_getPrompt(incompleteToken)); | |
| 56 rl.prompt(); | |
| 57 }); | |
| 58 rl.on("close", () { process.exit(0); }); | |
| 59 rl.prompt(); | |
| 60 } | |
| OLD | NEW |