diff options
| author | aarne <unknown> | 2004-03-24 15:09:06 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2004-03-24 15:09:06 +0000 |
| commit | dc71ffcf5bae1f2b91467de273c71e7c3294acb3 (patch) | |
| tree | a4e705bba717aa9f7421c000cfa5756d5eb8462b /src/GF/CF/CFtoGrammar.hs | |
| parent | 31836c0da9ba7a716ee0480e6219d771da4999fa (diff) | |
Restoring old functionality
Diffstat (limited to 'src/GF/CF/CFtoGrammar.hs')
| -rw-r--r-- | src/GF/CF/CFtoGrammar.hs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/GF/CF/CFtoGrammar.hs b/src/GF/CF/CFtoGrammar.hs new file mode 100644 index 000000000..440c4f7c3 --- /dev/null +++ b/src/GF/CF/CFtoGrammar.hs @@ -0,0 +1,50 @@ +module CFtoGrammar where + +import Ident +import Grammar +import qualified AbsGF as A +import qualified GrammarToSource as S +import Macros + +import CF +import CFIdent +import PPrCF + +import Operations + +import List (nub) +import Char (isSpace) + +-- 26/1/2000 -- 18/4 -- 24/3/2004 + +cf2grammar :: CF -> [A.TopDef] +cf2grammar cf = concatMap S.trAnyDef (abs ++ conc) where + rules = rulesOfCF cf + abs = cats ++ funs + conc = lintypes ++ lins + cats = [(cat, AbsCat (yes []) (yes [])) | + cat <- nub (concat (map cf2cat rules))] ----notPredef cat + lintypes = [] ----[(cat, CncCat (yes) nope Nothing) | (cat,AbsCat _ _) <- cats] + (funs,lins) = unzip (map cf2rule rules) + +cf2cat :: CFRule -> [Ident] +cf2cat (_,(cat, items)) = map cfCat2Ident $ cat : [c | CFNonterm c <- items] + +cf2rule :: CFRule -> ((Ident,Info),(Ident,Info)) +cf2rule (fun, (cat, items)) = (def,ldef) where + f = cfFun2Ident fun + def = (f, AbsFun (yes (mkProd (args', Cn (cfCat2Ident cat), []))) nope) + args0 = zip (map (mkIdent "x") [0..]) items + args = [(v, Cn (cfCat2Ident c)) | (v, CFNonterm c) <- args0] + args' = [(zIdent "_", Cn (cfCat2Ident c)) | (_, CFNonterm c) <- args0] + ldef = (f, CncFun + Nothing + (yes (mkAbs (map fst args) + (mkRecord linLabel [foldconcat (map mkIt args0)]))) + nope) + mkIt (v, CFNonterm _) = P (Vr v) (linLabel 0) + mkIt (_, CFTerm (RegAlts [a])) = K a + mkIt _ = K "" --- regexp not recognized in input CF ; use EBNF for this + foldconcat [] = K "" + foldconcat tt = foldr1 C tt + |
