-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP support sets (well, kinda of) #79
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,10 +76,12 @@ import qualified Data.Aeson as JS | |
import qualified Data.Aeson.Parser as JS | ||
import qualified Data.Aeson.Types as JS | ||
import Data.Attoparsec.ByteString | ||
import Data.Binary.Serialise.CBOR.JSON | ||
import qualified Data.ByteString.Char8 as B | ||
import qualified Data.ByteString.Base64 as B64 | ||
import qualified Data.ByteString.Lazy as BL | ||
import Data.Maybe | ||
import qualified Data.Set as Set | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Encoding as T | ||
import Data.Time | ||
|
@@ -206,6 +208,15 @@ instance FromJSONWithErrs a => FromJSONWithErrs [a] where | |
parseJSONWithErrs JS.Null = pure [] | ||
parseJSONWithErrs v = failWith $ expectedArray v | ||
|
||
instance (Ord a, FromJSONWithErrs a) => FromJSONWithErrs (Set.Set a) where | ||
parseJSONWithErrs v@(JS.Object kvs) = case jsonParseCborSet kvs of | ||
Nothing -> failWith $ expectedSet v | ||
Just xs -> fmap Set.fromList <$> traverse help $ zip (V.toList xs) [0..] | ||
where | ||
help (x, i) = stepInside (InElem i) $ parseJSONWithErrs x | ||
parseJSONWithErrs JS.Null = pure mempty | ||
parseJSONWithErrs v = failWith $ expectedArray v | ||
Comment on lines
+211
to
+218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the JSON representation of a set should simply be the list of its elements (insensitive to order, when decoding, and ordered when encoding). |
||
|
||
instance FromJSONWithErrs Int where | ||
parseJSONWithErrs = withInt "Int" pure | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ import Text.Regex | |
'|' { (,) _ Bar } | ||
'[' { (,) _ Bra } | ||
']' { (,) _ Ket } | ||
'{' { (,) _ Cu } | ||
'}' { (,) _ Rly } | ||
'::' { (,) _ ColCol } | ||
'=' { (,) _ Equals } | ||
'?' { (,) _ Query } | ||
|
@@ -188,6 +190,7 @@ Type :: { APIType } | |
Type | ||
: '?' Type { TyMaybe $2 } | ||
| '[' Type ']' { TyList $2 } | ||
| '{' Type '}' { TySet $2 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using |
||
| TypeName { TyName $1 } | ||
| BasicType { TyBasic $1 } | ||
| json { TyJSON } | ||
|
@@ -265,6 +268,7 @@ MbDefaultValue :: { Maybe DefaultValue } | |
|
||
DefaultValue :: { DefaultValue } | ||
: '[' ']' { DefValList } | ||
| '{' '}' { DefValSet } | ||
| nothing { DefValMaybe } | ||
| strlit { DefValString (T.pack $1) } | ||
| true { DefValBool True } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the elements are distinct and sorted looks a bit dangerous to me?