forked from OSS/graphql
Add "extend symbol" lexer to parse extensions
This commit is contained in:
parent
ba710a3c96
commit
3ef27f9d11
@ -20,6 +20,8 @@ and this project adheres to
|
|||||||
- Rename `AST.OperationSelectionSet` to `AST.Document.SelectionSet`.
|
- Rename `AST.OperationSelectionSet` to `AST.Document.SelectionSet`.
|
||||||
- Make `Schema.Subs` a `Data.HashMap.Strict` (was a function
|
- Make `Schema.Subs` a `Data.HashMap.Strict` (was a function
|
||||||
`key -> Maybe value` before).
|
`key -> Maybe value` before).
|
||||||
|
- Make `AST.Lexer.at` a text (symbol) parser. It was a char before and is
|
||||||
|
`symbol "@"` now.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- `AST.Field`, `AST.InlineFragment` and `AST.FragmentSpread`.
|
- `AST.Field`, `AST.InlineFragment` and `AST.FragmentSpread`.
|
||||||
|
@ -8,7 +8,7 @@ module Language.GraphQL.AST.Document
|
|||||||
( Alias
|
( Alias
|
||||||
, Argument(..)
|
, Argument(..)
|
||||||
, ArgumentsDefinition(..)
|
, ArgumentsDefinition(..)
|
||||||
, Definition(ExecutableDefinition, TypeSystemDefinition)
|
, Definition(..)
|
||||||
, Description(..)
|
, Description(..)
|
||||||
, Directive(..)
|
, Directive(..)
|
||||||
, Document
|
, Document
|
||||||
@ -26,6 +26,7 @@ module Language.GraphQL.AST.Document
|
|||||||
, OperationType(..)
|
, OperationType(..)
|
||||||
, OperationTypeDefinition(..)
|
, OperationTypeDefinition(..)
|
||||||
, OperationTypeDefinitions
|
, OperationTypeDefinitions
|
||||||
|
, SchemaExtension(..)
|
||||||
, Selection(..)
|
, Selection(..)
|
||||||
, SelectionSet
|
, SelectionSet
|
||||||
, SelectionSetOpt
|
, SelectionSetOpt
|
||||||
@ -34,6 +35,7 @@ module Language.GraphQL.AST.Document
|
|||||||
, TypeDefinition(..)
|
, TypeDefinition(..)
|
||||||
, TypeExtension(..)
|
, TypeExtension(..)
|
||||||
, TypeSystemDefinition(..)
|
, TypeSystemDefinition(..)
|
||||||
|
, TypeSystemExtension(..)
|
||||||
, UnionMemberTypes(..)
|
, UnionMemberTypes(..)
|
||||||
, Value(..)
|
, Value(..)
|
||||||
, VariableDefinition(..)
|
, VariableDefinition(..)
|
||||||
|
@ -15,6 +15,7 @@ module Language.GraphQL.AST.Lexer
|
|||||||
, dollar
|
, dollar
|
||||||
, comment
|
, comment
|
||||||
, equals
|
, equals
|
||||||
|
, extend
|
||||||
, integer
|
, integer
|
||||||
, float
|
, float
|
||||||
, lexeme
|
, lexeme
|
||||||
@ -31,6 +32,7 @@ module Language.GraphQL.AST.Lexer
|
|||||||
import Control.Applicative (Alternative(..), liftA2)
|
import Control.Applicative (Alternative(..), liftA2)
|
||||||
import Data.Char (chr, digitToInt, isAsciiLower, isAsciiUpper, ord)
|
import Data.Char (chr, digitToInt, isAsciiLower, isAsciiUpper, ord)
|
||||||
import Data.Foldable (foldl')
|
import Data.Foldable (foldl')
|
||||||
|
import Data.Functor (($>))
|
||||||
import Data.List (dropWhileEnd)
|
import Data.List (dropWhileEnd)
|
||||||
import Data.Proxy (Proxy(..))
|
import Data.Proxy (Proxy(..))
|
||||||
import Data.Void (Void)
|
import Data.Void (Void)
|
||||||
@ -217,3 +219,7 @@ escapeSequence = do
|
|||||||
-- | Parser for the "Byte Order Mark".
|
-- | Parser for the "Byte Order Mark".
|
||||||
unicodeBOM :: Parser ()
|
unicodeBOM :: Parser ()
|
||||||
unicodeBOM = optional (char '\xfeff') >> pure ()
|
unicodeBOM = optional (char '\xfeff') >> pure ()
|
||||||
|
|
||||||
|
-- | Parses "extend" followed by a 'symbol'. It is used by schema extensions.
|
||||||
|
extend :: Text -> Parser ()
|
||||||
|
extend token = symbol "extend" $> extend token >> pure ()
|
||||||
|
@ -87,6 +87,8 @@ spec = describe "Lexer" $ do
|
|||||||
parse blockString "" [r|""""""|] `shouldParse` ""
|
parse blockString "" [r|""""""|] `shouldParse` ""
|
||||||
it "lexes ampersand" $
|
it "lexes ampersand" $
|
||||||
parse amp "" "&" `shouldParse` "&"
|
parse amp "" "&" `shouldParse` "&"
|
||||||
|
it "lexes schema extensions" $
|
||||||
|
parse (extend "schema") "" `shouldSucceedOn` "extend schema"
|
||||||
|
|
||||||
runBetween :: (Parser () -> Parser ()) -> Text -> Either (ParseErrorBundle Text Void) ()
|
runBetween :: (Parser () -> Parser ()) -> Text -> Either (ParseErrorBundle Text Void) ()
|
||||||
runBetween parser = parse (parser $ pure ()) ""
|
runBetween parser = parse (parser $ pure ()) ""
|
||||||
|
Loading…
Reference in New Issue
Block a user