Skip to content

Commit

Permalink
Improve comment
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed Jan 14, 2024
1 parent 8cd1d4a commit 37e3417
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lsp-types/src/Language/LSP/Protocol/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,27 @@ k .=? v = case v of
Nothing -> mempty

{- |
Parse a value optionally, with lenient but careful handling of 'Null':
* If 'Null' can be converted to the desired type then the result is 'Just Null'
* If 'Null' cannot be converted to the desired type then the result is 'Nothing'
This differs from 'J..:!' because it allows 'Null' to parse as 'Nothing'.
This differs from 'J..:?' because it converts 'Null' to the desired type
in preference to parsing it as 'Nothing'.
Parse a value optionally. This behaves similarly to 'J..:!' and
'J..:?', but differs in how it handles 'Null':
* If 'Null' can be converted to the desired type...
* 'J.:?': the result is success with 'Nothing'
* 'J.:!': the result is success with 'Just <value>'
* '.:!?': the result is success with 'Just <value>'
* If 'Null' cannot be converted to the desired type...
* 'J.:?': the result is success with 'Nothing'
* 'J.:!': the result is failure
* '.:!?': the result is success with 'Nothing'
That is, we allow 'Null' to mean either 'Nothing' or 'Just <value>',
with the latter taking priority.
-}
(.:!?) :: (J.FromJSON v) => Object -> Key -> J.Parser (Maybe v)
o .:!? k =
-- Cases for 'Null'
-- If 'Null' can be converted to the desired type this succeeds
-- with Just the converted value
o J..:! k
-- otherwise...
<|>
-- If 'Null' cannot be converted to the desired type this succeeds
-- with Nothing
Expand Down

0 comments on commit 37e3417

Please sign in to comment.