mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
Changed gflib.js to handle linearization of literals. This duplicates some functionality from gfjseditor.js, but is required for the translator to be able to linearize literals. The editor should be fixed to remove the special code for literals, but it is a bit to much for me to understand right now.
This commit is contained in:
@@ -97,6 +97,9 @@ Fun.prototype.isComplete = function() {
|
||||
return true;
|
||||
}
|
||||
} ;
|
||||
Fun.prototype.isLiteral = function() {
|
||||
return (/^[\"\d]/).test(this.name);
|
||||
} ;
|
||||
|
||||
/* Concrete syntax terms */
|
||||
|
||||
@@ -279,7 +282,14 @@ function GFConcrete(flags, rules, parser) {
|
||||
this.parser = undefined;
|
||||
}
|
||||
}
|
||||
GFConcrete.prototype.rule = function (name, cs) { return this.rules[name](cs); };
|
||||
GFConcrete.prototype.rule = function (name, cs) {
|
||||
var r = this.rules[name];
|
||||
if (r) {
|
||||
return this.rules[name](cs);
|
||||
} else {
|
||||
window.alert("Missing rule " + name);
|
||||
}
|
||||
};
|
||||
GFConcrete.prototype.addRule = function (name, f) { this.rules[name] = f; };
|
||||
GFConcrete.prototype.lindef = function (cat, v) { return this.rules[cat]([new Str(v)]); } ;
|
||||
GFConcrete.prototype.linearize = function (tree) {
|
||||
@@ -297,8 +307,11 @@ GFConcrete.prototype.linearizeToTerm = function (tree) {
|
||||
for (var i in tree.args) {
|
||||
cs.push(this.linearizeToTerm(tree.args[i]));
|
||||
}
|
||||
var newTerm = this.rule(tree.name, cs);
|
||||
return newTerm;
|
||||
if (tree.isLiteral()) {
|
||||
return new Arr(new Str(tree.name));
|
||||
} else {
|
||||
return this.rule(tree.name, cs);
|
||||
}
|
||||
}
|
||||
};
|
||||
GFConcrete.prototype.unlex = function (ts) {
|
||||
|
||||
Reference in New Issue
Block a user