|
@ -84,6 +84,7 @@ function REPLServer(prompt, stream) { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
rli.addListener('line', function(cmd) { |
|
|
rli.addListener('line', function(cmd) { |
|
|
|
|
|
var skipCatchall = false; |
|
|
cmd = trimWhitespace(cmd); |
|
|
cmd = trimWhitespace(cmd); |
|
|
|
|
|
|
|
|
// Check to see if a REPL keyword was used. If it returns true,
|
|
|
// Check to see if a REPL keyword was used. If it returns true,
|
|
@ -92,43 +93,50 @@ function REPLServer(prompt, stream) { |
|
|
var matches = cmd.match(/^(\.[^\s]+)\s*(.*)$/); |
|
|
var matches = cmd.match(/^(\.[^\s]+)\s*(.*)$/); |
|
|
var keyword = matches && matches[1]; |
|
|
var keyword = matches && matches[1]; |
|
|
var rest = matches && matches[2]; |
|
|
var rest = matches && matches[2]; |
|
|
if (self.parseREPLKeyword(keyword, rest) === true) return; |
|
|
if (self.parseREPLKeyword(keyword, rest) === true) { |
|
|
|
|
|
return; |
|
|
|
|
|
} else { |
|
|
|
|
|
self.stream.write('Invalid REPL keyword\n'); |
|
|
|
|
|
skipCatchall = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// The catchall for errors
|
|
|
if (!skipCatchall) { |
|
|
try { |
|
|
// The catchall for errors
|
|
|
self.buffered_cmd += cmd; |
|
|
|
|
|
// This try is for determining if the command is complete, or should
|
|
|
|
|
|
// continue onto the next line.
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// Use evalcx to supply the global context
|
|
|
self.buffered_cmd += cmd; |
|
|
var ret = evalcx(self.buffered_cmd, context, 'repl'); |
|
|
// This try is for determining if the command is complete, or should
|
|
|
if (ret !== undefined) { |
|
|
// continue onto the next line.
|
|
|
context._ = ret; |
|
|
try { |
|
|
self.stream.write(exports.writer(ret) + '\n'); |
|
|
// Use evalcx to supply the global context
|
|
|
} |
|
|
var ret = evalcx(self.buffered_cmd, context, 'repl'); |
|
|
|
|
|
if (ret !== undefined) { |
|
|
|
|
|
context._ = ret; |
|
|
|
|
|
self.stream.write(exports.writer(ret) + '\n'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
self.buffered_cmd = ''; |
|
|
self.buffered_cmd = ''; |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
// instanceof doesn't work across context switches.
|
|
|
|
|
|
if (!(e && e.constructor && e.constructor.name === 'SyntaxError')) { |
|
|
|
|
|
throw e; |
|
|
|
|
|
// It could also be an error from JSON.parse
|
|
|
|
|
|
} else if (e && |
|
|
|
|
|
e.stack && |
|
|
|
|
|
e.stack.match('Unexpected token ILLEGAL') && |
|
|
|
|
|
e.stack.match(/Object.parse \(native\)/)) { |
|
|
|
|
|
throw e; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
// instanceof doesn't work across context switches.
|
|
|
// On error: Print the error and clear the buffer
|
|
|
if (!(e && e.constructor && e.constructor.name === 'SyntaxError')) { |
|
|
if (e.stack) { |
|
|
throw e; |
|
|
self.stream.write(e.stack + '\n'); |
|
|
// It could also be an error from JSON.parse
|
|
|
} else { |
|
|
} else if (e && |
|
|
self.stream.write(e.toString() + '\n'); |
|
|
e.stack && |
|
|
|
|
|
e.stack.match('Unexpected token ILLEGAL') && |
|
|
|
|
|
e.stack.match(/Object.parse \(native\)/)) { |
|
|
|
|
|
throw e; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
self.buffered_cmd = ''; |
|
|
} |
|
|
} |
|
|
} catch (e) { |
|
|
|
|
|
// On error: Print the error and clear the buffer
|
|
|
|
|
|
if (e.stack) { |
|
|
|
|
|
self.stream.write(e.stack + '\n'); |
|
|
|
|
|
} else { |
|
|
|
|
|
self.stream.write(e.toString() + '\n'); |
|
|
|
|
|
} |
|
|
|
|
|
self.buffered_cmd = ''; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.displayPrompt(); |
|
|
self.displayPrompt(); |
|
|