From 4fb5707b25abef3ddc079eba204cd323dc07f1f2 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Sun, 26 Jan 2025 15:40:15 -0500 Subject: [PATCH] json: Refactor string parser --- src/Parser/JSON.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Parser/JSON.md b/src/Parser/JSON.md index 48ecdbe..2634d83 100644 --- a/src/Parser/JSON.md +++ b/src/Parser/JSON.md @@ -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