0 | module Language.JSON.String.Parser
 1 |
 2 | import Language.JSON.String.Tokens
 3 | import Text.Lexer
 4 | import Text.Parser
 5 |
 6 | %default total
 7 |
 8 | private
 9 | stringChar : Grammar state JSONStringToken True Char
10 | stringChar = match JSTChar
11 |          <|> match JSTSimpleEscape
12 |          <|> match JSTUnicodeEscape
13 |
14 | private
15 | quotedString : Grammar state JSONStringToken True String
16 | quotedString = let q = match JSTQuote in
17 |                    do chars <- between q q (many stringChar)
18 |                       eof
19 |                       pure $ pack chars
20 |
21 | export
22 | parseString : List (WithBounds JSONStringToken) -> Maybe String
23 | parseString toks = case parse quotedString toks of
24 |                         Right (str, []) => Just str
25 |                         _ => Nothing
26 |