From eb7b0286016714128aae742b4cedccc3dc30a9a0 Mon Sep 17 00:00:00 2001 From: aarne Date: Sat, 10 Nov 2007 10:23:35 +0000 Subject: printing grammarReference.js with gfc -jsref --- src/GF/Devel/GFCCtoJS.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/GF/Devel/GFCCtoJS.hs') diff --git a/src/GF/Devel/GFCCtoJS.hs b/src/GF/Devel/GFCCtoJS.hs index 65d3185e2..5ec438bc7 100644 --- a/src/GF/Devel/GFCCtoJS.hs +++ b/src/GF/Devel/GFCCtoJS.hs @@ -1,4 +1,4 @@ -module GF.Devel.GFCCtoJS (gfcc2js) where +module GF.Devel.GFCCtoJS (gfcc2js,gfcc2grammarRef) where import qualified GF.GFCC.Macros as M import qualified GF.GFCC.DataGFCC as D @@ -84,3 +84,23 @@ children = JS.Ident "cs" new :: String -> [JS.Expr] -> JS.Expr new f xs = JS.ENew (JS.Ident f) xs + +-- grammar reference file for js applications. AR 10/11/2007 + +gfcc2grammarRef :: D.GFCC -> String +gfcc2grammarRef gfcc = + encodeUTF8 $ refs + where + C.CId abstr = D.absname gfcc + refs = unlines $ [ + "// Grammar Reference", + "function concreteReference(concreteSyntax, concreteSyntaxName) {", + "this.concreteSyntax = concreteSyntax;", + "this.concreteSyntaxName = concreteSyntaxName;", + "}", + "var myAbstract = " ++ abstr ++ " ;", + "var myConcrete = new Array();" + ] ++ [ + "myConcrete.push(new concreteReference(" ++ c ++ ",\"" ++ c ++ "\"));" + | C.CId c <- D.cncnames gfcc] + -- cgit v1.2.3