{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}

-- | Description: Parser for jQuery/CSS selector syntax
--
-- This module provides functions for parsing jQuery/CSS selectors into
-- 'Axis' functions.
--
-- The following selectors are currently supported:
--
-- - __Any selector__ (@*@): Select any node.
-- - __Element name selector__ (@div@): Select all elements of the given
--   element name.
-- - __Descendant selector__ (@a b@): Select /descendants/ of all the nodes
--   matching the LHS selector that match the RHS selector.
-- - __Child selector__ (@a > b@): Select /children/ of all the nodes
--   matching the LHS selector that match the RHS selector.
-- - __Following sibling selector__ (@a ~ b@): Select /siblings/ of all the
--   nodes matching the LHS selector that match the RHS selector.
-- - __Adjacent sibling selector__ (@a + b@):
--   Select /directly adjacent siblings/ of all the nodes matching the LHS
--   selector that match the RHS selector.
-- - __Alternative selector__ (@a , b@): Select all nodes that match the LHS
--   selector, and also all the nodes that match the RHS selector.
-- - __Class selector__ (@.classname@): Select all elements whose @class@
--   attribute contains the given class name.
-- - __ID selector__ (@#id@): Select the element whose @id@ attribute matches
--   the given ID. Note that while in a well-formed XML document, each ID may
--   only be used once, this selector will happily return multiple nodes if the
--   target document is not well-formed, or when it is combined with other
--   selectors that cause the same element to be matched via multiple paths
--   (see also the note below).
-- - __Attribute-exists selector__ (@[attr]@): Select elements that have an
--   attribute of the given name.
-- - __Attribute-is selector__ (@[attr="value"]@): Select elements whose @attr@
--   attribute is exactly equal to the given value.
-- - __Attribute-is-not selector__ (@[attr!="value"]@): Select elements whose
--   @attr@ attribute is not exactly equal to the given value.
-- - __Attribute-starts-with selector__ (@[attr^="value"]@): Select elements whose @attr@
--   attribute begins with the given value.
-- - __Attribute-ends-with selector__ (@[attr$="value"]@): Select elements whose @attr@
--   attribute ends with the given value.
-- - __Attribute-contains selector__ (@[attr*="value"]@): Select elements whose @attr@
--   attribute contains the given value.
-- - __Attribute-contains-word selector__ (@[attr~="value"]@): Select elements
--   whose @attr@ attribute contains the given value between word boundaries.
--   Word boundaries are the very beginning and end of the value, as well as
--   any nonzero number of whitespace characters.
-- - __Attribute-contains-prefix selector__ (@[attr|="value"]@): Select elements whose @attr@
--   attribute contains the given value as a prefix. A prefix is either the
--   entire value itself, or the given value plus a hyphen-minus character
--   (@-@) at the very beginning of the attribute value.
-- - __Not selector__ (@:not(a)@): Select all elements that do not match the
--   argument selector.
-- - __Has selector__ (@:has(a)@): Select all elements that have relatives
--   that match the argument selector. A relationship (@+@, @~@, @>@) can be
--   given at the start of the argument; if none is given, the /descendant/
--   relationship is the default.
-- - __First-child selector__ (@:first-child@): Select all elements that are
--   the first child of their respective parent.
-- - __Last-child selector__ (@:last-child@): Select all elements that are
--   the last child of their respective parent.
-- - __Nth-child selector__ (@:nth-child(n)@): Select all elements that are
--   the n-th child (1-based) of their respective parent.
-- - __Nth-last-child selector__ (@:nth-last-child(n)@): Select all elements
--   that are the n-th last child (1-based) of their respective parent.
--
-- __Note__: The way the 'Axis' and 'Cursor' types work, we cannot avoid
-- matching the same node multiple times - this is mainly because there is no
-- 'Eq' instance for 'Cursor', and thus we cannot remove duplicate matches from
-- the output of an 'Axis'. For example, the element @\<div id="foo"/\>@ would
-- match twice on the selector @div,#foo@: once because it matches the element
-- name @"div"@, and once because it matches the ID @"foo"@.
--
-- Depending on your needs, you may wish to either carefully design your
-- selectors to avoid this, or to cull the results yourself, using a reasonable
-- notion of equality.
module Text.XML.Selectors.Parsers.JQ
( jq
, jqFile
, jqFile'
, jqString
, jqText
, jqString'
, jqText'
, errorBundlePretty
)
where

import Text.Megaparsec
import Text.Megaparsec.Char
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Text.XML.Selectors.Types
import Text.XML (Name)
import Data.String (IsString, fromString)
import Data.Char (isAlphaNum, isDigit)

-- | Parse from a stream, error information in 'Left' on failure.
jq :: (IsString (Tokens s), Stream s, Token s ~ Char)
    => String -- ^ Name of source file
    -> s -- ^ Input stream
    -> Either (ParseErrorBundle s Text) Selector
jq :: String -> s -> Either (ParseErrorBundle s Text) Selector
jq = Parsec Text s Selector
-> String -> s -> Either (ParseErrorBundle s Text) Selector
forall e s a.
Parsec e s a -> String -> s -> Either (ParseErrorBundle s e) a
parse Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
jqSelector

-- | Parse from an unnamed 'String' input stream, error information in 'Left' on failure.
jqString :: String -- ^ Input stream
         -> Either (ParseErrorBundle String Text) Selector
jqString :: String -> Either (ParseErrorBundle String Text) Selector
jqString = String -> String -> Either (ParseErrorBundle String Text) Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
String -> s -> Either (ParseErrorBundle s Text) Selector
jq String
"<input>"

-- | Parse from an unnamed 'String' input stream, 'error' on failure.
jqString' :: String -- ^ Input stream
          -> Selector
jqString' :: String -> Selector
jqString' = (ParseErrorBundle String Text -> Selector)
-> (Selector -> Selector)
-> Either (ParseErrorBundle String Text) Selector
-> Selector
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Selector
forall a. HasCallStack => String -> a
error (String -> Selector)
-> (ParseErrorBundle String Text -> String)
-> ParseErrorBundle String Text
-> Selector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle String Text -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
errorBundlePretty) Selector -> Selector
forall a. a -> a
id (Either (ParseErrorBundle String Text) Selector -> Selector)
-> (String -> Either (ParseErrorBundle String Text) Selector)
-> String
-> Selector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> Either (ParseErrorBundle String Text) Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
String -> s -> Either (ParseErrorBundle s Text) Selector
jq String
"<input>"

