forked from OSS/graphql
Parse secure names
This commit is contained in:
parent
d88acf3d0e
commit
4f4e31805a
@ -12,7 +12,7 @@ import Data.Monoid (Monoid, mempty)
|
|||||||
import Control.Applicative ((<|>), empty, many, optional)
|
import Control.Applicative ((<|>), empty, many, optional)
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import Data.Text (Text, pack)
|
import Data.Text (Text, append)
|
||||||
import Data.Attoparsec.Text
|
import Data.Attoparsec.Text
|
||||||
( Parser
|
( Parser
|
||||||
, (<?>)
|
, (<?>)
|
||||||
@ -20,25 +20,28 @@ import Data.Attoparsec.Text
|
|||||||
, decimal
|
, decimal
|
||||||
, double
|
, double
|
||||||
, endOfLine
|
, endOfLine
|
||||||
|
, inClass
|
||||||
, many1
|
, many1
|
||||||
, manyTill
|
, manyTill
|
||||||
, option
|
, option
|
||||||
, peekChar
|
, peekChar
|
||||||
, satisfy
|
|
||||||
, sepBy1
|
, sepBy1
|
||||||
, signed
|
, signed
|
||||||
|
, takeWhile
|
||||||
|
, takeWhile1
|
||||||
)
|
)
|
||||||
|
|
||||||
import Data.GraphQL.AST
|
import Data.GraphQL.AST
|
||||||
|
|
||||||
-- * Name
|
-- * 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 :: 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
|
-- * Document
|
||||||
|
|
||||||
|
4
TODO
4
TODO
@ -6,15 +6,13 @@
|
|||||||
- Deal with location
|
- Deal with location
|
||||||
|
|
||||||
## Parser
|
## Parser
|
||||||
- Secure Names
|
|
||||||
- Optimize `name` and `whiteSpace`: `take...`, `T.fold`, ...
|
|
||||||
- Handle escape characters in string literals
|
- Handle escape characters in string literals
|
||||||
- Guard for `on` in `FragmentSpread`
|
- Guard for `on` in `FragmentSpread`
|
||||||
- Handle `[Const]` grammar parameter. Need examples
|
- Handle `[Const]` grammar parameter. Need examples
|
||||||
- Handle `maxBound` Int values.
|
- Handle `maxBound` Int values.
|
||||||
- Diagnostics. Perhaps port to `parsers` and use `trifecta` for diagnostics,
|
- Diagnostics. Perhaps port to `parsers` and use `trifecta` for diagnostics,
|
||||||
and `attoparsec` for performance.
|
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
|
## Tests
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user