module Language.Cimple.Pretty (ppTranslationUnit) where
import qualified Data.List as List
import Data.Text (Text)
import qualified Data.Text as Text
import Language.Cimple (AssignOp (..), BinaryOp (..),
CommentStyle (..), Lexeme (..),
LexemeClass (..), Node (..),
Scope (..), UnaryOp (..),
lexemeText)
import Prelude hiding ((<$>))
import Text.Groom (groom)
import Text.PrettyPrint.ANSI.Leijen
ppText :: Text -> Doc
ppText :: Text -> Doc
ppText = String -> Doc
text (String -> Doc) -> (Text -> String) -> Text -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack
ppLexeme :: Lexeme Text -> Doc
ppLexeme :: Lexeme Text -> Doc
ppLexeme = Text -> Doc
ppText (Text -> Doc) -> (Lexeme Text -> Text) -> Lexeme Text -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme Text -> Text
forall text. Lexeme text -> text
lexemeText
ppCommaSep :: (a -> Doc) -> [a] -> Doc
ppCommaSep :: (a -> Doc) -> [a] -> Doc
ppCommaSep a -> Doc
go = (Doc -> Doc -> Doc) -> Doc -> [Doc] -> Doc
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
(<>) Doc
empty ([Doc] -> Doc) -> ([a] -> [Doc]) -> [a] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
List.intersperse (String -> Doc
text String
", ") ([Doc] -> [Doc]) -> ([a] -> [Doc]) -> [a] -> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc
go
ppLineSep :: (a -> Doc) -> [a] -> Doc
ppLineSep :: (a -> Doc) -> [a] -> Doc
ppLineSep a -> Doc
go = (Doc -> Doc -> Doc) -> Doc -> [Doc] -> Doc
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
(<>) Doc
empty ([Doc] -> Doc) -> ([a] -> [Doc]) -> [a] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
List.intersperse Doc
linebreak ([Doc] -> [Doc]) -> ([a] -> [Doc]) -> [a] -> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc
go
ppComment :: CommentStyle -> [Node (Lexeme Text)] -> Doc
CommentStyle
style [Node (Lexeme Text)]
cs =
Int -> Doc -> Doc
nest Int
1 (CommentStyle -> Doc
ppCommentStyle CommentStyle
style Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Node (Lexeme Text)] -> Doc
ppCommentBody [Node (Lexeme Text)]
cs) Doc -> Doc -> Doc
<+> String -> Doc
text String
"*/"
ppCommentStyle :: CommentStyle -> Doc
CommentStyle
Block = String -> Doc
text String
"/***"
ppCommentStyle CommentStyle
Doxygen = String -> Doc
text String
"/**"
ppCommentStyle CommentStyle
Regular = String -> Doc
text String
"/*"
ppCommentBody :: [Node (Lexeme Text)] -> Doc
ppCommentBody :: [Node (Lexeme Text)] -> Doc
ppCommentBody = [Lexeme Text] -> Doc
go ([Lexeme Text] -> Doc)
-> ([Node (Lexeme Text)] -> [Lexeme Text])
-> [Node (Lexeme Text)]
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Node (Lexeme Text) -> Lexeme Text)
-> [Node (Lexeme Text)] -> [Lexeme Text]
forall a b. (a -> b) -> [a] -> [b]
map Node (Lexeme Text) -> Lexeme Text
forall p. Show p => Node p -> p
unCommentWord
where
unCommentWord :: Node p -> p
unCommentWord (CommentWord p
l) = p
l
unCommentWord Node p
x = String -> p
forall a. HasCallStack => String -> a
error (String -> p) -> String -> p
forall a b. (a -> b) -> a -> b
$ Node p -> String
forall a. Show a => a -> String
groom Node p
x
go :: [Lexeme Text] -> Doc
go (L AlexPosn
_ LexemeClass
LitInteger Text
t1 : L AlexPosn
_ LexemeClass
PctMinus Text
m : L AlexPosn
_ LexemeClass
LitInteger Text
t2 : [Lexeme Text]
xs) =
Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t1 Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
m Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t2 Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Lexeme Text] -> Doc
go [Lexeme Text]
xs
go (L AlexPosn
_ LexemeClass
PctMinus Text
m : L AlexPosn
_ LexemeClass
LitInteger Text
t : [Lexeme Text]
xs) =
Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
m Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Lexeme Text] -> Doc
go [Lexeme Text]
xs
go (Lexeme Text
l : L AlexPosn
_ LexemeClass
PctPeriod Text
t : [Lexeme Text]
xs) = [Lexeme Text] -> Doc
go [Lexeme Text
l] Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Lexeme Text] -> Doc
go [Lexeme Text]
xs
go (Lexeme Text
l : L AlexPosn
_ LexemeClass
PctComma Text
t : [Lexeme Text]
xs) = [Lexeme Text] -> Doc
go [Lexeme Text
l] Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Lexeme Text] -> Doc
go [Lexeme Text]
xs
go (Lexeme Text
x : [Lexeme Text]
xs) = Lexeme Text -> Doc
ppWord Lexeme Text
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Lexeme Text] -> Doc
go [Lexeme Text]
xs
go [] = Doc
empty
ppWord :: Lexeme Text -> Doc
ppWord (L AlexPosn
_ LexemeClass
CmtSpdxLicense Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
CmtSpdxCopyright Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
CmtWord Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
CmtCode Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
CmtRef Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
CmtIndent Text
_) = Char -> Doc
char Char
'*'
ppWord (L AlexPosn
_ LexemeClass
PpNewline Text
_) = Doc
linebreak
ppWord (L AlexPosn
_ LexemeClass
LitInteger Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
LitString Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctEMark Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctPlus Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctEq Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctMinus Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctPeriod Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctLParen Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctRParen Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctSemicolon Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctColon Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctQMark Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctSlash Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctGreater Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctLess Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord (L AlexPosn
_ LexemeClass
PctComma Text
t) = Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Text -> Doc
ppText Text
t
ppWord Lexeme Text
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Lexeme Text -> String
forall a. Show a => a -> String
groom Lexeme Text
x
ppScope :: Scope -> Doc
ppScope :: Scope -> Doc
ppScope Scope
Global = Doc
empty
ppScope Scope
Static = String -> Doc
text String
"static "
ppType :: Node (Lexeme Text) -> Doc
ppType :: Node (Lexeme Text) -> Doc
ppType (TyPointer Node (Lexeme Text)
ty) = Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
'*'
ppType (TyConst Node (Lexeme Text)
ty) = Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> String -> Doc
text String
"const"
ppType (TyUserDefined Lexeme Text
l ) = Lexeme Text -> Doc
ppLexeme Lexeme Text
l
ppType (TyStd Lexeme Text
l ) = Lexeme Text -> Doc
ppLexeme Lexeme Text
l
ppType (TyFunc Lexeme Text
l ) = Lexeme Text -> Doc
ppLexeme Lexeme Text
l
ppType (TyStruct Lexeme Text
l ) = String -> Doc
text String
"struct" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
l
ppType (TyVar Lexeme Text
l ) = Lexeme Text -> Doc
ppLexeme Lexeme Text
l
ppType Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc)
-> (Node (Lexeme Text) -> String) -> Node (Lexeme Text) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom (Node (Lexeme Text) -> Doc) -> Node (Lexeme Text) -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text)
x
ppAssignOp :: AssignOp -> Doc
ppAssignOp :: AssignOp -> Doc
ppAssignOp AssignOp
op = case AssignOp
op of
AssignOp
AopEq -> String -> Doc
text String
"="
AssignOp
AopMul -> String -> Doc
text String
"*="
AssignOp
AopDiv -> String -> Doc
text String
"/="
AssignOp
AopPlus -> String -> Doc
text String
"+="
AssignOp
AopMinus -> String -> Doc
text String
"-="
AssignOp
AopBitAnd -> String -> Doc
text String
"&="
AssignOp
AopBitOr -> String -> Doc
text String
"|="
AssignOp
AopBitXor -> String -> Doc
text String
"^="
AssignOp
AopMod -> String -> Doc
text String
"%="
AssignOp
AopLsh -> String -> Doc
text String
">>="
AssignOp
AopRsh -> String -> Doc
text String
"<<="
ppBinaryOp :: BinaryOp -> Doc
ppBinaryOp :: BinaryOp -> Doc
ppBinaryOp BinaryOp
op = case BinaryOp
op of
BinaryOp
BopNe -> String -> Doc
text String
"!="
BinaryOp
BopEq -> String -> Doc
text String
"=="
BinaryOp
BopOr -> String -> Doc
text String
"||"
BinaryOp
BopBitXor -> Char -> Doc
char Char
'^'
BinaryOp
BopBitOr -> Char -> Doc
char Char
'|'
BinaryOp
BopAnd -> String -> Doc
text String
"&&"
BinaryOp
BopBitAnd -> Char -> Doc
char Char
'&'
BinaryOp
BopDiv -> Char -> Doc
char Char
'/'
BinaryOp
BopMul -> Char -> Doc
char Char
'*'
BinaryOp
BopMod -> Char -> Doc
char Char
'%'
BinaryOp
BopPlus -> Char -> Doc
char Char
'+'
BinaryOp
BopMinus -> Char -> Doc
char Char
'-'
BinaryOp
BopLt -> Char -> Doc
char Char
'<'
BinaryOp
BopLe -> String -> Doc
text String
"<="
BinaryOp
BopLsh -> String -> Doc
text String
"<<"
BinaryOp
BopGt -> Char -> Doc
char Char
'>'
BinaryOp
BopGe -> String -> Doc
text String
">="
BinaryOp
BopRsh -> String -> Doc
text String
">>"
ppUnaryOp :: UnaryOp -> Doc
ppUnaryOp :: UnaryOp -> Doc
ppUnaryOp UnaryOp
op = case UnaryOp
op of
UnaryOp
UopNot -> Char -> Doc
char Char
'!'
UnaryOp
UopNeg -> Char -> Doc
char Char
'~'
UnaryOp
UopMinus -> Char -> Doc
char Char
'-'
UnaryOp
UopAddress -> Char -> Doc
char Char
'&'
UnaryOp
UopDeref -> Char -> Doc
char Char
'*'
UnaryOp
UopIncr -> String -> Doc
text String
"++"
UnaryOp
UopDecr -> String -> Doc
text String
"--"
ppInitialiserList :: [Node (Lexeme Text)] -> Doc
ppInitialiserList :: [Node (Lexeme Text)] -> Doc
ppInitialiserList [Node (Lexeme Text)]
l = Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<+> (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppCommaSep Node (Lexeme Text) -> Doc
ppExpr [Node (Lexeme Text)]
l Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'}'
ppDeclSpec :: Node (Lexeme Text) -> Doc
ppDeclSpec :: Node (Lexeme Text) -> Doc
ppDeclSpec (DeclSpecVar Lexeme Text
var ) = Lexeme Text -> Doc
ppLexeme Lexeme Text
var
ppDeclSpec (DeclSpecArray Node (Lexeme Text)
dspec Maybe (Node (Lexeme Text))
dim) = Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Maybe (Node (Lexeme Text)) -> Doc
ppDim Maybe (Node (Lexeme Text))
dim
where
ppDim :: Maybe (Node (Lexeme Text)) -> Doc
ppDim Maybe (Node (Lexeme Text))
Nothing = String -> Doc
text String
"[]"
ppDim (Just Node (Lexeme Text)
x) = Char -> Doc
char Char
'[' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
']'
ppDeclSpec Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppDeclarator :: Node (Lexeme Text) -> Doc
ppDeclarator :: Node (Lexeme Text) -> Doc
ppDeclarator (Declarator Node (Lexeme Text)
dspec Maybe (Node (Lexeme Text))
Nothing) =
Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec
ppDeclarator (Declarator Node (Lexeme Text)
dspec (Just Node (Lexeme Text)
initr)) =
Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'=' Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
initr
ppDeclarator Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppFunctionParamList :: [Node (Lexeme Text)] -> Doc
ppFunctionParamList :: [Node (Lexeme Text)] -> Doc
ppFunctionParamList [Node (Lexeme Text)]
xs = Char -> Doc
char Char
'(' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppCommaSep Node (Lexeme Text) -> Doc
go [Node (Lexeme Text)]
xs Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
where
go :: Node (Lexeme Text) -> Doc
go (TyStd l :: Lexeme Text
l@(L AlexPosn
_ LexemeClass
KwVoid Text
_)) = Lexeme Text -> Doc
ppLexeme Lexeme Text
l
go (FunctionParam Node (Lexeme Text)
ty Node (Lexeme Text)
dspec) = Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec
go Node (Lexeme Text)
Ellipsis = String -> Doc
text String
"..."
go Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppFunctionPrototype
:: Node (Lexeme Text)
-> Lexeme Text
-> [Node (Lexeme Text)]
-> Doc
ppFunctionPrototype :: Node (Lexeme Text) -> Lexeme Text -> [Node (Lexeme Text)] -> Doc
ppFunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params =
Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Node (Lexeme Text)] -> Doc
ppFunctionParamList [Node (Lexeme Text)]
params
ppWithError :: Maybe (Node (Lexeme Text)) -> Doc
ppWithError :: Maybe (Node (Lexeme Text)) -> Doc
ppWithError Maybe (Node (Lexeme Text))
Nothing = Char -> Doc
char Char
';'
ppWithError (Just (ErrorFor Lexeme Text
name)) =
String -> Doc
text String
" with error for" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
ppWithError (Just (ErrorList [Node (Lexeme Text)]
errs)) =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
" with error" Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppEnumeratorList [Node (Lexeme Text)]
errs
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppWithError Maybe (Node (Lexeme Text))
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Maybe (Node (Lexeme Text)) -> String
forall a. Show a => a -> String
groom Maybe (Node (Lexeme Text))
x
ppFunctionCall :: Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppFunctionCall :: Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppFunctionCall Node (Lexeme Text)
callee [Node (Lexeme Text)]
args =
Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
callee Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
'(' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppCommaSep Node (Lexeme Text) -> Doc
ppExpr [Node (Lexeme Text)]
args Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
ppMacroBody :: Node (Lexeme Text) -> Doc
ppMacroBody :: Node (Lexeme Text) -> Doc
ppMacroBody (MacroBodyFunCall e :: Node (Lexeme Text)
e@FunctionCall{}) = Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e
ppMacroBody (MacroBodyStmt [Node (Lexeme Text)]
body) =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"do {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"} while (0)"
ppMacroBody Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppMacroParam :: Node (Lexeme Text) -> Doc
ppMacroParam :: Node (Lexeme Text) -> Doc
ppMacroParam (MacroParam Lexeme Text
l) = Lexeme Text -> Doc
ppLexeme Lexeme Text
l
ppMacroParam Node (Lexeme Text)
Ellipsis = String -> Doc
text String
"..."
ppMacroParam Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppMacroParamList :: [Node (Lexeme Text)] -> Doc
ppMacroParamList :: [Node (Lexeme Text)] -> Doc
ppMacroParamList [Node (Lexeme Text)]
xs = Char -> Doc
char Char
'(' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppCommaSep Node (Lexeme Text) -> Doc
ppMacroParam [Node (Lexeme Text)]
xs Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
ppNamespace :: ([a] -> Doc) -> Scope -> Lexeme Text -> [a] -> Doc
ppNamespace :: ([a] -> Doc) -> Scope -> Lexeme Text -> [a] -> Doc
ppNamespace [a] -> Doc
pp Scope
scope Lexeme Text
name [a]
members =
Int -> Doc -> Doc
nest Int
2 (
Scope -> Doc
ppScope Scope
scope Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
String -> Doc
text String
"namespace" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[a] -> Doc
pp [a]
members
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppEnumerator :: Node (Lexeme Text) -> Doc
ppEnumerator :: Node (Lexeme Text) -> Doc
ppEnumerator (Comment CommentStyle
style Lexeme Text
_ [Node (Lexeme Text)]
cs Lexeme Text
_ ) = CommentStyle -> [Node (Lexeme Text)] -> Doc
ppComment CommentStyle
style [Node (Lexeme Text)]
cs
ppEnumerator (Enumerator Lexeme Text
name Maybe (Node (Lexeme Text))
Nothing) = Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
','
ppEnumerator (Enumerator Lexeme Text
name (Just Node (Lexeme Text)
value)) =
Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'=' Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
value Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
','
ppEnumerator (Namespace Scope
scope Lexeme Text
name [Node (Lexeme Text)]
members) =
([Node (Lexeme Text)] -> Doc)
-> Scope -> Lexeme Text -> [Node (Lexeme Text)] -> Doc
forall a. ([a] -> Doc) -> Scope -> Lexeme Text -> [a] -> Doc
ppNamespace [Node (Lexeme Text)] -> Doc
ppEnumeratorList Scope
scope Lexeme Text
name [Node (Lexeme Text)]
members
ppEnumerator Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppEnumeratorList :: [Node (Lexeme Text)] -> Doc
ppEnumeratorList :: [Node (Lexeme Text)] -> Doc
ppEnumeratorList = (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppLineSep Node (Lexeme Text) -> Doc
ppEnumerator
ppMemberDecl :: Node (Lexeme Text) -> Doc
ppMemberDecl :: Node (Lexeme Text) -> Doc
ppMemberDecl = Node (Lexeme Text) -> Doc
ppDecl
ppMemberDeclList :: [Node (Lexeme Text)] -> Doc
ppMemberDeclList :: [Node (Lexeme Text)] -> Doc
ppMemberDeclList = (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppLineSep Node (Lexeme Text) -> Doc
ppMemberDecl
ppAccessor :: Node (Lexeme Text) -> Doc
ppAccessor :: Node (Lexeme Text) -> Doc
ppAccessor (Comment CommentStyle
style Lexeme Text
_ [Node (Lexeme Text)]
cs Lexeme Text
_) = CommentStyle -> [Node (Lexeme Text)] -> Doc
ppComment CommentStyle
style [Node (Lexeme Text)]
cs
ppAccessor (Accessor Lexeme Text
name [Node (Lexeme Text)]
params Maybe (Node (Lexeme Text))
errs) =
Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Node (Lexeme Text)] -> Doc
ppFunctionParamList [Node (Lexeme Text)]
params Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Maybe (Node (Lexeme Text)) -> Doc
ppWithError Maybe (Node (Lexeme Text))
errs
ppAccessor Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppAccessorList :: [Node (Lexeme Text)] -> Doc
ppAccessorList :: [Node (Lexeme Text)] -> Doc
ppAccessorList = (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppLineSep Node (Lexeme Text) -> Doc
ppAccessor
ppEventType :: Node (Lexeme Text) -> Doc
ppEventType :: Node (Lexeme Text) -> Doc
ppEventType (Commented (Comment CommentStyle
style Lexeme Text
_ [Node (Lexeme Text)]
cs Lexeme Text
_) Node (Lexeme Text)
ty) =
CommentStyle -> [Node (Lexeme Text)] -> Doc
ppComment CommentStyle
style [Node (Lexeme Text)]
cs Doc -> Doc -> Doc
<$> Node (Lexeme Text) -> Doc
ppEventType Node (Lexeme Text)
ty
ppEventType (EventParams [Node (Lexeme Text)]
params) =
String -> Doc
text String
"typedef void" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Node (Lexeme Text)] -> Doc
ppFunctionParamList [Node (Lexeme Text)]
params
ppEventType Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppTypeParams :: [Node (Lexeme Text)] -> Doc
ppTypeParams :: [Node (Lexeme Text)] -> Doc
ppTypeParams [] = Doc
empty
ppTypeParams [Node (Lexeme Text)]
xs = Char -> Doc
char Char
'<' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppCommaSep Node (Lexeme Text) -> Doc
pp [Node (Lexeme Text)]
xs Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
'>'
where
pp :: Node (Lexeme Text) -> Doc
pp (TyVar Lexeme Text
x) = Lexeme Text -> Doc
ppLexeme Lexeme Text
x
pp Node (Lexeme Text)
x = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppCompoundStmt :: [Node (Lexeme Text)] -> Doc
ppCompoundStmt :: [Node (Lexeme Text)] -> Doc
ppCompoundStmt [Node (Lexeme Text)]
body =
Int -> Doc -> Doc
nest Int
2 (
Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppStmtList :: [Node (Lexeme Text)] -> Doc
ppStmtList :: [Node (Lexeme Text)] -> Doc
ppStmtList = (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppLineSep Node (Lexeme Text) -> Doc
ppDecl
ppIfStmt
:: Node (Lexeme Text)
-> [Node (Lexeme Text)]
-> Maybe (Node (Lexeme Text))
-> Doc
ppIfStmt :: Node (Lexeme Text)
-> [Node (Lexeme Text)] -> Maybe (Node (Lexeme Text)) -> Doc
ppIfStmt Node (Lexeme Text)
cond [Node (Lexeme Text)]
t Maybe (Node (Lexeme Text))
Nothing =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"if (" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
") {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
t
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppIfStmt Node (Lexeme Text)
cond [Node (Lexeme Text)]
t (Just Node (Lexeme Text)
e) =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"if (" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
") {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
t
) Doc -> Doc -> Doc
<$> Int -> Doc -> Doc
nest Int
2 (Char -> Doc
char Char
'}' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
" else " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
e)
ppForStmt
:: Node (Lexeme Text)
-> Node (Lexeme Text)
-> Node (Lexeme Text)
-> [Node (Lexeme Text)]
-> Doc
ppForStmt :: Node (Lexeme Text)
-> Node (Lexeme Text)
-> Node (Lexeme Text)
-> [Node (Lexeme Text)]
-> Doc
ppForStmt Node (Lexeme Text)
i Node (Lexeme Text)
c Node (Lexeme Text)
n [Node (Lexeme Text)]
body =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"for ("
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
i
Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
c Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
n
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
") {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppWhileStmt
:: Node (Lexeme Text)
-> [Node (Lexeme Text)]
-> Doc
ppWhileStmt :: Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppWhileStmt Node (Lexeme Text)
c [Node (Lexeme Text)]
body =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"while ("
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
c
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
") {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppDoWhileStmt
:: [Node (Lexeme Text)]
-> Node (Lexeme Text)
-> Doc
ppDoWhileStmt :: [Node (Lexeme Text)] -> Node (Lexeme Text) -> Doc
ppDoWhileStmt [Node (Lexeme Text)]
body Node (Lexeme Text)
c =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"do ("
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
") {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"} while (" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
c Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
ppSwitchStmt
:: Node (Lexeme Text)
-> [Node (Lexeme Text)]
-> Doc
ppSwitchStmt :: Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppSwitchStmt Node (Lexeme Text)
c [Node (Lexeme Text)]
body =
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"switch ("
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
c
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
") {" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ppExpr :: Node (Lexeme Text) -> Doc
ppExpr :: Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
expr = case Node (Lexeme Text)
expr of
VarExpr Lexeme Text
var -> Lexeme Text -> Doc
ppLexeme Lexeme Text
var
LiteralExpr LiteralType
_ Lexeme Text
l -> Lexeme Text -> Doc
ppLexeme Lexeme Text
l
SizeofExpr Node (Lexeme Text)
arg -> String -> Doc
text String
"sizeof(" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
arg Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
SizeofType Node (Lexeme Text)
arg -> String -> Doc
text String
"sizeof(" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
arg Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
BinaryExpr Node (Lexeme Text)
l BinaryOp
o Node (Lexeme Text)
r -> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
l Doc -> Doc -> Doc
<+> BinaryOp -> Doc
ppBinaryOp BinaryOp
o Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
r
AssignExpr Node (Lexeme Text)
l AssignOp
o Node (Lexeme Text)
r -> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
l Doc -> Doc -> Doc
<+> AssignOp -> Doc
ppAssignOp AssignOp
o Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
r
TernaryExpr Node (Lexeme Text)
c Node (Lexeme Text)
t Node (Lexeme Text)
e -> Node (Lexeme Text)
-> Node (Lexeme Text) -> Node (Lexeme Text) -> Doc
ppTernaryExpr Node (Lexeme Text)
c Node (Lexeme Text)
t Node (Lexeme Text)
e
UnaryExpr UnaryOp
o Node (Lexeme Text)
e -> UnaryOp -> Doc
ppUnaryOp UnaryOp
o Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e
ParenExpr Node (Lexeme Text)
e -> Char -> Doc
char Char
'(' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
FunctionCall Node (Lexeme Text)
c [Node (Lexeme Text)]
a -> Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppFunctionCall Node (Lexeme Text)
c [Node (Lexeme Text)]
a
ArrayAccess Node (Lexeme Text)
e Node (Lexeme Text)
i -> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
'[' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
i Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
']'
CastExpr Node (Lexeme Text)
ty Node (Lexeme Text)
e -> Char -> Doc
char Char
'(' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e
CompoundExpr Node (Lexeme Text)
ty Node (Lexeme Text)
e -> Char -> Doc
char Char
'(' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')' Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
'}'
PreprocDefined Lexeme Text
n -> String -> Doc
text String
"defined(" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Lexeme Text -> Doc
ppLexeme Lexeme Text
n Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
')'
InitialiserList [Node (Lexeme Text)]
l -> [Node (Lexeme Text)] -> Doc
ppInitialiserList [Node (Lexeme Text)]
l
PointerAccess Node (Lexeme Text)
e Lexeme Text
m -> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
"->" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Lexeme Text -> Doc
ppLexeme Lexeme Text
m
MemberAccess Node (Lexeme Text)
e Lexeme Text
m -> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
"." Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Lexeme Text -> Doc
ppLexeme Lexeme Text
m
CommentExpr Node (Lexeme Text)
c Node (Lexeme Text)
e -> Node (Lexeme Text) -> Node (Lexeme Text) -> Doc
ppCommentExpr Node (Lexeme Text)
c Node (Lexeme Text)
e
Node (Lexeme Text)
x -> String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
x
ppTernaryExpr
:: Node (Lexeme Text) -> Node (Lexeme Text) -> Node (Lexeme Text) -> Doc
ppTernaryExpr :: Node (Lexeme Text)
-> Node (Lexeme Text) -> Node (Lexeme Text) -> Doc
ppTernaryExpr Node (Lexeme Text)
c Node (Lexeme Text)
t Node (Lexeme Text)
e =
Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
c Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'?' Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
t Doc -> Doc -> Doc
<+> Char -> Doc
char Char
':' Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e
ppCommentExpr :: Node (Lexeme Text) -> Node (Lexeme Text) -> Doc
(Comment CommentStyle
style Lexeme Text
_ [Node (Lexeme Text)]
body Lexeme Text
_) Node (Lexeme Text)
e =
CommentStyle -> Doc
ppCommentStyle CommentStyle
style Doc -> Doc -> Doc
<+> [Node (Lexeme Text)] -> Doc
ppCommentBody [Node (Lexeme Text)]
body Doc -> Doc -> Doc
<+> String -> Doc
text String
"*/" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e
ppCommentExpr Node (Lexeme Text)
c Node (Lexeme Text)
_ = String -> Doc
forall a. HasCallStack => String -> a
error (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Node (Lexeme Text) -> String
forall a. Show a => a -> String
groom Node (Lexeme Text)
c
ppStmt :: Node (Lexeme Text) -> Doc
ppStmt :: Node (Lexeme Text) -> Doc
ppStmt = Node (Lexeme Text) -> Doc
ppDecl
ppDeclList :: [Node (Lexeme Text)] -> Doc
ppDeclList :: [Node (Lexeme Text)] -> Doc
ppDeclList = (Node (Lexeme Text) -> Doc) -> [Node (Lexeme Text)] -> Doc
forall a. (a -> Doc) -> [a] -> Doc
ppLineSep Node (Lexeme Text) -> Doc
ppDecl
ppDecl :: Node (Lexeme Text) -> Doc
ppDecl :: Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
decl = case Node (Lexeme Text)
decl of
PreprocElif Node (Lexeme Text)
cond [Node (Lexeme Text)]
decls (PreprocElse []) ->
String -> Doc
text String
"#elif" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocElif Node (Lexeme Text)
cond [Node (Lexeme Text)]
decls Node (Lexeme Text)
elseBranch ->
String -> Doc
text String
"#elif" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)
elseBranch] Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocIf Node (Lexeme Text)
cond [Node (Lexeme Text)]
decls (PreprocElse []) ->
Int -> Doc -> Doc
nest (-Int
100) (String -> Doc
text String
"#if") Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocIf Node (Lexeme Text)
cond [Node (Lexeme Text)]
decls Node (Lexeme Text)
elseBranch ->
String -> Doc
text String
"#if" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)
elseBranch] Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocIfdef Lexeme Text
name [Node (Lexeme Text)]
decls (PreprocElse []) ->
Int -> Doc -> Doc
indent (-Int
2) (String -> Doc
text String
"#ifndef" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls) Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocIfdef Lexeme Text
name [Node (Lexeme Text)]
decls Node (Lexeme Text)
elseBranch ->
String -> Doc
text String
"#ifdef" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)
elseBranch] Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocIfndef Lexeme Text
name [Node (Lexeme Text)]
decls (PreprocElse []) ->
String -> Doc
text String
"#ifndef" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocIfndef Lexeme Text
name [Node (Lexeme Text)]
decls Node (Lexeme Text)
elseBranch ->
String -> Doc
text String
"#ifndef" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)
elseBranch] Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
PreprocElse [Node (Lexeme Text)]
decls ->
String -> Doc
text String
"#else" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls
PreprocScopedDefine Node (Lexeme Text)
def [Node (Lexeme Text)]
stmts Node (Lexeme Text)
undef ->
Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
def Doc -> Doc -> Doc
<$> [Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
stmts Doc -> Doc -> Doc
<$> Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
undef
PreprocInclude Lexeme Text
hdr ->
String -> Doc
text String
"#include" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
hdr
PreprocDefine Lexeme Text
name ->
String -> Doc
text String
"#define" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name
PreprocDefineConst Lexeme Text
name Node (Lexeme Text)
value ->
String -> Doc
text String
"#define" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
value
PreprocDefineMacro Lexeme Text
name [Node (Lexeme Text)]
params Node (Lexeme Text)
body ->
String -> Doc
text String
"#define" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Node (Lexeme Text)] -> Doc
ppMacroParamList [Node (Lexeme Text)]
params Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppMacroBody Node (Lexeme Text)
body
PreprocUndef Lexeme Text
name ->
String -> Doc
text String
"#undef" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name
StaticAssert Node (Lexeme Text)
cond Lexeme Text
msg ->
String -> Doc
text String
"static_assert" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
cond Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
',' Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
msg Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
");"
Comment CommentStyle
style Lexeme Text
_ [Node (Lexeme Text)]
cs Lexeme Text
_ ->
CommentStyle -> [Node (Lexeme Text)] -> Doc
ppComment CommentStyle
style [Node (Lexeme Text)]
cs
CommentBlock Lexeme Text
cs ->
Lexeme Text -> Doc
ppLexeme Lexeme Text
cs
Commented Node (Lexeme Text)
c Node (Lexeme Text)
d ->
Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
c Doc -> Doc -> Doc
<$> Node (Lexeme Text) -> Doc
ppDecl Node (Lexeme Text)
d
ClassForward Lexeme Text
name [] ->
String -> Doc
text String
"class" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Class Scope
scope Lexeme Text
name [Node (Lexeme Text)]
tyvars [Node (Lexeme Text)]
decls ->
Scope -> Doc
ppScope Scope
scope Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"class" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Node (Lexeme Text)] -> Doc
ppTypeParams [Node (Lexeme Text)]
tyvars Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"};"
EnumConsts Maybe (Lexeme Text)
Nothing [Node (Lexeme Text)]
enums ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"enum" Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppEnumeratorList [Node (Lexeme Text)]
enums
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"};"
EnumConsts (Just Lexeme Text
name) [Node (Lexeme Text)]
enums ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"enum" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppEnumeratorList [Node (Lexeme Text)]
enums
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"};"
EnumClass Lexeme Text
name [Node (Lexeme Text)]
enums ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"enum class" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppEnumeratorList [Node (Lexeme Text)]
enums
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"};"
EnumDecl Lexeme Text
name [Node (Lexeme Text)]
enums Lexeme Text
ty ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"typedef enum" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppEnumeratorList [Node (Lexeme Text)]
enums
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"} " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Lexeme Text -> Doc
ppLexeme Lexeme Text
ty Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Namespace Scope
scope Lexeme Text
name [Node (Lexeme Text)]
decls ->
([Node (Lexeme Text)] -> Doc)
-> Scope -> Lexeme Text -> [Node (Lexeme Text)] -> Doc
forall a. ([a] -> Doc) -> Scope -> Lexeme Text -> [a] -> Doc
ppNamespace [Node (Lexeme Text)] -> Doc
ppDeclList Scope
scope Lexeme Text
name [Node (Lexeme Text)]
decls
ExternC [Node (Lexeme Text)]
decls ->
String -> Doc
text String
"#ifndef __cplusplus" Doc -> Doc -> Doc
<$>
String -> Doc
text String
"extern \"C\" {" Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif" Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#ifndef __cplusplus" Doc -> Doc -> Doc
<$>
String -> Doc
text String
"}" Doc -> Doc -> Doc
<$>
String -> Doc
text String
"#endif"
Struct Lexeme Text
name [Node (Lexeme Text)]
members ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"struct" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppMemberDeclList [Node (Lexeme Text)]
members
) Doc -> Doc -> Doc
<$> String -> Doc
text String
"};"
Typedef (Union Lexeme Text
name [Node (Lexeme Text)]
members) Lexeme Text
tyname ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"typedef union" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppMemberDeclList [Node (Lexeme Text)]
members
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}' Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
tyname Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Typedef (Struct Lexeme Text
name [Node (Lexeme Text)]
members) Lexeme Text
tyname ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"typedef struct" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppMemberDeclList [Node (Lexeme Text)]
members
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}' Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
tyname Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Typedef Node (Lexeme Text)
ty Lexeme Text
name ->
String -> Doc
text String
"typedef" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
TypedefFunction (FunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params) ->
String -> Doc
text String
"typedef" Doc -> Doc -> Doc
<+>
Node (Lexeme Text) -> Lexeme Text -> [Node (Lexeme Text)] -> Doc
ppFunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
Char -> Doc
char Char
';'
MemberDecl Node (Lexeme Text)
ty Node (Lexeme Text)
dspec Maybe (Lexeme Text)
Nothing ->
Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
MemberDecl Node (Lexeme Text)
ty Node (Lexeme Text)
dspec (Just Lexeme Text
size) ->
Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec Doc -> Doc -> Doc
<+> Char -> Doc
char Char
':' Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
size Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
FunctionDecl Scope
scope (FunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params) Maybe (Node (Lexeme Text))
err ->
Scope -> Doc
ppScope Scope
scope Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
Node (Lexeme Text) -> Lexeme Text -> [Node (Lexeme Text)] -> Doc
ppFunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
Maybe (Node (Lexeme Text)) -> Doc
ppWithError Maybe (Node (Lexeme Text))
err
FunctionDefn Scope
scope (FunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params) [Node (Lexeme Text)]
body ->
Scope -> Doc
ppScope Scope
scope Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
Node (Lexeme Text) -> Lexeme Text -> [Node (Lexeme Text)] -> Doc
ppFunctionPrototype Node (Lexeme Text)
ty Lexeme Text
name [Node (Lexeme Text)]
params Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppCompoundStmt [Node (Lexeme Text)]
body
ConstDecl Node (Lexeme Text)
ty Lexeme Text
name ->
String -> Doc
text String
"extern const" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
ConstDefn Scope
scope Node (Lexeme Text)
ty Lexeme Text
name Node (Lexeme Text)
value ->
Scope -> Doc
ppScope Scope
scope Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>
Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'=' Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
value Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Event Lexeme Text
name Node (Lexeme Text)
ty ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"event" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
Node (Lexeme Text) -> Doc
ppEventType Node (Lexeme Text)
ty
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
Property Node (Lexeme Text)
ty Node (Lexeme Text)
dspec [Node (Lexeme Text)]
accessors ->
Int -> Doc -> Doc
nest Int
2 (
Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppDeclSpec Node (Lexeme Text)
dspec Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppAccessorList [Node (Lexeme Text)]
accessors
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
ErrorDecl Lexeme Text
name [Node (Lexeme Text)]
errs ->
Int -> Doc -> Doc
nest Int
2 (
String -> Doc
text String
"error for" Doc -> Doc -> Doc
<+> Lexeme Text -> Doc
ppLexeme Lexeme Text
name Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$>
[Node (Lexeme Text)] -> Doc
ppEnumeratorList [Node (Lexeme Text)]
errs
) Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
Node (Lexeme Text)
Continue -> String -> Doc
text String
"continue;"
Node (Lexeme Text)
Break -> String -> Doc
text String
"break;"
Return Maybe (Node (Lexeme Text))
Nothing -> String -> Doc
text String
"return;"
Return (Just Node (Lexeme Text)
e) -> String -> Doc
text String
"return" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
VarDecl Node (Lexeme Text)
ty Node (Lexeme Text)
declr -> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppDeclarator Node (Lexeme Text)
declr Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
IfStmt Node (Lexeme Text)
cond [Node (Lexeme Text)]
t Maybe (Node (Lexeme Text))
e -> Node (Lexeme Text)
-> [Node (Lexeme Text)] -> Maybe (Node (Lexeme Text)) -> Doc
ppIfStmt Node (Lexeme Text)
cond [Node (Lexeme Text)]
t Maybe (Node (Lexeme Text))
e
ForStmt Node (Lexeme Text)
i Node (Lexeme Text)
c Node (Lexeme Text)
n [Node (Lexeme Text)]
body -> Node (Lexeme Text)
-> Node (Lexeme Text)
-> Node (Lexeme Text)
-> [Node (Lexeme Text)]
-> Doc
ppForStmt Node (Lexeme Text)
i Node (Lexeme Text)
c Node (Lexeme Text)
n [Node (Lexeme Text)]
body
Default Node (Lexeme Text)
s -> String -> Doc
text String
"default:" Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppStmt Node (Lexeme Text)
s
Label Lexeme Text
l Node (Lexeme Text)
s -> Lexeme Text -> Doc
ppLexeme Lexeme Text
l Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
':' Doc -> Doc -> Doc
<$> Node (Lexeme Text) -> Doc
ppStmt Node (Lexeme Text)
s
Goto Lexeme Text
l -> String -> Doc
text String
"goto " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Lexeme Text -> Doc
ppLexeme Lexeme Text
l Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
Case Node (Lexeme Text)
e Node (Lexeme Text)
s -> String -> Doc
text String
"case " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
e Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
':' Doc -> Doc -> Doc
<+> Node (Lexeme Text) -> Doc
ppStmt Node (Lexeme Text)
s
WhileStmt Node (Lexeme Text)
c [Node (Lexeme Text)]
body -> Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppWhileStmt Node (Lexeme Text)
c [Node (Lexeme Text)]
body
DoWhileStmt [Node (Lexeme Text)]
body Node (Lexeme Text)
c -> [Node (Lexeme Text)] -> Node (Lexeme Text) -> Doc
ppDoWhileStmt [Node (Lexeme Text)]
body Node (Lexeme Text)
c
SwitchStmt Node (Lexeme Text)
c [Node (Lexeme Text)]
body -> Node (Lexeme Text) -> [Node (Lexeme Text)] -> Doc
ppSwitchStmt Node (Lexeme Text)
c [Node (Lexeme Text)]
body
CompoundStmt [Node (Lexeme Text)]
body -> Char -> Doc
char Char
'{' Doc -> Doc -> Doc
<$> [Node (Lexeme Text)] -> Doc
ppStmtList [Node (Lexeme Text)]
body Doc -> Doc -> Doc
<$> Char -> Doc
char Char
'}'
VLA Node (Lexeme Text)
ty Lexeme Text
n Node (Lexeme Text)
sz -> Node (Lexeme Text) -> Lexeme Text -> Node (Lexeme Text) -> Doc
ppVLA Node (Lexeme Text)
ty Lexeme Text
n Node (Lexeme Text)
sz
Node (Lexeme Text)
x -> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Char -> Doc
char Char
';'
ppVLA :: Node (Lexeme Text) -> Lexeme Text -> Node (Lexeme Text) -> Doc
ppVLA :: Node (Lexeme Text) -> Lexeme Text -> Node (Lexeme Text) -> Doc
ppVLA Node (Lexeme Text)
ty Lexeme Text
n Node (Lexeme Text)
sz =
String -> Doc
text String
"VLA("
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppType Node (Lexeme Text)
ty
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
", "
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Lexeme Text -> Doc
ppLexeme Lexeme Text
n
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
", "
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Node (Lexeme Text) -> Doc
ppExpr Node (Lexeme Text)
sz
Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text String
");"
ppTranslationUnit :: [Node (Lexeme Text)] -> Doc
ppTranslationUnit :: [Node (Lexeme Text)] -> Doc
ppTranslationUnit [Node (Lexeme Text)]
decls = [Node (Lexeme Text)] -> Doc
ppDeclList [Node (Lexeme Text)]
decls Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
linebreak