コード例 #1
0
        private TypeSelector ParseTypeSelector()
        {
            TypeSelector            selector = null;
            SelectorNamespacePrefix prefix   = ParseNamespacePrefix();

            if (CurrentToken != null && CurrentToken.TokenType == SelectorTokenType.Ident)
            {
                selector = new TypeSelector(CurrentToken.Text, prefix);
                currentPosition++;
            }

            return(selector);
        }
コード例 #2
0
        private TypeSelector ParseUniversalSelector()
        {
            TypeSelector            selector = null;
            SelectorNamespacePrefix prefix   = ParseNamespacePrefix();

            if (CurrentToken != null && CurrentToken.Text == "*")
            {
                selector = new UniversalSelector(prefix);
                currentPosition++;
            }

            return(selector);
        }
コード例 #3
0
        private SelectorNamespacePrefix ParseNamespacePrefix()
        {
            SelectorNamespacePrefix prefix = null;

            if (CurrentToken != null)
            {
                if (CurrentToken.TokenType == SelectorTokenType.Ident)
                {
                    string ident = CurrentToken.Text;
                    currentPosition++;
                    if (CurrentToken == null)
                    {
                        currentPosition--;
                    }
                    else if (CurrentToken.Text == "|")
                    {
                        prefix = new SelectorNamespacePrefix(ident);
                        currentPosition++;
                    }
                    else
                    {
                        currentPosition--;
                    }
                }
                else if (CurrentToken.Text == "*")
                {
                    currentPosition++;
                    if (CurrentToken == null)
                    {
                        currentPosition--;
                    }
                    else if (CurrentToken.Text == "|")
                    {
                        prefix = new SelectorNamespacePrefix("*");
                        currentPosition++;
                    }
                    else
                    {
                        currentPosition--;
                    }
                }
                else if (CurrentToken.Text == "|")
                {
                    //TODO: is this supposed to mean universal selector?
                    prefix = new SelectorNamespacePrefix("");
                    currentPosition++;
                }
            }
            return(prefix);
        }
コード例 #4
0
        private SelectorNamespacePrefix ParseNamespacePrefix()
        {
            SelectorNamespacePrefix prefix = null;

            if (CurrentToken != null)
            {
                if (CurrentToken.TokenType == SelectorTokenType.Ident)
                {
                    string ident = CurrentToken.Text;
                    currentPosition++;
                    if (CurrentToken == null)
                    {
                        currentPosition--;
                    }
                    else if (CurrentToken.Text == "|")
                    {
                        prefix = new SelectorNamespacePrefix(ident);
                        currentPosition++;
                    }
                    else
                    {
                        currentPosition--;
                    }
                }
                else if (CurrentToken.Text == "*")
                {
                    currentPosition++;
                    if (CurrentToken == null)
                    {
                        currentPosition--;
                    }
                    else if (CurrentToken.Text == "|")
                    {
                        prefix = new SelectorNamespacePrefix("*");
                        currentPosition++;
                    }
                    else
                    {
                        currentPosition--;
                    }
                }
                else if (CurrentToken.Text == "|")
                {
                    //TODO: is this supposed to mean universal selector?
                    prefix = new SelectorNamespacePrefix("");
                    currentPosition++;
                }
            }
            return prefix;
        }
コード例 #5
0
ファイル: TypeSelector.cs プロジェクト: Nord001/htmlsharp
 public TypeSelector(string name, SelectorNamespacePrefix prefix)
     : this(name)
 {
     this.Namespace = prefix;
 }
コード例 #6
0
 public UniversalSelector(SelectorNamespacePrefix prefix)
     : base("*", prefix)
 {
 }
コード例 #7
0
        private IFilter ParseAttributeFilter()
        {
            IFilter selector = null;

            if (CurrentToken.Text == "[")
            {
                currentPosition++;
                SkipWhiteSpace();
                SelectorNamespacePrefix ns = ParseNamespacePrefix();
                string attributeType       = Consume(SelectorTokenType.Ident);
                SkipWhiteSpace();
                var filterLookup = new Dictionary <SelectorToken, Func <string, IFilter> >()
                {
                    { new  SelectorToken(SelectorTokenType.PrefixMatch, "^="),
                      text => new AttributePrefixFilter(attributeType, text) },
                    { new SelectorToken(SelectorTokenType.SuffixMatch, "$="),
                      text => new AttributeSuffixFilter(attributeType, text) },
                    { new SelectorToken(SelectorTokenType.SubstringMatch, "*="),
                      text => new AttributeSubstringFilter(attributeType, text) },
                    { new SelectorToken(SelectorTokenType.Text, "="),
                      text => new AttributeExactFilter(attributeType, text) },
                    { new SelectorToken(SelectorTokenType.Includes, "~="),
                      text => new AttributeIncludesFilter(attributeType, text) },
                    { new SelectorToken(SelectorTokenType.DashMatch, "|="),
                      text => new AttributeDashFilter(attributeType, text) }
                };
                if (filterLookup.ContainsKey(CurrentToken))
                {
                    SelectorToken token = CurrentToken;
                    currentPosition++;
                    SkipWhiteSpace();
                    if (CurrentToken.TokenType == SelectorTokenType.Ident)
                    {
                        selector = filterLookup[token](CurrentToken.Text);
                    }
                    else if (CurrentToken.TokenType == SelectorTokenType.String)
                    {
                        selector = filterLookup[token](CurrentToken.Text.Substring(1, CurrentToken.Text.Length - 2));
                    }
                    else
                    {
                        ParseError("Unexpected token type for attribute matcher");
                    }
                    currentPosition++;
                    SkipWhiteSpace();
                }
                else
                {
                    Expect("]");
                }

                if (CurrentToken.Text == "]" && selector == null)
                {
                    selector = new AttributeFilter(attributeType);
                    currentPosition++;
                }
                else if (CurrentToken.Text == "]" && selector != null)
                {
                    currentPosition++;
                }
                else
                {
                    //parse error lolz
                }
            }

            return(selector);
        }
コード例 #8
0
 public TypeSelector(string name, SelectorNamespacePrefix prefix)
     : this(name)
 {
     this.Namespace = prefix;
 }
コード例 #9
0
 public UniversalSelector(SelectorNamespacePrefix prefix)
     : base("*", prefix)
 {
 }