{-# LANGUAGE NamedFieldPuns #-}
module Data.Morpheus.Parsing.Internal.Arguments
( maybeArguments,
parseArgumentsOpt
)
where
import Text.Megaparsec ( label)
import Data.Morpheus.Parsing.Internal.Internal
( Parser
, getLocation
)
import Data.Morpheus.Parsing.Internal.Terms
( parseAssignment
, uniqTupleOpt
, token
)
import Data.Morpheus.Parsing.Internal.Value
( parseRawValue
, parseValue
)
import Data.Morpheus.Types.Internal.AST
( Argument(..)
, Arguments
, RAW
, VALID
)
valueArgument :: Parser (Argument RAW)
valueArgument =
label "Argument" $ do
argumentPosition <- getLocation
(argumentName, argumentValue )<- parseAssignment token parseRawValue
pure $ Argument { argumentName, argumentValue, argumentPosition }
parseArgument :: Parser (Argument VALID)
parseArgument =
label "Argument" $ do
argumentPosition <- getLocation
(argumentName, argumentValue )<- parseAssignment token parseValue
pure $ Argument { argumentName, argumentValue, argumentPosition }
parseArgumentsOpt :: Parser (Arguments VALID)
parseArgumentsOpt =
label "Arguments"
$ uniqTupleOpt parseArgument
maybeArguments :: Parser (Arguments RAW)
maybeArguments =
label "Arguments"
$ uniqTupleOpt valueArgument