Exemplo n.º 1
0
        private static bool TryParseSimpleSelector(CssStringStreamReader reader, out CssSimpleSelector selector)
        {
            selector = null;
            reader.SkipWhitespaceAndComments();

            switch (reader.CurrentChar)
            {
            case '#':
                reader.Advance();
                return
                    (reader.TryReadIdentifier(out var id) &&
                     TryParseSimpleSelector(reader, CssSimpleSelectorType.IdSelector, new CssQualifiedName(id), out selector));

            case '.':
                reader.Advance();
                return
                    (reader.TryReadIdentifier(out var className) &&
                     TryParseSimpleSelector(reader, CssSimpleSelectorType.ClassSelector, new CssQualifiedName(className), out selector));

            case '*':
                reader.Advance();
                return(TryParseUniversalSelector(reader, out selector));

            case '[':
            case ':':
                return(TryParseUniversalSelector(reader, out selector));

            default:
                return
                    (reader.TryReadQualifiedName(out var typeName) &&
                     TryParseSimpleSelector(reader, CssSimpleSelectorType.TypeSelector, typeName, out selector));
            }
        }
Exemplo n.º 2
0
        public virtual void VisitSimpleSelector(CssSimpleSelector selector)
        {
            switch (selector?.SimpleSelectorType)
            {
            case CssSimpleSelectorType.TypeSelector:
                VisitTypeSelector(selector);
                break;

            case CssSimpleSelectorType.UniversalSelector:
                VisitUniversalSelector(selector);
                break;

            case CssSimpleSelectorType.ClassSelector:
                VisitClassSelector(selector);
                break;

            case CssSimpleSelectorType.IdSelector:
                VisitIdSelector(selector);
                break;

            case null:
                DefaultVisit(null);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(selector), $"Unknown simple selector type '{selector.SimpleSelectorType}'");
            }
            DefaultVisitList(selector?.AttributeSelectors);
        }
Exemplo n.º 3
0
        private static bool TryParseSimpleSelector(CssStringStreamReader reader, CssSimpleSelectorType simpleSelectorType, CssQualifiedName name, out CssSimpleSelector selector)
        {
            var attributeSelectors = ParseAttributeSelectors(reader);
            var pseudoClasses      = ParsePseudoClasses(reader);

            if (attributeSelectors == null || pseudoClasses == null)
            {
                selector = null;
                return(false);
            }
            selector = new CssSimpleSelector(simpleSelectorType, name, attributeSelectors, pseudoClasses);
            return(true);
        }
Exemplo n.º 4
0
 private static bool TryParseUniversalSelector(CssStringStreamReader reader, out CssSimpleSelector selector)
 => TryParseSimpleSelector(reader, CssSimpleSelectorType.UniversalSelector, new CssQualifiedName("*"), out selector);
Exemplo n.º 5
0
 public virtual void VisitUniversalSelector(CssSimpleSelector selector)
 => DefaultVisit(selector);
Exemplo n.º 6
0
 public virtual void VisitTypeSelector(CssSimpleSelector selector)
 => DefaultVisit(selector);