Meta variables are now treated as functions with name ? in SISR, VoiceXML and JavaScript linearization. VoiceXML now returns the partial result when update() is false.

This commit is contained in:
bringert
2006-12-21 16:48:46 +00:00
parent 51df5b8a8d
commit a335b29c0a
11 changed files with 178 additions and 88 deletions

View File

@@ -119,22 +119,22 @@ catForms gr qs cat fs =
cat2form :: String -> CatQuestions -> VIdent -> [(VIdent, [VIdent])] -> XML
cat2form gr qs cat fs =
form (catFormId cat) $
[var "value" (Just "'?'"),
[var "value" (Just "{ name : '?' }"),
var "update" Nothing,
blockCond "value != '?'" [assign (catFieldId cat) "value"],
blockCond "value.name != '?'" [assign (catFieldId cat) "value"],
field (catFieldId cat) []
[promptString (getCatQuestion cat qs),
grammar (gr++"#"++catFormId cat),
nomatch [Data "I didn't understand you.", reprompt],
help [Data ("help_"++cat)],
filled [] [if_else (catFieldId cat ++ " == '?'") [reprompt] feedback]]
filled [] [if_else (catFieldId cat ++ ".name == '?'") [reprompt] feedback]]
]
++ concatMap (uncurry (fun2sub gr cat)) fs
++ [block [return_ [catFieldId cat]]]
where feedback = [if_ ("typeof update != 'undefined' && !update("++string cat++","++ catFieldId cat ++ ")") [return_ []]]
where feedback = [if_ ("typeof update != 'undefined' && !update("++string cat++","++ catFieldId cat ++ ")") [return_ [catFieldId cat]]]
fun2sub :: String -> VIdent -> VIdent -> [VIdent] -> [XML]
fun2sub gr cat fun args = comments [fun ++ " : " ++ cat] ++ ss
fun2sub gr cat fun args = comments [fun ++ " : (" ++ concat (intersperse ", " args) ++ ") " ++ cat] ++ ss
where
argNames = zip ["arg"++show n | n <- [0..]] args
ss = map (uncurry mkSub) argNames

View File

@@ -44,7 +44,7 @@ topCatSISR i c fmt = map JS.DExpr [field (fmtOut fmt) i `ass` fmtRef fmt c]
profileInitSISR :: CFTerm -> SISRFormat -> SISRTag
profileInitSISR t fmt
| null (usedChildren t) = []
| otherwise = [JS.Decl [JS.DInit children (JS.ENew (JS.Ident "Array") [])]]
| otherwise = [JS.Decl [JS.DInit children (JS.EArray [])]]
usedChildren :: CFTerm -> [Int]
usedChildren (CFObj _ ts) = foldr union [] (map usedChildren ts)
@@ -60,24 +60,15 @@ catSISR t (c,i) fmt
| otherwise = []
profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag
profileFinalSISR term fmt = map JS.DExpr $ g term
profileFinalSISR term fmt = [JS.DExpr $ fmtOut fmt `ass` f term]
where
-- optimization for tokens
g (CFObj n []) = [field (fmtOut fmt) "name" `ass` JS.EStr (prIdent n)]
g t = [fmtOut fmt `ass` f t]
f (CFObj n ts) =
JS.ESeq $ [ret `ass` JS.ENew (JS.Ident "Object") [],
field ret "name" `ass` JS.EStr (prIdent n)]
++ [field ret ("arg"++show i) `ass` f t
| (i,t) <- zip [0..] ts ]
++ [ret]
where ret = JS.EVar (JS.Ident "ret")
f (CFObj n ts) = tree (prIdent n) (map f ts)
f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)]
f (CFApp x y) = JS.ECall (f x) [f y]
f (CFRes i) = JS.EIndex (JS.EVar children) (JS.EInt (fromIntegral i))
f (CFVar v) = JS.EVar (var v)
f (CFConst s) = JS.EStr s
f CFMeta = tree "?" []
fmtOut SISROld = JS.EVar (JS.Ident "$")
@@ -89,4 +80,7 @@ var v = JS.Ident ("x" ++ show v)
field x y = JS.EMember x (JS.Ident y)
ass = JS.EAssign
ass = JS.EAssign
tree n xs = JS.EObj $ [JS.Prop (JS.Ident "name") (JS.EStr n)]
++ [JS.Prop (JS.Ident ("arg"++show i)) x | (i,x) <- zip [0..] xs]

View File

@@ -54,6 +54,7 @@ data CFTerm
| CFRes Int
| CFVar Int
| CFConst String
| CFMeta
deriving (Eq,Show)
type Cat_ = String
@@ -69,7 +70,7 @@ cfgToCFRules cfg =
where symb = mapSymbol catToString id
catToString = prt
nameToTerm (Name f prs) = CFObj f (map profileToTerm prs)
profileToTerm (Unify []) = CFConst "?"
profileToTerm (Unify []) = CFMeta
profileToTerm (Unify xs) = CFRes (last xs) -- FIXME: unify
profileToTerm (Constant f) = CFConst (maybe "?" prIdent (forestName f))