Commit d87e5524 authored by Finn Teegen's avatar Finn Teegen
Browse files

Move pretty printing for conditional compiling

parent 0ae1998b
......@@ -64,7 +64,6 @@ Library
Curry.Base.Span
Curry.CondCompile.Parser
Curry.CondCompile.Type
Curry.CondCompile.Pretty
Curry.CondCompile.CondTransform
Curry.Files.Filenames
Curry.Files.PathUtils
......
......@@ -16,7 +16,6 @@ module Curry.CondCompile.CondTransform
) where
import Control.Monad.State
import Curry.CondCompile.Pretty
import Control.Monad.Extra (concatMapM)
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
......@@ -25,6 +24,7 @@ import Text.Parsec.Error ()
import Curry.Base.Message
import Curry.Base.Position
import Curry.Base.Pretty
import Curry.CondCompile.Parser
import Curry.CondCompile.Type
......
module Curry.CondCompile.Pretty(Pretty(pPrint, pPrintList)) where
import Curry.Base.Pretty
import Curry.CondCompile.Type
instance Pretty Stmt where
pPrint (If c t i e) = prettyIf (text "#if" <+> pPrint c) t i e
pPrint (IfDef s t i e) = prettyIf (text "#ifdef" <+> text s ) t i e
pPrint (IfNDef s t i e) = prettyIf (text "#ifndef" <+> text s ) t i e
pPrint (Define s i) = text "#define" <+> text s <+> int i
pPrint (Undef s ) = text "#undef" <+> text s
pPrint (Line s ) = text s
pPrintList = foldr (($+$) . pPrint) empty
instance Pretty Elif where
pPrint (Elif (c, p)) = text "#elif " <+> pPrint c $+$
pPrint p
pPrintList = foldr (($+$) . pPrint) empty
instance Pretty Else where
pPrint (Else (Just xs)) = text "#else" $+$
pPrint xs
pPrint (Else Nothing) = empty
prettyIf :: Doc -> [Stmt] -> [Elif] -> Else -> Doc
prettyIf pre t i e = pre $+$
pPrint t $+$
pPrint i $+$
pPrint e $+$
text "#endif"
instance Pretty Cond where
pPrint (Comp s o v) = text s <+> pPrint o <+> int v
pPrint (Defined s) = text "defined(" <> text s <> char ')'
pPrint (NDefined s) = text "!defined(" <> text s <> char ')'
instance Pretty Op where
pPrint Eq = text "="
pPrint Neq = text "/="
pPrint Lt = text "<"
pPrint Leq = text "<="
pPrint Gt = text ">"
pPrint Geq = text ">="
......@@ -11,8 +11,11 @@
TODO
-}
module Curry.CondCompile.Type where
module Curry.CondCompile.Type
( Program, Stmt (..), Else (..), Elif (..), Cond (..), Op (..)
) where
import Curry.Base.Pretty
type Program = [Stmt]
......@@ -42,3 +45,39 @@ data Op = Eq
| Gt
| Geq
deriving Show
instance Pretty Stmt where
pPrint (If c stmts is e) = prettyIf "#if" (pPrint c) stmts is e
pPrint (IfDef v stmts is e) = prettyIf "#ifdef" (text v) stmts is e
pPrint (IfNDef v stmts is e) = prettyIf "#ifndef" (text v) stmts is e
pPrint (Define v i ) = text "#define" <+> text v <+> int i
pPrint (Undef v ) = text "#undef" <+> text v
pPrint (Line s ) = text s
pPrintList = foldr (($+$) . pPrint) empty
instance Pretty Elif where
pPrint (Elif (c, stmts)) = text "#elif" <+> pPrint c $+$ pPrint stmts
pPrintList = foldr (($+$) . pPrint) empty
instance Pretty Else where
pPrint (Else (Just stmts)) = text "#else" $+$ pPrint stmts
pPrint (Else Nothing) = empty
prettyIf :: String -> Doc -> [Stmt] -> [Elif] -> Else -> Doc
prettyIf k doc stmts is e = foldr ($+$) empty
[text k <+> doc, pPrint stmts, pPrint is, pPrint e, text "#endif"]
instance Pretty Cond where
pPrint (Comp v op i) = text v <+> pPrint op <+> int i
pPrint (Defined v ) = text "defined(" <> text v <> char ')'
pPrint (NDefined v ) = text "!defined(" <> text v <> char ')'
instance Pretty Op where
pPrint Eq = text "=="
pPrint Neq = text "/="
pPrint Lt = text "<"
pPrint Leq = text "<="
pPrint Gt = text ">"
pPrint Geq = text ">="
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment