mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-21 02:31:50 +03:00
1576a578a0
* contrib library unused import removal * remove a few unused imports. * another round of unused import removal * another round of unused import deletion. * another round of unused import deletion.
41 lines
1001 B
Idris
41 lines
1001 B
Idris
module Language.JSON.Lexer
|
|
|
|
import Language.JSON.String
|
|
import Text.Lexer
|
|
|
|
import public Language.JSON.Tokens
|
|
|
|
%default total
|
|
|
|
private
|
|
numberLit : Lexer
|
|
numberLit
|
|
= let sign = is '-'
|
|
whole = is '0' <|> range '1' '9' <+> many digit
|
|
frac = is '.' <+> digits
|
|
exp = like 'e' <+> opt (oneOf "+-") <+> digits in
|
|
opt sign <+> whole <+> opt frac <+> opt exp
|
|
|
|
private
|
|
jsonTokenMap : TokenMap JSONToken
|
|
jsonTokenMap = toTokenMap $
|
|
[ (spaces, JTIgnore)
|
|
, (is ',', JTPunct Comma)
|
|
, (is ':', JTPunct Colon)
|
|
, (is '[', JTPunct $ Square Open)
|
|
, (is ']', JTPunct $ Square Close)
|
|
, (is '{', JTPunct $ Curly Open)
|
|
, (is '}', JTPunct $ Curly Close)
|
|
, (exact "null", JTNull)
|
|
, (exact strTrue <|> exact strFalse, JTBoolean)
|
|
, (numberLit, JTNumber)
|
|
, (permissiveStringLit, JTString)
|
|
]
|
|
|
|
export
|
|
lexJSON : String -> Maybe (List (WithBounds JSONToken))
|
|
lexJSON str
|
|
= case lex jsonTokenMap str of
|
|
(tokens, _, _, "") => Just $ tokens
|
|
_ => Nothing
|