json: Refactor string parser

This commit is contained in:
Nathan McCarty 2025-01-26 15:40:15 -05:00
parent 91e1d2c9b1
commit 4fb5707b25

View file

@ -209,13 +209,15 @@ array = do
```idris
string = do
_ <- parseExactChar '"'
-- TODO: Handle control characters properly
e1 <- parseError "Expected non-quote, got quote"
e2 <- parseError "End of input"
contents <- parseString . many $ parseCharE (not . (== '"')) (\_ => e1) e2
_ <- parseExactChar '"'
pure $ VString contents
str <- parseString $ delimited '"' '"' (many stringCharacter)
pure $ VString str
where
-- 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
```
```idris