diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-01-13 08:11:22 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-01-13 08:11:22 +0100 |
| commit | f4f076fa59ec393fa0e03595deb82d94c01142d3 (patch) | |
| tree | 911acefecc627b2d2457987c143a2db49923ea85 /src/Language/GraphQL/AST/Parser.hs | |
| parent | 6d951491be0093f7568462a3139115cdab6766ed (diff) | |
| download | graphql-f4f076fa59ec393fa0e03595deb82d94c01142d3.tar.gz | |
Reduce usage of the opt parser
opt directives = some directive
All other occurrences of opt parse an optional list withing some
delimiters (braces, parens).
Diffstat (limited to 'src/Language/GraphQL/AST/Parser.hs')
| -rw-r--r-- | src/Language/GraphQL/AST/Parser.hs | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/Language/GraphQL/AST/Parser.hs b/src/Language/GraphQL/AST/Parser.hs index 8268687..d8b467a 100644 --- a/src/Language/GraphQL/AST/Parser.hs +++ b/src/Language/GraphQL/AST/Parser.hs @@ -32,8 +32,8 @@ operationDefinition = SelectionSet <$> selectionSet operationDefinition' = OperationDefinition <$> operationType <*> optional name - <*> opt variableDefinitions - <*> opt directives + <*> variableDefinitions + <*> directives <*> selectionSet operationType :: Parser OperationType @@ -47,7 +47,7 @@ selectionSet :: Parser SelectionSet selectionSet = braces $ NonEmpty.some selection selectionSetOpt :: Parser SelectionSetOpt -selectionSetOpt = braces $ some selection +selectionSetOpt = listOptIn braces selection selection :: Parser Selection selection = field @@ -61,9 +61,9 @@ field :: Parser Selection field = Field <$> optional alias <*> name - <*> opt arguments - <*> opt directives - <*> opt selectionSetOpt + <*> arguments + <*> directives + <*> selectionSetOpt alias :: Parser Alias alias = try $ name <* colon @@ -71,7 +71,7 @@ alias = try $ name <* colon -- * Arguments arguments :: Parser [Argument] -arguments = parens $ some argument +arguments = listOptIn parens argument argument :: Parser Argument argument = Argument <$> name <* colon <*> value @@ -82,13 +82,13 @@ fragmentSpread :: Parser Selection fragmentSpread = FragmentSpread <$ spread <*> fragmentName - <*> opt directives + <*> directives inlineFragment :: Parser Selection inlineFragment = InlineFragment <$ spread <*> optional typeCondition - <*> opt directives + <*> directives <*> selectionSet fragmentDefinition :: Parser FragmentDefinition @@ -96,7 +96,7 @@ fragmentDefinition = FragmentDefinition <$ symbol "fragment" <*> name <*> typeCondition - <*> opt directives + <*> directives <*> selectionSet fragmentName :: Parser Name @@ -139,13 +139,15 @@ objectField = ObjectField <$> name <* symbol ":" <*> value -- * Variables variableDefinitions :: Parser [VariableDefinition] -variableDefinitions = parens $ some variableDefinition +variableDefinitions = listOptIn parens variableDefinition variableDefinition :: Parser VariableDefinition -variableDefinition = VariableDefinition <$> variable - <* colon - <*> type_ - <*> optional defaultValue +variableDefinition = VariableDefinition + <$> variable + <* colon + <*> type_ + <*> optional defaultValue + variable :: Parser Name variable = dollar *> name @@ -168,18 +170,18 @@ nonNullType = NonNullTypeNamed <$> name <* bang -- * Directives directives :: Parser [Directive] -directives = some directive +directives = many directive directive :: Parser Directive directive = Directive - <$ at - <*> name - <*> opt arguments + <$ at + <*> name + <*> arguments -- * Internal -opt :: Monoid a => Parser a -> Parser a -opt = option mempty +listOptIn :: (Parser [a] -> Parser [a]) -> Parser a -> Parser [a] +listOptIn surround = option [] . surround . some -- Hack to reverse parser success but :: Parser a -> Parser () |
