diff options
| author | hallgren <hallgren@chalmers.se> | 2013-11-20 00:45:33 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-11-20 00:45:33 +0000 |
| commit | 018c9838ed31571b699118ae75b1d62d5527fd77 (patch) | |
| tree | e3ff7163a838915020f2a1e355c984d22df7ad9c /src/compiler/GF/Grammar/CF.hs | |
| parent | ddac5f9e5aa935f4c154253831a36e49a48cdc8d (diff) | |
Reduced clutter in monadic code
+ Eliminated vairous ad-hoc coersion functions between specific monads
(IO, Err, IOE, Check) in favor of more general lifting functions
(liftIO, liftErr).
+ Generalized many basic monadic operations from specific monads to
arbitrary monads in the appropriate class (MonadIO and/or ErrorMonad),
thereby completely eliminating the need for lifting functions in lots
of places.
This can be considered a small step forward towards a cleaner
compiler API and more malleable compiler code in general.
Diffstat (limited to 'src/compiler/GF/Grammar/CF.hs')
| -rw-r--r-- | src/compiler/GF/Grammar/CF.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/compiler/GF/Grammar/CF.hs b/src/compiler/GF/Grammar/CF.hs index fe76d7af8..a48238e42 100644 --- a/src/compiler/GF/Grammar/CF.hs +++ b/src/compiler/GF/Grammar/CF.hs @@ -28,14 +28,14 @@ import Data.Char import Data.List --import System.FilePath -getCF :: FilePath -> String -> Err SourceGrammar +getCF :: ErrorMonad m => FilePath -> String -> m SourceGrammar getCF fpath = fmap (cf2gf fpath . uniqueFuns) . pCF --------------------- -- the parser ------- --------------------- -pCF :: String -> Err CF +pCF :: ErrorMonad m => String -> m CF pCF s = do rules <- mapM getCFRule $ filter isRule $ lines s return $ concat rules @@ -48,14 +48,14 @@ pCF s = do -- fun. C -> item1 item2 ... where unquoted items are treated as cats -- Actually would be nice to add profiles to this. -getCFRule :: String -> Err [CFRule] +getCFRule :: ErrorMonad m => String -> m [CFRule] getCFRule s = getcf (wrds s) where getcf ws = case ws of fun : cat : a : its | isArrow a -> - Ok [L NoLoc (init fun, (cat, map mkIt its))] + return [L NoLoc (init fun, (cat, map mkIt its))] cat : a : its | isArrow a -> - Ok [L NoLoc (mkFun cat it, (cat, map mkIt it)) | it <- chunk its] - _ -> Bad (" invalid rule:" +++ s) + return [L NoLoc (mkFun cat it, (cat, map mkIt it)) | it <- chunk its] + _ -> raise (" invalid rule:" +++ s) isArrow a = elem a ["->", "::="] mkIt w = case w of ('"':w@(_:_)) -> Right (init w) |
