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 where
emptyArray : Parser (JSONValue TArray) emptyArray : Parser (JSONValue TArray)
emptyArray = do emptyArray = do
_ <- parseExactChar '[' delimited '[' ']' (nom whitespace)
_ <- many whitespace
_ <- parseExactChar ']'
pure $ VArray Nil pure $ VArray Nil
restValue : Parser (t : JSONType ** JSONValue t) restValue : Parser (t : JSONType ** JSONValue t)
restValue = do restValue = do
_ <- parseExactChar ',' _ <- parseExactChar ','
value value
values : Parser (List1 (t : JSONType ** JSONValue t))
values = do
first <- value
rest <- many restValue
pure $ first ::: rest
occupiedArray : Parser (JSONValue TArray) occupiedArray : Parser (JSONValue TArray)
occupiedArray = do occupiedArray = do
_ <- parseExactChar '[' _ <- parseExactChar '['
first <- value xs <- values
rest <- many restValue
_ <- parseExactChar ']' _ <- 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 pure $ VArray xs
``` ```