{-# LANGUAGE PostfixOperators #-}
module GOOL.Drasil.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 GOOL.Drasil.CodeType (CodeType(..))
import GOOL.Drasil.ClassInterface (Label, Library, SValue, BodySym(Body),
PermanenceSym(Permanence), TypeSym(Type), TypeElim(..), VariableSym(Variable),
VariableElim(..), ValueSym(..), StatementSym(Statement), ScopeSym(Scope),
ParameterSym(Parameter))
import GOOL.Drasil.RendererClasses (RenderSym)
import qualified GOOL.Drasil.RendererClasses as RC (PermElim(..), BodyElim(..),
InternalTypeElim(..), InternalVarElim(..), ValueElim(..), StatementElim(..),
ScopeElim(..), ParamElim(..))
import GOOL.Drasil.AST (Terminator(..), FileData(..), fileD, updateFileMod,
updateMod, TypeData(..), VarData(..))
import GOOL.Drasil.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)
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 "class"
dot :: Doc
dot = String -> Doc
text "."
= String -> Doc
text "//"
returnLabel :: Doc
returnLabel = String -> Doc
text "return"
ifLabel :: Doc
ifLabel = String -> Doc
text "if"
elseLabel :: Doc
elseLabel = String -> Doc
text "else"
elseIfLabel :: Doc
elseIfLabel = Doc
elseLabel Doc -> Doc -> Doc
<+> Doc
ifLabel
forLabel :: Doc
forLabel = String -> Doc
text "for"
inLabel :: Doc
inLabel = String -> Doc
text "in"
whileLabel :: Doc
whileLabel = String -> Doc
text "while"
tryLabel :: Doc
tryLabel = String -> Doc
text "try"
catchLabel :: Doc
catchLabel = String -> Doc
text "catch"
throwLabel :: Doc
throwLabel = String -> Doc
text "throw"
throwsLabel :: Doc
throwsLabel = String -> Doc
text "throws"
importLabel :: Doc
importLabel = String -> Doc
text "import"
blockCmtStart :: Doc
blockCmtStart = String -> Doc
text "/*"
blockCmtEnd :: Doc
blockCmtEnd = String -> Doc
text "*/"
docCmtStart :: Doc
docCmtStart = String -> Doc
text "/**"
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 = "argc"
argv :: String
argv = "argv"
args :: String
args = "args"
printLabel :: String
printLabel = "print"
constDec :: String
constDec = "const"
exceptionObj :: String
exceptionObj = "Exception"
mainFunc :: String
mainFunc = "main"
new :: String
new = "new"
this :: String
this = "this"
self :: String
self = "self"
nullLabel :: String
nullLabel = "null"
array :: String
array = "[]"
listSep :: String
listSep = ", "
sqrt, abs, fabs, log10, log, exp, sin, cos, tan, asin, acos, atan, floor,
ceil, pow, piLabel :: String
sqrt :: String
sqrt = "sqrt"
abs :: String
abs = "abs"
fabs :: String
fabs = "fabs"
log10 :: String
log10 = "log10"
log :: String
log = "log"
exp :: String
exp = "exp"
sin :: String
sin = "sin"
cos :: String
cos = "cos"
tan :: String
tan = "tan"
asin :: String
asin = "asin"
acos :: String
acos = "acos"
atan :: String
atan = "atan"
floor :: String
floor = "floor"
ceil :: String
ceil = "ceil"
pow :: String
pow = "pow"
piLabel :: String
piLabel = "pi"
access :: String -> String -> String
access :: String -> String -> String
access q :: String
q n :: String
n = String
q String -> String -> String
forall a. [a] -> [a] -> [a]
++ "." String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
n
containing :: String -> String -> String
containing :: String -> String -> String
containing l :: String
l e :: String
e = String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ "<" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e String -> String -> String
forall a. [a] -> [a] -> [a]
++ ">"
tuple :: [String] -> String
tuple :: [String] -> String
tuple ts :: [String]
ts = "(" 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]
++ ")"
mathFunc :: String -> String
mathFunc :: String -> String
mathFunc = String -> String -> String
access "Math"
addExt :: String -> String -> String
addExt :: String -> String -> String
addExt ext :: String
ext nm :: String
nm = String
nm String -> String -> String
forall a. [a] -> [a] -> [a]
++ "." String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
ext
package :: Label -> Doc -> FileData -> FileData
package :: String -> Doc -> FileData -> FileData
package n :: String
n end :: Doc
end f :: FileData
f = String -> ModData -> FileData
fileD (String
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ "/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ FileData -> String
filePath FileData
f) ((Doc -> Doc) -> ModData -> ModData
updateMod
(\d :: Doc
d -> Doc -> Doc -> Doc
emptyIfEmpty Doc
d ([Doc] -> Doc
vibcat [String -> Doc
text "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 t :: Doc
t m :: Doc
m b :: Doc
b = [Doc] -> Doc
vibcat [
Doc
t,
Doc
m,
Doc
b]
module' :: Doc -> Doc -> Doc -> Doc
module' :: Doc -> Doc -> Doc -> Doc
module' ls :: Doc
ls fs :: Doc
fs cs :: 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' n :: String
n p :: Doc
p s :: Doc
s vs :: Doc
vs fs :: 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 sts :: [(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 [(s :: Doc
s, _)] = [Doc
s]
applyEnd ((s :: Doc
s, t :: Terminator
t):ss :: [(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 ss :: [(a, Terminator)]
ss = (a, Terminator) -> Terminator
forall a b. (a, b) -> b
snd ([(a, Terminator)] -> (a, Terminator)
forall a. [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 s :: (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 sts :: [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 bs :: [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 :: (RenderSym r) => r (Value r) -> r (Value r) -> Doc
print :: r (Value r) -> r (Value r) -> Doc
print printFn :: r (Value r)
printFn v :: 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 fn :: String
fn f :: Doc
f = Doc
f Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> String -> Doc
text String
fn
param :: (RenderSym r) => r (Variable r) -> Doc
param :: r (Variable r) -> Doc
param v :: 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 :: (RenderSym r) => Label -> r (Scope r) -> r (Permanence r) ->
r (Type r) -> [r (Parameter r)] -> r (Body r) -> Doc
method :: String
-> r (Scope r)
-> r (Permanence r)
-> r (Type r)
-> [r (Parameter r)]
-> r (Body r)
-> Doc
method n :: String
n s :: r (Scope r)
s p :: r (Permanence r)
p t :: r (Type r)
t ps :: [r (Parameter r)]
ps b :: r (Body r)
b = [Doc] -> Doc
vcat [
r (Scope r) -> Doc
forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope 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 :: * -> *). RenderSym 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 s :: Doc
s p :: Doc
p dec :: 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 s :: Doc
s end :: Doc
end p :: Doc
p v :: 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 :: (RenderSym r) => (Doc -> Doc) -> r (Statement r) -> r (Value r) -> r (Body r) ->
[(r (Value r), r (Body r))] -> Doc
switch :: (Doc -> Doc)
-> r (Statement r)
-> r (Value r)
-> r (Body r)
-> [(r (Value r), r (Body r))]
-> Doc
switch f :: Doc -> Doc
f st :: r (Statement r)
st v :: r (Value r)
v defBody :: r (Body r)
defBody cs :: [(r (Value r), r (Body r))]
cs =
let caseDoc :: (r (Value r), r (Body r)) -> Doc
caseDoc (l :: r (Value r)
l, result :: r (Body r)
result) = [Doc] -> Doc
vcat [
String -> Doc
text "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 "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 "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 :: (RenderSym r) => r (Variable r) -> r (Value r) -> Doc
assign :: r (Variable r) -> r (Value r) -> Doc
assign vr :: r (Variable r)
vr vl :: 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 :: (RenderSym r) => r (Variable r) -> r (Value r) -> Doc
addAssign :: r (Variable r) -> r (Value r) -> Doc
addAssign vr :: r (Variable r)
vr vl :: 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 "+=" Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
vl
subAssign :: (RenderSym r) => r (Variable r) -> r (Value r) -> Doc
subAssign :: r (Variable r) -> r (Value r) -> Doc
subAssign vr :: r (Variable r)
vr vl :: 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 "-=" Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
vl
increment :: (RenderSym r) => r (Variable r) -> Doc
increment :: r (Variable r) -> Doc
increment v :: 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 "++"
decrement :: (RenderSym r) => r (Variable r) -> Doc
decrement :: r (Variable r) -> Doc
decrement v :: 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 "--"
listDec :: (RenderSym r) => r (Variable r) -> r (Value r) -> Doc
listDec :: r (Variable r) -> r (Value r) -> Doc
listDec v :: r (Variable r)
v n :: 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 :: (RenderSym r) => r (Variable r) -> r (Value r) -> Doc
constDecDef :: r (Variable r) -> r (Value r) -> Doc
constDecDef v :: r (Variable r)
v def :: 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' :: (RenderSym r) => [r (Value r)] -> Doc
return' :: [r (Value r)] -> Doc
return' vs :: [r (Value r)]
vs = Doc
returnLabel Doc -> Doc -> Doc
<+> [r (Value r)] -> Doc
forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vs
comment :: Label -> Doc -> Doc
cmt :: String
cmt cStart :: Doc
cStart = Doc
cStart Doc -> Doc -> Doc
<+> String -> Doc
text String
cmt
statement :: (Doc, Terminator) -> (Doc, Terminator)
statement :: (Doc, Terminator) -> (Doc, Terminator)
statement (s :: Doc
s, t :: Terminator
t) = (Doc
s Doc -> Doc -> Doc
<> Terminator -> Doc
getTerm Terminator
t, Terminator
Empty)
getTerm :: Terminator -> Doc
getTerm :: Terminator -> Doc
getTerm Semi = Doc
semi
getTerm Empty = Doc
empty
var :: Label -> Doc
var :: String -> Doc
var = String -> Doc
text
extVar :: Library -> Label -> Doc
extVar :: String -> String -> Doc
extVar l :: String
l n :: String
n = String -> Doc
text String
l Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> String -> Doc
text String
n
arg :: (RenderSym r) => r (Value r) -> r (Value r) -> Doc
arg :: r (Value r) -> r (Value r) -> Doc
arg n :: r (Value r)
n argsList :: 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 c :: Doc
c v :: Doc
v = Doc
c Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> Doc
v
objVar :: Doc -> Doc -> Doc
objVar :: Doc -> Doc -> Doc
objVar n1 :: Doc
n1 n2 :: Doc
n2 = Doc
n1 Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> Doc
n2
unOpDocD :: Doc -> Doc -> Doc
unOpDocD :: Doc -> Doc -> Doc
unOpDocD op :: Doc
op v :: Doc
v = Doc
op Doc -> Doc -> Doc
<> Doc -> Doc
parens Doc
v
unOpDocD' :: Doc -> Doc -> Doc
unOpDocD' :: Doc -> Doc -> Doc
unOpDocD' op :: Doc
op v :: Doc
v = Doc
op Doc -> Doc -> Doc
<> Doc
v
binOpDocD :: Doc -> Doc -> Doc -> Doc
binOpDocD :: Doc -> Doc -> Doc -> Doc
binOpDocD op :: Doc
op v1 :: Doc
v1 v2 :: 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' op :: Doc
op v1 :: Doc
v1 v2 :: 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 fnApp :: Doc
fnApp = Doc
dot Doc -> Doc -> Doc
<> Doc
fnApp
cast :: Doc -> Doc
cast :: Doc -> Doc
cast = Doc -> Doc
parens
listAccessFunc :: (RenderSym r) => r (Value r) -> Doc
listAccessFunc :: r (Value r) -> Doc
listAccessFunc v :: 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 i :: Doc
i v :: 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 v :: Doc
v f :: Doc
f = Doc
v Doc -> Doc -> Doc
<> Doc
f
castObj :: Doc -> Doc -> Doc
castObj :: Doc -> Doc -> Doc
castObj t :: Doc
t v :: Doc
v = Doc
t Doc -> Doc -> Doc
<> Doc -> Doc
parens Doc
v
static :: Doc
static :: Doc
static = String -> Doc
text "static"
dynamic :: Doc
dynamic :: Doc
dynamic = Doc
empty
break :: Doc
break :: Doc
break = String -> Doc
text "break"
continue :: Doc
continue :: Doc
continue = String -> Doc
text "continue"
private :: Doc
private :: Doc
private = String -> Doc
text "private"
public :: Doc
public :: Doc
public = String -> Doc
text "public"
blockCmt :: [String] -> Doc -> Doc -> Doc
blockCmt :: [String] -> Doc -> Doc -> Doc
blockCmt lns :: [String]
lns start :: Doc
start end :: 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 lns :: [String]
lns start :: Doc
start end :: 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
cmt :: Doc
cmt itm :: Doc
itm = Doc -> Doc -> Doc
emptyIfEmpty Doc
itm Doc
cmt Doc -> Doc -> Doc
$+$ Doc
itm
commentLength :: Int
= 75
endCommentLabel :: Label
= "End"
addComments :: Label -> Doc -> Doc -> Doc
c :: String
c cStart :: Doc
cStart b :: 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
c :: String
c cStart :: Doc
cStart =
let com :: Doc
com = Doc
cStart Doc -> Doc -> Doc
<> String -> Doc
text (" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
c String -> String -> String
forall a. [a] -> [a] -> [a]
++ " ")
in Doc
com Doc -> Doc -> Doc
<> String -> Doc
text (String -> Int -> String
dashes (Doc -> String
render Doc
com) Int
commentLength)
endCommentDelimit :: Label -> Doc -> Doc
c :: String
c = String -> Doc -> Doc
commentDelimit (String
endCommentLabel String -> String -> String
forall a. [a] -> [a] -> [a]
++ " " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
c)
dashes :: String -> Int -> String
dashes :: String -> Int -> String
dashes s :: String
s l :: 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 (t :: * -> *) a. Foldable t => t a -> Int
length String
s) '-'
type FuncDocRenderer = String -> [(String, String)] -> [String] -> [String]
functionDox :: FuncDocRenderer
functionDox :: FuncDocRenderer
functionDox desc :: String
desc params :: [(String, String)]
params returns :: [String]
returns = [String
doxBrief String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
desc | Bool -> Bool
not (String -> 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 (\(v :: String
v, vDesc :: 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
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 -> String -> String
forall a. [a] -> [a] -> [a]
++) [String]
returns
type ClassDocRenderer = String -> [String]
classDox :: ClassDocRenderer
classDox :: ClassDocRenderer
classDox desc :: String
desc = [String
doxBrief String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
desc | Bool -> Bool
not (String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]
type ModuleDocRenderer = String -> [String] -> String -> String -> [String]
moduleDox :: ModuleDocRenderer
moduleDox :: ModuleDocRenderer
moduleDox desc :: String
desc as :: [String]
as date :: String
date m :: 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 (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 (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 (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]
commentedMod :: FileData -> Doc -> FileData
m :: FileData
m cmt :: Doc
cmt = ModData -> FileData -> FileData
updateFileMod ((Doc -> Doc) -> ModData -> ModData
updateMod (Doc -> Doc -> Doc
commentedItem Doc
cmt) (FileData -> ModData
fileMod FileData
m)) FileData
m
valueList :: (RenderSym r) => [r (Value r)] -> Doc
valueList :: [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 :: (RenderSym r) => [r (Variable r)] -> Doc
variableList :: [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 :: (RenderSym r) => [r (Parameter r)] -> Doc
parameterList :: [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 :: (RenderSym r) => Doc -> [(r (Variable r), r (Value r))] -> Doc
namedArgList :: Doc -> [(r (Variable r), r (Value r))] -> Doc
namedArgList sep :: 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 (\(vr :: r (Variable r)
vr,vl :: 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 s :: (Doc, Terminator)
s b :: 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 b :: Doc
b s :: (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 p :: (Doc, Terminator)
p b :: Doc
b a :: (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 s :: String
s = "get" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
capitalize String
s
setterName :: String -> String
setterName :: String -> String
setterName s :: String
s = "set" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
capitalize String
s
intValue :: (RenderSym r) => SValue r -> SValue r
intValue :: SValue r -> SValue r
intValue i :: SValue r
i = SValue r
i SValue r -> (r (Value r) -> SValue r) -> SValue r
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' Integer = SValue r
i
intValue' _ = String -> SValue r
forall a. HasCallStack => String -> a
error "Value passed to intValue must be Integer"
doxCommand, doxBrief, doxParam, doxReturn, doxFile, doxAuthor, doxDate :: String
doxCommand :: String
doxCommand = "\\"
doxBrief :: String
doxBrief = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ "brief "
doxParam :: String
doxParam = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ "param "
doxReturn :: String
doxReturn = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ "return "
doxFile :: String
doxFile = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ "file "
doxAuthor :: String
doxAuthor = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ "author "
doxDate :: String
doxDate = String
doxCommand String -> String -> String
forall a. [a] -> [a] -> [a]
++ "date "