Наследование: IPosition, IWritable
Пример #1
0
        public AdjacentSiblingSelector(Selector older, Selector younger, int start, int stop, string filePath)
        {
            Older = older;
            Younger = younger;

            Start = start;
            Stop = stop;
            FilePath = filePath;
        }
Пример #2
0
        public IncludeSelectorProperty(Selector selector, bool overrides, int start, int stop, string file)
        {
            Selector = selector;

            Overrides = overrides;

            Start = start;
            Stop = stop;
            FilePath = file;
        }
Пример #3
0
        internal NotPseudoClassSelector(Selector sel, int start, int stop, string filePath)
            : base("not")
        {
            Selector = sel;

            Start = start;
            Stop = stop;
            FilePath = filePath;
        }
Пример #4
0
 public ConcatWithParentSelector(Selector sel, int start, int stop, string filePath)
 {
     Selector = sel;
     Start = start;
     Stop = stop;
     FilePath = filePath;
 }
Пример #5
0
        public static Selector CombineSelectors(Selector outer, Selector inner, int start, int stop, string filePath)
        {
            if (outer is MultiSelector) throw new InvalidOperationException("Cannot combine MultiSelectors, outer was a MultiSelector");
            if (inner is MultiSelector) throw new InvalidOperationException("Cannot combine MultiSelectors, inner was a MultiSelector");

            var outerConcat = outer as ConcatWithParentSelector;
            var innerConcat = inner as ConcatWithParentSelector;

            if (outerConcat == null && innerConcat == null) return new CompoundSelector(outer, inner, start, stop, filePath);

            if (outerConcat == null)
            {
                return new ConcatSelector(new List<Selector>(){outer, innerConcat.Selector}, start, stop, filePath);
            }

            if (innerConcat == null)
            {
                return new ConcatWithParentSelector(new CompoundSelector(outerConcat.Selector, inner, start, stop, filePath), start, stop, filePath);
            }

            return new ConcatWithParentSelector(new ConcatSelector(new List<Selector>() { outerConcat.Selector, innerConcat.Selector }, start, stop, filePath), start, stop, filePath);
        }
Пример #6
0
        private CompoundSelector(Selector outer, Selector inner, int start, int stop, string filePath)
        {
            Outer = outer;
            Inner = inner;

            Start = start;
            Stop = stop;
            FilePath = filePath;
        }
Пример #7
0
        public ChildSelector(Selector parent, Selector child, int start, int stop, string filePath)
        {
            Parent = parent;
            Child = child;

            Start = start;
            Stop = stop;
            FilePath = filePath;
        }
Пример #8
0
        internal ResetProperty(Selector sel, int start, int stop, string file)
        {
            Selector = sel;

            Start = start;
            Stop = stop;
            FilePath = file;
        }
