mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
gflib.ts: fix in annotation when type is unknown
This commit is contained in:
@@ -57,7 +57,7 @@ class GFGrammar { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|||||||
class Fun {
|
class Fun {
|
||||||
public name: string
|
public name: string
|
||||||
public args: Fun[]
|
public args: Fun[]
|
||||||
public type?: string
|
public type?: string // only used for meta variables
|
||||||
|
|
||||||
public constructor(name: string, ...args: Fun[]) {
|
public constructor(name: string, ...args: Fun[]) {
|
||||||
this.name = name
|
this.name = name
|
||||||
@@ -173,11 +173,12 @@ class GFAbstract {
|
|||||||
return this.types[fun].cat
|
return this.types[fun].cat
|
||||||
}
|
}
|
||||||
|
|
||||||
private annotate(tree: Fun, type: string): Fun {
|
// Annotate (only) meta variables
|
||||||
if (tree.name == '?') {
|
private annotate(tree: Fun, type?: string): Fun {
|
||||||
|
let typ: Type | undefined = this.types[tree.name]
|
||||||
|
if (tree.isMeta()) {
|
||||||
tree.type = type
|
tree.type = type
|
||||||
} else {
|
} else if (!isUndefined(typ)) {
|
||||||
let typ = this.types[tree.name]
|
|
||||||
for (let i in tree.args) {
|
for (let i in tree.args) {
|
||||||
this.annotate(tree.args[i], typ.args[i])
|
this.annotate(tree.args[i], typ.args[i])
|
||||||
}
|
}
|
||||||
@@ -214,7 +215,7 @@ class GFAbstract {
|
|||||||
return t
|
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)
|
let pt = this.parseTree_(str.match(/[\w\u00C0-\u00FF\'\.\"]+|\(|\)|\?|\:/g) || [], 0)
|
||||||
return pt ? this.annotate(pt, type) : null
|
return pt ? this.annotate(pt, type) : null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,11 +133,11 @@ var GFAbstract = (function () {
|
|||||||
return this.types[fun].cat;
|
return this.types[fun].cat;
|
||||||
};
|
};
|
||||||
GFAbstract.prototype.annotate = function (tree, type) {
|
GFAbstract.prototype.annotate = function (tree, type) {
|
||||||
if (tree.name == '?') {
|
var typ = this.types[tree.name];
|
||||||
|
if (tree.isMeta()) {
|
||||||
tree.type = type;
|
tree.type = type;
|
||||||
}
|
}
|
||||||
else {
|
else if (!isUndefined(typ)) {
|
||||||
var typ = this.types[tree.name];
|
|
||||||
for (var i in tree.args) {
|
for (var i in tree.args) {
|
||||||
this.annotate(tree.args[i], typ.args[i]);
|
this.annotate(tree.args[i], typ.args[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user