-- | Parse from an unnamed 'Text' input stream, error information in 'Left' on failure.
jqText :: Text -- ^ Input stream
       -> Either (ParseErrorBundle Text Text) Selector
jqText :: Text -> Either (ParseErrorBundle Text Text) Selector
jqText = String -> Text -> Either (ParseErrorBundle Text Text) Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
String -> s -> Either (ParseErrorBundle s Text) Selector
jq String
"<input>"

-- | Parse from an unnamed 'Text' input stream, 'error' on failure.
jqText' :: Text -- ^ Input stream
        -> Selector
jqText' :: Text -> Selector
jqText' = (ParseErrorBundle Text Text -> Selector)
-> (Selector -> Selector)
-> Either (ParseErrorBundle Text Text) Selector
-> Selector
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Selector
forall a. HasCallStack => String -> a
error (String -> Selector)
-> (ParseErrorBundle Text Text -> String)
-> ParseErrorBundle Text Text
-> Selector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle Text Text -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
errorBundlePretty) Selector -> Selector
forall a. a -> a
id (Either (ParseErrorBundle Text Text) Selector -> Selector)
-> (Text -> Either (ParseErrorBundle Text Text) Selector)
-> Text
-> Selector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text -> Either (ParseErrorBundle Text Text) Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
String -> s -> Either (ParseErrorBundle s Text) Selector
jq String
"<input>"

-- | Parse from a file input stream, error information in 'Left' on failure.
jqFile :: FilePath
       -> IO (Either (ParseErrorBundle Text Text) Selector)
