on master help sign in
Move JSON errors to Reporting.Error
1373388Evan Czaplicki
compiler/src/Json/Decode/Error.hs → compiler/src/Reporting/Error/Json.hsrenamed+82−13
@@ -1,23 +1,20 @@
1+{-# OPTIONS_GHC -Wall #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2−module Json.Decode.Error
3+module Reporting.Error.Json
3 ( Error(..)
4 ( Error(..)
4− , toDoc
5+ , Problem(..)
6+ , DecodeExpectation(..)
7+ , ParseExpectation(..)
8+ , Context(..)
9+ , toReport
5 )
10 )
6 where
11 where
7
12
8
13
9−import Prelude hiding (userError)
14+import qualified Data.Utf8 as Utf8
10−import qualified Data.Char as Char
15+import Data.Word (Word16)
11−import qualified Data.List as List
12−import qualified Data.Map as Map
13−import qualified Data.Text as Text
14
16
15−import qualified Json.Decode.Internals as Json
17+import qualified Parse.Primitives as P
16−import qualified Json.Encode as E
17−import Reporting.Doc ((<+>), (<>))
18−import qualified Reporting.Doc as D
19−import qualified Reporting.Error.Syntax as Syntax
20−import qualified Reporting.Render.Code as Code
21import qualified Reporting.Report as Report
18import qualified Reporting.Report as Report
22
19
23
20
@@ -25,6 +22,76 @@ import qualified Reporting.Report as Report
25-- ERROR
22-- ERROR
26
23
27
24
25+data Error e
26+ = DecodeProblem (Problem e)
27+ | ParseProblem Word16 Word16 (P.Context Context) ParseExpectation
28+
29+
30+
31+-- DECODE PROBLEMS
32+
33+
34+data Problem e
35+ = Field Utf8.String (Problem e)
36+ | Index Int (Problem e)
37+ | OneOf (Problem e) [Problem e]
38+ | Failure e
39+ | Expecting DecodeExpectation
40+
41+
42+data DecodeExpectation
43+ = TObject
44+ | TArray
45+ | TString
46+ | TBool
47+ | TInt
48+ | TObjectWith Utf8.String
49+ | TArrayPair Int
50+
51+
52+
53+-- PARSE EXPECTATION
54+
55+
56+data ParseExpectation
57+ = ObjectStart
58+ | ObjectMore
59+ | ObjectEnd
60+ | ArrayStart
61+ | ArrayMore
62+ | ArrayEnd
63+ | StringStart
64+ | StringEnd
65+ | IntStart
66+ | NoLeadingZeros
67+ | NoFloats
68+ | Bool
69+ | Null
70+ | Value
71+ | Colon
72+ | EndOfFile
73+
74+
75+
76+data Context
77+ = CIndex Int
78+ | CField Utf8.String
79+
80+
81+
82+-- TO REPORT
83+
84+
85+toReport :: Error e -> Report.Report
86+toReport err =
87+ error "TODO Reporting.Error.Json.toReport" err
88+
89+
90+{-
91+
92+-- ERROR
93+
94+
28data Error e
95data Error e
29 = BadJson Syntax.Error
96 = BadJson Syntax.Error
30 | BadContent (Json.Error e)
97 | BadContent (Json.Error e)
@@ -263,3 +330,5 @@ fieldToName field =
263indexToName :: Int -> String
330indexToName :: Int -> String
264indexToName index =
331indexToName index =
265 "[" ++ show index ++ "]"
332 "[" ++ show index ++ "]"
333+
334+-}