1
0
forked from GitHub/gf-core

Rename children to args in VoiceXML/SISR/JavaScript.

This commit is contained in:
bringert
2007-01-22 20:48:14 +00:00
parent 6bbc7e804f
commit 979a54af35
3 changed files with 29 additions and 29 deletions

View File

@@ -1,7 +1,7 @@
/* Abstract syntax trees */ /* Abstract syntax trees */
function Fun(name) { function Fun(name) {
this.name = name; this.name = name;
this.children = copy_arguments(arguments, 1); this.args = copy_arguments(arguments, 1);
} }
Fun.prototype.print = function () { return this.show(0); } ; Fun.prototype.print = function () { return this.show(0); } ;
Fun.prototype.show = function (prec) { Fun.prototype.show = function (prec) {
@@ -17,7 +17,7 @@ Fun.prototype.show = function (prec) {
} }
} else { } else {
var s = this.name; var s = this.name;
var cs = this.children; var cs = this.args;
for (var i in cs) { for (var i in cs) {
s += " " + cs[i].show(1); s += " " + cs[i].show(1);
} }
@@ -27,11 +27,11 @@ Fun.prototype.show = function (prec) {
return s; return s;
} }
}; };
Fun.prototype.getChild = function (i) { Fun.prototype.getArg = function (i) {
return this.children[i]; return this.args[i];
}; };
Fun.prototype.setChild = function (i,c) { Fun.prototype.setArg = function (i,c) {
this.children[i] = c; this.args[i] = c;
}; };
Fun.prototype.isMeta = function() { Fun.prototype.isMeta = function() {
return this.name == '?'; return this.name == '?';
@@ -40,8 +40,8 @@ Fun.prototype.isComplete = function() {
if (this.isMeta()) { if (this.isMeta()) {
return false; return false;
} else { } else {
for (var i in tree.children) { for (var i in tree.args) {
if (!tree.children[i].isComplete()) { if (!tree.args[i].isComplete()) {
return false; return false;
} }
} }
@@ -94,8 +94,8 @@ Abstract.prototype.annotate = function(tree, type) {
tree.type = type; tree.type = type;
} else { } else {
var typ = this.types[tree.name]; var typ = this.types[tree.name];
for (var i in tree.children) { for (var i in tree.args) {
this.annotate(tree.children[i], typ.args[i]); this.annotate(tree.args[i], typ.args[i]);
} }
} }
return tree; return tree;
@@ -106,10 +106,10 @@ Abstract.prototype.copyTree = function(x) {
if (!isUndefined(x.type)) { if (!isUndefined(x.type)) {
t.type = x.type; t.type = x.type;
} }
var cs = x.children; var cs = x.args;
if (!isUndefined(cs)) { if (!isUndefined(cs)) {
for (var i in cs) { for (var i in cs) {
t.setChild(i, this.copyTree(cs[i])); t.setArg(i, this.copyTree(cs[i]));
} }
} }
return t; return t;
@@ -131,7 +131,7 @@ Abstract.prototype.parseTree_ = function(tokens, prec) {
if (prec == 0) { if (prec == 0) {
var c, i; var c, i;
for (i = 0; (c = this.parseTree_(tokens, 1)) !== null; i++) { for (i = 0; (c = this.parseTree_(tokens, 1)) !== null; i++) {
tree.setChild(i,c); tree.setArg(i,c);
} }
} }
return tree; return tree;
@@ -162,8 +162,8 @@ Concrete.prototype.linearizeToTerm = function (tree) {
} }
} else { } else {
var cs = new Array(); var cs = new Array();
for (var i in tree.children) { for (var i in tree.args) {
cs.push(this.linearizeToTerm(tree.children[i])); cs.push(this.linearizeToTerm(tree.args[i]));
} }
return this.rule(tree.name, cs); return this.rule(tree.name, cs);
} }

View File

@@ -161,7 +161,7 @@ fun2sub gr cat fun args =
[param "old" v, [param "old" v,
filled [] [assign v (s++".term")]] filled [] [assign v (s++".term")]]
where s = prid fun ++ "_" ++ show n where s = prid fun ++ "_" ++ show n
v = "term.children["++show n++"]" v = "term.args["++show n++"]"
catFormId :: VIdent -> String catFormId :: VIdent -> String
catFormId c = prid c ++ "_cat" catFormId c = prid c ++ "_cat"

View File

@@ -43,20 +43,20 @@ topCatSISR c fmt = map JS.DExpr [fmtOut fmt `ass` fmtRef fmt c]
profileInitSISR :: CFTerm -> SISRFormat -> SISRTag profileInitSISR :: CFTerm -> SISRFormat -> SISRTag
profileInitSISR t fmt profileInitSISR t fmt
| null (usedChildren t) = [] | null (usedArgs t) = []
| otherwise = [JS.Decl [JS.DInit children (JS.EArray [])]] | otherwise = [JS.Decl [JS.DInit args (JS.EArray [])]]
usedChildren :: CFTerm -> [Int] usedArgs :: CFTerm -> [Int]
usedChildren (CFObj _ ts) = foldr union [] (map usedChildren ts) usedArgs (CFObj _ ts) = foldr union [] (map usedArgs ts)
usedChildren (CFAbs _ x) = usedChildren x usedArgs (CFAbs _ x) = usedArgs x
usedChildren (CFApp x y) = usedChildren x `union` usedChildren y usedArgs (CFApp x y) = usedArgs x `union` usedArgs y
usedChildren (CFRes i) = [i] usedArgs (CFRes i) = [i]
usedChildren _ = [] usedArgs _ = []
catSISR :: CFTerm -> SRGNT -> SISRFormat -> SISRTag catSISR :: CFTerm -> SRGNT -> SISRFormat -> SISRTag
catSISR t (c,i) fmt catSISR t (c,i) fmt
| i `elem` usedChildren t = map JS.DExpr | i `elem` usedArgs t = map JS.DExpr
[JS.EIndex (JS.EVar children) (JS.EInt (fromIntegral i)) `ass` fmtRef fmt c] [JS.EIndex (JS.EVar args) (JS.EInt (fromIntegral i)) `ass` fmtRef fmt c]
| otherwise = [] | otherwise = []
profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag
@@ -65,7 +65,7 @@ profileFinalSISR term fmt = [JS.DExpr $ fmtOut fmt `ass` f term]
f (CFObj n ts) = tree (prIdent n) (map f ts) f (CFObj n ts) = tree (prIdent n) (map f ts)
f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)] f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)]
f (CFApp x y) = JS.ECall (f x) [f y] f (CFApp x y) = JS.ECall (f x) [f y]
f (CFRes i) = JS.EIndex (JS.EVar children) (JS.EInt (fromIntegral i)) f (CFRes i) = JS.EIndex (JS.EVar args) (JS.EInt (fromIntegral i))
f (CFVar v) = JS.EVar (var v) f (CFVar v) = JS.EVar (var v)
f (CFConst s) = JS.EStr s f (CFConst s) = JS.EStr s
f (CFMeta typ) = obj [("name",JS.EStr "?"), ("type",JS.EStr typ)] f (CFMeta typ) = obj [("name",JS.EStr "?"), ("type",JS.EStr typ)]
@@ -74,7 +74,7 @@ fmtOut SISROld = JS.EVar (JS.Ident "$")
fmtRef SISROld c = JS.EVar (JS.Ident ("$" ++ c)) fmtRef SISROld c = JS.EVar (JS.Ident ("$" ++ c))
children = JS.Ident "c" args = JS.Ident "a"
var v = JS.Ident ("x" ++ show v) var v = JS.Ident ("x" ++ show v)
@@ -82,7 +82,7 @@ field x y = JS.EMember x (JS.Ident y)
ass = JS.EAssign ass = JS.EAssign
tree n xs = obj [("name", JS.EStr n), ("children", JS.EArray xs)] tree n xs = obj [("name", JS.EStr n), ("args", JS.EArray xs)]
obj ps = JS.EObj [JS.Prop (JS.Ident x) y | (x,y) <- ps] obj ps = JS.EObj [JS.Prop (JS.Ident x) y | (x,y) <- ps]