json: Notes

This commit is contained in:
Nathan McCarty 2025-01-26 20:06:53 -05:00
parent da44cf72cf
commit 2e4ab42aa0

View file

@ -108,6 +108,7 @@ Define a `whitespace` character class based on the json specifications
```idris ```idris
whitespace : Parser Char whitespace : Parser Char
whitespace = do whitespace = do
pnote "Whitespace character"
result <- result <-
parseChar (\x => any (== x) $ the (List _) [' ', '\n', '\r', '\t']) id parseChar (\x => any (== x) $ the (List _) [' ', '\n', '\r', '\t']) id
case result of case result of
@ -132,6 +133,7 @@ Top level json value parser
export export
value : Parser (t : JSONType ** JSONValue t) value : Parser (t : JSONType ** JSONValue t)
value = do value = do
pnote "JSON Value"
surround whitespace $ oneOfE surround whitespace $ oneOfE
"Expected JSON Value" "Expected JSON Value"
[ [
@ -148,6 +150,7 @@ Now go through our json value types
```idris ```idris
object = do object = do
pnote "JSON Object"
oneOfE oneOfE
"Expected Object" "Expected Object"
[emptyObject, occupiedObject] [emptyObject, occupiedObject]
@ -180,6 +183,7 @@ object = do
```idris ```idris
array = do array = do
pnote "JSON Array"
oneOfE oneOfE
"Expected Array" "Expected Array"
[emptyArray, occupiedArray] [emptyArray, occupiedArray]
@ -210,6 +214,7 @@ array = do
```idris ```idris
string = do string = do
pnote "JSON String"
str <- parseString $ delimited '"' '"' (many stringCharacter) str <- parseString $ delimited '"' '"' (many stringCharacter)
pure $ VString str pure $ VString str
where where
@ -223,12 +228,14 @@ string = do
```idris ```idris
number = do number = do
pnote "JSON Number"
d <- double d <- double
pure $ VNumber d pure $ VNumber d
``` ```
```idris ```idris
bool = do bool = do
pnote "JSON Bool"
oneOfE oneOfE
"Expected Bool" "Expected Bool"
[true, false] [true, false]
@ -245,6 +252,7 @@ bool = do
```idris ```idris
null = do null = do
pnote "JSON null"
_ <- exactString "null" _ <- exactString "null"
pure VNull pure VNull
``` ```