printing grammarReference.js with gfc -jsref

This commit is contained in:
aarne
2007-11-10 10:23:35 +00:00
parent 3f5801ed85
commit 980ec19999
3 changed files with 33 additions and 11 deletions

View File

@@ -50,20 +50,21 @@ file2gfcc f =
---- TODO: nicer and richer print options
alsoPrint opts abs gr (opt,name) =
if oElem (iOpt opt) opts
then do
let outfile = name
let output = prGFCC opt gr
writeFile outfile output
putStrLn $ "wrote file " ++ outfile
else return ()
alsoPrint opts abs gr (opt,name) = do
if oElem (iOpt opt) opts
then do
let outfile = name
let output = prGFCC opt gr
writeFile outfile output
putStrLn $ "wrote file " ++ outfile
else return ()
printOptions = [
("haskell","GSyntax.hs"),
("haskell_gadt","GSyntax.hs"),
("js","grammar.js")
("js","grammar.js"),
("jsref","grammarReference.js")
]
usageMsg =
"usage: gfc (-h | --make (-noopt) (-js | -haskell | -haskell_gadt)) (-src) FILES"
"usage: gfc (-h | --make (-noopt) (-js | -jsref | -haskell | -haskell_gadt)) (-src) FILES"

View File

@@ -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]

View File

@@ -11,4 +11,5 @@ prGFCC printer gr = case printer of
"haskell" -> grammar2haskell gr
"haskell_gadt" -> grammar2haskellGADT gr
"js" -> gfcc2js gr
"jsref" -> gfcc2grammarRef gr
_ -> printGFCC gr