CombineSelectors() public static méthode

public static CombineSelectors ( Selector outer, Selector inner, int start, int stop, string filePath ) : Selector
outer Selector
inner Selector
start int
stop int
filePath string
Résultat Selector
Exemple #1
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);
        }
Exemple #2
0
        private static Selector ParseRawSelector(string raw, int start, int stop, string filePath)
        {
            var escapeMap = BuildEscapeMap(ref raw);

            raw = raw.Trim();

            if (raw.Contains(','))
            {
                return(ApplyEscapeMap(ParseRawCommaDelimittedSelector(raw.Split(','), start, stop, filePath), escapeMap));
            }
            if (raw.Contains('>'))
            {
                return(ApplyEscapeMap(ParseRawChildSelector(raw.Split('>'), start, stop, filePath), escapeMap));
            }
            if (raw.Contains('+'))
            {
                return(ApplyEscapeMap(ParseRawSiblingSelector(raw.Split('+'), start, stop, filePath), escapeMap));
            }

            var parts = new List <Selector>();

            foreach (var x in raw.Split(' '))
            {
                if (x.Trim().Length == 0)
                {
                    continue;
                }

                parts.Add(ParseRawCompoundSelector(x, start, stop, filePath));
            }

            if (parts.Count == 0)
            {
                Current.RecordError(ErrorType.Parser, Position.Create(start, stop, filePath), "Expected selector");
                throw new StoppedParsingException();
            }

            if (parts.Count == 1)
            {
                return(ApplyEscapeMap(parts[0], escapeMap));
            }

            var ret = parts[parts.Count - 1];

            for (int i = parts.Count - 2; i >= 0; i--)
            {
                ret = CompoundSelector.CombineSelectors(parts[i], ret, start, stop, filePath);
            }

            return(ApplyEscapeMap(ret, escapeMap));
        }