on 63243ca help sign in
elk/compiler/Elm/Internal/Documentation.hs
41 lines 1.1 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Elm.Internal.Documentation where
4import Control.Applicative ((<$>),(<*>))
5import Control.Monad
6import Data.Aeson
8data Document = Doc
9 { moduleName :: String
10 , structure :: String
11 , entries :: [Entry]
12 } deriving (Show)
14data Entry = Entry
15 { name :: String
16 , comment :: String
17 , raw :: String
18 , assocPrec :: Maybe (String,Int)
19 } deriving (Show)
21instance FromJSON Document where
22 parseJSON (Object v) =
23 Doc <$> v .: "name"
24 <*> v .: "document"
25 <*> (concat <$> sequence [ v .: "aliases", v .: "datatypes", v .: "values" ])
27 parseJSON _ = fail "Conversion to Document was expecting an object"
29instance FromJSON Entry where
30 parseJSON (Object v) =
31 Entry <$> v .: "name"
32 <*> v .: "comment"
33 <*> v .: "raw"
34 <*> (liftM2 (,) <$> v .:? "associativity"
35 <*> v .:? "precedence")
37 parseJSON _ = fail "Conversion to Entry was expecting an object"
39data Content = Markdown String | Value String
40 deriving Show