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
|
-- generated file, do not modify!
<<<<<<< 4d40c4ee5ed15544d2ac7fb1ea7b61e89766d277
<<<<<<< c5e063b3c9aeff65161e24445e9672daff980b45
<<<<<<< 3b50722f433ec5ecc515ea1441fd633d85118cb9
-- 2016-03-01T13:00:40.810157000000Z
=======
-- 2016-03-20T21:42:12.996366000000Z
>>>>>>> working c# backend
=======
-- 2016-03-20T22:19:43.646837000000Z
>>>>>>> fix c#
=======
-- 2016-03-21T11:36:01.199696000000Z
>>>>>>> work on java json loader
{-# 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 CompileResult
= CompileError (Vector Range) String (Vector TypeInfo)
| Compiled String String Pipeline (Vector TypeInfo)
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 CompileResult where
toJSON v = case v of
CompileError arg0 arg1 arg2 -> object [ "tag" .= ("CompileError" :: Text), "arg0" .= arg0, "arg1" .= arg1, "arg2" .= arg2]
Compiled arg0 arg1 arg2 arg3 -> object [ "tag" .= ("Compiled" :: Text), "arg0" .= arg0, "arg1" .= arg1, "arg2" .= arg2, "arg3" .= arg3]
instance FromJSON CompileResult where
parseJSON (Object obj) = do
tag <- obj .: "tag"
case tag :: Text of
"CompileError" -> CompileError <$> obj .: "arg0" <*> obj .: "arg1" <*> obj .: "arg2"
"Compiled" -> Compiled <$> obj .: "arg0" <*> obj .: "arg1" <*> obj .: "arg2" <*> obj .: "arg3"
parseJSON _ = mzero
|