From d02b7715728eb23bc45bdac586ea1f0d35f91b79 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 5 Mar 2008 16:05:21 +0000 Subject: [PATCH] Tidied up the type of handleDirective to make it easier to use --- frontends/PreprocessOccam.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontends/PreprocessOccam.hs b/frontends/PreprocessOccam.hs index 50deeae..0d0eb2a 100644 --- a/frontends/PreprocessOccam.hs +++ b/frontends/PreprocessOccam.hs @@ -102,8 +102,7 @@ expandIncludes (t:ts) = expandIncludes ts >>* (t :) preprocessOccam :: [Token] -> PassM [Token] preprocessOccam [] = return [] preprocessOccam ((m, TokPreprocessor s):ts) - = do beforeRest <- handleDirective m (stripPrefix s) - beforeRest ts >>= preprocessOccam + = handleDirective m (stripPrefix s) ts >>= preprocessOccam where stripPrefix :: String -> String stripPrefix (' ':cs) = stripPrefix cs @@ -131,9 +130,12 @@ preprocessOccam (t:ts) type DirectiveFunc = Meta -> [String] -> PassM ([Token] -> PassM [Token]) -- | Call the handler for a preprocessor directive. -handleDirective :: Meta -> String -> PassM ([Token] -> PassM [Token]) -handleDirective m s = lookup s directives +handleDirective :: Meta -> String -> [Token] -> PassM [Token] +handleDirective m s x + = do f <- lookup s directives + f x where + lookup :: String -> [(Regex, DirectiveFunc)] -> PassM ([Token] -> PassM [Token]) -- FIXME: This should really be an error rather than a warning, but -- currently we support so few preprocessor directives that this is more -- useful.