json: Refactor string parser
This commit is contained in:
parent
91e1d2c9b1
commit
4fb5707b25
1 changed files with 9 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue