gflib.ts: fix in annotation when type is unknown

This commit is contained in:
John J. Camilleri
2019-06-13 14:12:53 +02:00
parent bc61f8c191
commit 498ad572ac
3 changed files with 11 additions and 10 deletions

View File

@@ -57,7 +57,7 @@ class GFGrammar { // eslint-disable-line @typescript-eslint/no-unused-vars
class Fun {
public name: string
public args: Fun[]
public type?: string
public type?: string // only used for meta variables
public constructor(name: string, ...args: Fun[]) {
this.name = name
@@ -173,11 +173,12 @@ class GFAbstract {
return this.types[fun].cat
}
private annotate(tree: Fun, type: string): Fun {
if (tree.name == '?') {
// Annotate (only) meta variables
private annotate(tree: Fun, type?: string): Fun {
let typ: Type | undefined = this.types[tree.name]
if (tree.isMeta()) {
tree.type = type
} else {
let typ = this.types[tree.name]
} else if (!isUndefined(typ)) {
for (let i in tree.args) {
this.annotate(tree.args[i], typ.args[i])
}
@@ -214,7 +215,7 @@ class GFAbstract {
return t
}
public parseTree(str: string, type: string): Fun | null {
public parseTree(str: string, type?: string): Fun | null {
let pt = this.parseTree_(str.match(/[\w\u00C0-\u00FF\'\.\"]+|\(|\)|\?|\:/g) || [], 0)
return pt ? this.annotate(pt, type) : null
}

View File

@@ -133,11 +133,11 @@ var GFAbstract = (function () {
return this.types[fun].cat;
};
GFAbstract.prototype.annotate = function (tree, type) {
if (tree.name == '?') {
var typ = this.types[tree.name];
if (tree.isMeta()) {
tree.type = type;
}
else {
var typ = this.types[tree.name];
else if (!isUndefined(typ)) {
for (var i in tree.args) {
this.annotate(tree.args[i], typ.args[i]);
}

File diff suppressed because one or more lines are too long