Example #1
0
 public override SelectorMatcher GetCombinator(SelectorMatcher left)
 {
     // 14.2. Child combinator (>)
     // https://www.w3.org/TR/selectors-4/#child-combinators
     return((in SelectorMatcherContext ctx) =>
     {
         return ctx.Node.Parent != null && left(ctx.WithSyntaxNode(ctx.Node.Parent));
     });
Example #2
0
        public override SelectorMatcher GetMatcher()
        {
            SelectorMatcher matcher = (in SelectorMatcherContext ctx) => false;

            foreach (var selector in Children)
            {
                matcher = SelectorCompilerHelper.ComposeOr(SelectorCompiler.Compile(selector), matcher);
            }

            return(matcher);
        }
Example #3
0
        public override SelectorMatcher GetMatcher()
        {
            SelectorMatcher composedMatcher = (in SelectorMatcherContext _) => true;

            for (var i = Children.Count - 1; i >= 0; i--)
            {
                var child   = Children[i];
                var matcher = child.GetMatcher();
                composedMatcher = SelectorCompilerHelper.ComposeAnd(composedMatcher, matcher);
            }

            return(composedMatcher);
        }
Example #4
0
        public override SelectorMatcher GetMatcher()
        {
            SelectorMatcher matcher = (in SelectorMatcherContext _) => false;

            foreach (var selector in _relativeSelectors)
            {
                matcher = SelectorCompilerHelper.ComposeOr(matcher, selector.GetMatcher());
            }

            var query = new QulalySelector(matcher, this);

            return((in SelectorMatcherContext ctx) =>
            {
                return ctx.Node.QuerySelector(query) != null;
            });
Example #5
0
 public override SelectorMatcher GetCombinator(SelectorMatcher left)
 {
     // 14.1. Descendant combinator ( )
     // https://www.w3.org/TR/selectors-4/#descendant-combinators
     return((in SelectorMatcherContext ctx) =>
     {
         var parent = ctx.Node.Parent;
         while (parent != null)
         {
             if (left(ctx.WithSyntaxNode(parent)))
             {
                 return true;
             }
             parent = parent.Parent;
         }
         return false;
     });
Example #6
0
        public override SelectorMatcher GetCombinator(SelectorMatcher left)
        {
            // 14.3. Next-sibling combinator (+)
            // The elements represented by the two compound selectors share the same parent
            // in the document tree and the element represented by the first compound selector
            // immediately precedes the element represented by the second one.
            // https://www.w3.org/TR/selectors-4/#adjacent-sibling-combinators
            return((in SelectorMatcherContext ctx) =>
            {
                var node = ctx.Node;
                if (ctx.Node.Parent == null)
                {
                    return false;
                }

                var beforeNode = ctx.Node.Parent.ChildNodes().TakeWhile(x => x != node).LastOrDefault();
                return beforeNode != null && left(ctx.WithSyntaxNode(beforeNode));
            });
Example #7
0
        public override SelectorMatcher GetCombinator(SelectorMatcher left)
        {
            // Subsequent-sibling combinator (~)
            // The elements represented by the two compound selectors share the same parent
            // in the document tree and the element represented by the first compound selector
            // precedes (not necessarily immediately) the element represented by the second one.
            // https://www.w3.org/TR/selectors-4/#general-sibling-combinators
            return((in SelectorMatcherContext ctx) =>
            {
                var node = ctx.Node;
                if (ctx.Node.Parent == null)
                {
                    return false;
                }

                var beforeNodes = ctx.Node.Parent.ChildNodes().TakeWhile(x => x != node).ToList(); // before self.
                var ctx_ = ctx;
                return beforeNodes.Any(x => left(ctx_.WithSyntaxNode(x)));
            });
        public override void OnValueReady(CssLexer lexer)
        {
            // Create the set:
            List <SelectorMatcher> multi = new List <SelectorMatcher>();

            for (int i = 0; i < Count; i++)
            {
                // Read and add:
                SelectorMatcher sm = Css.CssLexer.ReadSelectorMatcher(this[i]);

                if (sm == null)
                {
                    // Entire any should be ignored.
                    return;
                }

                multi.Add(sm);
            }

            Matchers = multi.ToArray();
        }
Example #9
0
        public static SelectorMatcher Compile(SelectorElement selector)
        {
            SelectorMatcher composedMatcher = (in SelectorMatcherContext _) => true;

            if (selector is SelectorList <SelectorElement> selectorList)
            {
                for (var i = 0; i < selectorList.Children.Count; i++)
                {
                    var child = selectorList.Children[i];
                    if (child is Combinator combinator)
                    {
                        var matcher = combinator.GetCombinator(composedMatcher);
                        composedMatcher = SelectorCompilerHelper.ComposeAnd(matcher, Compile(selectorList.Children[i + 1]));
                    }
                    else if (child is Selector childSelector)
                    {
                        var matcher = childSelector.GetMatcher();
                        composedMatcher = SelectorCompilerHelper.ComposeAnd(composedMatcher, matcher);
                    }
                }
            }

            return(composedMatcher);
        }
Example #10
0
 public static SelectorMatcher ComposeOr(SelectorMatcher left, SelectorMatcher right)
 {
     return((in SelectorMatcherContext ctx) => right(ctx) || left(ctx));
 }
Example #11
0
 public QulalySelector(SelectorMatcher matcher, Selector selector)
 {
     Matcher  = matcher;
     Selector = selector;
 }
Example #12
0
 private static bool MatchesOnVisualTree(SelectorMatcher lastFragment)
 {
     return(lastFragment.Type == CssParsing.CssNodeType.PseudoSelector &&
            lastFragment.Text == ":visualtree");
 }
Example #13
0
 public abstract SelectorMatcher GetCombinator(SelectorMatcher left);