Exemplo n.º 1
0
        /// <summary>
        /// This must be called at the start of any @directive's Parse() function.
        /// It fills in the "At" and "Keyword" variables.
        /// "Keyword" could end up being null, but "At" is always set.
        /// </summary>
        protected virtual void ParseAtAndKeyword(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            Debug.Assert(tokens.CurrentToken.TokenType == CssTokenType.At);

            At = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.AtDirectiveName);

            if (tokens.CurrentToken.Start == At.AfterEnd &&
                tokens.CurrentToken.TokenType == CssTokenType.At &&
                AllowDoubleAt(text))
            {
                // Two @'s in a row (@@directive). Ignore the first one for Razor support.

                At = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.AtDirectiveName);
            }

            // Check for the directive name
            if (tokens.CurrentToken.Start == At.AfterEnd &&
                tokens.CurrentToken.TokenType == CssTokenType.Identifier)
            {
                Keyword = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.AtDirectiveName);
            }
            else
            {
                At.AddParseError(ParseErrorType.AtDirectiveNameMissing, ParseErrorLocation.AfterItem);
            }
        }
Exemplo n.º 2
0
 protected override void ParseDirective(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
 {
     if (stream.Current.Type == TokenType.Identifier)
     {
         AnimationName = Children.AddCurrentAndAdvance(stream, SassClassifierType.Default);
     }
 }
Exemplo n.º 3
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.XmlDocumentationComment)
            {
                Opening = Children.AddCurrentAndAdvance(stream, SassClassifierType.XmlDocumentationTag);

                // look for <reference
                if (stream.Current.Type == TokenType.LessThan)
                {
                    var tag = itemFactory.CreateSpecific <XmlDocumentationTag>(this, text, stream);
                    if (tag.Parse(itemFactory, text, stream))
                    {
                        Tag = tag;
                        Children.Add(tag);
                    }
                    else
                    {
                        Children.AddCurrentAndAdvance(stream, SassClassifierType.XmlDocumentationComment);
                    }
                }
                else
                {
                    while (!IsCommentTerminator(stream.Current.Type))
                    {
                        Children.AddCurrentAndAdvance(stream, SassClassifierType.XmlDocumentationComment);
                    }
                }

                //if (stream.Current.Type == TokenType.NewLine)
                //    NewLine = Children.AddCurrentAndAdvance(stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 4
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (IsFunctionCall(stream) && IsFunctionNameValid(text, stream))
            {
                Name = Children.AddCurrentAndAdvance(stream, FunctionClassifierType);
                if (Name != null)
                {
                    FunctionName = text.GetText(Name.Start, Name.Length);
                }

                if (stream.Current.Type == TokenType.OpenFunctionBrace)
                {
                    OpenBrace = Children.AddCurrentAndAdvance(stream, SassClassifierType.FunctionBrace);
                }

                ParseArguments(itemFactory, text, stream);

                if (OpenBrace != null && stream.Current.Type == TokenType.CloseFunctionBrace)
                {
                    CloseBrace = Children.AddCurrentAndAdvance(stream, SassClassifierType.FunctionBrace);
                }
            }

            return(Children.Count > 0);
        }
Exemplo n.º 5
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Comma)
            {
                Children.AddCurrentAndAdvance(stream, SassClassifierType.Punctuation);
            }

            while (!IsSelectorTerminator(stream.Current.Type))
            {
                ParseItem item;
                if (itemFactory.TryCreateParsed <SimpleSelector>(this, text, stream, out item))
                {
                    Children.Add(item);
                    if (item is SimpleSelector)
                    {
                        _SimpleSelectors.Add(item as SimpleSelector);
                    }
                }
                else
                {
                    // swallow up unknown and keep going
                    Children.AddCurrentAndAdvance(stream);
                }
            }

            return(Children.Count > 0);
        }
Exemplo n.º 6
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (AtRule.IsRule(text, stream, "extend"))
            {
                Rule = AtRule.CreateParsed(itemFactory, text, stream);
                if (Rule != null)
                {
                    Children.Add(Rule);
                }

                var selector = itemFactory.CreateSpecific <SelectorGroup>(this, text, stream);
                if (selector.Parse(itemFactory, text, stream))
                {
                    Selector = selector;
                    Children.Add(selector);
                }

                if (stream.Current.Type == TokenType.Bang)
                {
                    var modifier = new OptionalModifier();
                    if (modifier.Parse(itemFactory, text, stream))
                    {
                        Modifier = modifier;
                        Children.Add(modifier);
                    }
                }

                if (stream.Current.Type == TokenType.Semicolon)
                {
                    Semicolon = Children.AddCurrentAndAdvance(stream, SassClassifierType.Punctuation);
                }
            }

            return(Children.Count > 0);
        }
