summaryrefslogtreecommitdiff
path: root/src/GF/CF
diff options
context:
space:
mode:
authoraarne <unknown>2004-04-16 15:21:56 +0000
committeraarne <unknown>2004-04-16 15:21:56 +0000
commitfa07ada6ab11f8e0820fe075ce58d8ca700e13e3 (patch)
treefa818d252e54bf621e61204cec19e8ed49ba2ae3 /src/GF/CF
parent26b03cef106c399f6417d9157466dee139c54c5a (diff)
added srg; extended shallow
Diffstat (limited to 'src/GF/CF')
-rw-r--r--src/GF/CF/CFtoSRG.hs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/GF/CF/CFtoSRG.hs b/src/GF/CF/CFtoSRG.hs
new file mode 100644
index 000000000..c90a772d8
--- /dev/null
+++ b/src/GF/CF/CFtoSRG.hs
@@ -0,0 +1,48 @@
+{-
+ **************************************************************
+ GF Module
+
+ Description : This module prints a CF as a SRG (Speech
+ Recognition Grammar).
+
+ Author : Markus Forsberg (markus@cs.chalmers.se)
+
+ License : GPL (GNU General Public License)
+
+ Created : 21 January, 2001
+
+ Modified : 16 April, 2004 by Aarne Ranta for GF 2
+ **************************************************************
+-}
+
+module CFtoSRG where
+
+import Operations
+import CF
+import CFIdent
+---import UseGrammar
+import PPrCF
+import List (intersperse)
+
+header :: String
+header = unlines ["#ABNF 1.0 ISO-8859-1;\n",
+ "language en;",
+ "mode voice;",
+ "root $Main;",
+ "meta \"author\" is \"Grammatical Framework\";\n"]
+
+prSRG :: CF -> String
+prSRG cf = (header ++) $ prSRGC (catsOfCF cf) cf
+
+prSRGC :: [CFCat] -> CF -> String
+prSRGC [] _ = []
+prSRGC (c:cs) cf = "$" ++ prCFCat c ++ " = " ++ items ++ ";\n"++ prSRGC cs cf
+ where items = concat $ intersperse " | " $
+ map f $ map valItemsCF (rulesForCFCat cf c)
+ f [] = "$NULL"
+ f xs = unwords $ map prSRGItem xs
+
+prSRGItem :: CFItem -> [Char]
+prSRGItem (CFNonterm c) = "$" ++ prCFCat c
+prSRGItem (CFTerm a) = prRegExp a
+