Пример #9
0
        /// <summary>
        /// Reverses the transformation applied by BuildEscapeMap on a selector.
        /// </summary>
        private static Selector ApplyEscapeMap(Selector sel, Dictionary<char, string> map)
        {
            // shortcircuit the typical case
            if (map.Count == 0) return sel;

            var multi = sel as MultiSelector;
            if (multi != null)
            {
                var ret = multi.Selectors.Select(s => ApplyEscapeMap(s, map)).ToList();
                return new MultiSelector(ret, multi.Start, multi.Stop, multi.FilePath);
            }

            var childSel = sel as ChildSelector;
            if (childSel != null)
            {
                var parent = ApplyEscapeMap(childSel.Parent, map);
                var child = ApplyEscapeMap(childSel.Child, map);

                return new ChildSelector(parent, child, childSel.Start, childSel.Stop, childSel.FilePath);
            }

            var sibling = sel as AdjacentSiblingSelector;
            if(sibling != null)
            {
                var older = ApplyEscapeMap(sibling.Older, map);
                var younger = ApplyEscapeMap(sibling.Younger, map);

                return new AdjacentSiblingSelector(older, younger, sibling.Start, sibling.Stop, sibling.FilePath);
            }

            var compound = sel as CompoundSelector;
            if (compound != null)
            {
                var inner = ApplyEscapeMap(compound.Inner, map);
                var outer = ApplyEscapeMap(compound.Outer, map);

                return new CompoundSelector(inner, outer, compound.Start, compound.Stop, compound.FilePath);
            }

            var concat = sel as ConcatWithParentSelector;
            if (concat != null)
            {
                var subSel = ApplyEscapeMap(concat.Selector, map);

                return new ConcatWithParentSelector(subSel, concat.Start, concat.Stop, concat.FilePath);
            }

            var attrOp = sel as AttributeOperatorSelector;
            if (attrOp != null)
            {
                var attr = ApplyEscapeMap(attrOp.Attribute, map);
                var value = ApplyEscapeMap(attrOp.Value, map);

                return new AttributeOperatorSelector(attr, attrOp.Operator, value, attrOp.Start, attrOp.Stop, attrOp.FilePath);
            }

            var attrSet = sel as AttributeSetSelector;
            if (attrSet != null)
            {
                var attr = ApplyEscapeMap(attrSet.Attribute, map);

                return new AttributeSetSelector(attr, attrSet.Start, attrSet.Stop, attrSet.FilePath);
            }

            var @class = sel as ClassSelector;
            if (@class != null)
            {
                var className = ApplyEscapeMap(@class.Name, map);

                return new ClassSelector(className, @class.Start, @class.Stop, @class.FilePath);
            }

            var concatSel = sel as ConcatSelector;
            if (concatSel != null)
            {
                var sels = concatSel.Selectors.Select(s => ApplyEscapeMap(s, map)).ToList();

                return new ConcatSelector(sels, concatSel.Start, concatSel.Stop, concatSel.FilePath);
            }

            var elem = sel as ElementSelector;
            if (elem != null)
            {
                var name = ApplyEscapeMap(elem.Name, map);

                return new ElementSelector(name, elem.Start, elem.Stop, elem.FilePath);
            }

            var id = sel as IdSelector;
            if (id != null)
            {
                var name = ApplyEscapeMap(id.Name, map);

                return new IdSelector(name, id.Start, id.Stop, id.FilePath);
            }

            var langSel = sel as LangPseudoClassSelector;
            if (langSel != null)
            {
                var lang = ApplyEscapeMap(langSel.Language, map);

                return new LangPseudoClassSelector(lang, langSel.Start, langSel.Stop, langSel.FilePath);
            }

            var not = sel as NotPseudoClassSelector;
            if (not != null)
            {
                var innerSel = ApplyEscapeMap(not.Selector, map);

                return new NotPseudoClassSelector(innerSel, not.Start, not.Stop, not.FilePath);
            }

            // You can't really escape and have valid versions of these selectors
            if (sel is NthChildPsuedoClassSelector || sel is NthLastChildPseudoClassSelector) return sel;

            // Likewise
            if (sel is NthOfTypePseudoClassSelector || sel is NthLastOfTypePseudoClassSelector) return sel;

            // Ditto
            if (sel is PseudoClassSelector) return sel;

            // And lucky #4
            if (sel is WildcardSelector) return sel;

            throw new InvalidOperationException(sel + " should have been handled but wasn't");
        }
Пример #10
0
        internal static List<Property> ParseCssRules(Selector selector, ParserStream stream)
        {
            var ret = new List<Property>();

            while (stream.HasMore() && stream.Peek() != '}')
            {
                var c = stream.Peek();

                if (char.IsWhiteSpace(c))
                {
                    stream.AdvancePastWhiteSpace();
                }
                else
                {
                    ret.Add(ParseRule(stream));
                }
            }

            stream.AdvancePast("}");
            return ret;
        }
Пример #11
0
        private static bool AreEqual(Selector knownSingle, Selector other)
        {
            var multiOther = other as MultiSelector;
            if (multiOther != null)
            {
                return multiOther.Selectors.Any(a => AreEqual(knownSingle, a));
            }

            if (knownSingle.GetType() != other.GetType()) return false;

            string knownStr, otherStr;
            using (var str = new StringWriter())
            {
                knownSingle.Write(str);
                knownStr = str.ToString();
            }

            using (var str = new StringWriter())
            {
                other.Write(str);
                otherStr = str.ToString();
            }

            return knownStr.Equals(otherStr, StringComparison.InvariantCultureIgnoreCase);
        }
