예제 #1
0
        public virtual ParseItem CreateNextChild(ParseItem previousChild, ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            if (IsNestedBlock)
            {
                if (tokens.CurrentToken.IsScopeBlocker())
                {
                    return(null);
                }

                // Only nested stylesheets (like in @media) should look for braces

                if (previousChild is TokenItem && ((TokenItem)previousChild).TokenType == CssTokenType.CloseCurlyBrace)
                {
                    // No more children after the close curly brace
                    return(null);
                }

                if (previousChild == null && tokens.CurrentToken.TokenType != CssTokenType.OpenCurlyBrace)
                {
                    // First child must be a curly brace
                    return(null);
                }

                if (tokens.CurrentToken.TokenType == CssTokenType.OpenCurlyBrace)
                {
                    return((previousChild == null) ? new TokenItem(tokens.AdvanceToken(), CssClassifierContextType.CurlyBrace) : null);
                }

                if (tokens.CurrentToken.TokenType == CssTokenType.CloseCurlyBrace)
                {
                    return(new TokenItem(tokens.AdvanceToken(), CssClassifierContextType.CurlyBrace));
                }
            }

            ParseItem newChild = null;

            switch (tokens.CurrentToken.TokenType)
            {
            case CssTokenType.EndOfFile:
                break;

            case CssTokenType.ScopeBlocker:
                newChild = UnknownItem.ParseUnknown(this, itemFactory, text, tokens);
                break;

            case CssTokenType.At:
                newChild = AtDirective.ParseDirective(this, itemFactory, text, tokens);
                break;

            default:
                newChild = ParseDefaultChild(itemFactory, text, tokens);
                break;
            }

            return(newChild);
        }
예제 #2
0
        protected virtual ParseItem ParseDefaultChild(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            ParseItem newChild = itemFactory.Create <RuleSet>(this);

            if (!newChild.Parse(itemFactory, text, tokens))
            {
                newChild = UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.UnexpectedToken);
            }

            return(newChild);
        }
예제 #3
0
        protected virtual ParseItem CreateDefaultChild(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            ParseItem newChild = itemFactory.Create <Declaration>(this);

            if (!newChild.Parse(itemFactory, text, tokens))
            {
                newChild = UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.DeclarationExpected);
            }

            return(newChild);
        }