Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Finn Teegen
curry-base
Commits
d87e5524
Commit
d87e5524
authored
Jul 06, 2017
by
Finn Teegen
Browse files
Move pretty printing for conditional compiling
parent
0ae1998b
Changes
4
Hide whitespace changes
Inline
Side-by-side
curry-base.cabal
View file @
d87e5524
...
...
@@ -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
...
...
src/Curry/CondCompile/CondTransform.hs
View file @
d87e5524
...
...
@@ -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
...
...
src/Curry/CondCompile/Pretty.hs
deleted
100644 → 0
View file @
0ae1998b
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
">="
src/Curry/CondCompile/Type.hs
View file @
d87e5524
...
...
@@ -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
">="
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment