summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2019-07-22 05:50:00 +0200
committerEugen Wissner <belka@caraus.de>2019-07-22 05:50:00 +0200
commit1b5094b6a3e6eb68f67bc3238487818f7b7d552a (patch)
tree6e51bc6bba9613b60af81d56a39b8dad10750cef /src
parent9d15b831648ff7a7acb1327efbce3b22181b6157 (diff)
downloadgraphql-1b5094b6a3e6eb68f67bc3238487818f7b7d552a.tar.gz
Parse the BOM header if any
Diffstat (limited to 'src')
-rw-r--r--src/Language/GraphQL/Lexer.hs11
-rw-r--r--src/Language/GraphQL/Parser.hs2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/Language/GraphQL/Lexer.hs b/src/Language/GraphQL/Lexer.hs
index 655be3d..8ca03bf 100644
--- a/src/Language/GraphQL/Lexer.hs
+++ b/src/Language/GraphQL/Lexer.hs
@@ -1,5 +1,8 @@
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE OverloadedStrings #-}
+
+-- | This module defines a bunch of small parsers used to parse individual
+-- lexemes.
module Language.GraphQL.Lexer
( Parser
, amp
@@ -22,6 +25,7 @@ module Language.GraphQL.Lexer
, spread
, string
, symbol
+ , unicodeBOM
) where
import Control.Applicative ( Alternative(..)
@@ -44,6 +48,7 @@ import Text.Megaparsec ( Parsec
, notFollowedBy
, oneOf
, option
+ , optional
, satisfy
, sepBy
, skipSome
@@ -73,9 +78,11 @@ spaceConsumer = Lexer.space ignoredCharacters comment empty
comment :: Parser ()
comment = Lexer.skipLineComment "#"
+-- | Lexeme definition which ignores whitespaces and commas.
lexeme :: forall a. Parser a -> Parser a
lexeme = Lexer.lexeme spaceConsumer
+-- | Symbol definition which ignores whitespaces and commas.
symbol :: T.Text -> Parser T.Text
symbol = Lexer.symbol spaceConsumer
@@ -213,3 +220,7 @@ escapeSequence = do
_ -> return escaped
where
step accumulator = (accumulator * 16 +) . digitToInt
+
+-- | Parser for the "Byte Order Mark".
+unicodeBOM :: Parser ()
+unicodeBOM = optional (char '\xfeff') >> pure ()
diff --git a/src/Language/GraphQL/Parser.hs b/src/Language/GraphQL/Parser.hs
index f18621a..dac15c2 100644
--- a/src/Language/GraphQL/Parser.hs
+++ b/src/Language/GraphQL/Parser.hs
@@ -17,7 +17,7 @@ import Text.Megaparsec ( lookAhead
)
document :: Parser Document
-document = spaceConsumer >> lexeme (manyNE definition)
+document = unicodeBOM >> spaceConsumer >> lexeme (manyNE definition)
definition :: Parser Definition
definition = DefinitionOperation <$> operationDefinition