Пример #12
0
        private static List<NameValueProperty> FindMatches(Selector sel, List<SelectorAndBlock> resetBlocks)
        {
            var ret = new List<NameValueProperty>();

            var multiSel = sel as MultiSelector;
            if(multiSel != null)
            {
                foreach (var part in multiSel.Selectors)
                {
                    ret.AddRange(FindMatches(part, resetBlocks));
                }

                return ret;
            }

            foreach (var block in resetBlocks)
            {
                if (AreEqual(sel, block.Selector))
                {
                    ret.AddRange(block.Properties.Cast<NameValueProperty>());
                }
            }

            return ret;
        }
Пример #13
0
        private static List<Selector> CombineSelectors(Selector s1, Selector s2, int start, int stop, string filePath)
        {
            var ret = new List<Selector>();

            if (!(s1 is MultiSelector) && !(s2 is MultiSelector))
            {
                var s2Child = s2 as ChildSelector;
                if (s2Child != null && s2Child.Parent == null)
                {
                    ret.Add(new ChildSelector(s1, s2Child.Child, start, stop, filePath));
                    return ret;
                }

                var s2Sibling = s2 as AdjacentSiblingSelector;
                if(s2Sibling != null && s2Sibling.Older == null)
                {
                    ret.Add(new AdjacentSiblingSelector(s1, s2Sibling.Younger, start, stop, filePath));
                    return ret;
                }

                ret.Add(CompoundSelector.CombineSelectors(s1, s2, start, stop, filePath));
                return ret;
            }

            var multi1 = s1 as MultiSelector;
            var multi2 = s2 as MultiSelector;

            var left = new List<Selector>();
            var right = new List<Selector>();

            if (multi1 != null)
            {
                left = multi1.Selectors.ToList();
            }
            else
            {
                left.Add(s1);
            }

            if (multi2 != null)
            {
                right = multi2.Selectors.ToList();
            }
            else
            {
                right.Add(s2);
            }

            foreach (var l in left)
            {
                foreach (var r in right)
                {
                    ret.AddRange(CombineSelectors(l, r, start, stop, filePath));
                }
            }

            return ret;
        }
Пример #14
0
 public ResetSelfProperty BindToSelector(Selector sel)
 {
     return new ResetSelfProperty(sel, Start, Stop, FilePath);
 }
Пример #15
0
 internal ResetSelfProperty(Selector effectiveSelector, int start, int stop, string file)
 {
     EffectiveSelector = effectiveSelector;
     Start = start;
     Stop = stop;
     FilePath = file;
 }
Пример #16
0
        public SelectorAndBlock(Selector selector, IEnumerable<Property> cssRules, IEnumerable<MoreVariable> resetContext, int start, int stop, string filePath)
        {
            Selector = selector;
            Properties = cssRules.ToList().AsReadOnly();
            ResetContext = resetContext != null ? resetContext.ToList().AsReadOnly() : null;

            Start = start;
            Stop = stop;
            FilePath = filePath;
        }
Пример #17
0
        private static List<Selector> CombineSelectors(Selector s1, Selector s2, int start, int stop, string filePath)
        {
            var ret = new List<Selector>();

            if (!(s1 is MultiSelector) && !(s2 is MultiSelector))
            {
                ret.Add(CompoundSelector.CombineSelectors(s1, s2, start, stop, filePath));
                return ret;
            }

            var multi1 = s1 as MultiSelector;
            var multi2 = s2 as MultiSelector;

            var left = new List<Selector>();
            var right = new List<Selector>();

            if (multi1 != null)
            {
                left = multi1.Selectors.ToList();
            }
            else
            {
                left.Add(s1);
            }

            if (multi2 != null)
            {
                right = multi2.Selectors.ToList();
            }
            else
            {
                right.Add(s2);
            }

            foreach (var l in left)
            {
                foreach (var r in right)
                {
                    ret.AddRange(CombineSelectors(l, r, start, stop, filePath));
                }
            }

            return ret;
        }
Пример #18
0
 public IncludeSelectorValue(Selector sel)
 {
     Selector = sel;
 }