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