Parse secure names

This commit is contained in:
Danny Navarro 2015-09-18 15:43:22 +02:00
parent d88acf3d0e
commit 4f4e31805a
2 changed files with 11 additions and 10 deletions

View File

@ -12,7 +12,7 @@ import Data.Monoid (Monoid, mempty)
import Control.Applicative ((<|>), empty, many, optional)
import Control.Monad (when)
import Data.Char
import Data.Text (Text, pack)
import Data.Text (Text, append)
import Data.Attoparsec.Text
( Parser
, (<?>)
@ -20,25 +20,28 @@ import Data.Attoparsec.Text
, decimal
, double
, endOfLine
, inClass
, many1
, manyTill
, option
, peekChar
, satisfy
, sepBy1
, signed
, takeWhile
, takeWhile1
)
import Data.GraphQL.AST
-- * Name
-- XXX: Handle starting `_` and no number at the beginning:
-- https://facebook.github.io/graphql/#sec-Names
-- TODO: Use takeWhile1 instead for efficiency. With takeWhile1 there is no
-- parsing failure.
name :: Parser Name
name = tok $ pack <$> many1 (satisfy isAlphaNum)
name = tok $ append <$> takeWhile1 isA_z
<*> takeWhile ((||) <$> isDigit <*> isA_z)
where
-- `isAlpha` handles many more Unicode Chars
isA_z = inClass $ '_' : ['A'..'Z'] ++ ['a'..'z']
-- * Document

4
TODO
View File

@ -6,15 +6,13 @@
- Deal with location
## Parser
- Secure Names
- Optimize `name` and `whiteSpace`: `take...`, `T.fold`, ...
- Handle escape characters in string literals
- Guard for `on` in `FragmentSpread`
- Handle `[Const]` grammar parameter. Need examples
- Handle `maxBound` Int values.
- Diagnostics. Perhaps port to `parsers` and use `trifecta` for diagnostics,
and `attoparsec` for performance.
- Improve comment handling: perhaps front the main parser with a lexer.
- Optimize `whiteSpace`, perhaps front the main parser with a lexer.
## Tests