Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gilles Coremans
ASTTool
Commits
ab9c7053
Commit
ab9c7053
authored
Sep 23, 2019
by
marton bognar
Browse files
Change more capitalization in printers
parent
8ed5057e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Tool/Printer/Haskell.hs
View file @
ab9c7053
...
...
@@ -75,7 +75,7 @@ printTypeDecls decls =
printOneType
::
(
Type
,
[
Constructor
])
->
Doc
String
printOneType
(
t
,
cs
)
=
hsep
[
pretty
"data"
,
pretty
t
,
pretty
(
upperFirst
t
)
,
pretty
"="
,
hsep
$
punctuate
(
pretty
" |"
)
(
map
pretty
cs
),
pretty
"deriving(Show, Eq)"
...
...
@@ -87,7 +87,7 @@ printFunctions fns = intoLines $ punctuate nl (map pretty fns)
printInstances
::
[(
Type
,
Type
,
[
Function
])]
->
Doc
String
printInstances
ids
=
intoLines
$
map
(
\
(
cls
,
typ
,
fns
)
->
intoLines
[
hsep
[
pretty
"instance"
,
pretty
cls
,
pretty
typ
,
pretty
"where"
],
hsep
[
pretty
"instance"
,
pretty
(
upperFirst
cls
)
,
pretty
(
upperFirst
typ
)
,
pretty
"where"
],
printFunctions
(
map
(
\
(
Fn
n
lns
)
->
Fn
(
" "
++
n
)
lns
)
fns
)
]
)
ids
...
...
Tool/Printer/OCaml.hs
View file @
ab9c7053
...
...
@@ -4,21 +4,23 @@ module Printer.OCaml where
import
Data.Text.Prettyprint.Doc
import
Program
import
Utility
import
GeneralTerms
instance
Pretty
Constructor
where
pretty
(
Constr
n
[]
)
=
pretty
n
pretty
(
Constr
n
ts
)
=
hsep
(
pretty
(
n
++
" of"
)
:
punctuate
(
pretty
" *"
)
(
map
(
\
t
->
pretty
(
't'
:
t
))
ts
))
pretty
(
Constr
n
[]
)
=
pretty
(
upperFirst
n
)
pretty
(
Constr
n
ts
)
=
hsep
(
pretty
(
upperFirst
n
++
" of"
)
:
punctuate
(
pretty
" *"
)
(
map
(
\
t
->
pretty
(
lowerFirst
t
))
ts
))
instance
Pretty
Parameter
where
pretty
(
VarParam
n
)
=
pretty
n
pretty
(
ConstrParam
n
ps
)
=
parens
(
hsep
(
pretty
n
:
(
punctuate
comma
(
map
pretty
ps
))))
pretty
(
VarParam
n
)
=
pretty
(
lowerFirst
n
)
pretty
(
ConstrParam
n
ps
)
=
parens
(
hsep
(
pretty
(
upperFirst
n
)
:
(
punctuate
comma
(
map
pretty
ps
))))
pretty
(
StringParam
s
)
=
pretty
"
\"
"
<>
pretty
s
<>
pretty
"
\"
"
pretty
(
IntParam
i
)
=
pretty
i
instance
Pretty
Expression
where
pretty
(
FnCall
n
ps
)
=
parens
$
hsep
(
pretty
n
:
map
pretty
ps
)
pretty
(
ConstrInst
n
ps
)
=
parens
$
hsep
(
pretty
n
:
(
punctuate
comma
(
map
pretty
ps
)))
pretty
(
VarExpr
x
)
=
pretty
x
pretty
(
FnCall
n
ps
)
=
parens
$
hsep
(
pretty
(
lowerFirst
n
)
:
map
pretty
ps
)
pretty
(
ConstrInst
n
ps
)
=
parens
$
hsep
(
pretty
(
upperFirst
n
)
:
(
punctuate
comma
(
map
pretty
ps
)))
pretty
(
VarExpr
x
)
=
pretty
(
lowerFirst
x
)
pretty
(
Minus
a
b
)
=
parens
(
pretty
a
<+>
pretty
"-"
<+>
pretty
b
)
pretty
(
IntExpr
i
)
=
pretty
i
pretty
(
StringExpr
s
)
=
pretty
"
\"
"
<>
pretty
s
<>
pretty
"
\"
"
...
...
@@ -35,8 +37,8 @@ instance Pretty Function where
replacedParams
=
replaceMatched
matchedParams
params
matchedParamNames
=
[
param
|
(
param
,
b
)
<-
zip
replacedParams
matchedParams
,
b
]
in
if
or
matchedParams
then
intoLines
((
pretty
"let rec"
<+>
pretty
n
<+>
(
hsep
$
map
pretty
replacedParams
)
<+>
pretty
"= match"
<+>
hsep
(
punctuate
comma
(
map
pretty
matchedParamNames
))
<+>
pretty
"with"
)
:
map
(
oneMatchedLine
matchedParams
)
lns
)
else
pretty
"let rec"
<+>
pretty
n
<+>
hsep
(
map
pretty
(
fst
(
head
lns
)))
<+>
pretty
"="
<+>
pretty
(
snd
(
head
lns
))
-- if no matched params, it should only have one line
then
intoLines
((
pretty
"let rec"
<+>
pretty
(
lowerFirst
n
)
<+>
(
hsep
$
map
pretty
replacedParams
)
<+>
pretty
"= match"
<+>
hsep
(
punctuate
comma
(
map
pretty
matchedParamNames
))
<+>
pretty
"with"
)
:
map
(
oneMatchedLine
matchedParams
)
lns
)
else
pretty
"let rec"
<+>
pretty
(
lowerFirst
n
)
<+>
hsep
(
map
pretty
(
fst
(
head
lns
)))
<+>
pretty
"="
<+>
pretty
(
snd
(
head
lns
))
-- if no matched params, it should only have one line
where
mapMatchedParams
::
[[
Parameter
]]
->
[
Bool
]
mapMatchedParams
[]
=
[]
...
...
@@ -88,7 +90,7 @@ printTypeDecls decls =
printOneType
::
(
Type
,
[
Constructor
])
->
Doc
String
printOneType
(
t
,
cs
)
=
hsep
[
pretty
"type"
,
pretty
(
't'
:
t
),
pretty
(
lowerFirst
t
),
pretty
"="
,
hsep
$
punctuate
(
pretty
" |"
)
(
map
pretty
cs
)
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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