diff options
| author | Danny Navarro <j@dannynavarro.net> | 2015-09-14 13:04:06 +0200 |
|---|---|---|
| committer | Danny Navarro <j@dannynavarro.net> | 2015-09-14 13:16:58 +0200 |
| commit | c0b6fc8a05bb36e37bffd392a9a1883782ac5143 (patch) | |
| tree | da45a7367d76e21890be719bd9d3cc1f117d2843 | |
| parent | 62adfd89cdb8cafc7ff75b8680456d62b02c6d50 (diff) | |
| download | graphql-c0b6fc8a05bb36e37bffd392a9a1883782ac5143.tar.gz | |
Replace `take...` functions with `many...`
They are less efficient but they are giving me issues because they don't
fail. Once this is working I'll look into optimizing.
Also disable skipping comments until I figure out how to skip both
comments and space at the same time.
| -rw-r--r-- | Data/GraphQL/Parser.hs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs index 3e01064..9e3c562 100644 --- a/Data/GraphQL/Parser.hs +++ b/Data/GraphQL/Parser.hs @@ -5,7 +5,7 @@ import Prelude hiding (takeWhile) import Control.Applicative (Alternative, (<|>), empty, many, optional) import Data.Char -import Data.Text (Text) +import Data.Text (Text, pack) import Data.Attoparsec.Text ( Parser , (<?>) @@ -14,6 +14,7 @@ import Data.Attoparsec.Text , double , endOfLine , isEndOfLine + , letter , many1 , manyTill , option @@ -36,8 +37,10 @@ import Data.GraphQL.AST -- 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 $ takeWhile1 isAlphaNum +name = tok $ pack <$> many1 (satisfy isAlphaNum) -- * Document @@ -144,14 +147,14 @@ typeCondition = namedType -- * Values -- This will try to pick the first type it can parse. If you are working with --- explicit types use the `typedValue` parser. +-- explicit types use the `typedValue` parser. value :: Parser Value value = -- TODO: Handle arbitrary precision. ValueInt <$> signed decimal <|> ValueFloat <$> signed double <|> ValueBoolean <$> bool -- TODO: Handle escape characters, unicode, etc - <|> ValueString <$ "\"" <*> takeWhile isAlphaNum <* "\"" + <|> ValueString <$ "\"" <*> (pack <$> many anyChar) <* "\"" -- `true` and `false` have been tried before <|> ValueEnum <$> name <|> ValueList <$> listValue @@ -315,13 +318,11 @@ optempty = option mempty -- ** WhiteSpace -- whiteSpace :: Parser () -whiteSpace = comments - <|> skipWhile (\c -> isSpace c - || ',' == c - || isEndOfLine c) +whiteSpace = + skipMany (satisfy (\c -> isSpace c || ',' == c || isEndOfLine c)) -comments :: Parser () -comments = skipMany comment +skipComments :: Parser () +skipComments = skipMany comment comment :: Parser Text -comment = "#" *> takeTill isEndOfLine +comment = "#" *> (pack <$> manyTill anyChar endOfLine) |
