示例#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
        private ParseItemList Parse(ITextProvider text, IItemFactory itemFactory, ITokenStream stream, IParsingExecutionContext context)
        {
            var results = new ParseItemList();
            while (!context.IsCancellationRequested && stream.Current.Type != TokenType.EndOfFile)
            {
                int position = stream.Position;

                ParseItem item;
                if (!itemFactory.TryCreate(null, text, stream, out item))
                    break;

                if (item.Parse(itemFactory, text, stream))
                    results.Add(item);

                // guard against infinite loop (in case token couldn't be handled)
                if (stream.Position == position)
                    stream.Advance();
            }

            // freeze everything
            if (!context.IsCancellationRequested)
                foreach (var item in results)
                    item.Freeze();

            return results;
        }
示例#3
0
        public TokenItem AddCurrentAndAdvance(ITokenStream stream, SassClassifierType classifierType = SassClassifierType.Default)
        {
            var item = new TokenItem(stream.Current, classifierType);

            Add(item);

            stream.Advance();
            return(item);
        }
示例#4
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;
        }
示例#5
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type != TokenType.EndOfFile)
            {
                var token = stream.Current;
                _Start     = token.Start;
                _Length    = token.Length;
                _End       = _Start + _Length;
                SourceType = token.Type;

                stream.Advance();
                return(true);
            }

            return(false);
        }
示例#6
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type != TokenType.EndOfFile)
            {
                var token = stream.Current;
                _Start = token.Start;
                _Length = token.Length;
                _End = _Start + _Length;
                SourceType = token.Type;

                stream.Advance();
                return true;
            }

            return false;
        }
示例#7
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;
        }
示例#8
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);
        }
示例#10
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.StartOfFile)
            {
                stream.Advance();
                while (stream.Current.Type != TokenType.EndOfFile)
                {
                    int position = stream.Position;
                    ParseItem item;
                    if (itemFactory.TryCreateParsedOrDefault(this, text, stream, out item))
                    {
                        Children.Add(item);
                    }
                    else if (stream.Position == position)
                    {
                        // add current token if and only if we didn't move position at all
                        Children.AddCurrentAndAdvance(stream);
                    }
                }
            }

            return Children.Count > 0;
        }
示例#11
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.StartOfFile)
            {
                stream.Advance();
                while (stream.Current.Type != TokenType.EndOfFile)
                {
                    int       position = stream.Position;
                    ParseItem item;
                    if (itemFactory.TryCreateParsedOrDefault(this, text, stream, out item))
                    {
                        Children.Add(item);
                    }
                    else if (stream.Position == position)
                    {
                        // add current token if and only if we didn't move position at all
                        Children.AddCurrentAndAdvance(stream);
                    }
                }
            }

            return(Children.Count > 0);
        }
示例#12
0
        private ParseItemList Parse(ITextProvider text, IItemFactory itemFactory, ITokenStream stream, IParsingExecutionContext context)
        {
            var results = new ParseItemList();

            while (!context.IsCancellationRequested && stream.Current.Type != TokenType.EndOfFile)
            {
                int position = stream.Position;

                ParseItem item;
                if (!itemFactory.TryCreate(null, text, stream, out item))
                {
                    break;
                }

                if (item.Parse(itemFactory, text, stream))
                {
                    results.Add(item);
                }

                // guard against infinite loop (in case token couldn't be handled)
                if (stream.Position == position)
                {
                    stream.Advance();
                }
            }

            // freeze everything
            if (!context.IsCancellationRequested)
            {
                foreach (var item in results)
                {
                    item.Freeze();
                }
            }

            return(results);
        }
示例#13
0
        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;
        }