From 3cf9e2522547c790dec7a7cb359ede52547e4008 Mon Sep 17 00:00:00 2001 From: bringert Date: Fri, 15 Dec 2006 17:25:45 +0000 Subject: [PATCH] JavaScript: change Fun.toString to print(). Metavariables in abstract syntax are now Funs with name ? --- lib/javascript/gflib.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/javascript/gflib.js b/lib/javascript/gflib.js index 630c01a3d..194fe57db 100644 --- a/lib/javascript/gflib.js +++ b/lib/javascript/gflib.js @@ -3,12 +3,12 @@ function Fun(name) { this.name = name; } -Fun.prototype.toString = function () { return this.show(0); } ; +Fun.prototype.print = function () { return this.show(0); } ; Fun.prototype.show = function (prec) { var s = this.name; var cs = this.getChildren(); - for (var c in cs) { - s += " " + c.show(1); + for (var i in cs) { + s += " " + cs[i].show(1); } if (prec > 0 && cs.length > 0) { s = "(" + s + ")" ; @@ -36,7 +36,7 @@ Fun.prototype.getChildren = function () { /* Hack to get around the fact that our SISR doesn't build real Fun objects. */ function copyTree(x) { if (typeof x == 'string' && x == '?') { - return '?'; + return new Fun('?'); } else { var t = new Fun(x.name); for (var i = 0; ; i++) { @@ -116,7 +116,7 @@ Linearizer.prototype.rule = function (name, cs) { return this.rules[name](cs); } Linearizer.prototype.addRule = function (name, f) { this.rules[name] = f; }; Linearizer.prototype.linearize = function (tree) { return this.linearizeToTerm(tree).print(); }; Linearizer.prototype.linearizeToTerm = function (tree) { - if (typeof tree == 'string' && tree == '?') { + if (tree.name == '?') { return new Meta(); } else { var cs = tree.getChildren();