jqFile :: String -> IO (Either (ParseErrorBundle Text Text) Selector)
jqFile String
fn = do
  String -> Text -> Either (ParseErrorBundle Text Text) Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
String -> s -> Either (ParseErrorBundle s Text) Selector
jq String
fn (Text -> Either (ParseErrorBundle Text Text) Selector)
-> IO Text -> IO (Either (ParseErrorBundle Text Text) Selector)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> IO Text
Text.readFile String
fn

-- | Parse from a file input stream, throw a 'UserError' in 'IO' on failure.
jqFile' :: FilePath
        -> IO Selector
jqFile' :: String -> IO Selector
jqFile' String
fn =
  String -> IO (Either (ParseErrorBundle Text Text) Selector)
jqFile String
fn IO (Either (ParseErrorBundle Text Text) Selector)
-> (Either (ParseErrorBundle Text Text) Selector -> IO Selector)
-> IO Selector
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ParseErrorBundle Text Text -> IO Selector)
-> (Selector -> IO Selector)
-> Either (ParseErrorBundle Text Text) Selector
-> IO Selector
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> IO Selector
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO Selector)
-> (ParseErrorBundle Text Text -> String)
-> ParseErrorBundle Text Text
-> IO Selector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle Text Text -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
errorBundlePretty) Selector -> IO Selector
forall (m :: * -> *) a. Monad m => a -> m a
return


instance ShowErrorComponent Text where
  showErrorComponent :: Text -> String
showErrorComponent = Text -> String
Text.unpack

jqSelector :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
jqSelector :: Parsec Text s Selector
jqSelector = ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
choices Parsec Text s Selector
-> ParsecT Text s Identity () -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space Parsec Text s Selector
-> ParsecT Text s Identity () -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof

choices :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
choices :: Parsec Text s Selector
choices = do
  [Selector]
