From c0f3b83319002965175a023f56964acedec05a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Payrard?= Date: Sat, 10 Aug 2013 01:41:48 +0200 Subject: [PATCH 1/2] Add comment support at end of line Unlike a whole comment line. A trailing comment does not appear in the javascript source. That should be fixable but less urgent --- src/grammar.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/grammar.js b/src/grammar.js index e3febbc..1dc784c 100644 --- a/src/grammar.js +++ b/src/grammar.js @@ -33,6 +33,8 @@ var grammar = { "line": [ ["statement", "$$ = $1;"], ["expression", "$$ = $1;"], + ["statement COMMENT", "$$ = $1;"], + ["expression COMMENT", "$$ = $1;"], ["COMMENT", n("$$ = new yy.Comment($1);")] ], "block": [ From f4c6641c8ffb1b1b0b0db2a4f083189e96a8a125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Payrard?= Date: Thu, 15 Aug 2013 07:57:36 +0200 Subject: [PATCH 2/2] show a usage message for a unkown command --- src/node-repl.js | 67 ++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/src/node-repl.js b/src/node-repl.js index 22f6f5f..f171b6d 100644 --- a/src/node-repl.js +++ b/src/node-repl.js @@ -49,6 +49,7 @@ var getFileContents = function(filename) { return source; }; + var nodeRepl = function(opts) { var readline = require('readline'), path = require('path'), @@ -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); @@ -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) {