diff options
| author | aarne <unknown> | 2003-09-22 13:16:55 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2003-09-22 13:16:55 +0000 |
| commit | b1402e8bd6a68a891b00a214d6cf184d66defe19 (patch) | |
| tree | 90372ac4e53dce91cf949dbf8e93be06f1d9e8bd /src/GF/CF/PPrCF.hs | |
Founding the newly structured GF2.0 cvs archive.
Diffstat (limited to 'src/GF/CF/PPrCF.hs')
| -rw-r--r-- | src/GF/CF/PPrCF.hs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/GF/CF/PPrCF.hs b/src/GF/CF/PPrCF.hs new file mode 100644 index 000000000..ff4b64e66 --- /dev/null +++ b/src/GF/CF/PPrCF.hs @@ -0,0 +1,59 @@ +module PPrCF where + +import Operations +import CF +import CFIdent +import AbsGFC +import PrGrammar + +-- printing and parsing CF grammars, rules, and trees AR 26/1/2000 -- 9/6/2003 +---- use the Print class instead! + +prCF :: CF -> String +prCF = unlines . (map prCFRule) . rulesOfCF -- hiding the literal recogn function + +prCFTree :: CFTree -> String +prCFTree (CFTree (fun, (_,trees))) = prCFFun fun ++ prs trees where + prs [] = "" + prs ts = " " ++ unwords (map ps ts) + ps t@(CFTree (_,(_,[]))) = prCFTree t + ps t = prParenth (prCFTree t) + +prCFRule :: CFRule -> String +prCFRule (fun,(cat,its)) = + prCFFun fun ++ "." +++ prCFCat cat +++ "::=" +++ + unwords (map prCFItem its) +++ ";" + +prCFFun :: CFFun -> String +prCFFun = prCFFun' True ---- False -- print profiles for debug + +prCFFun' :: Bool -> CFFun -> String +prCFFun' profs (CFFun (t, p)) = prt t ++ pp p where + pp p = if (not profs || normal p) then "" else "_" ++ concat (map show p) + normal p = and [x==y && null b | ((b,x),y) <- zip p (map (:[]) [0..])] + +prCFCat :: CFCat -> String +prCFCat (CFCat (c,l)) = prt c ++ "-" ++ prt l ---- + +prCFItem (CFNonterm c) = prCFCat c +prCFItem (CFTerm a) = prRegExp a + +prRegExp (RegAlts tt) = case tt of + [t] -> prQuotedString t + _ -> prParenth (prTList " | " (map prQuotedString tt)) + +{- ---- +-- rules have an amazingly easy parser, if we use the format +-- fun. C -> item1 item2 ... where unquoted items are treated as cats +-- Actually would be nice to add profiles to this. + +getCFRule :: String -> Maybe CFRule +getCFRule s = getcf (wrds s) where + getcf ww | length ww > 2 && ww !! 2 `elem` ["->", "::="] = + Just (string2CFFun (init fun), (string2CFCat cat, map mkIt its)) where + fun : cat : _ : its = words s + mkIt ('"':w@(_:_)) = atomCFTerm (string2CFTok (init w)) + mkIt w = CFNonterm (string2CFCat w) + getcf _ = Nothing + wrds = takeWhile (/= ";") . words -- to permit semicolon in the end +-}
\ No newline at end of file |
