From 4f4e31805ab259fe7c818f0b4f58fce2ab3ee373 Mon Sep 17 00:00:00 2001 From: Danny Navarro Date: Fri, 18 Sep 2015 15:43:22 +0200 Subject: Parse secure names --- Data/GraphQL/Parser.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Data') 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 -- cgit v1.2.3