mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
Extract the line fields into a function.
This commit is contained in:
parent
e7d6c122f7
commit
8bc5ef427a
@ -36,8 +36,8 @@ json diff sources = toLazyByteString . fromEncoding . pairs $
|
||||
newtype NumberedLine a = NumberedLine (Int, Line a)
|
||||
|
||||
instance ToJSON a => ToJSON (NumberedLine a) where
|
||||
toJSON (NumberedLine (n, a)) = object [ "number" .= n, "terms" .= unLine a ]
|
||||
toEncoding (NumberedLine (n, a)) = pairs ("number" .= n <> "terms" .= unLine a)
|
||||
toJSON (NumberedLine (n, a)) = object (lineFields n a)
|
||||
toEncoding (NumberedLine (n, a)) = pairs $ mconcat (lineFields n a)
|
||||
instance ToJSON Category where
|
||||
toJSON (Other s) = String $ T.pack s
|
||||
toJSON s = String . T.pack $ show s
|
||||
@ -59,6 +59,9 @@ instance ToJSON (Term leaf Info) where
|
||||
toJSON (info :< syntax) = object (termFields info syntax)
|
||||
toEncoding (info :< syntax) = pairs $ mconcat (termFields info syntax)
|
||||
|
||||
lineFields :: (ToJSON a, KeyValue kv) => Int -> Line a -> [kv]
|
||||
lineFields n line = [ "number" .= n, "terms" .= unLine line ]
|
||||
|
||||
termFields :: (ToJSON recur, KeyValue kv) => Info -> Syntax leaf recur -> [kv]
|
||||
termFields (Info range categories) syntax = "range" .= range : "categories" .= categories : case syntax of
|
||||
Leaf _ -> []
|
||||
|
Loading…
Reference in New Issue
Block a user