summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Navarro <j@dannynavarro.net>2015-09-18 15:43:22 +0200
committerDanny Navarro <j@dannynavarro.net>2015-09-18 15:43:22 +0200
commit4f4e31805ab259fe7c818f0b4f58fce2ab3ee373 (patch)
treeee7a43954438fe61a747193147b5d6e6f45ab816
parentd88acf3d0e8f9b9d5345477b23e329cefec89b6f (diff)
downloadgraphql-4f4e31805ab259fe7c818f0b4f58fce2ab3ee373.tar.gz
Parse secure names
-rw-r--r--Data/GraphQL/Parser.hs17
-rw-r--r--TODO4
2 files changed, 11 insertions, 10 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs
index 99700c0..b4af436 100644
--- a/Data/GraphQL/Parser.hs
+++ b/Data/GraphQL/Parser.hs
@@ -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
diff --git a/TODO b/TODO
index 6e61bf1..488947e 100644
--- a/TODO
+++ b/TODO
@@ -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