Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Add comment support at end of line #194

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var grammar = {
"line": [
["statement", "$$ = $1;"],
["expression", "$$ = $1;"],
["statement COMMENT", "$$ = $1;"],
["expression COMMENT", "$$ = $1;"],
["COMMENT", n("$$ = new yy.Comment($1);")]
],
"block": [
Expand Down
67 changes: 39 additions & 28 deletions src/node-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var getFileContents = function(filename) {
return source;
};


var nodeRepl = function(opts) {
var readline = require('readline'),
path = require('path'),
Expand All @@ -69,6 +70,16 @@ var nodeRepl = function(opts) {
console.log(opts.info.author);
console.log(":? for help");

var usage = function() {
colorLog(32, "Commands available from the prompt");
console.log(":l -- load and run an external file");
console.log(":q -- exit REPL");
console.log(":s -- show original code about identifier");
console.log(":t -- show the type of the identifier");
console.log(":? -- show help");
}


var colorLog = function(color) {
var args = [].slice.call(arguments, 1);

Expand Down Expand Up @@ -133,37 +144,37 @@ var nodeRepl = function(opts) {
break;
case ":?":
// Help
colorLog(32, "Commands available from the prompt");
console.log(":l -- load and run an external file");
console.log(":q -- exit REPL");
console.log(":s -- show original code about identifier");
console.log(":t -- show the type of the identifier");
console.log(":? -- show help");
usage()
break;
default:
// The line isn't a metacommand

// Remember the source if it's a binding
tokens = lexer.tokenise(line);
ast = parser.parse(tokens);
if (typeof ast.body[0] != 'undefined') {
ast.body[0].accept({
// Simple bindings.
// E.g.: let x = 37
visitLet: function(n) {
sources[n.name] = n.value;
},
// Bindings that are actually functions.
// E.g.: let f x = 37
visitFunction: function(n) {
sources[n.name] = n;
}
});
}
if (metacommand[0].substr(0, 1) == ':') {
// The line isn't a known metacommand
colorLog(33, "Command " + metacommand[0] + "is not defined")
usage()
} else {

// Just eval it
compiled = compile(line, env, aliases, {nodejs: true, filename: ".", run: true});
break;
// Remember the source if it's a binding
tokens = lexer.tokenise(line);
ast = parser.parse(tokens);
if (typeof ast.body[0] != 'undefined') {
ast.body[0].accept({
// Simple bindings.
// E.g.: let x = 37
visitLet: function(n) {
sources[n.name] = n.value;
},
// Bindings that are actually functions.
// E.g.: let f x = 37
visitFunction: function(n) {
sources[n.name] = n;
}
});
}

// Just eval it
compiled = compile(line, env, aliases, {nodejs: true, filename: ".", run: true});
break;
}
}

if(compiled) {
Expand Down