Esempio n. 1
0
        private void OnAttributeOperator(Token token)
        {
            if (token.Type == TokenType.Whitespace)
            {
                return;
            }

            if (token.Type == TokenType.SquareBracketClose)
            {
                _state = State.AttributeValue;
                OnAttributeEnd(token);
            }
            else if ((token.Type == TokenType.Match) || (token.Type == TokenType.Delim))
            {
                _state  = State.AttributeValue;
                _attrOp = token.ToValue();

                if (_attrOp != Combinators.Pipe)
                {
                    return;
                }
                _attrNs   = _attrName;
                _attrName = null;
                _attrOp   = string.Empty;
                _state    = State.Attribute;
            }
            else
            {
                _state = State.AttributeEnd;
                _valid = false;
            }
        }
Esempio n. 2
0
        private void OnAttribute(Token token)
        {
            if (token.Type == TokenType.Whitespace)
            {
                return;
            }

            if ((token.Type == TokenType.Ident) || (token.Type == TokenType.String))
            {
                _state    = State.AttributeOperator;
                _attrName = token.Data;
            }
            else if ((token.Type == TokenType.Delim) && token.Data.Is(Combinators.Pipe))
            {
                _state  = State.Attribute;
                _attrNs = string.Empty;
            }
            else if ((token.Type == TokenType.Delim) && token.Data.Is(Keywords.Asterisk))
            {
                _state    = State.AttributeOperator;
                _attrName = token.ToValue();
            }
            else
            {
                _state = State.Data;
                _valid = false;
            }
        }
Esempio n. 3
0
        private void ParseComments(ref Token token)
        {
            var preserveComments = _parser.Options.PreserveComments;

            while ((token.Type == TokenType.Whitespace) || (token.Type == TokenType.Comment) ||
                   (token.Type == TokenType.Cdc) || (token.Type == TokenType.Cdo))
            {
                if (preserveComments && (token.Type == TokenType.Comment))
                {
                    var current = _nodes.Peek();
                    var comment = new Comment(token.Data);
                    var start   = token.Position;
                    var end     = start.After(token.ToValue());
                    comment.StylesheetText = CreateView(start, end);
                    current.AppendChild(comment);
                }

                token = _lexer.Get();
            }
        }
Esempio n. 4
0
        public Property CreateDeclarationWith(Func <string, Property> createProperty, ref Token token)
        {
            var property = default(Property);

            var sb    = Pool.NewStringBuilder();
            var start = token.Position;

            while (token.IsDeclarationName())
            {
                sb.Append(token.ToValue());
                token = NextToken();
            }

            var propertyName = sb.ToPool();

            if (propertyName.Length > 0)
            {
                property = _parser.Options.IncludeUnknownDeclarations ||
                           _parser.Options.AllowInvalidValues
                    ? new UnknownProperty(propertyName)
                    : createProperty(propertyName);

                if (property == null)
                {
                    RaiseErrorOccurred(ParseError.UnknownDeclarationName, start);
                }
                else
                {
                    _nodes.Push(property);
                }

                ParseComments(ref token);

                if (token.Type == TokenType.Colon)
                {
                    bool important;
                    var  value = CreateValue(TokenType.CurlyBracketClose, ref token, out important);

                    if (value == null)
                    {
                        RaiseErrorOccurred(ParseError.ValueMissing, token.Position);
                    }
                    else if ((property != null) && property.TrySetValue(value))
                    {
                        property.IsImportant = important;
                    }

                    ParseComments(ref token);
                }
                else
                {
                    RaiseErrorOccurred(ParseError.ColonMissing, token.Position);
                }

                JumpToDeclEnd(ref token);

                if (property != null)
                {
                    _nodes.Pop();
                }
            }
            else if (token.Type != TokenType.EndOfFile)
            {
                RaiseErrorOccurred(ParseError.IdentExpected, start);
                JumpToDeclEnd(ref token);
            }

            if (token.Type == TokenType.Semicolon)
            {
                token = NextToken();
            }

            return(property);
        }