Exemplo n.º 1
0
        void Attrib()
        {
            //attrib
            //  : '[' S* [ namespace_prefix ]? IDENT S*
            //        [ [ PREFIXMATCH |
            //            SUFFIXMATCH |
            //            SUBSTRINGMATCH |
            //            '=' |
            //            INCLUDES |
            //            DASHMATCH ] S* [ IDENT | STRING ] S*
            //        ]? ']'
            //  ;

            Read(ToTokenSpec(Token.LeftBracket()));
            var prefix = TryNamespacePrefix() ?? NamespacePrefix.None;
            var name   = Read(ToTokenSpec(TokenKind.Ident)).Text;

            var hasValue = false;

            while (true)
            {
                var op = TryRead(TokenSpecs.Equals_Includes_DashMatch_PrefixMatch_SuffixMatch_SubstringMatch);

                if (op == null)
                {
                    break;
                }

                hasValue = true;
                var value = Read(TokenSpecs.String_Ident).Text;

                if (op.Value == Token.Equals())
                {
                    _generator.AttributeExact(prefix, name, value);
                }
                else
                {
                    switch (op.Value.Kind)
                    {
                    case TokenKind.Includes: _generator.AttributeIncludes(prefix, name, value); break;

                    case TokenKind.DashMatch: _generator.AttributeDashMatch(prefix, name, value); break;

                    case TokenKind.PrefixMatch: _generator.AttributePrefixMatch(prefix, name, value); break;

                    case TokenKind.SuffixMatch: _generator.AttributeSuffixMatch(prefix, name, value); break;

                    case TokenKind.SubstringMatch: _generator.AttributeSubstring(prefix, name, value); break;
                    }
                }
            }

            if (!hasValue)
            {
                _generator.AttributeExists(prefix, name);
            }

            Read(ToTokenSpec(Token.RightBracket()));
        }