Exemplo n.º 7
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            while (!IsSelectorTerminator(stream.Current.Type))
            {
                var selector = itemFactory.CreateSpecific <SelectorGroup>(this, text, stream);
                if (!selector.Parse(itemFactory, text, stream))
                {
                    break;
                }

                _Selectors.Add(selector);
                Children.Add(selector);

                if (stream.Current.Type == TokenType.Comma)
                {
                    Children.AddCurrentAndAdvance(stream, SassClassifierType.Punctuation);
                }
            }

            if (stream.Current.Type == TokenType.OpenCurlyBrace)
            {
                var block = itemFactory.CreateSpecific <RuleBlock>(this, text, stream);
                if (block.Parse(itemFactory, text, stream))
                {
                    Block = block;
                    Children.Add(block);
                }
            }

            return(Children.Count > 0);
        }
Exemplo n.º 8
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (AtRule.IsRule(text, stream, "each"))
            {
                ParseRule(itemFactory, text, stream);
                while (!IsListTerminator(stream.Current.Type))
                {
                    var item = itemFactory.CreateSpecific <ListItem>(this, text, stream);
                    if (item != null && item.Parse(itemFactory, text, stream))
                    {
                        _Items.Add(item);
                        Children.Add(item);
                    }
                    else
                    {
                        // bad news bears
                        Children.AddCurrentAndAdvance(stream);
                    }
                }

                ParseBody(itemFactory, text, stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 9
0
        protected virtual ParseItem ParseName(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            ParseItem name = null;

            if (tokens.CurrentToken.TokenType == CssTokenType.Asterisk)
            {
                StarHackPropertyName customName = new StarHackPropertyName();
                if (customName.Parse(itemFactory, text, tokens))
                {
                    name = customName;
                    Children.Add(customName);
                }
            }
            else if (tokens.CurrentToken.TokenType == CssTokenType.Identifier)
            {
                CssClassifierContextType contextType = CssClassifierContextType.PropertyName;
                if (text.CompareTo(tokens.CurrentToken.Start, "--", true))
                {
                    IsCustomProperty = true;
                    contextType      = CssClassifierContextType.CustomPropertyName;
                }

                name = Children.AddCurrentAndAdvance(tokens, contextType);
            }

            return(name);
        }
Exemplo n.º 10
0
 protected virtual void ParseAfterValues(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
 {
     if (tokens.CurrentToken.TokenType == CssTokenType.Semicolon)
     {
         Semicolon = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.Punctuation);
     }
 }
Exemplo n.º 11
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (AtRule.IsRule(text, stream, "media"))
            {
                Rule = AtRule.CreateParsed(itemFactory, text, stream);
                if (Rule != null)
                {
                    Children.Add(Rule);
                }

                while (!IsTerminator(stream.Current.Type))
                {
                    var query = itemFactory.CreateSpecific <MediaQuery>(this, text, stream);
                    if (query.Parse(itemFactory, text, stream))
                    {
                        _Queries.Add(query);
                        Children.Add(query);
                    }
                    else
                    {
                        Children.AddCurrentAndAdvance(stream);
                    }
                }

                var block = itemFactory.CreateSpecific <MediaQueryBlock>(this, text, stream);
                if (block.Parse(itemFactory, text, stream))
                {
                    Body = block;
                    Children.Add(block);
                }
            }

            return(Children.Count > 0);
        }
Exemplo n.º 12
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (AtRule.IsRule(text, stream, "for"))
            {
                ParseRule(itemFactory, text, stream);

                var variable = new VariableName(SassClassifierType.VariableDefinition);
                if (variable.Parse(itemFactory, text, stream))
                {
                    Variable = variable;
                    Children.Add(Variable);
                }

                if (IsKeyword(text, stream, "from"))
                {
                    FromKeyword = Children.AddCurrentAndAdvance(stream, SassClassifierType.Keyword);

                    while (!(IsKeyword(text, stream, "to") || IsKeyword(text, stream, "through")))
                    {
                        ParseItem fromValue;
                        if (itemFactory.TryCreateParsedOrDefault(this, text, stream, out fromValue))
                        {
                            FromExpressionValues.Add(fromValue);
                            Children.Add(fromValue);
                        }
                    }
                }

                bool isToKeyword      = IsKeyword(text, stream, "to");
                bool isThroughKeyword = !isToKeyword && IsKeyword(text, stream, "through");

                if (isToKeyword || isThroughKeyword)
                {
                    if (isToKeyword)
                    {
                        ToKeyword = Children.AddCurrentAndAdvance(stream, SassClassifierType.Keyword);
                    }

                    if (isThroughKeyword)
                    {
                        ThroughKeyword = Children.AddCurrentAndAdvance(stream, SassClassifierType.Keyword);
                    }

                    while (!IsRangeTerminator(stream.Current.Type))
                    {
                        ParseItem rangeValue;
                        if (itemFactory.TryCreateParsedOrDefault(this, text, stream, out rangeValue))
                        {
                            RangeExpressionValues.Add(rangeValue);
                            Children.Add(rangeValue);
                        }
                    }
                }

                ParseBody(itemFactory, text, stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 13
0
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            FunctionName = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.FunctionName);
            ParseArguments(itemFactory, text, tokens);
            CheckCloseFunctionBrace(tokens);

            return(Children.Count > 0);
        }
Exemplo n.º 14
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.String || stream.Current.Type == TokenType.BadString)
            {
                Value = Children.AddCurrentAndAdvance(stream, SassClassifierType.String);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 15
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (AtRule.IsRule(text, stream, "include"))
            {
                Rule = AtRule.CreateParsed(itemFactory, text, stream);
                if (Rule != null)
                {
                    Children.Add(Rule);
                }

                Name = MixinName.CreateParsed(itemFactory, text, stream, SassClassifierType.MixinReference);
                if (Name != null)
                {
                    Children.Add(Name);
                }

                if (stream.Current.Type == TokenType.OpenFunctionBrace)
                {
                    OpenBrace = Children.AddCurrentAndAdvance(stream, SassClassifierType.FunctionBrace);

                    while (!IsTerminator(stream.Current.Type))
                    {
                        var argument = itemFactory.CreateSpecific <FunctionArgument>(this, text, stream);
                        if (argument != null && argument.Parse(itemFactory, text, stream))
                        {
                            _Arguments.Add(argument);
                            Children.Add(argument);
                        }
                        else
                        {
                            Children.AddCurrentAndAdvance(stream);
                        }
                    }
                }

                if (stream.Current.Type == TokenType.CloseFunctionBrace)
                {
                    CloseBrace = Children.AddCurrentAndAdvance(stream, SassClassifierType.FunctionBrace);
                }

                if (stream.Current.Type == TokenType.Semicolon)
                {
                    Semicolon = Children.AddCurrentAndAdvance(stream);
                }
                else if (stream.Current.Type == TokenType.OpenCurlyBrace)
                {
                    var content = new MixinContentBlock();
                    if (content.Parse(itemFactory, text, stream))
                    {
                        Content = content;
                        Children.Add(content);
                    }
                }
            }

            return(Children.Count > 0);
        }
