forked from GitHub/gf-core
JavaScript: change Fun.toString to print(). Metavariables in abstract syntax are now Funs with name ?
This commit is contained in:
@@ -3,12 +3,12 @@
|
|||||||
function Fun(name) {
|
function Fun(name) {
|
||||||
this.name = 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) {
|
Fun.prototype.show = function (prec) {
|
||||||
var s = this.name;
|
var s = this.name;
|
||||||
var cs = this.getChildren();
|
var cs = this.getChildren();
|
||||||
for (var c in cs) {
|
for (var i in cs) {
|
||||||
s += " " + c.show(1);
|
s += " " + cs[i].show(1);
|
||||||
}
|
}
|
||||||
if (prec > 0 && cs.length > 0) {
|
if (prec > 0 && cs.length > 0) {
|
||||||
s = "(" + s + ")" ;
|
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. */
|
/* Hack to get around the fact that our SISR doesn't build real Fun objects. */
|
||||||
function copyTree(x) {
|
function copyTree(x) {
|
||||||
if (typeof x == 'string' && x == '?') {
|
if (typeof x == 'string' && x == '?') {
|
||||||
return '?';
|
return new Fun('?');
|
||||||
} else {
|
} else {
|
||||||
var t = new Fun(x.name);
|
var t = new Fun(x.name);
|
||||||
for (var i = 0; ; i++) {
|
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.addRule = function (name, f) { this.rules[name] = f; };
|
||||||
Linearizer.prototype.linearize = function (tree) { return this.linearizeToTerm(tree).print(); };
|
Linearizer.prototype.linearize = function (tree) { return this.linearizeToTerm(tree).print(); };
|
||||||
Linearizer.prototype.linearizeToTerm = function (tree) {
|
Linearizer.prototype.linearizeToTerm = function (tree) {
|
||||||
if (typeof tree == 'string' && tree == '?') {
|
if (tree.name == '?') {
|
||||||
return new Meta();
|
return new Meta();
|
||||||
} else {
|
} else {
|
||||||
var cs = tree.getChildren();
|
var cs = tree.getChildren();
|
||||||
|
|||||||
Reference in New Issue
Block a user