Idris2/libs/contrib/Language/JSON/String/Parser.idr
Alex Humphreys f3855d7100
Update contrib Text.Parser to match Library.Text.Parser (#1808)
Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
2021-08-06 10:03:13 +01:00

27 lines
730 B
Idris

module Language.JSON.String.Parser
import Language.JSON.String.Tokens
import Text.Lexer
import Text.Parser
%default total
private
stringChar : Grammar state JSONStringToken True Char
stringChar = match JSTChar
<|> match JSTSimpleEscape
<|> match JSTUnicodeEscape
private
quotedString : Grammar state JSONStringToken True String
quotedString = let q = match JSTQuote in
do chars <- between q q (many stringChar)
eof
pure $ pack chars
export
parseString : List (WithBounds JSONStringToken) -> Maybe String
parseString toks = case parse quotedString toks of
Right (str, []) => Just str
_ => Nothing