    {-# OPTIONS_GHC -Wno-unused-do-bind #-}
    module Data.Aeson.JSONPath.Parser.Filter
      ( pFilter )
      where

    import qualified Data.Text                      as T
    import qualified Text.ParserCombinators.Parsec  as P

    import Data.Functor                  (($>))
    import Data.Maybe                    (isNothing)
    import Data.Scientific               (Scientific)
    import Text.ParserCombinators.Parsec ((<|>))

    import Data.Aeson.JSONPath.Parser.Name
    import Data.Aeson.JSONPath.Parser.Number
    import Data.Aeson.JSONPath.Parser.Common

    import Data.Aeson.JSONPath.Types

    import Prelude

    pFilter :: P.Parser a -> P.Parser (Selector a)
    pFilter :: forall a. Parser a -> Parser (Selector a)
    pFilter Parser a
    pQ = do
      Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '?'
      Parser String
    pSpaces
      LogicalOrExpr a -> Selector a
    forall a. LogicalOrExpr a -> Selector a
    Filter (LogicalOrExpr a -> Selector a)
    -> ParsecT String () Identity (LogicalOrExpr a)
    -> ParsecT String () Identity (Selector a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser a -> ParsecT String () Identity (LogicalOrExpr a)
    forall a. Parser a -> Parser (LogicalOrExpr a)
    pLogicalOrExpr Parser a
    pQ

    pLogicalOrExpr :: P.Parser a -> P.Parser (LogicalOrExpr a)
    pLogicalOrExpr :: forall a. Parser a -> Parser (LogicalOrExpr a)
    pLogicalOrExpr Parser a
    pQ = do
      expr <- Parser a -> Parser (LogicalAndExpr a)
    forall a. Parser a -> Parser (LogicalAndExpr a)
    pLogicalAndExpr Parser a
    pQ
      optionalExprs <- P.many $ pOrSepLogicalAndExprs pQ
      return $ LogicalOr (expr:optionalExprs)
        where
          pOrSepLogicalAndExprs :: P.Parser a -> P.Parser (LogicalAndExpr a)
          pOrSepLogicalAndExprs :: forall a. Parser a -> Parser (LogicalAndExpr a)
    pOrSepLogicalAndExprs Parser a
    pQ' = GenParser Char () (LogicalAndExpr a)
    -> GenParser Char () (LogicalAndExpr a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (GenParser Char () (LogicalAndExpr a)
     -> GenParser Char () (LogicalAndExpr a))
    -> GenParser Char () (LogicalAndExpr a)
    -> GenParser Char () (LogicalAndExpr a)
    forall a b. (a -> b) -> a -> b
    $ Parser String
    pSpaces Parser String -> Parser String -> Parser String
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "||" Parser String -> Parser String -> Parser String
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> Parser String
    pSpaces Parser String
    -> GenParser Char () (LogicalAndExpr a)
    -> GenParser Char () (LogicalAndExpr a)
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> Parser a -> GenParser Char () (LogicalAndExpr a)
    forall a. Parser a -> Parser (LogicalAndExpr a)
    pLogicalAndExpr Parser a
    pQ'

    pLogicalAndExpr :: P.Parser a -> P.Parser (LogicalAndExpr a)
    pLogicalAndExpr :: forall a. Parser a -> Parser (LogicalAndExpr a)
    pLogicalAndExpr Parser a
    pQ = do
      expr <- Parser a -> Parser (BasicExpr a)
    forall a. Parser a -> Parser (BasicExpr a)
    pBasicExpr Parser a
    pQ
      optionalExprs <- P.many $ pAndSepBasicExprs pQ
      return $ LogicalAnd (expr:optionalExprs)
        where
          pAndSepBasicExprs :: P.Parser a -> P.Parser (BasicExpr a)
          pAndSepBasicExprs :: forall a. Parser a -> Parser (BasicExpr a)
    pAndSepBasicExprs Parser a
    pQ' = GenParser Char () (BasicExpr a) -> GenParser Char () (BasicExpr a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (GenParser Char () (BasicExpr a)
     -> GenParser Char () (BasicExpr a))
    -> GenParser Char () (BasicExpr a)
    -> GenParser Char () (BasicExpr a)
    forall a b. (a -> b) -> a -> b
    $ Parser String
    pSpaces Parser String -> Parser String -> Parser String
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "&&" Parser String -> Parser String -> Parser String
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> Parser String
    pSpaces Parser String
    -> GenParser Char () (BasicExpr a)
    -> GenParser Char () (BasicExpr a)
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> Parser a -> GenParser Char () (BasicExpr a)
    forall a. Parser a -> Parser (BasicExpr a)
    pBasicExpr Parser a
    pQ'

    pBasicExpr :: P.Parser a -> P.Parser (BasicExpr a)
    pBasicExpr :: forall a. Parser a -> Parser (BasicExpr a)
    pBasicExpr Parser a
    pQ
      = GenParser Char () (BasicExpr a) -> GenParser Char () (BasicExpr a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (Parser a -> GenParser Char () (BasicExpr a)
    forall a. Parser a -> Parser (BasicExpr a)
    pParenExpr Parser a
    pQ)
     GenParser Char () (BasicExpr a)
    -> GenParser Char () (BasicExpr a)
    -> GenParser Char () (BasicExpr a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> GenParser Char () (BasicExpr a) -> GenParser Char () (BasicExpr a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try GenParser Char () (BasicExpr a)
    forall a. Parser (BasicExpr a)
    pComparisonExpr
     GenParser Char () (BasicExpr a)
    -> GenParser Char () (BasicExpr a)
    -> GenParser Char () (BasicExpr a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> GenParser Char () (BasicExpr a) -> GenParser Char () (BasicExpr a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (Parser a -> GenParser Char () (BasicExpr a)
    forall a. Parser a -> Parser (BasicExpr a)
    pTestExpr Parser a
    pQ)

    pParenExpr :: P.Parser a -> P.Parser (BasicExpr a)
    pParenExpr :: forall a. Parser a -> Parser (BasicExpr a)
    pParenExpr Parser a
    pQ = do
      notOp <- ParsecT String () Identity Char
    -> ParsecT String () Identity (Maybe Char)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m (Maybe a)
    P.optionMaybe (Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '!' ParsecT String () Identity Char
    -> Parser String -> ParsecT String () Identity Char
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Parser String
    pSpaces)
      P.char '('
      pSpaces
      expr <- pLogicalOrExpr pQ
      pSpaces
      P.char ')'
      let parenExp = if Maybe Char -> Bool
    forall a. Maybe a -> Bool
    isNothing Maybe Char
    notOp then LogicalOrExpr a -> BasicExpr a
    forall a. LogicalOrExpr a -> BasicExpr a
    Paren LogicalOrExpr a
    expr else LogicalOrExpr a -> BasicExpr a
    forall a. LogicalOrExpr a -> BasicExpr a
    NotParen LogicalOrExpr a
    expr
      return parenExp

    pTestExpr :: P.Parser a -> P.Parser (BasicExpr a)
    pTestExpr :: forall a. Parser a -> Parser (BasicExpr a)
    pTestExpr Parser a
    pQ = do
      notOp <- ParsecT String () Identity Char
    -> ParsecT String () Identity (Maybe Char)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m (Maybe a)
    P.optionMaybe (Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '!' ParsecT String () Identity Char
    -> Parser String -> ParsecT String () Identity Char
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Parser String
    pSpaces)
      q <- P.try (FilterQuery <$> pQ)
      let testExp = if Maybe Char -> Bool
    forall a. Maybe a -> Bool
    isNothing Maybe Char
    notOp then TestExpr a -> BasicExpr a
    forall a. TestExpr a -> BasicExpr a
    Test TestExpr a
    q else TestExpr a -> BasicExpr a
    forall a. TestExpr a -> BasicExpr a
    NotTest TestExpr a
    q
      return testExp

    pComparisonExpr :: P.Parser (BasicExpr a)
    pComparisonExpr :: forall a. Parser (BasicExpr a)
    pComparisonExpr = do
      leftC <- Parser Comparable
    pComparable
      pSpaces
      compOp <- pComparisonOp
      pSpaces
      Comparison . Comp leftC compOp <$> pComparable

    pComparisonOp :: P.Parser ComparisonOp
    pComparisonOp :: Parser ComparisonOp
    pComparisonOp = Parser ComparisonOp -> Parser ComparisonOp
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    ">=" Parser String -> ComparisonOp -> Parser ComparisonOp
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> ComparisonOp
    GreaterOrEqual)
                 Parser ComparisonOp -> Parser ComparisonOp -> Parser ComparisonOp
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser ComparisonOp -> Parser ComparisonOp
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "<=" Parser String -> ComparisonOp -> Parser ComparisonOp
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> ComparisonOp
    LessOrEqual)
                 Parser ComparisonOp -> Parser ComparisonOp -> Parser ComparisonOp
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser ComparisonOp -> Parser ComparisonOp
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '>' ParsecT String () Identity Char
    -> ComparisonOp -> Parser ComparisonOp
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> ComparisonOp
    Greater)
                 Parser ComparisonOp -> Parser ComparisonOp -> Parser ComparisonOp
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser ComparisonOp -> Parser ComparisonOp
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '<' ParsecT String () Identity Char
    -> ComparisonOp -> Parser ComparisonOp
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> ComparisonOp
    Less)
                 Parser ComparisonOp -> Parser ComparisonOp -> Parser ComparisonOp
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser ComparisonOp -> Parser ComparisonOp
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "!=" Parser String -> ComparisonOp -> Parser ComparisonOp
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> ComparisonOp
    NotEqual)
                 Parser ComparisonOp -> Parser ComparisonOp -> Parser ComparisonOp
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser ComparisonOp -> Parser ComparisonOp
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "==" Parser String -> ComparisonOp -> Parser ComparisonOp
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> ComparisonOp
    Equal)

    pComparable :: P.Parser Comparable
    pComparable :: Parser Comparable
    pComparable = Parser Comparable -> Parser Comparable
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try Parser Comparable
    pCompLit Parser Comparable -> Parser Comparable -> Parser Comparable
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser Comparable -> Parser Comparable
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try Parser Comparable
    pCompSQ

    pCompLit :: P.Parser Comparable
    pCompLit :: Parser Comparable
    pCompLit = Literal -> Comparable
    CompLit
                (Literal -> Comparable)
    -> ParsecT String () Identity Literal -> Parser Comparable
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity Literal
    pLitString
                ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity Literal
    pLitNum
                ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity Literal
    pLitBool
                ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Literal
    -> ParsecT String () Identity Literal
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity Literal
    pLitNull)

    pLitString :: P.Parser Literal
    pLitString :: ParsecT String () Identity Literal
    pLitString = Text -> Literal
    LitString (Text -> Literal) -> (String -> Text) -> String -> Literal
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Text
    T.pack (String -> Literal)
    -> Parser String -> ParsecT String () Identity Literal
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Parser String -> Parser String
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try Parser String
    pSingleQuotted Parser String -> Parser String -> Parser String
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser String -> Parser String
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try Parser String
    pDoubleQuotted)

    pLitNum :: P.Parser Literal
    pLitNum :: ParsecT String () Identity Literal
    pLitNum = Scientific -> Literal
    LitNum
               (Scientific -> Literal)
    -> ParsecT String () Identity Scientific
    -> ParsecT String () Identity Literal
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "-0" Parser String
    -> Scientific -> ParsecT String () Identity Scientific
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> (Scientific
    0 :: Scientific)) -- edge case
               ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity Scientific
    pDoubleScientific
               ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Scientific
    -> ParsecT String () Identity Scientific
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity Scientific
    pScientific)

    pLitBool :: P.Parser Literal
    pLitBool :: ParsecT String () Identity Literal
    pLitBool = Bool -> Literal
    LitBool (Bool -> Literal)
    -> ParsecT String () Identity Bool
    -> ParsecT String () Identity Literal
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (ParsecT String () Identity Bool -> ParsecT String () Identity Bool
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "true" Parser String -> Bool -> ParsecT String () Identity Bool
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Bool
    True) ParsecT String () Identity Bool
    -> ParsecT String () Identity Bool
    -> ParsecT String () Identity Bool
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Bool -> ParsecT String () Identity Bool
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "false" Parser String -> Bool -> ParsecT String () Identity Bool
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Bool
    False))

    pLitNull :: P.Parser Literal
    pLitNull :: ParsecT String () Identity Literal
    pLitNull = String -> Parser String
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m String
    P.string String
    "null" Parser String -> Literal -> ParsecT String () Identity Literal
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Literal
    LitNull

    pCompSQ :: P.Parser Comparable
    pCompSQ :: Parser Comparable
    pCompSQ = SingularQuery -> Comparable
    CompSQ (SingularQuery -> Comparable)
    -> ParsecT String () Identity SingularQuery -> Parser Comparable
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (ParsecT String () Identity SingularQuery
    -> ParsecT String () Identity SingularQuery
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity SingularQuery
    pCurrentSingleQ ParsecT String () Identity SingularQuery
    -> ParsecT String () Identity SingularQuery
    -> ParsecT String () Identity SingularQuery
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity SingularQuery
    -> ParsecT String () Identity SingularQuery
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity SingularQuery
    pRootSingleQ)

    pCurrentSingleQ :: P.Parser SingularQuery
    pCurrentSingleQ :: ParsecT String () Identity SingularQuery
    pCurrentSingleQ = do
      Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '@'
      segs <- ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity [SingularQuerySegment]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    P.many (ParsecT String () Identity SingularQuerySegment
     -> ParsecT String () Identity [SingularQuerySegment])
    -> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity [SingularQuerySegment]
    forall a b. (a -> b) -> a -> b
    $ ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (Parser String
    pSpaces Parser String
    -> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT String () Identity SingularQuerySegment
    pSingularQuerySegment)
      return $ SingularQuery { singularQueryType = CurrentSQ, singularQuerySegments = segs }

    pRootSingleQ :: P.Parser SingularQuery
    pRootSingleQ :: ParsecT String () Identity SingularQuery
    pRootSingleQ = do
      Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '$'
      segs <- ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity [SingularQuerySegment]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    P.many (ParsecT String () Identity SingularQuerySegment
     -> ParsecT String () Identity [SingularQuerySegment])
    -> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity [SingularQuerySegment]
    forall a b. (a -> b) -> a -> b
    $ ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try (Parser String
    pSpaces Parser String
    -> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall a b.
    ParsecT String () Identity a
    -> ParsecT String () Identity b -> ParsecT String () Identity b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT String () Identity SingularQuerySegment
    pSingularQuerySegment)
      return $ SingularQuery { singularQueryType = RootSQ, singularQuerySegments = segs }

    pSingularQuerySegment :: P.Parser SingularQuerySegment
    pSingularQuerySegment :: ParsecT String () Identity SingularQuerySegment
    pSingularQuerySegment = ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity SingularQuerySegment
    pSingularQNameSeg ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity SingularQuerySegment
    pSingularQIndexSeg

    pSingularQNameSeg :: P.Parser SingularQuerySegment
    pSingularQNameSeg :: ParsecT String () Identity SingularQuerySegment
    pSingularQNameSeg = ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity SingularQuerySegment
    pSingularQNameBracketed ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity SingularQuerySegment
    -> ParsecT String () Identity SingularQuerySegment
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try ParsecT String () Identity SingularQuerySegment
    pSingularQNameDotted
      where
        pSingularQNameBracketed :: ParsecT String () Identity SingularQuerySegment
    pSingularQNameBracketed = do
          Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '['
          name <- String -> Text
    T.pack (String -> Text)
    -> Parser String -> ParsecT String () Identity Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Parser String -> Parser String
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try Parser String
    pSingleQuotted Parser String -> Parser String -> Parser String
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Parser String -> Parser String
    forall tok st a. GenParser tok st a -> GenParser tok st a
    P.try Parser String
    pDoubleQuotted)
          P.char ']'
          return $ NameSQSeg name

        pSingularQNameDotted :: ParsecT String () Identity SingularQuerySegment
    pSingularQNameDotted = do
          Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '.'
          ParsecT String () Identity Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    P.lookAhead (ParsecT String () Identity Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    P.letter ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> String -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m Char
    P.oneOf String
    "_" ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Char
    pUnicodeChar)
          name <- String -> Text
    T.pack (String -> Text)
    -> Parser String -> ParsecT String () Identity Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT String () Identity Char -> Parser String
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    P.many1 (ParsecT String () Identity Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    P.alphaNum ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> String -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    String -> ParsecT s u m Char
    P.oneOf String
    "_" ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    -> ParsecT String () Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT String () Identity Char
    pUnicodeChar)
          return $ NameSQSeg name

    pSingularQIndexSeg :: P.Parser SingularQuerySegment
    pSingularQIndexSeg :: ParsecT String () Identity SingularQuerySegment
    pSingularQIndexSeg = do
      Char -> ParsecT String () Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    P.char Char
    '['
      idx <- Parser Int
    pSignedInt
      P.char ']'
      return $ IndexSQSeg idx