X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Fparse.js;h=27182189aa9b29b3e9b89a9d0765a7731911d078;hp=2e0745bafdbcf0742761eb32d4dce936bf7cc7e6;hb=c5d5e93f0c0aedb6c149f06870792c7d219a5081;hpb=15b7032f306b4635b92feb1a43a33b501f5861d4 diff --git a/code/parse.js b/code/parse.js index 2e0745ba..27182189 100644 --- a/code/parse.js +++ b/code/parse.js @@ -34,10 +34,10 @@ var make_parse = function () { a = t.type; if (a === "name") { o = symbol_table[v]; - if (o && typeof o !== 'function') { - a = "keyword"; - } else { + if (!o || typeof o === 'function') { o = symbol_table["(name)"]; + } else { + a = o.arity || "keyword"; } } else if (a === "number") { o = symbol_table["(literal)"]; @@ -65,6 +65,14 @@ var make_parse = function () { } }; + try { + if (console && console.debug) { + function print() { + console.debug.apply(this, arguments); + } + } + } catch (e) {} + var symbol = function (id) { var s = symbol_table[id]; if (!s) { @@ -75,14 +83,6 @@ var make_parse = function () { return s; }; -// try { -// if (console && console.debug) { -// function print() { -// console.debug.apply(this, arguments); -// } -// } -// } catch (e) {} - var var_table; var name_table; @@ -149,10 +149,10 @@ var make_parse = function () { var x = symbol(s); x.handler = function () { this.value = symbol_table[this.id].value; - this.arity = "literal"; return this; }; x.value = v; + x.arity = "literal"; return x; }; @@ -212,7 +212,11 @@ var make_parse = function () { n = token; advance(); } - if (token.id === ".") { + if (token.arity === "literal" && t.first.length === 0) { + t.first.push(n); + t.second = token; + advance(); + } else if (token.id === ".") { t.first.push(n); advance(); t.second = expression(in_let); @@ -248,8 +252,8 @@ var make_parse = function () { n = token; advance(")"); } else { - if (token.arity !== "name") { - token.error("Expected a variable name."); + if (token.arity !== "name" && token.arity !== "literal") { + token.error("Expected a variable name or literal."); } token.first = n; n = token;