json: More refactor

This commit is contained in:
Nathan McCarty 2025-01-25 14:21:53 -05:00
parent a3c7729ab2
commit 91e1d2c9b1

View file

@ -185,21 +185,25 @@ array = do
where
emptyArray : Parser (JSONValue TArray)
emptyArray = do
_ <- parseExactChar '['
_ <- many whitespace
_ <- parseExactChar ']'
delimited '[' ']' (nom whitespace)
pure $ VArray Nil
restValue : Parser (t : JSONType ** JSONValue t)
restValue = do
_ <- parseExactChar ','
value
values : Parser (List1 (t : JSONType ** JSONValue t))
values = do
first <- value
rest <- many restValue
pure $ first ::: rest
occupiedArray : Parser (JSONValue TArray)
occupiedArray = do
_ <- parseExactChar '['
first <- value
rest <- many restValue
xs <- values
_ <- parseExactChar ']'
let (types ** xs) = DList.fromList (first :: rest)
-- TODO: Why is this busted?
-- xs <- delimited '[' ']' values
let (types ** xs) = DList.fromList (forget xs)
pure $ VArray xs
```