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:
parent
62adfd89cd
commit
c0b6fc8a05
@ -5,7 +5,7 @@ import Prelude hiding (takeWhile)
|
|||||||
import Control.Applicative (Alternative, (<|>), empty, many, optional)
|
import Control.Applicative (Alternative, (<|>), empty, many, optional)
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text, pack)
|
||||||
import Data.Attoparsec.Text
|
import Data.Attoparsec.Text
|
||||||
( Parser
|
( Parser
|
||||||
, (<?>)
|
, (<?>)
|
||||||
@ -14,6 +14,7 @@ import Data.Attoparsec.Text
|
|||||||
, double
|
, double
|
||||||
, endOfLine
|
, endOfLine
|
||||||
, isEndOfLine
|
, isEndOfLine
|
||||||
|
, letter
|
||||||
, many1
|
, many1
|
||||||
, manyTill
|
, manyTill
|
||||||
, option
|
, option
|
||||||
@ -36,8 +37,10 @@ import Data.GraphQL.AST
|
|||||||
|
|
||||||
-- XXX: Handle starting `_` and no number at the beginning:
|
-- XXX: Handle starting `_` and no number at the beginning:
|
||||||
-- https://facebook.github.io/graphql/#sec-Names
|
-- 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 $ takeWhile1 isAlphaNum
|
name = tok $ pack <$> many1 (satisfy isAlphaNum)
|
||||||
|
|
||||||
-- * Document
|
-- * Document
|
||||||
|
|
||||||
@ -144,14 +147,14 @@ typeCondition = namedType
|
|||||||
-- * Values
|
-- * Values
|
||||||
|
|
||||||
-- This will try to pick the first type it can parse. If you are working with
|
-- 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 :: Parser Value
|
||||||
value = -- TODO: Handle arbitrary precision.
|
value = -- TODO: Handle arbitrary precision.
|
||||||
ValueInt <$> signed decimal
|
ValueInt <$> signed decimal
|
||||||
<|> ValueFloat <$> signed double
|
<|> ValueFloat <$> signed double
|
||||||
<|> ValueBoolean <$> bool
|
<|> ValueBoolean <$> bool
|
||||||
-- TODO: Handle escape characters, unicode, etc
|
-- TODO: Handle escape characters, unicode, etc
|
||||||
<|> ValueString <$ "\"" <*> takeWhile isAlphaNum <* "\""
|
<|> ValueString <$ "\"" <*> (pack <$> many anyChar) <* "\""
|
||||||
-- `true` and `false` have been tried before
|
-- `true` and `false` have been tried before
|
||||||
<|> ValueEnum <$> name
|
<|> ValueEnum <$> name
|
||||||
<|> ValueList <$> listValue
|
<|> ValueList <$> listValue
|
||||||
@ -315,13 +318,11 @@ optempty = option mempty
|
|||||||
-- ** WhiteSpace
|
-- ** WhiteSpace
|
||||||
--
|
--
|
||||||
whiteSpace :: Parser ()
|
whiteSpace :: Parser ()
|
||||||
whiteSpace = comments
|
whiteSpace =
|
||||||
<|> skipWhile (\c -> isSpace c
|
skipMany (satisfy (\c -> isSpace c || ',' == c || isEndOfLine c))
|
||||||
|| ',' == c
|
|
||||||
|| isEndOfLine c)
|
|
||||||
|
|
||||||
comments :: Parser ()
|
skipComments :: Parser ()
|
||||||
comments = skipMany comment
|
skipComments = skipMany comment
|
||||||
|
|
||||||
comment :: Parser Text
|
comment :: Parser Text
|
||||||
comment = "#" *> takeTill isEndOfLine
|
comment = "#" *> (pack <$> manyTill anyChar endOfLine)
|
||||||
|
Loading…
Reference in New Issue
Block a user