on master help sign in
errorToDoc replaces errorToString and errorToStdout
65e6ff1Evan Czaplicki
src/Elm/Compiler.hs+15−25
@@ -4,8 +4,8 @@ module Elm.Compiler
4 , parseDependencies, Tag(..)
4 , parseDependencies, Tag(..)
5 , compile, Context(..), Result(..)
5 , compile, Context(..), Result(..)
6 , Localizer, dummyLocalizer
6 , Localizer, dummyLocalizer
7− , Error, errorToString, errorToJson, printError
7+ , Error, errorToDoc, errorToJson
8− , Warning, warningToString, warningToJson, printWarning
8+ , Warning, warningToDoc, warningToJson
9 )
9 )
10 where
10 where
11
11
@@ -13,7 +13,7 @@ import qualified Data.Aeson as Json
13import qualified Data.Map as Map
13import qualified Data.Map as Map
14import qualified Data.Text.Lazy as LazyText
14import qualified Data.Text.Lazy as LazyText
15import Data.Text (Text)
15import Data.Text (Text)
16−import System.IO (Handle)
16+import Text.PrettyPrint.ANSI.Leijen (Doc)
17
17
18import qualified AST.Module as Module
18import qualified AST.Module as Module
19import qualified AST.Module.Name as ModuleName
19import qualified AST.Module.Name as ModuleName
@@ -55,18 +55,18 @@ data Tag
55 | Port
55 | Port
56
56
57
57
58−parseDependencies :: Maybe Package.Name -> Text -> Either Error (Tag, M.Raw, [M.Raw])
58+parseDependencies :: Package.Name -> Text -> Either Error (Tag, M.Raw, [M.Raw])
59−parseDependencies maybePkgName sourceCode =
59+parseDependencies pkgName sourceCode =
60 case Parse.run Parse.header sourceCode of
60 case Parse.run Parse.header sourceCode of
61 Right header ->
61 Right header ->
62− Right $ getDeps maybePkgName header
62+ Right $ getDeps pkgName header
63
63
64 Left err ->
64 Left err ->
65 Left (Error (A.map Error.Syntax err))
65 Left (Error (A.map Error.Syntax err))
66
66
67
67
68−getDeps :: Maybe Package.Name -> Module.Header [Module.UserImport] -> (Tag, M.Raw, [M.Raw])
68+getDeps :: Package.Name -> Module.Header [Module.UserImport] -> (Tag, M.Raw, [M.Raw])
69−getDeps maybePkgName (Module.Header sourceTag name _ _ _ imports) =
69+getDeps pkgName (Module.Header sourceTag name _ _ _ imports) =
70 let
70 let
71 tag =
71 tag =
72 case sourceTag of
72 case sourceTag of
@@ -75,7 +75,7 @@ getDeps maybePkgName (Module.Header sourceTag name _ _ _ imports) =
75 Module.Effect _ -> Effect
75 Module.Effect _ -> Effect
76
76
77 deps =
77 deps =
78− if maybePkgName == Just Package.core then
78+ if pkgName == Package.core then
79 map (fst . A.drop) imports
79 map (fst . A.drop) imports
80 else
80 else
81 map (fst . A.drop) imports ++ map fst Imports.defaults
81 map (fst . A.drop) imports ++ map fst Imports.defaults
@@ -159,14 +159,9 @@ newtype Error =
159 Error (A.Located Error.Error)
159 Error (A.Located Error.Error)
160
160
161
161
162−errorToString :: Localizer -> String -> Text -> Error -> String
162+errorToDoc :: Localizer -> String -> Text -> Error -> Doc
163−errorToString (Localizer localizer) location source (Error (A.A region err)) =
163+errorToDoc (Localizer localizer) location source (Error (A.A region err)) =
164− Report.toString location region (Error.toReport localizer err) source
165−
166−
167−printError :: Handle -> Localizer -> String -> Text -> Error -> IO ()
168−printError handle (Localizer localizer) location source (Error (A.A region err)) =
169− Report.toHandle handle location region (Error.toReport localizer err) source
164+ Report.toDoc location region (Error.toReport localizer err) source
170
165
171
166
172errorToJson :: Localizer -> String -> Error -> Json.Value
167errorToJson :: Localizer -> String -> Error -> Json.Value
@@ -182,14 +177,9 @@ newtype Warning =
182 Warning (A.Located Warning.Warning)
177 Warning (A.Located Warning.Warning)
183
178
184
179
185−warningToString :: Localizer -> String -> Text -> Warning -> String
180+warningToDoc :: Localizer -> String -> Text -> Warning -> Doc
186−warningToString (Localizer localizer) location source (Warning (A.A region wrn)) =
181+warningToDoc (Localizer localizer) location source (Warning (A.A region wrn)) =
187− Report.toString location region (Warning.toReport localizer wrn) source
188−
189−
190−printWarning :: Handle -> Localizer -> String -> Text -> Warning -> IO ()
191−printWarning handle (Localizer localizer) location source (Warning (A.A region wrn)) =
192− Report.toHandle handle location region (Warning.toReport localizer wrn) source
182+ Report.toDoc location region (Warning.toReport localizer wrn) source
193
183
194
184
195warningToJson :: Localizer -> String -> Warning -> Json.Value
185warningToJson :: Localizer -> String -> Warning -> Json.Value
src/Reporting/Report.hs+7−33
@@ -3,9 +3,8 @@
3module Reporting.Report
3module Reporting.Report
4 ( Report
4 ( Report
5 , report
5 , report
6− , toString
6+ , toDoc
7 , toJson
7 , toJson
8− , toHandle
9 )
8 )
10 where
9 where
11
10
@@ -13,11 +12,7 @@ import Data.Aeson ((.=))
13import qualified Data.Aeson.Types as Json
12import qualified Data.Aeson.Types as Json
14import qualified Data.Text as Text
13import qualified Data.Text as Text
15import Data.Text (Text)
14import Data.Text (Text)
16−import System.IO (Handle)
17−import Text.PrettyPrint.ANSI.Leijen
18− ( Doc, (<>), displayS, displayIO, dullcyan
19− , hardline, plain, renderPretty, text
15+import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), displayS, dullcyan, hardline, plain, renderPretty, text)
20− )
21
16
22import qualified Reporting.Helpers as Help
17import qualified Reporting.Helpers as Help
23import qualified Reporting.Region as R
18import qualified Reporting.Region as R
@@ -57,6 +52,11 @@ toJson extraFields (Report title subregion pre post) =
57 (subregion, fields ++ extraFields)
52 (subregion, fields ++ extraFields)
58
53
59
54
55+nonAnsiRender :: Doc -> String
56+nonAnsiRender doc =
57+ displayS (renderPretty 1 80 (plain doc)) ""
58+
59+
60
60
61-- REPORT TO DOC
61-- REPORT TO DOC
62
62
@@ -83,29 +83,3 @@ messageBar tag location =
83 "-- " ++ Text.unpack tag
83 "-- " ++ Text.unpack tag
84 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
84 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
85 ++ " " ++ location
85 ++ " " ++ location
86−
87−
88−
89−-- RENDER DOCS
90−
91−
92−toHandle :: Handle -> String -> R.Region -> Report -> Text -> IO ()
93−toHandle handle location region rprt source =
94− displayIO
95− handle
96− (renderPretty 1 80 (toDoc location region rprt source))
97−
98−
99−toString :: String -> R.Region -> Report -> Text -> String
100−toString location region rprt source =
101− nonAnsiRender (toDoc location region rprt source)
102−
103−
104−
105−-- DOC TO STRING WITH NO ANSI CODES
106−
107−
108−nonAnsiRender :: Doc -> String
109−nonAnsiRender doc =
110− displayS (renderPretty 1 80 (plain doc)) ""
111−