@@ -1,8 +1,6 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Elm.Compiler
3− ( version
4− , Compile.DocsFlag(..)
5− , Compile.Artifacts(..)
3+ ( Compile.Artifacts(..)
64 , compile
75 , Error.Error
86 , errorsToDoc
@@ -14,52 +12,43 @@ module Elm.Compiler
1412
1513import qualified Data.ByteString as BS
1614import qualified Data.Map as Map
17−import qualified Data.Text as Text
15+import qualified Data.Name as Name
16+import qualified Data.Utf8 as Utf8
1817
1918import qualified Compile
20−import qualified Elm.Compiler.Version
2119import qualified Elm.Interface as I
2220import qualified Elm.ModuleName as ModuleName
2321import qualified Elm.Package as Pkg
24−import qualified Json.Encode as Encode
22+import qualified Json.Encode as E
23+import Json.Encode ((==>))
24+import qualified Reporting.Annotation as A
2525import qualified Reporting.Doc as D
2626import qualified Reporting.Error as Error
2727import qualified Reporting.Render.Code as Code
28−import qualified Reporting.Region as Region
2928import qualified Reporting.Report as Report
3029import qualified Reporting.Result as Result
3130import qualified Reporting.Warning as Warning
3231
3332
3433
35−-- VERSION
36−
37−
38−version :: Pkg.Version
39−version =
40− Elm.Compiler.Version.version
41−
42−
43−
4434-- COMPILE
4535
4636
4737compile
48− :: Compile.DocsFlag
49− -> Pkg.Name
38+ :: Pkg.Name
5039 -> Map.Map ModuleName.Raw ModuleName.Canonical
5140 -> I.Interfaces
5241 -> BS.ByteString
5342 -> ( [Warning.Warning], Either [Error.Error] Compile.Artifacts )
54−compile docsFlag pkg importDict interfaces source =
55− Result.run $ Compile.compile docsFlag pkg importDict interfaces source
43+compile pkg importDict interfaces source =
44+ Result.run $ Compile.compile pkg importDict interfaces source
5645
5746
5847
5948-- ERRORS TO DOC
6049
6150
62−errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> D.Doc
51+errorsToDoc :: FilePath -> String -> [Error.Error] -> D.Doc
6352errorsToDoc filePath source errors =
6453 let
6554 reports =
@@ -72,23 +61,39 @@ errorsToDoc filePath source errors =
7261-- ERRORS TO JSON
7362
7463
75−errorsToJson :: ModuleName.Raw -> FilePath -> Text.Text -> [Error.Error] -> Encode.Value
64+errorsToJson :: ModuleName.Raw -> FilePath -> String -> [Error.Error] -> E.Value
7665errorsToJson moduleName filePath source errors =
7766 let
7867 reports =
7968 concatMap (Error.toReports (Code.toSource source)) errors
8069 in
81− Encode.object
82− [ ("path", Encode.text (Text.pack filePath))
83− , ("name", Encode.name moduleName)
84− , ("problems", Encode.array (map reportToJson reports))
70+ E.object
71+ [ "path" ==> E.string (Utf8.fromChars filePath)
72+ , "name" ==> E.string (Name.toUtf8 moduleName)
73+ , "problems" ==> E.array (map reportToJson reports)
8574 ]
8675
8776
88−reportToJson :: Report.Report -> Encode.Value
77+reportToJson :: Report.Report -> E.Value
8978reportToJson (Report.Report title region _sgstns message) =
90− Encode.object
91− [ ("title", Encode.text (Text.pack title))
92− , ("region", Region.encode region)
93− , ("message", D.encode message)
94− ]
79+ E.object
80+ [ "title" ==> E.string (Utf8.fromChars title)
81+ , "region" ==> encodeRegion region
82+ , "message" ==> D.encode message
83+ ]
84+
85+
86+encodeRegion :: A.Region -> E.Value
87+encodeRegion (A.Region (A.Position sr sc) (A.Position er ec)) =
88+ E.object
89+ [ "start" ==>
90+ E.object
91+ [ ("line", E.int (fromIntegral sr))
92+ , ("column", E.int (fromIntegral sc))
93+ ]
94+ , "end" ==>
95+ E.object
96+ [ ("line", E.int (fromIntegral er))
97+ , ("column", E.int (fromIntegral ec))
98+ ]
99+ ]