{-# LANGUAGE PostfixOperators #-}
module Drasil.GOOL.LanguageRenderer (
classDec, dot, commentStart, returnLabel, ifLabel, elseLabel, elseIfLabel,
forLabel, inLabel, whileLabel, tryLabel, catchLabel, throwLabel, throwsLabel,
importLabel, blockCmtStart, blockCmtEnd, docCmtStart, bodyStart, bodyEnd,
endStatement, constDec', exceptionObj', new', this', self', array', listSep',
argc, argv, args, printLabel, constDec, exceptionObj, mainFunc, new, this,
self, nullLabel, array, listSep, sqrt, abs, fabs, log10, log, exp, sin, cos,
tan, asin, acos, atan, floor, ceil, pow, piLabel, access, containing, tuple,
mathFunc, addExt,
package, file, module', class', multiStmt, block, body, print, printFile,
param, method, stateVar, constVar, stateVarList, switch, assign,
addAssign, subAssign, increment, decrement, listDec, getTerm, return',
comment, var, extVar, arg, classVar, objVar, unOpDocD, unOpDocD', binOpDocD,
binOpDocD', constDecDef, func, cast, listAccessFunc, listSetFunc,
objAccess, castObj, break, continue, static, dynamic, private, public,
blockCmt, docCmt, commentedItem, addComments, FuncDocRenderer, functionDox,
ClassDocRenderer, classDox, ModuleDocRenderer, moduleDox, commentedMod,
valueList, variableList, parameterList, namedArgList, prependToBody,
appendToBody, surroundBody, getterName, setterName, intValue
) where
import Utils.Drasil (blank, capitalize, indent, indentList, stringList)
import Drasil.GOOL.CodeType (CodeType(..))
import Drasil.GOOL.InterfaceCommon (Label, Library, SValue, BodySym(Body),
TypeSym(Type), TypeElim(..), VariableSym(Variable), VariableElim(..),
ValueSym(..), StatementSym(Statement), VisibilitySym(Visibility),
ParameterSym(Parameter))
import Drasil.GOOL.InterfaceGOOL (PermanenceSym(Permanence))
import Drasil.GOOL.RendererClassesCommon (CommonRenderSym)
import qualified Drasil.GOOL.RendererClassesCommon as RC (BodyElim(..),
InternalTypeElim(..), InternalVarElim(..), ValueElim(..), StatementElim(..),
VisibilityElim(..), ParamElim(..))
import Drasil.GOOL.RendererClassesOO (OORenderSym)
import qualified Drasil.GOOL.RendererClassesOO as RC (PermElim(..))
import Drasil.GOOL.AST (Terminator(..), FileData(..), fileD, updateFileMod,
updateMod, TypeData(..), VarData(..))
import Drasil.GOOL.Helpers (hicat, vibcat, vmap, emptyIfEmpty, emptyIfNull)
import Data.List (last, intercalate)
import Prelude hiding (break,print,last,sqrt,abs,log,exp,sin,cos,tan,asin,acos,
atan,floor,mod,(<>))
import Text.PrettyPrint.HughesPJ (Doc, text, empty, render, (<>), (<+>), ($+$),
space, brackets, parens, isEmpty, rbrace, lbrace, vcat, semi, equals, colon,
comma)
import Metadata.Drasil.DrasilMetaCall(watermark)
classDec, dot, commentStart, returnLabel, ifLabel, elseLabel, elseIfLabel,
forLabel, inLabel, whileLabel, tryLabel, catchLabel, throwLabel, throwsLabel,
importLabel, blockCmtStart, blockCmtEnd, docCmtStart, bodyStart, bodyEnd,
endStatement, constDec', exceptionObj', new', this', self', array',
listSep' :: Doc
classDec :: Doc
classDec = String -> Doc
text String
"class"
dot :: Doc
dot = String -> Doc
text String
"."
= String -> Doc
text String
"//"
returnLabel :: Doc
returnLabel = String -> Doc
text String
"return"
ifLabel :: Doc
ifLabel = String -> Doc
text String
"if"
elseLabel :: Doc
elseLabel = String -> Doc
text String
"else"
elseIfLabel :: Doc
elseIfLabel = Doc
elseLabel Doc -> Doc -> Doc
<+> Doc
ifLabel
forLabel :: Doc
forLabel = String -> Doc
text String
"for"
inLabel :: Doc
inLabel = String -> Doc
text String
"in"
whileLabel :: Doc
whileLabel = String -> Doc
text String
"while"
tryLabel :: Doc
tryLabel = String -> Doc
text String
"try"
catchLabel :: Doc
catchLabel = String -> Doc
text String
"catch"
throwLabel :: Doc
throwLabel = String -> Doc
text String
"throw"
throwsLabel :: Doc
throwsLabel = String -> Doc
text String
"throws"
importLabel :: Doc
importLabel = String -> Doc
text String
"import"
blockCmtStart :: Doc
blockCmtStart = String -> Doc
text String
"/*"
blockCmtEnd :: Doc
blockCmtEnd = String -> Doc
text String
"*/"
docCmtStart :: Doc
docCmtStart = String -> Doc
text String
"/**"
bodyStart :: Doc
bodyStart = Doc
lbrace
bodyEnd :: Doc
bodyEnd = Doc
rbrace
endStatement :: Doc
endStatement = Doc
semi
constDec' :: Doc
constDec' = String -> Doc
text String
constDec
exceptionObj' :: Doc
exceptionObj' = String -> Doc
text String
exceptionObj
new' :: Doc
new' = String -> Doc
text String
new
this' :: Doc
this' = String -> Doc
text String
this
self' :: Doc
self' = String -> Doc
text String
self
array' :: Doc
array' = String -> Doc
text String
array
listSep' :: Doc
listSep' = String -> Doc
text String
listSep
argc, argv, args, printLabel, constDec, exceptionObj, mainFunc, new, this,
self, nullLabel, array, listSep :: String
argc :: String
argc = String
"argc"
argv :: String
argv = String
"argv"
args :: String
args = String
"args"
printLabel :: String
printLabel = String
"print"
constDec :: String
constDec = String
"const"
exceptionObj :: String
exceptionObj = String
"Exception"
mainFunc :: String
mainFunc = String
"main"
new :: String
new = String
"new"
this :: String
this = String
"this"
self :: String
self = String
"self"
nullLabel :: String
nullLabel = String
"null"
array :: String
array = String
"[]"
listSep :: String
listSep = String
", "
sqrt, abs, fabs, log10, log, exp, sin, cos, tan, asin, acos, atan, floor,
ceil, pow, piLabel :: String
sqrt :: String
sqrt = String
"sqrt"
abs :: String
abs = String
"abs"
fabs :: String
fabs = String
"fabs"
log10 :: String
log10 = String
"log10"
log :: String
log = String
"log"
exp :: String
exp = String
"exp"
sin :: String
sin = String
"sin"
cos :: String
cos = String
"cos"
tan :: String
tan = String
"tan"
asin :: String
asin = String
"asin"
acos :: String
acos = String
"acos"
atan :: String
atan = String
"atan"
floor :: String
floor = String
"floor"
ceil :: String
ceil = String
"ceil"
pow :: String
pow = String
"pow"
piLabel :: String
piLabel = String
"pi"
access :: String -> String -> String
access :: String -> String -> String
access String
q String
n = String
q String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"." String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
n
containing :: String -> String -> String
containing :: String -> String -> String
containing String
l String
e = String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"<" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">"
tuple :: [String] -> String
tuple :: [String] -> String
tuple [String]
ts = String
"(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
listSep [String]
ts String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")"
mathFunc :: String -> String
mathFunc :: String -> String
mathFunc = String -> String -> String
access String
"Math"
addExt :: String -> String -> String
addExt :: String -> String -> String
addExt String
ext String
nm = String
nm String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"." String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
ext
package :: Label -> Doc -> FileData -> FileData
package :: String -> Doc -> FileData -> FileData
package String
n Doc
end FileData
f = String -> ModData -> FileData
fileD (String
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ FileData -> String
filePath FileData
f) ((Doc -> Doc) -> ModData -> ModData
updateMod
(\Doc
d -> Doc -> Doc -> Doc
emptyIfEmpty Doc
d ([Doc] -> Doc
vibcat [String -> Doc
text String
"package" Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<> Doc
end, Doc
d]))
(FileData -> ModData
fileMod FileData
f))
file :: Doc -> Doc -> Doc -> Doc
file :: Doc -> Doc -> Doc -> Doc
file Doc
t Doc
m Doc
b = [Doc] -> Doc
vibcat [
Doc
t,
Doc
m,
Doc
b]
module' :: Doc -> Doc -> Doc -> Doc
module' :: Doc -> Doc -> Doc -> Doc
module' Doc
ls Doc
fs Doc
cs = Doc -> Doc -> Doc
emptyIfEmpty (Doc
fs Doc -> Doc -> Doc
<> Doc
cs) ([Doc] -> Doc
vibcat ((Doc -> Bool) -> [Doc] -> [Doc]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Doc -> Bool) -> Doc -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Bool
isEmpty)
[Doc
ls, Doc
fs, Doc
cs]))
class' :: Label -> Doc -> Doc -> Doc -> Doc -> Doc
class' :: String -> Doc -> Doc -> Doc -> Doc -> Doc
class' String
n Doc
p Doc
s Doc
vs Doc
fs = [Doc] -> Doc
vcat [
Doc
s Doc -> Doc -> Doc
<+> Doc
classDec Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<+> Doc
p Doc -> Doc -> Doc
<+> Doc
lbrace,
[Doc] -> Doc
indentList [
Doc
vs,
Doc
blank,
Doc
fs],
Doc
rbrace]
multiStmt :: [(Doc, Terminator)] -> (Doc, Terminator)
multiStmt :: [(Doc, Terminator)] -> (Doc, Terminator)
multiStmt [(Doc, Terminator)]
sts = ([Doc] -> Doc
vcat ([(Doc, Terminator)] -> [Doc]
applyEnd [(Doc, Terminator)]
statements), [(Doc, Terminator)] -> Terminator
forall {a}. [(a, Terminator)] -> Terminator
needsEnd [(Doc, Terminator)]
statements)
where applyEnd :: [(Doc, Terminator)] -> [Doc]
applyEnd [] = []
applyEnd [(Doc
s, Terminator
_)] = [Doc
s]
applyEnd ((Doc
s, Terminator
t):[(Doc, Terminator)]
ss) = (Doc
s Doc -> Doc -> Doc
<> Terminator -> Doc
getTerm Terminator
t) Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: [(Doc, Terminator)] -> [Doc]
applyEnd [(Doc, Terminator)]
ss
needsEnd :: [(a, Terminator)] -> Terminator
needsEnd [] = Terminator
Empty
needsEnd [(a, Terminator)]
ss = (a, Terminator) -> Terminator
forall a b. (a, b) -> b
snd ([(a, Terminator)] -> (a, Terminator)
forall a. HasCallStack => [a] -> a
last [(a, Terminator)]
ss)
statements :: [(Doc, Terminator)]
statements = ((Doc, Terminator) -> Bool)
-> [(Doc, Terminator)] -> [(Doc, Terminator)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Doc, Terminator) -> Bool
forall {b}. (Doc, b) -> Bool
notNullStatement [(Doc, Terminator)]
sts
notNullStatement :: (Doc, b) -> Bool
notNullStatement (Doc, b)
s = Bool -> Bool
not (Doc -> Bool
isEmpty ((Doc, b) -> Doc
forall a b. (a, b) -> a
fst (Doc, b)
s))
block :: [Doc] -> Doc
block :: [Doc] -> Doc
block [Doc]
sts = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Doc -> Bool) -> [Doc] -> [Doc]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Doc -> Bool) -> Doc -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Bool
isEmpty) [Doc]
sts
body :: [Doc] -> Doc
body :: [Doc] -> Doc
body [Doc]
bs = [Doc] -> Doc
vibcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Doc -> Bool) -> [Doc] -> [Doc]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Doc -> Bool) -> Doc -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Bool
isEmpty) [Doc]
bs
print :: (CommonRenderSym r) => r (Value r) -> r (Value r) -> Doc
print :: forall (r :: * -> *).
CommonRenderSym r =>
r (Value r) -> r (Value r) -> Doc
print r (Value r)
printFn r (Value r)
v = r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
printFn Doc -> Doc -> Doc
<> Doc -> Doc
parens (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v)
printFile :: Label -> Doc -> Doc
printFile :: String -> Doc -> Doc
printFile String
fn Doc
f = Doc
f Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> String -> Doc
text String
fn
param :: (CommonRenderSym r) => r (Variable r) -> Doc
param :: forall (r :: * -> *). CommonRenderSym r => r (Variable r) -> Doc
param r (Variable r)
v = r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v) Doc -> Doc -> Doc
<+> r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v
method :: (OORenderSym r) => Label -> r (Visibility r) -> r (Permanence r) ->
r (Type r) -> [r (Parameter r)] -> r (Body r) -> Doc
method :: forall (r :: * -> *).
OORenderSym r =>
String
-> r (Visibility r)
-> r (Permanence r)
-> r (Type r)
-> [r (Parameter r)]
-> r (Body r)
-> Doc
method String
n r (Visibility r)
s r (Permanence r)
p r (Type r)
t [r (Parameter r)]
ps r (Body r)
b = [Doc] -> Doc
vcat [
r (Visibility r) -> Doc
forall (r :: * -> *). VisibilityElim r => r (Visibility r) -> Doc
RC.visibility r (Visibility r)
s Doc -> Doc -> Doc
<+> r (Permanence r) -> Doc
forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm r (Permanence r)
p Doc -> Doc -> Doc
<+> r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
t Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<>
Doc -> Doc
parens ([r (Parameter r)] -> Doc
forall (r :: * -> *). CommonRenderSym r => [r (Parameter r)] -> Doc
parameterList [r (Parameter r)]
ps) Doc -> Doc -> Doc
<+> Doc
lbrace,
Doc -> Doc
indent (r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
b),
Doc
rbrace]
stateVar :: Doc -> Doc -> Doc -> Doc
stateVar :: Doc -> Doc -> Doc -> Doc
stateVar Doc
s Doc
p Doc
dec = Doc
s Doc -> Doc -> Doc
<+> Doc
p Doc -> Doc -> Doc
<+> Doc
dec
constVar :: Doc -> Doc -> Doc -> VarData -> Doc
constVar :: Doc -> Doc -> Doc -> VarData -> Doc
constVar Doc
s Doc
end Doc
p VarData
v = Doc
s Doc -> Doc -> Doc
<+> Doc
p Doc -> Doc -> Doc
<+> Doc
constDec' Doc -> Doc -> Doc
<+> TypeData -> Doc
typeDoc (VarData -> TypeData
varType VarData
v) Doc -> Doc -> Doc
<+>
VarData -> Doc
varDoc VarData
v Doc -> Doc -> Doc
<> Doc
end
stateVarList :: [Doc] -> Doc
stateVarList :: [Doc] -> Doc
stateVarList = [Doc] -> Doc
vcat
switch :: (CommonRenderSym r) => (Doc -> Doc) -> r (Statement r) -> r (Value r) -> r (Body r) ->
[(r (Value r), r (Body r))] -> Doc
switch :: forall (r :: * -> *).
CommonRenderSym r =>
(Doc -> Doc)
-> r (Statement r)
-> r (Value r)
-> r (Body r)
-> [(r (Value r), r (Body r))]
-> Doc
switch Doc -> Doc
f r (Statement r)
st r (Value r)
v r (Body r)
defBody [(r (Value r), r (Body r))]
cs =
let caseDoc :: (r (Value r), r (Body r)) -> Doc
caseDoc (r (Value r)
l, r (Body r)
result) = [Doc] -> Doc
vcat [
String -> Doc
text String
"case" Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
l Doc -> Doc -> Doc
<> Doc
colon,
[Doc] -> Doc
indentList [
r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
result,
r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement r (Statement r)
st]]
defaultSection :: Doc
defaultSection = [Doc] -> Doc
vcat [
String -> Doc
text String
"default" Doc -> Doc -> Doc
<> Doc
colon,
[Doc] -> Doc
indentList [
r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
defBody,
r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement r (Statement r)
st]]
in [Doc] -> Doc
vcat [
String -> Doc
text String
"switch" Doc -> Doc -> Doc
<> Doc -> Doc
f (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v) Doc -> Doc -> Doc
<+> Doc
lbrace,
[Doc] -> Doc
indentList [
((r (Value r), r (Body r)) -> Doc)
-> [(r (Value r), r (Body r))] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
vmap (r (Value r), r (Body r)) -> Doc
forall {r :: * -> *} {r :: * -> *}.
(ValueElim r, BodyElim r) =>
(r (Value r), r (Body r)) -> Doc
caseDoc [(r (Value r), r (Body r))]
cs,
Doc
defaultSection],
Doc
rbrace]
assign :: (CommonRenderSym r) => r (Variable r) -> r (Value r) -> Doc
assign :: forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
assign r (Variable r)
vr r (Value r)
vl = r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
vr Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
vl
addAssign :: (CommonRenderSym r) => r (Variable r) -> r (Value r) -> Doc
addAssign :: forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
addAssign r (Variable r)
vr r (Value r)
vl = r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
vr Doc -> Doc -> Doc
<+> String -> Doc
text String
"+=" Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
vl
subAssign :: (CommonRenderSym r) => r (Variable r) -> r (Value r) -> Doc
subAssign :: forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
subAssign r (Variable r)
vr r (Value r)
vl = r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
vr Doc -> Doc -> Doc
<+> String -> Doc
text String
"-=" Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
vl
increment :: (CommonRenderSym r) => r (Variable r) -> Doc
increment :: forall (r :: * -> *). CommonRenderSym r => r (Variable r) -> Doc
increment r (Variable r)
v = r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v Doc -> Doc -> Doc
<> String -> Doc
text String
"++"
decrement :: (CommonRenderSym r) => r (Variable r) -> Doc
decrement :: forall (r :: * -> *). CommonRenderSym r => r (Variable r) -> Doc
decrement r (Variable r)
v = r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v Doc -> Doc -> Doc
<> String -> Doc
text String
"--"
listDec :: (CommonRenderSym r) => r (Variable r) -> r (Value r) -> Doc
listDec :: forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
listDec r (Variable r)
v r (Value r)
n = Doc
space Doc -> Doc -> Doc
<> Doc
equals Doc -> Doc -> Doc
<+> Doc
new' Doc -> Doc -> Doc
<+> r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v)
Doc -> Doc -> Doc
<> Doc -> Doc
parens (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
n)
constDecDef :: (CommonRenderSym r) => r (Variable r) -> r (Value r) -> Doc
constDecDef :: forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
constDecDef r (Variable r)
v r (Value r)
def = Doc
constDec' Doc -> Doc -> Doc
<+> r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v) Doc -> Doc -> Doc
<+>
r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
def
return' :: (CommonRenderSym r) => [r (Value r)] -> Doc
return' :: forall (r :: * -> *). CommonRenderSym r => [r (Value r)] -> Doc
return' [r (Value r)]
vs = Doc
returnLabel Doc -> Doc -> Doc
<+> [r (Value r)] -> Doc
forall (r :: * -> *). CommonRenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vs
comment :: Label -> Doc -> Doc
String
cmt Doc
cStart = Doc
cStart Doc -> Doc -> Doc
<+> String -> Doc
text String
cmt
statement :: (Doc, Terminator) -> (Doc, Terminator)
statement :: (Doc, Terminator) -> (Doc, Terminator)
statement (Doc
s, Terminator
t) = (Doc
s Doc -> Doc -> Doc
<> Terminator -> Doc
getTerm Terminator
t, Terminator
Empty)
getTerm :: Terminator -> Doc
getTerm :: Terminator -> Doc
getTerm Terminator
Semi = Doc
semi
getTerm Terminator
Empty = Doc
empty
var :: Label -> Doc
var :: String -> Doc
var = String -> Doc
text
extVar :: Library -> Label -> Doc
extVar :: String -> String -> Doc
extVar String
l String
n = String -> Doc
text String
l Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> String -> Doc
text String
n
arg :: (CommonRenderSym r) => r (Value r) -> r (Value r) -> Doc
arg :: forall (r :: * -> *).
CommonRenderSym r =>
r (Value r) -> r (Value r) -> Doc
arg r (Value r)
n r (Value r)
argsList = r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
argsList Doc -> Doc -> Doc
<> Doc -> Doc
brackets (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
n)
classVar :: Doc -> Doc -> Doc
classVar :: Doc -> Doc -> Doc
classVar Doc
c Doc
v = Doc
c Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> Doc
v
objVar :: Doc -> Doc -> Doc
objVar :: Doc -> Doc -> Doc
objVar Doc
n1 Doc
n2 = Doc
n1 Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> Doc
n2
unOpDocD :: Doc -> Doc -> Doc
unOpDocD :: Doc -> Doc -> Doc
unOpDocD Doc
op Doc
v = Doc
op Doc -> Doc -> Doc
<> Doc -> Doc
parens Doc
v
unOpDocD' :: Doc -> Doc -> Doc
unOpDocD' :: Doc -> Doc -> Doc
unOpDocD' Doc
op Doc
v = Doc
op Doc -> Doc -> Doc
<> Doc
v
binOpDocD :: Doc -> Doc -> Doc -> Doc
binOpDocD :: Doc -> Doc -> Doc -> Doc
binOpDocD Doc
op Doc
v1 Doc
v2 = Doc
v1 Doc -> Doc -> Doc
<+> Doc
op Doc -> Doc -> Doc
<+> Doc
v2
binOpDocD' :: Doc -> Doc -> Doc -> Doc
binOpDocD' :: Doc -> Doc -> Doc -> Doc
binOpDocD' Doc
op Doc
v1 Doc
v2 = Doc
op Doc -> Doc -> Doc
<> Doc -> Doc
parens (Doc
v1 Doc -> Doc -> Doc
<> Doc
comma Doc -> Doc -> Doc
<+> Doc
v2)
func :: Doc -> Doc
func :: Doc -> Doc
func Doc
fnApp = Doc
dot Doc -> Doc -> Doc
<> Doc
fnApp
cast :: Doc -> Doc
cast :: Doc -> Doc
cast = Doc -> Doc
parens
listAccessFunc :: (CommonRenderSym r) => r (Value r) -> Doc
listAccessFunc :: forall (r :: * -> *). CommonRenderSym r => r (Value r) -> Doc
listAccessFunc r (Value r)
v = Doc -> Doc
brackets (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v
listSetFunc :: Doc -> Doc -> Doc
listSetFunc :: Doc -> Doc -> Doc
listSetFunc Doc
i Doc
v = Doc -> Doc
brackets Doc
i Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> Doc
v
objAccess :: Doc -> Doc -> Doc
objAccess :: Doc -> Doc -> Doc
objAccess Doc
v Doc
f = Doc
v Doc -> Doc -> Doc
<> Doc
f
castObj :: Doc -> Doc -> Doc
castObj :: Doc -> Doc -> Doc
castObj Doc
t Doc
v = Doc
t Doc -> Doc -> Doc
<> Doc -> Doc
parens Doc
v
static :: Doc
static :: Doc
static = String -> Doc
text String
"static"
dynamic :: Doc
dynamic :: Doc
dynamic = Doc
empty
break :: Doc
break :: Doc
break = String -> Doc
text String
"break"
continue :: Doc
continue :: Doc
continue = String -> Doc
text String
"continue"
private :: Doc
private :: Doc
private = String -> Doc
text String
"private"
public :: Doc
public :: Doc
public = String -> Doc
text String
"public"
blockCmt :: [String] -> Doc -> Doc -> Doc
blockCmt :: [String] -> Doc -> Doc -> Doc
blockCmt [String]
lns Doc
start Doc
end = Doc
start Doc -> Doc -> Doc
<+> [Doc] -> Doc
vcat ((String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map String -> Doc
text [String]
lns) Doc -> Doc -> Doc
<+> Doc
end
docCmt :: [String] -> Doc -> Doc -> Doc
docCmt :: [String] -> Doc -> Doc -> Doc
docCmt [String]
lns Doc
start Doc
end = [String] -> Doc -> Doc
forall a. [a] -> Doc -> Doc
emptyIfNull [String]
lns (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$
[Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
start Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc
indent (Doc -> Doc) -> (String -> Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text) [String]
lns [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Doc
end]
commentedItem :: Doc -> Doc -> Doc
Doc
cmt Doc
itm = Doc -> Doc -> Doc
emptyIfEmpty Doc
itm Doc
cmt Doc -> Doc -> Doc
$+$ Doc
itm
commentLength :: Int
= Int
75
endCommentLabel :: Label
= String
"End"
addComments :: Label -> Doc -> Doc -> Doc
String
c Doc
cStart Doc
b = [Doc] -> Doc
vcat [
String -> Doc -> Doc
commentDelimit String
c Doc
cStart,
Doc
b,
String -> Doc -> Doc
endCommentDelimit String
c Doc
cStart]
commentDelimit :: Label -> Doc -> Doc
String
c Doc
cStart =
let com :: Doc
com = Doc
cStart Doc -> Doc -> Doc
<> String -> Doc
text (String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
c String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" ")
in Doc
com Doc -> Doc -> Doc
<> String -> Doc
text (String -> Int -> String
dashes (Doc -> String
render Doc
com) Int
commentLength)
endCommentDelimit :: Label -> Doc -> Doc
String
c = String -> Doc -> Doc
commentDelimit (String
endCommentLabel String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
c)
dashes :: String -> Int -> String
dashes :: String -> Int -> String
dashes String
s Int
l = Int -> Char -> String
forall a. Int -> a -> [a]
replicate (Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) Char
'-'
type FuncDocRenderer = String -> [(String, String)] -> [String] -> [String]
functionDox :: FuncDocRenderer
functionDox :: FuncDocRenderer
functionDox String
desc [(String, String)]
params [String]
returns = [String
doxBrief String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
desc | Bool -> Bool
not (String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]
[String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ ((String, String) -> String) -> [(String, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\(String
v, String
vDesc) -> String
doxParam String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
vDesc) [(String, String)]
params
[String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String
doxReturn ++) [String]
returns
type ClassDocRenderer = String -> [String]
classDox :: ClassDocRenderer
classDox :: ClassDocRenderer
classDox String
desc = [String
doxBrief String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
desc | Bool -> Bool
not (String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]
type ModuleDocRenderer = String -> [String] -> String -> String -> [String]
moduleDox :: ModuleDocRenderer
moduleDox :: ModuleDocRenderer
moduleDox String
desc [String]
as String
date String
m = (String
doxFile String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
m) String -> [String] -> [String]
forall a. a -> [a] -> [a]
:
[String
doxAuthor String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
stringList [String]
as | Bool -> Bool
not ([String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
as)] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
[String
doxDate String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
date | Bool -> Bool
not (String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
date)] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
[String
doxBrief String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
desc | Bool -> Bool
not (String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
[String
doxNote String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
watermark]
commentedMod :: FileData -> Doc -> FileData
FileData
m Doc
cmt = ModData -> FileData -> FileData
updateFileMod ((Doc -> Doc) -> ModData -> ModData
updateMod (Doc -> Doc -> Doc
commentedItem (Doc -> Doc -> Doc) -> Doc -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
cmt Doc -> Doc -> Doc
$+$ Doc
blank) (FileData -> ModData
fileMod FileData
m)) FileData
m
valueList :: (CommonRenderSym r) => [r (Value r)] -> Doc
valueList :: forall (r :: * -> *). CommonRenderSym r => [r (Value r)] -> Doc
valueList = Doc -> [Doc] -> Doc
hicat Doc
listSep' ([Doc] -> Doc) -> ([r (Value r)] -> [Doc]) -> [r (Value r)] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r (Value r) -> Doc) -> [r (Value r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value
variableList :: (CommonRenderSym r) => [r (Variable r)] -> Doc
variableList :: forall (r :: * -> *). CommonRenderSym r => [r (Variable r)] -> Doc
variableList = Doc -> [Doc] -> Doc
hicat Doc
listSep' ([Doc] -> Doc)
-> ([r (Variable r)] -> [Doc]) -> [r (Variable r)] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r (Variable r) -> Doc) -> [r (Variable r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable
parameterList :: (CommonRenderSym r) => [r (Parameter r)] -> Doc
parameterList :: forall (r :: * -> *). CommonRenderSym r => [r (Parameter r)] -> Doc
parameterList = Doc -> [Doc] -> Doc
hicat Doc
listSep' ([Doc] -> Doc)
-> ([r (Parameter r)] -> [Doc]) -> [r (Parameter r)] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r (Parameter r) -> Doc) -> [r (Parameter r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Parameter r) -> Doc
forall (r :: * -> *). ParamElim r => r (Parameter r) -> Doc
RC.parameter
namedArgList :: (CommonRenderSym r) => Doc -> [(r (Variable r), r (Value r))] -> Doc
namedArgList :: forall (r :: * -> *).
CommonRenderSym r =>
Doc -> [(r (Variable r), r (Value r))] -> Doc
namedArgList Doc
sep = Doc -> [Doc] -> Doc
hicat Doc
listSep' ([Doc] -> Doc)
-> ([(r (Variable r), r (Value r))] -> [Doc])
-> [(r (Variable r), r (Value r))]
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((r (Variable r), r (Value r)) -> Doc)
-> [(r (Variable r), r (Value r))] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (\(r (Variable r)
vr,r (Value r)
vl) -> r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
vr Doc -> Doc -> Doc
<> Doc
sep
Doc -> Doc -> Doc
<> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
vl)
prependToBody :: (Doc, Terminator) -> Doc -> Doc
prependToBody :: (Doc, Terminator) -> Doc -> Doc
prependToBody (Doc, Terminator)
s Doc
b = [Doc] -> Doc
vcat [(Doc, Terminator) -> Doc
forall a b. (a, b) -> a
fst ((Doc, Terminator) -> Doc) -> (Doc, Terminator) -> Doc
forall a b. (a -> b) -> a -> b
$ (Doc, Terminator) -> (Doc, Terminator)
statement (Doc, Terminator)
s, Doc
maybeBlank, Doc
b]
where maybeBlank :: Doc
maybeBlank = Doc -> Doc -> Doc
emptyIfEmpty ((Doc, Terminator) -> Doc
forall a b. (a, b) -> a
fst (Doc, Terminator)
s) (Doc -> Doc -> Doc
emptyIfEmpty Doc
b Doc
blank)
appendToBody :: Doc -> (Doc, Terminator) -> Doc
appendToBody :: Doc -> (Doc, Terminator) -> Doc
appendToBody Doc
b (Doc, Terminator)
s = [Doc] -> Doc
vcat [Doc
b, Doc
maybeBlank, (Doc, Terminator) -> Doc
forall a b. (a, b) -> a
fst ((Doc, Terminator) -> Doc) -> (Doc, Terminator) -> Doc
forall a b. (a -> b) -> a -> b
$ (Doc, Terminator) -> (Doc, Terminator)
statement (Doc, Terminator)
s]
where maybeBlank :: Doc
maybeBlank = Doc -> Doc -> Doc
emptyIfEmpty Doc
b (Doc -> Doc -> Doc
emptyIfEmpty ((Doc, Terminator) -> Doc
forall a b. (a, b) -> a
fst (Doc, Terminator)
s) Doc
blank)
surroundBody :: (Doc, Terminator) -> Doc -> (Doc, Terminator) -> Doc
surroundBody :: (Doc, Terminator) -> Doc -> (Doc, Terminator) -> Doc
surroundBody (Doc, Terminator)
p Doc
b (Doc, Terminator)
a = (Doc, Terminator) -> Doc -> Doc
prependToBody (Doc, Terminator)
p (Doc -> (Doc, Terminator) -> Doc
appendToBody Doc
b (Doc, Terminator)
a)
getterName :: String -> String
getterName :: String -> String
getterName String
s = String
"get" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
capitalize String
s
setterName :: String -> String
setterName :: String -> String
setterName String
s = String
"set" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
capitalize String
s
intValue :: (CommonRenderSym r) => SValue r -> SValue r
intValue :: forall (r :: * -> *). CommonRenderSym r => SValue r -> SValue r
intValue SValue r
i = SValue r
i SValue r -> (r (Value r) -> SValue r) -> SValue r
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> SValue r
intValue' (CodeType -> SValue r)
-> (r (Value r) -> CodeType) -> r (Value r) -> SValue r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType (r (Type r) -> CodeType)
-> (r (Value r) -> r (Type r)) -> r (Value r) -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType
where intValue' :: CodeType -> SValue r
intValue' CodeType
Integer = SValue r
i
intValue' CodeType
_ = String -> SValue r
forall a. HasCallStack => String -> a
error String
"Value passed to intValue must be Integer"
doxCommand, doxBrief, doxParam, doxReturn, doxFile, doxAuthor, doxDate, doxNote :: String
doxCommand :: String
doxCommand = String
"\\"
doxBrief :: String
doxBrief = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"brief "
doxParam :: String
doxParam = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"param "
doxReturn :: String
doxReturn = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"return "
doxFile :: String
doxFile = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"file "
doxAuthor :: String
doxAuthor = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"author "
doxDate :: String
doxDate = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"date "
doxNote :: String
doxNote = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"note "