summaryrefslogtreecommitdiff
path: root/src/GF/CF/PPrCF.hs
diff options
context:
space:
mode:
authoraarne <unknown>2004-03-24 15:09:06 +0000
committeraarne <unknown>2004-03-24 15:09:06 +0000
commitdc71ffcf5bae1f2b91467de273c71e7c3294acb3 (patch)
treea4e705bba717aa9f7421c000cfa5756d5eb8462b /src/GF/CF/PPrCF.hs
parent31836c0da9ba7a716ee0480e6219d771da4999fa (diff)
Restoring old functionality
Diffstat (limited to 'src/GF/CF/PPrCF.hs')
-rw-r--r--src/GF/CF/PPrCF.hs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/GF/CF/PPrCF.hs b/src/GF/CF/PPrCF.hs
index ff4b64e66..91ab240ea 100644
--- a/src/GF/CF/PPrCF.hs
+++ b/src/GF/CF/PPrCF.hs
@@ -6,6 +6,8 @@ import CFIdent
import AbsGFC
import PrGrammar
+import Char
+
-- printing and parsing CF grammars, rules, and trees AR 26/1/2000 -- 9/6/2003
---- use the Print class instead!
@@ -42,18 +44,25 @@ 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
+getCFRule :: String -> String -> Err CFRule
+getCFRule mo s = getcf (wrds s) where
getcf ww | length ww > 2 && ww !! 2 `elem` ["->", "::="] =
- Just (string2CFFun (init fun), (string2CFCat cat, map mkIt its)) where
+ Ok (string2CFFun mo (init fun), (string2CFCat mo cat, map mkIt its)) where
fun : cat : _ : its = words s
mkIt ('"':w@(_:_)) = atomCFTerm (string2CFTok (init w))
- mkIt w = CFNonterm (string2CFCat w)
- getcf _ = Nothing
+ mkIt w = CFNonterm (string2CFCat mo w)
+ getcf _ = Bad "invalid rule"
wrds = takeWhile (/= ";") . words -- to permit semicolon in the end
--} \ No newline at end of file
+
+pCF :: String -> String -> Err CF
+pCF mo s = do
+ rules <- mapM (getCFRule mo) $ filter isRule $ lines s
+ return $ rules2CF rules
+ where
+ isRule line = case line of
+ '-':'-':_ -> False
+ _ -> not $ all isSpace line