tweak lambda evaluator
[lambda.git] / code / parse.js
index cb412f7..2718218 100644 (file)
@@ -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)"];
@@ -79,7 +79,6 @@ var make_parse = function () {
             s = Object.create(original_symbol);
             s.id = s.value = id;
             symbol_table[id] = s;
-                       print(s, s.arity);
         }
         return s;
     };
@@ -150,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;
                };
 
@@ -213,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);
@@ -249,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;