json: parse char result

This commit is contained in:
Nathan McCarty 2025-01-26 20:51:24 -05:00
parent 40251a1455
commit 08a2f263bb

View file

@ -110,7 +110,7 @@ whitespace : Parser Char
whitespace = do
pnote "Whitespace character"
result <-
parseChar (\x => any (== x) $ the (List _) [' ', '\n', '\r', '\t']) id
parseChar (\x => any (== x) $ the (List _) [' ', '\n', '\r', '\t'])
case result of
GotChar char => pure char
GotError err => throwParseError "Expected whitespace, got: \{show err}"
@ -221,9 +221,12 @@ string = do
-- TODO: Handle control characters properly
stringCharacter : Parser Char
stringCharacter = do
e1 <- parseError "Expected non-quote, got quote"
e2 <- parseError "End of input"
parseCharE (not . (== '"')) (\_ => e1) e2
result <- parseChar (not . (== '"'))
case result of
GotChar char => pure char
GotError err =>
throwParseError "Expected string character, got \{show err}"
EndOfInput => throwParseError "Unexpected end of input"
```
```idris