From 042a950cffd37f2e38875914062d37dcc6b344f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Tue, 22 Jan 2013 03:07:19 -0500 Subject: [PATCH 1/5] Git ignore node_modules folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules From 9fb0c570f15d36013532b44c22b4f57606d539c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Tue, 22 Jan 2013 03:07:33 -0500 Subject: [PATCH 2/5] fix typo in header of macros.ls --- src/macros.ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macros.ls b/src/macros.ls index ca29755..d7b70f9 100644 --- a/src/macros.ls +++ b/src/macros.ls @@ -2,7 +2,7 @@ ;; default by the LispyScript compiler. -;;;;;;;;;;;;;;;;;;;; Conditinals ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;; Conditionals ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (macro undefined? (obj) (= (typeof ~obj) "undefined")) From b98a366cc6a2ff26e9360a6ebd0f991b9823f042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Tue, 22 Jan 2013 03:10:52 -0500 Subject: [PATCH 3/5] in ls.js parse, separate sections with whitespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each section parses only related constructs. Separating the sections makes it easier to skim them to find the section you’re looking for. I also added header comments for especially long or non-obvious sections – “strings”, “data types”, and “regexes”. --- lib/ls.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ls.js b/lib/ls.js index 793ed9b..9b2816f 100755 --- a/lib/ls.js +++ b/lib/ls.js @@ -68,16 +68,21 @@ var parse = function(code, filename) { while (pos < length) { var c = code.charAt(pos); pos++; + if (c == "\n") { lineno++; if (isComment) isComment = false; } + if (isComment) continue; + if (isEscape) { isEscape = false; token += c; continue; } + + // strings if (c == '"') { isString = !isString; token += c; @@ -101,6 +106,8 @@ var parse = function(code, filename) { token += c; continue; } + + // data types if (c == '[') { isJSArray++; token += c; @@ -131,10 +138,13 @@ var parse = function(code, filename) { token += c; continue; } + if (c == ";") { isComment = true; continue; } + + // regexes // regex in function position with first char " " is a prob. Use \s instead. if (c === "/" && !(tree.length === 0 && token.length === 0 && isWhitespace.test(code.charAt(pos)))) { isRegex = !isRegex; @@ -146,6 +156,7 @@ var parse = function(code, filename) { token += c; continue; } + if (c == "(") { tree.push(parser()); continue; @@ -155,10 +166,12 @@ var parse = function(code, filename) { handleToken(); break; } + if (isWhitespace.test(c)) { handleToken(); continue; } + token += c; } if (isString) handleError(3, tree._line, tree._filename); From 42767b7893b201eda7f7356f54293020480280cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Tue, 22 Jan 2013 04:16:43 -0500 Subject: [PATCH 4/5] change whitespace from tabs to spaces to match the whitespace style of the rest of the file I had forgotten that my Vim configuration was set to tabs. --- lib/ls.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ls.js b/lib/ls.js index 9b2816f..1c4d500 100755 --- a/lib/ls.js +++ b/lib/ls.js @@ -82,7 +82,7 @@ var parse = function(code, filename) { continue; } - // strings + // strings if (c == '"') { isString = !isString; token += c; @@ -107,7 +107,7 @@ var parse = function(code, filename) { continue; } - // data types + // data types if (c == '[') { isJSArray++; token += c; @@ -144,7 +144,7 @@ var parse = function(code, filename) { continue; } - // regexes + // regexes // regex in function position with first char " " is a prob. Use \s instead. if (c === "/" && !(tree.length === 0 && token.length === 0 && isWhitespace.test(code.charAt(pos)))) { isRegex = !isRegex; From f9004378fa4c6294470ec7f7783e102a4a9e7bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Tue, 22 Jan 2013 05:24:36 -0500 Subject: [PATCH 5/5] ls.js: extract variable indentSize=4 --- lib/ls.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ls.js b/lib/ls.js index 1c4d500..debeb15 100755 --- a/lib/ls.js +++ b/lib/ls.js @@ -24,7 +24,8 @@ var banner = "// Generated by LispyScript v" + this.version + "\n", noReturn = /^var\b|^set\b|^throw\b/, isHomoiconicExpr = /^#args-if\b|^#args-shift\b|^#args-second\b/, noSemiColon = false; - indent = -4, + indentSize = 4; + indent = -indentSize, keywords = {}, macros = {}, templates = {}; @@ -188,7 +189,7 @@ var parse = function(code, filename) { }; var handleExpressions = function(exprs) { - indent += 4; + indent += indentSize; var ret = "", l = exprs.length, indentstr = " ".repeat(indent); @@ -214,7 +215,7 @@ var handleExpressions = function(exprs) { ret += indentstr + r + tmp + endline; } }); - indent -= 4; + indent -= indentSize; return ret; }; @@ -380,14 +381,14 @@ keywords["try"] = function(arr) { keywords["if"] = function(arr) { if (arr.length < 3 || arr.length > 4) handleError(0, arr._line, arr._filename); - indent += 4; + indent += indentSize; handleSubExpressions(arr); var ret = templates["if"]({ condition: arr[1], trueexpr: arr[2], falseexpr: arr[3] || "undefined", indent: " ".repeat(indent)}); - indent -= 4; + indent -= indentSize; return ret; }; @@ -417,7 +418,7 @@ var includeFile = (function () { keywords["include"] = function(arr) { if (arr.length != 2) handleError(0, arr._line, arr._filename); - indent -= 4; + indent -= indentSize; var filename = arr[1]; if (typeof filename === "string") filename = filename.replace(/["']/g, ""); @@ -431,7 +432,7 @@ keywords["include"] = function(arr) { } } var ret = includeFile(filename); - indent += 4; + indent += indentSize; return ret; };