Skip to content

Commit 839553d

Browse files
authored
Merge pull request #185 from haskell-works/document-LightJson-and-PartialJsonValue
Document LightJson and PartialJsonValue
2 parents cfd3a83 + 93595b9 commit 839553d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/HaskellWorks/Data/Json/PartialValue.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ import qualified Data.DList as DL
4848
import qualified Data.Text as T
4949
import qualified HaskellWorks.Data.BalancedParens as BP
5050

51+
-- | Partial JSON type.
52+
--
53+
-- This data type has an additional 'JsonPartialError' data constructor to indicate parsing
54+
-- errors. This allows parsing to be more lazy because parsing errors may now be expressed
55+
-- anywhere in the parsed document so the parser no longer needs to make a verdict about whether
56+
-- there are any parsing errors in the entire document.
57+
--
58+
-- See 'jsonPartialJsonValueAt' on how to parse JSON text into this datatype.
59+
--
60+
-- Although this data type allows for lazier parsing it doesn't allow for sub-trees to be
61+
-- garbage collected if a reference to an ancestor node is held. To avoid holding onto
62+
-- sub-trees that are no longer needed without having to drop references to ancestors use
63+
-- 'HaskellWorks.Data.Json.LightJson.LightJson' instead.
5164
data JsonPartialValue
5265
= JsonPartialString Text
5366
| JsonPartialNumber Double
@@ -59,6 +72,15 @@ data JsonPartialValue
5972
deriving (Eq, Show, Ord)
6073

6174
class JsonPartialValueAt a where
75+
-- | Get a JSON partial value from another type
76+
--
77+
-- This function can always "succeed" because the data type it returns allows for the document value
78+
-- to contain an arbitrary number of errors. This means errors can be reported in document nodes
79+
-- as parsing occurs lazily.
80+
--
81+
-- There are garbage collection implementations you may want to consider. If you would like to be
82+
-- able to hold onto ancestor nodes and still be able to garbage collect visited sub-trees, then
83+
-- consider using 'HaskellWorks.Data.Json.LightJson.lightJsonAt' instead.
6284
jsonPartialJsonValueAt :: a -> JsonPartialValue
6385

6486
data JsonPartialField = JsonPartialField Text JsonPartialValue

0 commit comments

Comments
 (0)