mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-30 07:02:24 +03:00
f3855d7100
Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
27 lines
730 B
Idris
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
|