summaryrefslogtreecommitdiff
path: root/ddl/out/haskell/LambdaCube/TypeInfo.hs
blob: 3aed0716c28a369998ca0b71b5d0634be478adb7 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
-- generated file, do not modify!
-- 2016-11-11T11:17:03.605012000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module LambdaCube.TypeInfo where

import Data.Int
import Data.Word
import Data.Map
import Data.Vector (Vector(..))
import LambdaCube.Linear

import Data.Text
import Data.Aeson hiding (Value,Bool)
import Data.Aeson.Types hiding (Value,Bool)
import Control.Monad

import LambdaCube.IR

data Range
  = Range
  { startLine :: Int
  , startColumn :: Int
  , endLine :: Int
  , endColumn :: Int
  }

  deriving (Show, Eq, Ord)

data TypeInfo
  = TypeInfo
  { range :: Range
  , text :: String
  }

  deriving (Show, Eq, Ord)

data WarningInfo
  = WarningInfo
  { wRange :: Range
  , wText :: String
  }

  deriving (Show, Eq, Ord)

data ErrorInfo
  = ErrorInfo
  { eRange :: Range
  , eText :: String
  }

  deriving (Show, Eq, Ord)

data CompileResult
  = CompileError String (Vector TypeInfo) (Vector WarningInfo) (Vector ErrorInfo)
  | Compiled String String Pipeline (Vector TypeInfo) (Vector WarningInfo)
  deriving (Show, Eq, Ord)


instance ToJSON Range where
  toJSON v = case v of
    Range{..} -> object
      [ "tag" .= ("Range" :: Text)
      , "startLine" .= startLine
      , "startColumn" .= startColumn
      , "endLine" .= endLine
      , "endColumn" .= endColumn
      ]

instance FromJSON Range where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "Range" -> do
        startLine <- obj .: "startLine"
        startColumn <- obj .: "startColumn"
        endLine <- obj .: "endLine"
        endColumn <- obj .: "endColumn"
        pure $ Range
          { startLine = startLine
          , startColumn = startColumn
          , endLine = endLine
          , endColumn = endColumn
          } 
  parseJSON _ = mzero

instance ToJSON TypeInfo where
  toJSON v = case v of
    TypeInfo{..} -> object
      [ "tag" .= ("TypeInfo" :: Text)
      , "range" .= range
      , "text" .= text
      ]

instance FromJSON TypeInfo where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "TypeInfo" -> do
        range <- obj .: "range"
        text <- obj .: "text"
        pure $ TypeInfo
          { range = range
          , text = text
          } 
  parseJSON _ = mzero

instance ToJSON WarningInfo where
  toJSON v = case v of
    WarningInfo{..} -> object
      [ "tag" .= ("WarningInfo" :: Text)
      , "wRange" .= wRange
      , "wText" .= wText
      ]

instance FromJSON WarningInfo where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "WarningInfo" -> do
        wRange <- obj .: "wRange"
        wText <- obj .: "wText"
        pure $ WarningInfo
          { wRange = wRange
          , wText = wText
          } 
  parseJSON _ = mzero

instance ToJSON ErrorInfo where
  toJSON v = case v of
    ErrorInfo{..} -> object
      [ "tag" .= ("ErrorInfo" :: Text)
      , "eRange" .= eRange
      , "eText" .= eText
      ]

instance FromJSON ErrorInfo where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "ErrorInfo" -> do
        eRange <- obj .: "eRange"
        eText <- obj .: "eText"
        pure $ ErrorInfo
          { eRange = eRange
          , eText = eText
          } 
  parseJSON _ = mzero

instance ToJSON CompileResult where
  toJSON v = case v of
    CompileError arg0 arg1 arg2 arg3 -> object [ "tag" .= ("CompileError" :: Text), "arg0" .= arg0, "arg1" .= arg1, "arg2" .= arg2, "arg3" .= arg3]
    Compiled arg0 arg1 arg2 arg3 arg4 -> object [ "tag" .= ("Compiled" :: Text), "arg0" .= arg0, "arg1" .= arg1, "arg2" .= arg2, "arg3" .= arg3, "arg4" .= arg4]

instance FromJSON CompileResult where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "CompileError" -> CompileError <$> obj .: "arg0" <*> obj .: "arg1" <*> obj .: "arg2" <*> obj .: "arg3"
      "Compiled" -> Compiled <$> obj .: "arg0" <*> obj .: "arg1" <*> obj .: "arg2" <*> obj .: "arg3" <*> obj .: "arg4"
  parseJSON _ = mzero