Exemplo n.º 16
0
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            // foo : bar rgb(1,2,3) "baz" url(quux) / moo goo ! important ;
            // First item is property name. Allow -webkit and *foo - the latter is used for 'commenting out'

            PropertyName = ParseName(itemFactory, text, tokens);

            if (tokens.CurrentToken.TokenType == CssTokenType.Colon ||
                tokens.CurrentToken.TokenType == CssTokenType.DoubleColon)
            {
                Colon = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.Punctuation);

                if (Colon.TokenType != CssTokenType.Colon)
                {
                    Colon.AddParseError(ParseErrorType.UnexpectedToken, ParseErrorLocation.WholeItem);
                }
            }

            // Parse values
            while (KeepParsingValues(tokens))
            {
                switch (tokens.CurrentToken.TokenType)
                {
                case CssTokenType.Bang:
                    ParseBang(itemFactory, text, tokens);
                    break;

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

            ParseAfterValues(itemFactory, text, tokens);

            // Add appropriate errors

            if (PropertyName == null)
            {
                AddParseError(ParseErrorType.PropertyNameMissing, ParseErrorLocation.BeforeItem);
            }
            else if (Colon != null)
            {
                int semiColonIndex = (Semicolon != null) ? Children.IndexOf(Semicolon) : Children.Count;

                if (Children.IndexOf(Colon) + 1 == semiColonIndex)
                {
                    Colon.AddParseError(ParseErrorType.PropertyValueMissing, ParseErrorLocation.AfterItem);
                }
            }
            else
            {
                AddColonMissingError();
            }

            return(Children.Count > 0);
        }
Exemplo n.º 17
0
        protected override bool ParseSelectorToken(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Ampersand)
            {
                Ampersand = Children.AddCurrentAndAdvance(stream, SassClassifierType.ParentReference);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 18
0
        protected override bool ParseSelectorToken(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Asterisk)
            {
                Asterisk = Children.AddCurrentAndAdvance(stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 19
0
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            UnitType = UnitType.Unknown;

            if (tokens.CurrentToken.TokenType == CssTokenType.Number)
            {
                if (!base.Parse(itemFactory, text, tokens))
                {
                    return(false);
                }
            }

            Debug.Assert(tokens.CurrentToken.TokenType == CssTokenType.Units);
            UnitToken = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.Units);
            UnitType  = UnitHelpers.GetUnitType(text, UnitToken.Start, UnitToken.Length);

            CssClassifierContextType ct = CssClassifierContextType.Units;

            switch (UnitType)
            {
            case UnitType.Angle:
                ct = CssClassifierContextType.AngleUnits;
                break;

            case UnitType.Frequency:
                ct = CssClassifierContextType.FrequencyUnits;
                break;

            case UnitType.Grid:
                ct = CssClassifierContextType.GridUnits;
                break;

            case UnitType.Length:
                ct = CssClassifierContextType.LengthUnits;
                break;

            case UnitType.Percentage:
                ct = CssClassifierContextType.PercentUnits;
                break;

            case UnitType.Resolution:
                ct = CssClassifierContextType.ResolutionUnits;
                break;

            case UnitType.Time:
                ct = CssClassifierContextType.TimeUnits;
                break;

            case UnitType.Viewport:
                ct = CssClassifierContextType.ViewUnits;
                break;
            }

            UnitToken.Context = CssClassifierContextCache.FromTypeEnum(ct);

            return(Children.Count > 0);
        }
Exemplo n.º 20
0
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            if (tokens.CurrentToken.TokenType == CssTokenType.Bang)
            {
                Bang = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.SelectorOperator);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 21
0
        protected override bool ParseSelectorToken(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Identifier)
            {
                Name = Children.AddCurrentAndAdvance(stream, SassClassifierType.ElementName);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 22
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Identifier || stream.Current.Type == TokenType.Function)
            {
                Name      = Children.AddCurrentAndAdvance(stream, ClassifierType);
                NameValue = text.GetText(Name.Start, Name.Length);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 23
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Bang && IsValidModifier(text, stream.Peek(1), FlagName))
            {
                Bang = Children.AddCurrentAndAdvance(stream);
                Flag = Children.AddCurrentAndAdvance(stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 24
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Hash)
            {
                Hash  = Children.AddCurrentAndAdvance(stream, SassClassifierType.Default);
                Color = Children.AddCurrentAndAdvance(stream, SassClassifierType.Default);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 25
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.At && IsValidTokenType(stream.Peek(1).Type))
            {
                At   = Children.AddCurrentAndAdvance(stream);
                Name = Children.AddCurrentAndAdvance(stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 26
0
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            Debug.Assert(
                tokens.CurrentToken.TokenType == CssTokenType.OpenHtmlComment ||
                tokens.CurrentToken.TokenType == CssTokenType.CloseHtmlComment);

            Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.Default);

            return(Children.Count > 0);
        }
Exemplo n.º 27
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.PercentSign && stream.Peek(1).Type == TokenType.Identifier)
            {
                Prefix = Children.AddCurrentAndAdvance(stream);
                Name   = Children.AddCurrentAndAdvance(stream);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 28
0
        protected override bool ParseSelectorToken(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Colon && stream.Peek(1).Type == TokenType.Identifier)
            {
                Prefix    = Children.AddCurrentAndAdvance(stream, SassClassifierType.PseudoClass);
                ClassName = Children.AddCurrentAndAdvance(stream, SassClassifierType.PseudoClass);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 29
0
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            if (tokens.CurrentToken.TokenType == CssTokenType.Dot)
            {
                Dot = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.ClassSelector);
                ParseName(itemFactory, text, tokens);
            }

            return(Children.Count > 0);
        }
Exemplo n.º 30
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (IsValidName(stream))
            {
                Dot  = Children.AddCurrentAndAdvance(stream, ClassifierType);
                Name = Children.AddCurrentAndAdvance(stream, ClassifierType);
            }

            return(Children.Count > 0);
        }