2020-05-18 15:59:07 +03:00
|
|
|
module Language.JSON.String.Parser
|
|
|
|
|
|
|
|
import Language.JSON.String.Tokens
|
|
|
|
import Text.Lexer
|
|
|
|
import Text.Parser
|
|
|
|
|
2020-05-21 15:08:19 +03:00
|
|
|
-- TODO: totality checking for codata
|
|
|
|
-- %default total
|
2020-05-18 15:59:07 +03:00
|
|
|
|
|
|
|
private
|
|
|
|
stringChar : Grammar JSONStringToken True Char
|
|
|
|
stringChar = match JSTChar
|
|
|
|
<|> match JSTSimpleEscape
|
|
|
|
<|> match JSTUnicodeEscape
|
|
|
|
|
|
|
|
private
|
|
|
|
quotedString : Grammar JSONStringToken True String
|
|
|
|
quotedString = let q = match JSTQuote in
|
|
|
|
do chars <- between q q (many stringChar)
|
|
|
|
eof
|
|
|
|
pure $ pack chars
|
|
|
|
|
|
|
|
export
|
|
|
|
parseString : List JSONStringToken -> Maybe String
|
|
|
|
parseString toks = case parse quotedString toks of
|
|
|
|
Right (str, []) => Just str
|
|
|
|
_ => Nothing
|