summaryrefslogtreecommitdiff
path: root/src/GF/Canon
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2006-12-21 00:01:45 +0000
committerbringert <bringert@cs.chalmers.se>2006-12-21 00:01:45 +0000
commit15fd1d590a70be3af1b4e0a6488ebba795922342 (patch)
tree6d1216f60425c92b1830cf7dce6722490fa96f3e /src/GF/Canon
parent7cceec08026535852091aa3db2ce73da32c06e17 (diff)
Generate JavaScript type annotator. Use lindef in JavaScript.
Diffstat (limited to 'src/GF/Canon')
-rw-r--r--src/GF/Canon/CanonToJS.hs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/GF/Canon/CanonToJS.hs b/src/GF/Canon/CanonToJS.hs
index 8260557a6..161a21fb0 100644
--- a/src/GF/Canon/CanonToJS.hs
+++ b/src/GF/Canon/CanonToJS.hs
@@ -11,11 +11,22 @@ prCanon2js :: CanonGrammar -> String
prCanon2js gr = gfcc2js $ mkCanon2gfcc gr
gfcc2js :: C.Grammar -> String
-gfcc2js (C.Grm _ _ cs) = JS.printTree $ JS.Program $ concatMap concrete2js cs
+gfcc2js (C.Grm (C.Hdr n _) as cs) = JS.printTree $ JS.Program $ abstract2js n as ++ concatMap (concrete2js n) cs
-concrete2js :: C.Concrete -> [JS.Element]
-concrete2js (C.Cnc (C.CId c) ds) =
- [JS.ElStmt $ JS.SDeclOrExpr $ JS.Decl [JS.DInit l (new "Linearizer" [])]]
+abstract2js :: C.CId -> C.Abstract -> [JS.Element]
+abstract2js (C.CId n) (C.Abs ds) =
+ [JS.ElStmt $ JS.SDeclOrExpr $ JS.Decl [JS.DInit a (new "Abstract" [])]]
+ ++ concatMap (absdef2js a) ds
+ where a = JS.Ident n
+
+absdef2js :: JS.Ident -> C.AbsDef -> [JS.Element]
+absdef2js a (C.Fun (C.CId f) (C.Typ args (C.CId cat)) _) =
+ [JS.ElStmt $ JS.SDeclOrExpr $ JS.DExpr $ JS.ECall (JS.EMember (JS.EVar a) (JS.Ident "addType"))
+ [JS.EStr f, JS.EArray [JS.EStr x | C.CId x <- args], JS.EStr cat]]
+
+concrete2js :: C.CId -> C.Concrete -> [JS.Element]
+concrete2js (C.CId a) (C.Cnc (C.CId c) ds) =
+ [JS.ElStmt $ JS.SDeclOrExpr $ JS.Decl [JS.DInit l (new "Concrete" [JS.EVar (JS.Ident a)])]]
++ concatMap (cncdef2js l) ds
where l = JS.Ident c