aboutsummaryrefslogtreecommitdiff
path: root/src/Fun/Tree.hs
blob: 26b415f6c98b69c2344c3157c2e4d9a422362689 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Fun.Tree where

import           Fun.Typer

data Visibility = PublicVisibility | PrivateVisibility
  deriving Show
-- TODO: Actually enforce danger-* in syntax-check
data FunctionFlag = FunctionInline | FunctionDeprecated | FunctionDangerVoid | FunctionDangerAsm | FunctionUnknown
  deriving Show
instance Read FunctionFlag where
  readsPrec _ "inline"      = [(FunctionInline, "")]
  readsPrec _ "deprecated"  = [(FunctionDeprecated, "")]
  readsPrec _ "danger-void" = [(FunctionDangerVoid, "")]
  readsPrec _ "danger-asm"  = [(FunctionDangerAsm, "")]
  readsPrec _ _             = [(FunctionUnknown, "")]

data Tree = Tree [Program]
  deriving Show

data Program = Program [Block]
  deriving Show

data Block = FunctionBlock
  { bDecl  :: FunctionDeclaration
  , bDefns :: [FunctionDefinition]
  } -- | DataBlock .. TODO
  deriving Show

data FunctionDeclaration = FunctionDeclaration
  { dName       :: String
  , dVisibility :: Visibility
  , dTypes      :: [Type]
  , dFlags      :: [FunctionFlag]
  }
  deriving Show

data FunctionDefinition = FunctionDefinition
  { dPattern :: FunctionPattern
  , dBody    :: FunctionBody
  }
  deriving Show

data FunctionPattern = FunctionPattern
  { pElements :: [FunctionPatternElement]
  }
  deriving Show

data FunctionPatternElement = FunctionPatternParameter String | FunctionPatternString String | FunctionPatternNumber Integer | FunctionPatternWildcard | FunctionPatternSuperWildcard
  deriving (Show, Eq, Ord)

data FunctionBody = FunctionBody
  { bElements :: [FunctionBodyElement]
  }
  deriving Show

data FunctionBodyElement = Statement String | FunctionBodyIdentifier String | FunctionBodyParameter String | FunctionBodyString String | FunctionBodyNumber Integer
  deriving Show