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.
This commit is contained in:
Danny Navarro 2015-09-14 13:04:06 +02:00
parent 62adfd89cd
commit c0b6fc8a05

View File

@ -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
@ -151,7 +154,7 @@ value = -- TODO: Handle arbitrary precision.
<|> 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)