git.iko.soy/rowtype-yoga/purescript-native
on eb144ec help sign in
71 lines 2.0 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Main
4-- Copyright : (c) 2013-15 Phil Freeman, (c) 2014-15 Gary Burgess
5-- License : MIT (http://opensource.org/licenses/MIT)
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15{-# LANGUAGE TemplateHaskell #-}
17module JSON where
19import Prelude ()
20import Prelude.Compat
22import qualified Data.Aeson.TH as A
24import qualified Language.PureScript as P
26data ErrorPosition = ErrorPosition
27 { startLine :: Int
28 , startColumn :: Int
29 , endLine :: Int
30 , endColumn :: Int
31 }
33data JSONError = JSONError
34 { position :: Maybe ErrorPosition
35 , message :: String
36 , errorCode :: String
37 , errorLink :: String
38 , filename :: Maybe String
39 , moduleName :: Maybe String
40 }
42data JSONResult = JSONResult
43 { warnings :: [JSONError]
44 , errors :: [JSONError]
45 }
47$(A.deriveJSON A.defaultOptions ''ErrorPosition)
48$(A.deriveJSON A.defaultOptions ''JSONError)
49$(A.deriveJSON A.defaultOptions ''JSONResult)
51toJSONErrors :: Bool -> P.Level -> P.MultipleErrors -> [JSONError]
52toJSONErrors verbose level = map (toJSONError verbose level) . P.runMultipleErrors
54toJSONError :: Bool -> P.Level -> P.ErrorMessage -> JSONError
55toJSONError verbose level e =
56 JSONError (toErrorPosition <$> sspan)
57 (P.renderBox (P.prettyPrintSingleError verbose level False (P.stripModuleAndSpan e)))
58 (P.errorCode e)
59 (P.wikiUri e)
60 (P.spanName <$> sspan)
61 (P.runModuleName <$> P.errorModule e)
62 where
63 sspan :: Maybe P.SourceSpan
64 sspan = P.errorSpan e
66 toErrorPosition :: P.SourceSpan -> ErrorPosition
67 toErrorPosition ss =
68 ErrorPosition (P.sourcePosLine (P.spanStart ss))
69 (P.sourcePosColumn (P.spanStart ss))
70 (P.sourcePosLine (P.spanEnd ss))
71 (P.sourcePosColumn (P.spanEnd ss))