diff options
| author | aarne <aarne@cs.chalmers.se> | 2007-05-10 12:51:40 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2007-05-10 12:51:40 +0000 |
| commit | 278a0ab45d02e85ba6d863615abaaf24bba5317b (patch) | |
| tree | 9be00a21360f6c0397760f8e181b99147607a6b1 /src/GF/Canon | |
| parent | e63fcd0a1fe2ae6bb1fa27bc04bcef22772954b0 (diff) | |
printing abs as BNF
Diffstat (limited to 'src/GF/Canon')
| -rw-r--r-- | src/GF/Canon/AbsToBNF.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/GF/Canon/AbsToBNF.hs b/src/GF/Canon/AbsToBNF.hs new file mode 100644 index 000000000..71845971c --- /dev/null +++ b/src/GF/Canon/AbsToBNF.hs @@ -0,0 +1,32 @@ +module GF.Canon.AbsToBNF where + +import GF.Grammar.SGrammar +import GF.Data.Operations +import GF.Infra.Option +import GF.Canon.GFC (CanonGrammar) + +abstract2bnf :: CanonGrammar -> String +abstract2bnf = sgrammar2bnf . gr2sgr noOptions emptyProbs + +sgrammar2bnf :: SGrammar -> String +sgrammar2bnf = unlines . map (prBNFRule . mkBNF) . allRules + +prBNFRule :: BNFRule -> String +prBNFRule = id + +type BNFRule = String + +mkBNF :: SRule -> BNFRule +mkBNF (pfun,(args,cat)) = + fun ++ "." +++ gfId cat +++ "::=" +++ rhs +++ ";" + where + fun = gfId (snd pfun) + rhs = case args of + [] -> prQuotedString (snd pfun) + _ -> unwords (map gfId args) + +gfId i = case i of + "Int" -> "Integer" + "String" -> i + "Float" -> "Double" + _ -> "G" ++ i ++ "_" |
