示例#1
0
        public static bool IsValidRuleSet(ITokenStream stream)
        {
            int position = stream.Position;

            try
            {
                bool seenColon = false;
                var  previous  = stream.Current;
                while (stream.Advance().Type != TokenType.EndOfFile)
                {
                    var curent = stream.Current;
                    // selector body
                    if (curent.Type == TokenType.OpenCurlyBrace)
                    {
                        return(true);
                    }
                    // parent terminator
                    if (curent.Type == TokenType.CloseCurlyBrace)
                    {
                        return(false);
                    }
                    // property terminator
                    if (curent.Type == TokenType.Semicolon)
                    {
                        return(false);
                    }
                    if (curent.Type == TokenType.Colon)
                    {
                        seenColon = true;
                        var next = stream.Advance();
                        // if space after colon, then we are in a property
                        if (curent.End != next.Start)
                        {
                            return(false);
                        }
                        // if next value is not identifer or function, then we are a property
                        if (!(next.Type == TokenType.Identifier || next.Type == TokenType.Function))
                        {
                            return(false);
                        }
                    }

                    // check for space
                    if (curent.Start != previous.End && !seenColon)
                    {
                        return(true);
                    }

                    previous = stream.Current;
                }
            }
            finally
            {
                stream.SeekTo(position);
            }

            return(false);
        }
示例#2
0
        public static bool IsValidName(ITokenStream stream)
        {
            int start = stream.Position;
            var lastToken = stream.Current;
            bool valid = false;
            while (IsValidNameComponent(stream.Current.Type))
            {
                valid = true;
                if (stream.Advance().Start != lastToken.End)
                    break;

                lastToken = stream.Current;
            }

            stream.SeekTo(start);
            return valid;
        }
示例#3
0
        public static bool IsValidName(ITokenStream stream)
        {
            int  start     = stream.Position;
            var  lastToken = stream.Current;
            bool valid     = false;

            while (IsValidNameComponent(stream.Current.Type))
            {
                valid = true;
                if (stream.Advance().Start != lastToken.End)
                {
                    break;
                }

                lastToken = stream.Current;
            }

            stream.SeekTo(start);
            return(valid);
        }
        public static bool IsDeclaration(ITextProvider text, ITokenStream stream)
        {
            int position = stream.Position;

            bool validPropertyName = false;

            while (true)
            {
                var last = stream.Current;
                var next = stream.Advance();

                if (next.Start > last.End || IsDeclarationTerminator(last.Type))
                {
                    break;
                }

                if (next.Type == TokenType.Colon)
                {
                    var value = stream.Peek(1);
                    switch (value.Type)
                    {
                    case TokenType.Ampersand:
                        validPropertyName = false;
                        break;

                    case TokenType.Identifier:
                    case TokenType.Function:
                        validPropertyName = value.Start > next.End || !IsPseudoSelector(text, value);
                        break;

                    default:
                        validPropertyName = true;
                        break;
                    }
                    break;
                }
            }

            stream.SeekTo(position);
            return(validPropertyName);
        }
示例#5
0
        public static bool IsValidRuleSet(ITokenStream stream)
        {
            int position = stream.Position;
            try
            {
                bool seenColon = false;
                var previous = stream.Current;
                while (stream.Advance().Type != TokenType.EndOfFile)
                {
                    var curent = stream.Current;
                    // selector body
                    if (curent.Type == TokenType.OpenCurlyBrace) return true;
                    // parent terminator
                    if (curent.Type == TokenType.CloseCurlyBrace) return false;
                    // property terminator
                    if (curent.Type == TokenType.Semicolon) return false;
                    if (curent.Type == TokenType.Colon)
                    {
                        seenColon = true;
                        var next = stream.Advance();
                        // if space after colon, then we are in a property
                        if (curent.End != next.Start) return false;
                        // if next value is not identifer or function, then we are a property
                        if (!(next.Type == TokenType.Identifier || next.Type == TokenType.Function)) return false;
                    }

                    // check for space
                    if (curent.Start != previous.End && !seenColon) return true;

                    previous = stream.Current;
                }
            }
            finally
            {
                stream.SeekTo(position);
            }

            return false;
        }
        public static bool IsDeclaration(ITextProvider text, ITokenStream stream)
        {
            int position = stream.Position;

            bool validPropertyName = false;
            while (true)
            {
                var last = stream.Current;
                var next = stream.Advance();

                if (next.Start > last.End || IsDeclarationTerminator(last.Type))
                    break;

                if (next.Type == TokenType.Colon)
                {
                    var value = stream.Peek(1);
                    switch (value.Type)
                    {
                        case TokenType.Ampersand:
                            validPropertyName = false;
                            break;
                        case TokenType.Identifier:
                        case TokenType.Function:
                            validPropertyName = value.Start > next.End || !IsPseudoSelector(text, value);
                            break;
                        default:
                            validPropertyName = true;
                            break;
                    }
                    break;
                }
            }

            stream.SeekTo(position);
            return validPropertyName;
        }