summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/AST/Lexer.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-01-28 11:08:28 +0100
committerEugen Wissner <belka@caraus.de>2020-01-28 11:08:28 +0100
commite8b82122c646ba159146c986cc8983d66f790142 (patch)
tree6563ee31014a1ff4f23905f1dc794302d2231872 /src/Language/GraphQL/AST/Lexer.hs
parenta6bd2370b6ba6f9eba6f0911ce9f8e8042a7f26b (diff)
downloadgraphql-e8b82122c646ba159146c986cc8983d66f790142.tar.gz
Try all extension parsers
Diffstat (limited to 'src/Language/GraphQL/AST/Lexer.hs')
-rw-r--r--src/Language/GraphQL/AST/Lexer.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Language/GraphQL/AST/Lexer.hs b/src/Language/GraphQL/AST/Lexer.hs
index e119303..0ba55e3 100644
--- a/src/Language/GraphQL/AST/Lexer.hs
+++ b/src/Language/GraphQL/AST/Lexer.hs
@@ -33,9 +33,12 @@ import Control.Applicative (Alternative(..), liftA2)
import Data.Char (chr, digitToInt, isAsciiLower, isAsciiUpper, ord)
import Data.Foldable (foldl')
import Data.List (dropWhileEnd)
+import qualified Data.List.NonEmpty as NonEmpty
+import Data.List.NonEmpty (NonEmpty(..))
import Data.Proxy (Proxy(..))
import Data.Void (Void)
import Text.Megaparsec ( Parsec
+ , (<?>)
, between
, chunk
, chunkToTokens
@@ -220,5 +223,14 @@ unicodeBOM :: Parser ()
unicodeBOM = optional (char '\xfeff') >> pure ()
-- | Parses "extend" followed by a 'symbol'. It is used by schema extensions.
-extend :: Text -> Parser ()
-extend token = symbol "extend" *> symbol token >> pure ()
+extend :: forall a. Text -> String -> NonEmpty (Parser a) -> Parser a
+extend token extensionLabel parsers
+ = foldr combine headParser (NonEmpty.tail parsers)
+ <?> extensionLabel
+ where
+ headParser = tryExtension $ NonEmpty.head parsers
+ combine current accumulated = accumulated <|> tryExtension current
+ tryExtension extensionParser = try
+ $ symbol "extend"
+ *> symbol token
+ *> extensionParser \ No newline at end of file