xs <- Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item Parsec Text s Selector
-> ParsecT Text s Identity Char
-> ParsecT Text s Identity [Selector]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepBy` (ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
',' ParsecT Text s Identity Char
-> ParsecT Text s Identity () -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space)
  case [Selector]
xs of
    [] -> Selector -> Parsec Text s Selector
forall (m :: * -> *) a. Monad m => a -> m a
return Selector
None
    [Selector
x] -> Selector -> Parsec Text s Selector
forall (m :: * -> *) a. Monad m => a -> m a
return Selector
x
    [Selector]
_ -> Selector -> Parsec Text s Selector
forall (m :: * -> *) a. Monad m => a -> m a
return (Selector -> Parsec Text s Selector)
-> Selector -> Parsec Text s Selector
forall a b. (a -> b) -> a -> b
$ [Selector] -> Selector
Choice [Selector]
xs

item :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
item :: Parsec Text s Selector
item = do
  Selector
what <- Selector -> Parsec Text s Selector -> Parsec Text s Selector
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option Selector
Any (Parsec Text s Selector
forall s. (Stream s, Token s ~ Char) => Parsec Text s Selector
anyElem Parsec Text s Selector
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parsec Text s Selector -> Parsec Text s Selector
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parsec Text s Selector
forall s. (Stream s, Token s ~ Char) => Parsec Text s Selector
elemName)
  [Selector]
qualifiers <- Parsec Text s Selector -> ParsecT Text s Identity [Selector]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
qualifier
  Maybe Selector
mcont <- Parsec Text s Selector -> ParsecT Text s Identity (Maybe Selector)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
continuation
  let self :: Selector
self = [Selector] -> Selector
forall a. Monoid a => [a] -> a
mconcat (Selector
what Selector -> [Selector] -> [Selector]
forall a. a -> [a] -> [a]
: [Selector]
qualifiers)
  case Maybe Selector
mcont of
    Maybe Selector
Nothing -> Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Applicative f => a -> f a
pure Selector
self
    Just Selector
cont -> Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Selector -> Parsec Text s Selector)
-> Selector -> Parsec Text s Selector
forall a b. (a -> b) -> a -> b
$ Selector
self Selector -> Selector -> Selector
forall a. Semigroup a => a -> a -> a
<> Selector
cont

anyElem :: (Stream s, Token s ~ Char) => Parsec Text s Selector
anyElem :: Parsec Text s Selector
anyElem = Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'*' ParsecT Text s Identity Char
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Applicative f => a -> f a
pure Selector
Any

elemName :: (Stream s, Token s ~ Char) => Parsec Text s Selector
elemName :: Parsec Text s Selector
elemName = Name -> Selector
Elem (Name -> Selector)
-> ParsecT Text s Identity Name -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text s Identity Name
forall n s.
(IsString n, Stream s, Token s ~ Char) =>
Parsec Text s n
name

name :: (IsString n, Stream s, Token s ~ Char) => Parsec Text s n
name :: Parsec Text s n
name = String -> n
forall a. IsString a => String -> a
fromString (String -> n) -> ParsecT Text s Identity String -> Parsec Text s n
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text s Identity Char -> ParsecT Text s Identity String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some ParsecT Text s Identity Char
forall s. (Stream s, Token s ~ Char) => Parsec Text s Char
nameChar

nameChar :: (Stream s, Token s ~ Char) => Parsec Text s Char
nameChar :: Parsec Text s Char
nameChar = (Token s -> Bool) -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy Char -> Bool
Token s -> Bool
isNameChar

isNameChar :: Char -> Bool
isNameChar :: Char -> Bool
isNameChar Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| (Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'_', Char
'-'])

continuation :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
continuation :: Parsec Text s Selector
continuation = [Parsec Text s Selector] -> Parsec Text s Selector
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
  [ Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
child
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
sibling
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
nextSibling
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
descendant
  ]

descendant :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
descendant :: Parsec Text s Selector
descendant = ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space1 ParsecT Text s Identity ()
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Selector
Descendant Selector -> Selector -> Selector
forall a. Semigroup a => a -> a -> a
<>) (Selector -> Selector)
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item)

child :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
child :: Parsec Text s Selector
child = ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'>' ParsecT Text s Identity Char
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space) ParsecT Text s Identity ()
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Selector
Child Selector -> Selector -> Selector
forall a. Semigroup a => a -> a -> a
<>) (Selector -> Selector)
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item)

sibling :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
sibling :: Parsec Text s Selector
sibling = ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'~' ParsecT Text s Identity Char
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space) ParsecT Text s Identity ()
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Selector
Sibling Selector -> Selector -> Selector
forall a. Semigroup a => a -> a -> a
<>) (Selector -> Selector)
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item)

nextSibling :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
nextSibling :: Parsec Text s Selector
nextSibling = ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'+' ParsecT Text s Identity Char
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space) ParsecT Text s Identity ()
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Selector
NextSibling Selector -> Selector -> Selector
forall a. Semigroup a => a -> a -> a
<>) (Selector -> Selector)
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item)

qualifier :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
qualifier :: Parsec Text s Selector
qualifier = [Parsec Text s Selector] -> Parsec Text s Selector
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
  [ Parsec Text s Selector
forall s. (Stream s, Token s ~ Char) => Parsec Text s Selector
classAttrib
  , Parsec Text s Selector
forall s. (Stream s, Token s ~ Char) => Parsec Text s Selector
idAttrib
  , Parsec Text s Selector
forall s. (Stream s, Token s ~ Char) => Parsec Text s Selector
attribSelector
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
firstChild
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
nthChild
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
nthLastChild
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
having
  , Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
not_
  ]

classAttrib :: (Stream s, Token s ~ Char) => Parsec Text s Selector
classAttrib :: Parsec Text s Selector
classAttrib = do
  Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'.'
  Text
value <- Parsec Text s Text
forall n s.
(IsString n, Stream s, Token s ~ Char) =>
Parsec Text s n
name
  Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Selector -> Parsec Text s Selector)
-> Selector -> Parsec Text s Selector
forall a b. (a -> b) -> a -> b
$ AttribSelector -> Selector
Attrib (Name -> Text -> AttribSelector
AttribContainsWord Name
"class" Text
value)

idAttrib :: (Stream s, Token s ~ Char) => Parsec Text s Selector
idAttrib :: Parsec Text s Selector
idAttrib = do
  Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'#'
  Text
value <- Parsec Text s Text
forall n s.
(IsString n, Stream s, Token s ~ Char) =>
Parsec Text s n
name
  Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Selector -> Parsec Text s Selector)
-> Selector -> Parsec Text s Selector
forall a b. (a -> b) -> a -> b
$ AttribSelector -> Selector
Attrib (Name -> Text -> AttribSelector
AttribIs Name
"id" Text
value)

attribSelector :: (Stream s, Token s ~ Char) => Parsec Text s Selector
attribSelector :: Parsec Text s Selector
attribSelector = do
  Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'['
  Name
aname <- Parsec Text s Name
forall n s.
(IsString n, Stream s, Token s ~ Char) =>
Parsec Text s n
name
  Maybe (Name -> Text -> AttribSelector)
mop <- ParsecT Text s Identity (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity (Maybe (Name -> Text -> AttribSelector))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT Text s Identity (Name -> Text -> AttribSelector)
forall s.
(Stream s, Token s ~ Char) =>
Parsec Text s (Name -> Text -> AttribSelector)
attribOp
  AttribSelector
asel <- case Maybe (Name -> Text -> AttribSelector)
mop of
    Maybe (Name -> Text -> AttribSelector)
Nothing -> AttribSelector -> ParsecT Text s Identity AttribSelector
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AttribSelector -> ParsecT Text s Identity AttribSelector)
-> AttribSelector -> ParsecT Text s Identity AttribSelector
forall a b. (a -> b) -> a -> b
$ Name -> AttribSelector
AttribExists Name
aname
    Just Name -> Text -> AttribSelector
op -> Name -> Text -> AttribSelector
op Name
aname (Text -> AttribSelector)
-> ParsecT Text s Identity Text
-> ParsecT Text s Identity AttribSelector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text s Identity Text
forall n s.
(IsString n, Stream s, Token s ~ Char) =>
Parsec Text s n
quotedStr ParsecT Text s Identity Text
-> ParsecT Text s Identity Text -> ParsecT Text s Identity Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT Text s Identity Text
forall n s.
(IsString n, Stream s, Token s ~ Char) =>
Parsec Text s n
name)
  Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
']'
  Selector -> Parsec Text s Selector
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Selector -> Parsec Text s Selector)
-> Selector -> Parsec Text s Selector
forall a b. (a -> b) -> a -> b
$ AttribSelector -> Selector
Attrib AttribSelector
asel

attribOp :: (Stream s, Token s ~ Char) => Parsec Text s (Name -> Text -> AttribSelector)
attribOp :: Parsec Text s (Name -> Text -> AttribSelector)
attribOp = [Parsec Text s (Name -> Text -> AttribSelector)]
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
  [ Name -> Text -> AttribSelector
AttribIs (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  , Name -> Text -> AttribSelector
AttribIsNot (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'!' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  , Name -> Text -> AttribSelector
AttribStartsWith (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'^' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  , Name -> Text -> AttribSelector
AttribEndsWith (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'$' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  , Name -> Text -> AttribSelector
AttribContains (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'*' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  , Name -> Text -> AttribSelector
AttribContainsWord (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'~' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  , Name -> Text -> AttribSelector
AttribContainsPrefix (Name -> Text -> AttribSelector)
-> ParsecT Text s Identity Char
-> Parsec Text s (Name -> Text -> AttribSelector)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'|' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'=')
  ]

quotedStr :: (IsString v, Stream s, Token s ~ Char) => Parsec Text s v
quotedStr :: Parsec Text s v
quotedStr = do
  Char
quoteSym <- Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'"' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'\''
  String
val <- ParsecT Text s Identity Char -> ParsecT Text s Identity String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many ((Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'\\' ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Token s -> Bool) -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy (Bool -> Char -> Bool
forall a b. a -> b -> a
const Bool
True)) ParsecT Text s Identity Char
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((Token s -> Bool) -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
quoteSym)))
  Char
_ <- Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
quoteSym
  v -> Parsec Text s v
forall (f :: * -> *) a. Applicative f => a -> f a
pure (v -> Parsec Text s v) -> v -> Parsec Text s v
forall a b. (a -> b) -> a -> b
$ String -> v
forall a. IsString a => String -> a
fromString String
val

firstChild :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
firstChild :: Parsec Text s Selector
firstChild = Selector
FirstChild Selector
-> ParsecT Text s Identity (Tokens s) -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Tokens s -> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens s
":first-child") Parsec Text s Selector
-> ParsecT Text s Identity () -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity Char -> ParsecT Text s Identity ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy ParsecT Text s Identity Char
forall s. (Stream s, Token s ~ Char) => Parsec Text s Char
nameChar

lastChild :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
lastChild :: Parsec Text s Selector
lastChild = Selector
LastChild Selector
-> ParsecT Text s Identity (Tokens s) -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Tokens s -> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens s
":last-child") Parsec Text s Selector
-> ParsecT Text s Identity () -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity Char -> ParsecT Text s Identity ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy ParsecT Text s Identity Char
forall s. (Stream s, Token s ~ Char) => Parsec Text s Char
nameChar

nthChild :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
nthChild :: Parsec Text s Selector
nthChild = do
  Int -> Selector
NthChild (Int -> Selector)
-> ParsecT Text s Identity Int -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Tokens s -> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens s
":nth-child") ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'(' ParsecT Text s Identity Char
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Int -> ParsecT Text s Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity Int
forall s. (Stream s, Token s ~ Char) => Parsec Text s Int
positiveInt ParsecT Text s Identity Int
-> ParsecT Text s Identity () -> ParsecT Text s Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity Int
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
')')

nthLastChild :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
nthLastChild :: Parsec Text s Selector
nthLastChild = do
  Int -> Selector
NthChild (Int -> Selector) -> (Int -> Int) -> Int -> Selector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Num a => a -> a
negate (Int -> Selector)
-> ParsecT Text s Identity Int -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Tokens s -> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens s
":nth-last-child") ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'(' ParsecT Text s Identity Char
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Int -> ParsecT Text s Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity Int
forall s. (Stream s, Token s ~ Char) => Parsec Text s Int
positiveInt ParsecT Text s Identity Int
-> ParsecT Text s Identity () -> ParsecT Text s Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity Int
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
')')

positiveInt :: (Stream s, Token s ~ Char) => Parsec Text s Int
positiveInt :: Parsec Text s Int
positiveInt = String -> Int
forall a. Read a => String -> a
read (String -> Int)
-> ParsecT Text s Identity String -> Parsec Text s Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text s Identity Char -> ParsecT Text s Identity String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some ParsecT Text s Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar

having :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
having :: Parsec Text s Selector
having = ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Tokens s -> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens s
":has") ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'(' ParsecT Text s Identity Char
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Selector -> Selector
Having (Selector -> Selector)
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item) Parsec Text s Selector
-> ParsecT Text s Identity Char -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
')'

not_ :: (IsString (Tokens s), Stream s, Token s ~ Char) => Parsec Text s Selector
not_ :: Parsec Text s Selector
not_ = ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Tokens s -> ParsecT Text s Identity (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens s
":not") ParsecT Text s Identity (Tokens s)
-> ParsecT Text s Identity () -> ParsecT Text s Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text s Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space ParsecT Text s Identity ()
-> ParsecT Text s Identity Char -> ParsecT Text s Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
'(' ParsecT Text s Identity Char
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Selector -> Selector
Not (Selector -> Selector)
-> Parsec Text s Selector -> Parsec Text s Selector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text s Selector
forall s.
(IsString (Tokens s), Stream s, Token s ~ Char) =>
Parsec Text s Selector
item) Parsec Text s Selector
-> ParsecT Text s Identity Char -> Parsec Text s Selector
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Token s -> ParsecT Text s Identity (Token s)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token s
')'