mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Implemented continuable lines in the REPL. Use a trailing slash. Multiline functions are now possible.
This commit is contained in:
parent
9a63b3147f
commit
d8823ed45e
2 changed files with 17 additions and 6 deletions
13
lib/repl.js
13
lib/repl.js
|
@ -1,18 +1,23 @@
|
|||
(function() {
|
||||
var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, helpers, readline, repl, run, stdio;
|
||||
var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, readline, repl, run, stdio;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
CoffeeScript = require('./coffee-script');
|
||||
helpers = require('./helpers');
|
||||
readline = require('readline');
|
||||
Script = process.binding('evals').Script;
|
||||
stdio = process.openStdin();
|
||||
error = function(err) {
|
||||
return stdio.write((err.stack || err.toString()) + '\n\n');
|
||||
};
|
||||
backlog = '';
|
||||
run = function(buffer) {
|
||||
var val;
|
||||
var code, val;
|
||||
code = backlog += '\n' + buffer.toString();
|
||||
if (code[code.length - 1] === '\\') {
|
||||
return backlog = backlog.slice(0, backlog.length - 1);
|
||||
}
|
||||
backlog = '';
|
||||
try {
|
||||
val = CoffeeScript.eval(buffer.toString(), {
|
||||
val = CoffeeScript.eval(code, {
|
||||
bare: true,
|
||||
globals: true,
|
||||
filename: 'repl'
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
# Require the **coffee-script** module to get access to the compiler.
|
||||
CoffeeScript = require './coffee-script'
|
||||
helpers = require './helpers'
|
||||
readline = require 'readline'
|
||||
Script = process.binding('evals').Script
|
||||
|
||||
|
@ -19,12 +18,19 @@ stdio = process.openStdin()
|
|||
error = (err) ->
|
||||
stdio.write (err.stack or err.toString()) + '\n\n'
|
||||
|
||||
# The current backlog of multi-line code.
|
||||
backlog = ''
|
||||
|
||||
# The main REPL function. **run** is called every time a line of code is entered.
|
||||
# Attempt to evaluate the command. If there's an exception, print it out instead
|
||||
# of exiting.
|
||||
run = (buffer) ->
|
||||
code = backlog += '\n' + buffer.toString()
|
||||
if code[code.length - 1] is '\\'
|
||||
return backlog = backlog[0...backlog.length - 1]
|
||||
backlog = ''
|
||||
try
|
||||
val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, filename: 'repl'
|
||||
val = CoffeeScript.eval code, bare: on, globals: on, filename: 'repl'
|
||||
console.log val if val isnt undefined
|
||||
catch err
|
||||
error err
|
||||
|
|
Loading…
Add table
Reference in a new issue