@@ -24,36 +24,40 @@
25module Gen.Types
25module Gen.Types
26 ( module Gen.Types
26 ( module Gen.Types
27+ , module Gen.Types.Help
28+ , module Gen.Types.Id
27 , module Gen.Types.Map
29 , module Gen.Types.Map
28 , module Gen.Types.NS
30 , module Gen.Types.NS
29− , module Gen.Types.Id
32import Control.Applicative
33import Control.Applicative
33−import Control.Lens hiding ((.=))
34+import Control.Lens hiding ((.=))
34−import Data.Aeson hiding (Bool, String)
35+import Data.Aeson hiding (Bool, String)
35import Data.Aeson.TH
36import Data.Aeson.TH
36import Data.Char
37import Data.Char
37−import Data.Function (on)
38+import Data.Function (on)
38−import Data.List.NonEmpty (NonEmpty (..))
39+import Data.List.NonEmpty (NonEmpty (..))
39−import qualified Data.List.NonEmpty as NE
40+import qualified Data.List.NonEmpty as NE
40import Data.Maybe
41import Data.Maybe
41import Data.Ord
42import Data.Ord
42−import Data.Semigroup ((<>))
43+import Data.Semigroup ((<>))
43−import Data.Text (Text)
44+import Data.Text (Text)
44−import qualified Data.Text as Text
45+import qualified Data.Text as Text
45−import qualified Data.Text.Lazy as LText
46+import qualified Data.Text.Lazy as LText
46−import qualified Data.Text.Lazy.Builder as Build
47+import qualified Data.Text.Lazy.Builder as Build
47−import qualified Data.Text.Read as Read
48+import qualified Data.Text.Read as Read
48−import qualified Filesystem.Path.CurrentOS as Path
49+import qualified Filesystem.Path.CurrentOS as Path
49import Formatting
50import Formatting
50import Gen.Text
51import Gen.Text
51import Gen.Types.Id
53import Gen.Types.Id
52import Gen.Types.Map
54import Gen.Types.Map
53import Gen.Types.NS
55import Gen.Types.NS
54import GHC.Generics
56import GHC.Generics
55import GHC.TypeLits
57import GHC.TypeLits
58+import Language.Haskell.Exts (Name)
59+import Language.Haskell.Exts.Pretty (Pretty, prettyPrint)
56−import Text.EDE (Template)
60+import Text.EDE (Template)
58default (Text)
62default (Text)
@@ -141,7 +145,7 @@ data Location
141deriveJSON (js "") ''Location
145deriveJSON (js "") ''Location
143data Info = Info
147data Info = Info
144− { _description :: Maybe Text
148+ { _description :: Maybe Help
145 , _defaulted :: Maybe Text
149 , _defaulted :: Maybe Text
146 , _required :: !Bool
150 , _required :: !Bool
147 , _location :: Maybe Location
151 , _location :: Maybe Location
@@ -164,8 +168,13 @@ parameter s = s ^. required && isNothing (s ^. defaulted)
171 deriving (Eq, Show)
180 deriving (Eq, Show)
@@ -178,8 +187,13 @@ instance FromJSON Lit where
178 "string" -> pure Text
187 "string" -> pure Text
179 "boolean" -> pure Bool
188 "boolean" -> pure Bool
180 -- Formats
189 -- Formats
190+ "float" -> pure Float
191+ "double" -> pure Double
192+ "byte" -> pure (nat n Byte)
193+ "uint32" -> pure (nat n UInt32)
181− "uint64" -> pure (nat n Long)
194+ "uint64" -> pure (nat n UInt64)
182− "int32" -> pure (nat n Int)
195+ "int32" -> pure (nat n Int32)
196+ "int64" -> pure (nat n Int64)
183 "date-time" -> pure Time
197 "date-time" -> pure Time
184 e -> fail $
198 e -> fail $
185 "Unable to parse Lit from " ++ Text.unpack e
199 "Unable to parse Lit from " ++ Text.unpack e
@@ -213,8 +227,8 @@ instance FromJSON (Fix Schema) where
213 Fix <$> (ref i o <|> schema i o)
227 Fix <$> (ref i o <|> schema i o)
215 schema i o = o .: "type" >>= \case
229 schema i o = o .: "type" >>= \case
216− "object" -> Obj i <$> o .: "properties"
230+ "object" -> Obj i <$> o .:? "properties" .!= mempty
217− "array" -> Arr i <$> o .: "items"
231+ "array" -> Arr i <$> o .: "items"
218 "any" -> pure (Any i)
232 "any" -> pure (Any i)
219 _ -> enm i o <|> Lit i <$> parseJSON (Object o)
233 _ -> enm i o <|> Lit i <$> parseJSON (Object o)
@@ -250,30 +264,39 @@ instance FromJSON Param where
251deriveToJSON (js "") ''Param
265deriveToJSON (js "") ''Param
267+data Syn a = Syn { syntax :: a }
269+instance Pretty a => ToJSON (Syn a) where
270+ toJSON = toJSON . prettyPrint . syntax
253−data Fun = Fun' Text Rendered Rendered
272+data Fun = Fun' Name (Maybe Help) Rendered Rendered
255instance ToJSON Fun where
274instance ToJSON Fun where
256− toJSON (Fun' h s d) = object
275+ toJSON (Fun' n h s d) = object
257− [ "help" .= h
277+ , "help" .= h
258 , "sig" .= s
278 , "sig" .= s
259 , "decl" .= d
279 , "decl" .= d
263− = Sum Text Rendered
283+ = Sum Name (Maybe Help) Rendered
264− | Prod Rendered Fun [Fun]
284+ | Prod Name (Maybe Help) Rendered Fun [Fun]
266instance ToJSON Data where
286instance ToJSON Data where
267 toJSON = \case
287 toJSON = \case
268− Sum h d -> object
288+ Sum n h d -> object
269− [ "type" .= "sum"
290+ , "type" .= "sum"
270 , "decl" .= d
291 , "decl" .= d
271 , "help" .= h
292 , "help" .= h
274− Prod d c ls -> object
295+ Prod n h d c ls -> object
275− [ "type" .= "prod"
297+ , "type" .= "prod"
276 , "decl" .= d
298 , "decl" .= d
277 , "ctor" .= c
300 , "ctor" .= c
278 , "lenses" .= ls
301 , "lenses" .= ls