コード例 #1
0
 public override CssRule Create(CssToken current)
 {
     var rule = new CssStyleRule(_parser);
     rule.Selector = CreateSelector(ref current);
     FillDeclarations(rule.Style);
     return rule.Selector != null ? rule : null;
 }
コード例 #2
0
        /// <summary>
        /// Called in the text for a frame in the @keyframes rule.
        /// </summary>
        public KeyframeSelector CreateKeyframeSelector(ref CssToken token)
        {
            var keys = new List<Percent>();

            while (token.Type != CssTokenType.Eof)
            {
                if (keys.Count > 0)
                {
                    if (token.Type == CssTokenType.CurlyBracketOpen)
                        break;
                    else if (token.Type != CssTokenType.Comma)
                        return null;

                    token = _tokenizer.Get();
                }

                if (token.Type == CssTokenType.Percentage)
                    keys.Add(new Percent(((CssUnitToken)token).Value));
                else if (token.Type == CssTokenType.Ident && token.Data.Equals(Keywords.From))
                    keys.Add(Percent.Zero);
                else if (token.Type == CssTokenType.Ident && token.Data.Equals(Keywords.To))
                    keys.Add(Percent.Hundred);
                else
                    return null;

                token = _tokenizer.Get();
            }

            return new KeyframeSelector(keys);
        }
コード例 #3
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Parses an @-rule with the given name, if there is any.
        /// </summary>
        public CssRule CreateAtRule(CssToken token)
        {
            if (token.Data == RuleNames.Media)
                return CreateMedia(token);
            else if (token.Data == RuleNames.FontFace)
                return CreateFontFace(token);
            else if (token.Data == RuleNames.Keyframes)
                return CreateKeyframes(token);
            else if (token.Data == RuleNames.Import)
                return CreateImport(token);
            else if (token.Data == RuleNames.Charset)
                return CreateCharset(token);
            else if (token.Data == RuleNames.Namespace)
                return CreateNamespace(token);
            else if (token.Data == RuleNames.Page)
                return CreatePage(token);
            else if (token.Data == RuleNames.Supports)
                return CreateSupports(token);
            else if (token.Data == RuleNames.ViewPort)
                return CreateViewport(token);
            else if (token.Data == RuleNames.Document)
                return CreateDocument(token);

            return CreateUnknown(token);
        }
コード例 #4
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Creates a rule with the enumeration of tokens.
        /// </summary>
        public CssRule CreateRule(CssToken token)
        {
            switch (token.Type)
            {
                case CssTokenType.AtKeyword:
                    return CreateAtRule(token);

                case CssTokenType.CurlyBracketOpen:
                    _tokenizer.RaiseErrorOccurred(CssParseError.InvalidBlockStart, token.Position);
                    _tokenizer.SkipUnknownRule();
                    return null;

                case CssTokenType.String:
                case CssTokenType.Url:
                case CssTokenType.CurlyBracketClose:
                case CssTokenType.RoundBracketClose:
                case CssTokenType.SquareBracketClose:
                    _tokenizer.RaiseErrorOccurred(CssParseError.InvalidToken, token.Position);
                    _tokenizer.SkipUnknownRule();
                    return null;

                default:
                    return CreateStyle(token);
            }
        }
コード例 #5
0
        /// <summary>
        /// Parses an @-rule with the given name, if there is any.
        /// </summary>
        public static CssRule CreateAtRule(this CssTokenizer tokenizer, CssToken token, CssParser parser)
        {
            Creator creator;

            if (creators.TryGetValue(token.Data, out creator))
                return creator(tokenizer, parser).Create(token);

            return new CssUnknownState(tokenizer, parser).Create(token);
        }
コード例 #6
0
        public override CssRule Create(CssToken current)
        {
            var token = _tokenizer.Get();
            var rule = new CssCharsetRule(_parser);

            if (token.Type == CssTokenType.String)
                rule.CharacterSet = token.Data;

            _tokenizer.JumpToNextSemicolon();
            return rule;
        }
コード例 #7
0
        public override CssRule Create(CssToken current)
        {
            var token = _tokenizer.Get();
            var rule = new CssKeyframesRule(_parser);
            rule.Name = GetRuleName(ref token);

            if (token.Type != CssTokenType.CurlyBracketOpen)
                return SkipDeclarations(token);

            FillKeyframeRules(rule);
            return rule;
        }
コード例 #8
0
        public override CssRule Create(CssToken current)
        {
            var token = _tokenizer.Get();
            var rule = new CssPageRule(_parser);
            rule.Selector = CreateSelector(ref token);

            if (token.Type != CssTokenType.CurlyBracketOpen)
                return SkipDeclarations(token);

            FillDeclarations(rule.Style);
            return rule;
        }
コード例 #9
0
        public override CssRule Create(CssToken current)
        {
            var token = _tokenizer.Get();
            var rule = new CssNamespaceRule(_parser);
            rule.Prefix = GetRuleName(ref token);

            if (token.Type == CssTokenType.Url)
                rule.NamespaceUri = token.Data;

            _tokenizer.JumpToNextSemicolon();
            return rule;
        }
コード例 #10
0
        public override CssRule Create(CssToken current)
        {
            var token = _tokenizer.Get();
            var rule = new CssMediaRule(_parser);
            FillMediaList(rule.Media, ref token);

            if (token.Type != CssTokenType.CurlyBracketOpen)
                return SkipDeclarations(token);

            FillRules(rule);
            return rule;
        }
コード例 #11
0
        /// <summary>
        /// Before the curly bracket of an @keyframes rule has been seen.
        /// </summary>
        public CssKeyframeRule CreateKeyframeRule(CssToken token)
        {
            var rule = new CssKeyframeRule(_parser);
            rule.Key = CreateKeyframeSelector(ref token);

            if (rule.Key == null)
            {
                _tokenizer.JumpToEndOfDeclaration();
                return null;
            }

            FillDeclarations(rule.Style);
            return rule;
        }
コード例 #12
0
        public List<CssMedium> CreateMedia(ref CssToken token)
        {
            var list = new List<CssMedium>();

            while (token.Type != CssTokenType.Eof)
            {
                var medium = CreateMedium(ref token);

                if (medium == null || token.IsNot(CssTokenType.Comma, CssTokenType.Eof))
                    throw new DomException(DomError.Syntax);

                list.Add(medium);
                token = _tokenizer.Get();
            }

            return list;
        }
コード例 #13
0
        public override CssRule Create(CssToken current)
        {
            if (_parser.Options.IsIncludingUnknownRules)
            {
                var unknown = new CssUnknownRule(current.Data, _parser);
                _tokenizer.State = CssParseMode.Text;
                unknown.Prelude = _tokenizer.Get().Data;
                _tokenizer.State = CssParseMode.Data;

                if (_tokenizer.Get().Type == CssTokenType.CurlyBracketOpen)
                    FillRules(unknown);

                return unknown;
            }
            else
            {
                RaiseErrorOccurred(CssParseError.UnknownAtRule, current);
                _tokenizer.SkipUnknownRule();
                return null;
            }
        }
コード例 #14
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Called when the document functions have to been found.
        /// </summary>
        public List<IDocumentFunction> CreateFunctions(ref CssToken token)
        {
            var list = new List<IDocumentFunction>();

            do
            {
                var function = token.ToDocumentFunction();

                if (function == null)
                    break;

                list.Add(function);
                token = _tokenizer.Get();
            }
            while (token.Type == CssTokenType.Comma);

            return list;
        }
コード例 #15
0
        /// <summary>
        /// Checks if the provided token is either of the first or the second
        /// type of token.
        /// </summary>
        /// <param name="token">The token to examine.</param>
        /// <param name="a">The first type to match.</param>
        /// <param name="b">The alternative match for the token.</param>
        /// <returns>Result of the examination.</returns>
        public static Boolean Is(this CssToken token, CssTokenType a, CssTokenType b)
        {
            var type = token.Type;

            return(type == a || type == b);
        }
コード例 #16
0
 /// <summary>
 /// Called after the arguments of a document function has been found.
 /// </summary>
 /// <param name="token">The current token.</param>
 /// <returns>The status.</returns>
 Boolean AfterDocumentFunction(CssToken token)
 {
     SwitchTo(CssState.BetweenDocumentFunctions);
     return(token.Type == CssTokenType.RoundBracketClose);
 }
コード例 #17
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// State that is called once we are in a CSS selector.
        /// </summary>
        ISelector CreateSelector(ref CssToken token)
        {
            var selector = Pool.NewSelectorConstructor();
            _tokenizer.State = CssParseMode.Selector;
            var start = token;

            while (token.IsNot(CssTokenType.Eof, CssTokenType.CurlyBracketOpen, CssTokenType.CurlyBracketClose))
            {
                selector.Apply(token);
                token = _tokenizer.Get();
            }

            if (selector.IsValid == false)
                RaiseErrorOccurred(CssParseError.InvalidSelector, start);

            _tokenizer.State = CssParseMode.Data;
            return selector.ToPool();
        }
コード例 #18
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        List<ICondition> MultipleConditions(ICondition condition, String connector, ref CssToken token)
        {
            var list = new List<ICondition>();
            list.Add(condition);

            while (token.Type != CssTokenType.Eof)
            {
                condition = ExtractCondition(ref token);

                if (condition == null)
                    break;

                list.Add(condition);

                if (!token.Data.Equals(connector, StringComparison.OrdinalIgnoreCase))
                    break;

                token = _tokenizer.Get();
            }

            return list;
        }
コード例 #19
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        ICondition ExtractCondition(ref CssToken token)
        {
            var condition = default(ICondition);

            if (token.Type == CssTokenType.RoundBracketOpen)
            {
                token = _tokenizer.Get();
                condition = CreateCondition(ref token);

                if (condition != null)
                    condition = new GroupCondition(condition);
                else if (token.Type == CssTokenType.Ident)
                    condition = DeclarationCondition(ref token);

                if (token.Type == CssTokenType.RoundBracketClose)
                    token = _tokenizer.Get();
            }
            else if (token.Data.Equals(Keywords.Not, StringComparison.OrdinalIgnoreCase))
            {
                token = _tokenizer.Get();
                condition = ExtractCondition(ref token);

                if (condition != null)
                    condition = new NotCondition(condition);
            }

            return condition;
        }
コード例 #20
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
 /// <summary>
 /// Called before the property name has been detected.
 /// </summary>
 public CssProperty CreateDeclaration(ref CssToken token)
 {
     return CreateDeclarationWith(Factory.Properties.Create, ref token);
 }
コード例 #21
0
        /// <summary>
        /// Examines the token by using the current state.
        /// </summary>
        /// <param name="token">The current token.</param>
        /// <returns>The status.</returns>
        Boolean General(CssToken token)
        {
            switch (state)
            {
            case CssState.Data:
                return(Data(token));

            case CssState.InSelector:
                return(InSelector(token));

            case CssState.InDeclaration:
                return(InDeclaration(token));

            case CssState.AfterProperty:
                return(AfterProperty(token));

            case CssState.BeforeValue:
                return(BeforeValue(token));

            case CssState.InValuePool:
                return(InValuePool(token));

            case CssState.InValueList:
                return(InValueList(token));

            case CssState.InSingleValue:
                return(InSingleValue(token));

            case CssState.ValueImportant:
                return(ValueImportant(token));

            case CssState.AfterValue:
                return(AfterValue(token));

            case CssState.InMediaList:
                return(InMediaList(token));

            case CssState.InMediaValue:
                return(InMediaValue(token));

            case CssState.BeforeImport:
                return(BeforeImport(token));

            case CssState.AfterInstruction:
                return(AfterInstruction(token));

            case CssState.BeforeCharset:
                return(BeforeCharset(token));

            case CssState.BeforeNamespacePrefix:
                return(BeforePrefix(token));

            case CssState.AfterNamespacePrefix:
                return(BeforeNamespace(token));

            case CssState.InCondition:
                return(InCondition(token));

            case CssState.InUnknown:
                return(InUnknown(token));

            case CssState.InKeyframeText:
                return(InKeyframeText(token));

            case CssState.BeforeDocumentFunction:
                return(BeforeDocumentFunction(token));

            case CssState.InDocumentFunction:
                return(InDocumentFunction(token));

            case CssState.AfterDocumentFunction:
                return(AfterDocumentFunction(token));

            case CssState.BetweenDocumentFunctions:
                return(BetweenDocumentFunctions(token));

            case CssState.BeforeKeyframesName:
                return(BeforeKeyframesName(token));

            case CssState.BeforeKeyframesData:
                return(BeforeKeyframesData(token));

            case CssState.KeyframesData:
                return(KeyframesData(token));

            case CssState.InHexValue:
                return(InHexValue(token));

            case CssState.InFunction:
                return(InValueFunction(token));

            default:
                return(false);
            }
        }
コード例 #22
0
 static bool Starts_Pseudo_Element_Selector(CssToken A, CssToken B, CssToken C)
 {
     return(A.Type == ECssTokenType.Colon && B.Type == ECssTokenType.Colon && (C.Type == ECssTokenType.Ident || C.Type == ECssTokenType.FunctionName));
 }
コード例 #23
0
 internal TokenItem(CssToken token, IClassifierContext context)
 {
     Token   = token;
     Context = context;
 }
コード例 #24
0
 internal TokenItem(CssToken token, CssClassifierContextType context)
     : this(token, CssClassifierContextCache.FromTypeEnum(context))
 {
 }
コード例 #25
0
ファイル: CssAssignment.cs プロジェクト: ishikasofat/Css
 public CssAssignment(CssToken name, CssValue value)
     : base(NodeKind.Assignment)
 {
     Name  = name.Text;
     Value = value;
 }
コード例 #26
0
 private void RunTest(string input, IList <CssToken> expectedTokens)
 {
     expectedTokens.Add(CssToken.EndOfFileToken(new StringTextProvider(input)));
     VerifyTokens(input, expectedTokens);
 }
コード例 #27
0
 static bool Starts_Pseudo_Class_Selector(CssToken A, CssToken B)
 {
     return(A.Type == ECssTokenType.Colon && (B.Type == ECssTokenType.Ident || B.Type == ECssTokenType.FunctionName));
 }
コード例 #28
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Called before the property name has been detected.
        /// </summary>
        public CssProperty CreateDeclarationWith(Func<String, CssProperty> createProperty, ref CssToken token)
        {
            var property = default(CssProperty);

            if (token.Type == CssTokenType.Ident)
            {
                var propertyName = token.Data;
                token = _tokenizer.Get();

                if (token.Type != CssTokenType.Colon)
                {
                    RaiseErrorOccurred(CssParseError.ColonMissing, token);
                }
                else
                {
                    property = _parser.Options.IsIncludingUnknownDeclarations || _parser.Options.IsToleratingInvalidValues ?
                        new CssUnknownProperty(propertyName) : createProperty(propertyName);

                    if (property == null)
                        RaiseErrorOccurred(CssParseError.UnknownDeclarationName, token);

                    var important = false;
                    var val = CreateValue(CssTokenType.CurlyBracketClose, ref token, out important);

                    if (val == null)
                        RaiseErrorOccurred(CssParseError.ValueMissing, token);
                    else if (property != null && property.TrySetValue(val))
                        property.IsImportant = important;
                }

                _tokenizer.JumpToEndOfDeclaration();
                token = _tokenizer.Get();
            }
            else if (token.Type != CssTokenType.Eof)
            {
                RaiseErrorOccurred(CssParseError.IdentExpected, token);
                _tokenizer.JumpToEndOfDeclaration();
                token = _tokenizer.Get();
            }

            if (token.Type == CssTokenType.Semicolon)
                token = _tokenizer.Get();

            return property;
        }
コード例 #29
0
        /// <summary>
        /// Checks if the provided token is neither of the first, nor the
        /// second nor the third type of token.
        /// </summary>
        /// <param name="token">The token to examine.</param>
        /// <param name="a">The first type to unmatch.</param>
        /// <param name="b">The alternative unmatch for the token.</param>
        /// <param name="c">The final unmatch for the token.</param>
        /// <returns>Result of the examination.</returns>
        public static Boolean IsNot(this CssToken token, CssTokenType a, CssTokenType b, CssTokenType c)
        {
            var type = token.Type;

            return(type != a && type != b && type != c);
        }
コード例 #30
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Scans the current medium for the @media or @import rule.
        /// </summary>
        public CssMedium CreateMedium(ref CssToken token)
        {
            var medium = new CssMedium();

            if (token.Type == CssTokenType.Ident)
            {
                var identifier = token.Data;

                if (identifier.Equals(Keywords.Not, StringComparison.OrdinalIgnoreCase))
                {
                    medium.IsInverse = true;
                    token = _tokenizer.Get();
                }
                else if (identifier.Equals(Keywords.Only, StringComparison.OrdinalIgnoreCase))
                {
                    medium.IsExclusive = true;
                    token = _tokenizer.Get();
                }
            }

            if (token.Type == CssTokenType.Ident)
            {
                medium.Type = token.Data;
                token = _tokenizer.Get();

                if (token.Type != CssTokenType.Ident || String.Compare(token.Data, Keywords.And, StringComparison.OrdinalIgnoreCase) != 0)
                    return medium;

                token = _tokenizer.Get();
            }

            do
            {
                if (token.Type != CssTokenType.RoundBracketOpen)
                    return null;

                token = _tokenizer.Get();
                var couldSetConstraint = TrySetConstraint(medium, ref token);

                if (token.Type != CssTokenType.RoundBracketClose)
                    return null;

                token = _tokenizer.Get();

                if (couldSetConstraint == false)
                    return null;

                if (token.Type != CssTokenType.Ident || String.Compare(token.Data, Keywords.And, StringComparison.OrdinalIgnoreCase) != 0)
                    break;

                token = _tokenizer.Get();
            }
            while (token.Type != CssTokenType.Eof);

            return medium;
        }
コード例 #31
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Called before any token in the value regime had been seen.
        /// </summary>
        CssValue CreateValue(CssTokenType closing, ref CssToken token, out Boolean important)
        {
            var value = Pool.NewValueBuilder();
            _tokenizer.State = CssParseMode.Value;
            token = _tokenizer.Get();

            while (token.Type != CssTokenType.Eof)
            {
                if (token.Is(CssTokenType.Semicolon, closing))
                    break;

                value.Apply(token);
                token = _tokenizer.Get();
            }

            important = value.IsImportant;
            _tokenizer.State = CssParseMode.Data;

            if (value.IsValid || _parser.Options.IsToleratingInvalidValues)
                return value.ToPool();

            value.ToPool();
            return null;
        }
コード例 #32
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        ICondition DeclarationCondition(ref CssToken token)
        {
            var name = token.Data;
            var property = Factory.Properties.Create(name);

            if (property == null)
                property = new CssUnknownProperty(name);

            token = _tokenizer.Get();

            if (token.Type == CssTokenType.Colon)
            {
                var important = false;
                var result = CreateValue(CssTokenType.RoundBracketClose, ref token, out important);
                property.IsImportant = important;

                if (result != null)
                    return new DeclarationCondition(property, result);
            }

            return null;
        }
コード例 #33
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Before any medium has been found for the @media or @import rule.
        /// </summary>
        void FillMediaList(MediaList list, CssTokenType end, ref CssToken token)
        {
            if (token.Type == end)
                return;

            while (token.Type != CssTokenType.Eof)
            {
                var medium = CreateMedium(ref token);

                if (medium != null)
                    list.Add(medium);

                if (token.Type != CssTokenType.Comma)
                    break;

                token = _tokenizer.Get();
            }

            if (token.Type == end && list.Length > 0)
                return;

            list.Clear();
            list.Add(new CssMedium
            {
                IsInverse = true,
                Type = Keywords.All
            });
        }
コード例 #34
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
 /// <summary>
 /// Skips the current declaration.
 /// </summary>
 CssRule SkipDeclarations(CssToken token)
 {
     RaiseErrorOccurred(CssParseError.InvalidToken, token);
     _tokenizer.SkipUnknownRule();
     return null;
 }
コード例 #35
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Tries to read and set media constraints for the provided medium.
        /// </summary>
        Boolean TrySetConstraint(CssMedium medium, ref CssToken token)
        {
            if (token.Type != CssTokenType.Ident)
            {
                _tokenizer.JumpToClosedArguments();
                token = _tokenizer.Get();
                return false;
            }

            var value = Pool.NewValueBuilder();
            var featureName = token.Data;
            var val = CssValue.Empty;
            var feature = _parser.Options.IsToleratingInvalidConstraints ?
                new UnknownMediaFeature(featureName) : Factory.MediaFeatures.Create(featureName);

            token = _tokenizer.Get();

            if (token.Type == CssTokenType.Colon)
            {
                _tokenizer.State = CssParseMode.Value;
                token = _tokenizer.Get();

                while (token.Type != CssTokenType.RoundBracketClose || value.IsReady == false)
                {
                    if (token.Type == CssTokenType.Eof)
                        break;

                    value.Apply(token);
                    token = _tokenizer.Get();
                }

                _tokenizer.State = CssParseMode.Data;

                val = value.ToPool();
            }
            else if (token.Type == CssTokenType.Eof)
                return false;

            if (feature != null && feature.TrySetValue(val))
            {
                medium.AddConstraint(feature);
                return true;
            }

            return false;
        }
コード例 #36
0
 static bool Starts_Attribute_Selector(CssToken A, CssToken B)
 {
     return(A.Type == ECssTokenType.SqBracket_Open && B.Type == ECssTokenType.QualifiedName);
 }
コード例 #37
0
        /// <summary>
        /// The general state.
        /// </summary>
        /// <param name="token">The current token.</param>
        /// <returns>The status.</returns>
        Boolean Data(CssToken token)
        {
            if (token.Type == CssTokenType.AtKeyword)
            {
                switch (((CssKeywordToken)token).Data)
                {
                case RuleNames.MEDIA:
                {
                    AddRule(new CSSMediaRule());
                    SwitchTo(CssState.InMediaList);
                    break;
                }

                case RuleNames.PAGE:
                {
                    AddRule(new CSSPageRule());
                    SwitchTo(CssState.InSelector);
                    break;
                }

                case RuleNames.IMPORT:
                {
                    AddRule(new CSSImportRule());
                    SwitchTo(CssState.BeforeImport);
                    break;
                }

                case RuleNames.FONT_FACE:
                {
                    AddRule(new CSSFontFaceRule());
                    SwitchTo(CssState.InDeclaration);
                    break;
                }

                case RuleNames.CHARSET:
                {
                    AddRule(new CSSCharsetRule());
                    SwitchTo(CssState.BeforeCharset);
                    break;
                }

                case RuleNames.NAMESPACE:
                {
                    AddRule(new CSSNamespaceRule());
                    SwitchTo(CssState.BeforeNamespacePrefix);
                    break;
                }

                case RuleNames.SUPPORTS:
                {
                    buffer = Pool.NewStringBuilder();
                    AddRule(new CSSSupportsRule());
                    SwitchTo(CssState.InCondition);
                    break;
                }

                case RuleNames.KEYFRAMES:
                {
                    AddRule(new CSSKeyframesRule());
                    SwitchTo(CssState.BeforeKeyframesName);
                    break;
                }

                case RuleNames.DOCUMENT:
                {
                    AddRule(new CSSDocumentRule());
                    SwitchTo(CssState.BeforeDocumentFunction);
                    break;
                }

                default:
                {
                    buffer = Pool.NewStringBuilder();
                    AddRule(new CSSUnknownRule());
                    SwitchTo(CssState.InUnknown);
                    InUnknown(token);
                    break;
                }
                }

                return(true);
            }
            else if (token.Type == CssTokenType.CurlyBracketClose)
            {
                return(CloseRule());
            }
            else
            {
                AddRule(new CSSStyleRule());
                SwitchTo(CssState.InSelector);
                InSelector(token);
                return(true);
            }
        }
コード例 #38
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Before the name of a rule has been detected.
        /// </summary>
        String GetRuleName(ref CssToken token)
        {
            var name = String.Empty;

            if (token.Type == CssTokenType.Ident)
            {
                name = token.Data;
                token = _tokenizer.Get();
            }

            return name;
        }
コード例 #39
0
 static bool Starts_Class_Selector(CssToken A, CssToken B)
 {
     return(Is_Char(A, '.') && B.Type == ECssTokenType.Ident);
 }
コード例 #40
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
 /// <summary>
 /// Fires an error occurred event.
 /// </summary>
 /// <param name="code">The associated error code.</param>
 /// <param name="token">The associated token.</param>
 void RaiseErrorOccurred(CssParseError code, CssToken token)
 {
     _tokenizer.RaiseErrorOccurred(code, token.Position);
 }
コード例 #41
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
 public CssValue CreateValue(ref CssToken token)
 {
     var important = false;
     return CreateValue(CssTokenType.CurlyBracketClose, ref token, out important);
 }
コード例 #42
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        /// <summary>
        /// Called before any token in the value regime had been seen.
        /// </summary>
        public ICondition CreateCondition(ref CssToken token)
        {
            var condition = ExtractCondition(ref token);

            if (condition != null)
            {
                if (token.Data.Equals(Keywords.And, StringComparison.OrdinalIgnoreCase))
                {
                    token = _tokenizer.Get();
                    var conditions = MultipleConditions(condition, Keywords.And, ref token);
                    return new AndCondition(conditions);
                }
                else if (token.Data.Equals(Keywords.Or, StringComparison.OrdinalIgnoreCase))
                {
                    token = _tokenizer.Get();
                    var conditions = MultipleConditions(condition, Keywords.Or, ref token);
                    return new OrCondition(conditions);
                }
            }

            return condition;
        }
コード例 #43
0
 static bool Starts_Universal_Selector(CssToken A, CssToken B)
 {
     return(Is_Char(A, '*') || A.Type == ECssTokenType.NamespacePrefix && Is_Char(B, '*'));
 }
コード例 #44
0
 static bool Is_Char(CssToken A, char CH)
 {
     return(A.Type == ECssTokenType.Delim && (A as DelimToken).Value == CH);
 }
コード例 #45
0
 static bool Starts_ID_Selector(CssToken A)
 {
     return(A.Type == ECssTokenType.Hash && (A as HashToken).HashType == EHashTokenType.ID);
 }
コード例 #46
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        public CssRule CreateUnknown(CssToken current)
        {
            if (_parser.Options.IsIncludingUnknownRules)
            {
                var unknown = new CssUnknownRule(current.Data, _parser);
                _tokenizer.State = CssParseMode.Text;
                unknown.Prelude = _tokenizer.Get().Data;
                _tokenizer.State = CssParseMode.Selector;
                var sb = Pool.NewStringBuilder();
                var token = _tokenizer.Get();
                sb.Append(token.ToValue());

                if (token.Type == CssTokenType.CurlyBracketOpen)
                {
                    var curly = 1;

                    do
                    {
                        token = _tokenizer.Get();
                        sb.Append(token.ToValue());

                        switch (token.Type)
                        {
                            case CssTokenType.CurlyBracketOpen:
                                curly++;
                                break;
                            case CssTokenType.CurlyBracketClose:
                                curly--;
                                break;
                            case CssTokenType.Eof:
                                curly = 0;
                                break;
                        }
                    }
                    while (curly != 0);
                }

                unknown.Content = sb.ToPool();
                _tokenizer.State = CssParseMode.Data;
                return unknown;
            }
            else
            {
                RaiseErrorOccurred(CssParseError.UnknownAtRule, current);
                _tokenizer.SkipUnknownRule();
                return null;
            }
        }
コード例 #47
0
        internal static ParseItem ParsePropertyValue(ComplexItem parent, ItemFactory itemFactory, ITextProvider text, TokenStream tokens, bool callExternalFactory)
        {
            ParseItem pv    = null;
            CssToken  token = tokens.CurrentToken;

            // First give opportunity to override property value parsing
            if (callExternalFactory)
            {
                pv = itemFactory.Create <UnknownPropertyValue>(parent);
            }

            if (pv == null || pv.GetType() == typeof(UnknownPropertyValue))
            {
                switch (token.TokenType)
                {
                case CssTokenType.HashName:
                    pv = itemFactory.Create <HexColorValue>(parent);
                    break;

                case CssTokenType.Number:
                    pv = NumericalValue.ParseNumber(parent, itemFactory, text, tokens);
                    return(pv);

                case CssTokenType.Url:
                case CssTokenType.UnquotedUrlString:
                    pv = itemFactory.Create <UrlItem>(parent);
                    break;

                case CssTokenType.Function:
                    pv = Function.ParseFunction(parent, itemFactory, text, tokens);
                    return(pv);

                case CssTokenType.UnicodeRange:
                    pv = new TokenItem(tokens.CurrentToken, CssClassifierContextType.UnicodeRange);
                    break;

                case CssTokenType.Comma:
                case CssTokenType.Slash:
                    pv = new TokenItem(tokens.CurrentToken, CssClassifierContextType.Punctuation);
                    break;

                case CssTokenType.String:
                case CssTokenType.MultilineString:
                case CssTokenType.InvalidString:
                    pv = new TokenItem(tokens.CurrentToken, CssClassifierContextType.String);
                    break;

                case CssTokenType.Identifier:
                    pv = new TokenItem(tokens.CurrentToken, null);
                    break;

                case CssTokenType.OpenSquareBracket:
                case CssTokenType.OpenFunctionBrace:
                case CssTokenType.OpenCurlyBrace:
                    // "grid-rows" uses square brackets - http://dev.w3.org/csswg/css3-grid/
                    // And this is from a Win8 spec: -ms-grid-columns: (200px 10px)[3];
                    // Also, custom property values may have curly brace blocks
                    pv = itemFactory.Create <PropertyValueBlock>(parent);
                    break;

                default:
                    if (callExternalFactory)
                    {
                        pv = itemFactory.Create <UnknownPropertyValue>(parent);

                        if (pv.GetType() == typeof(UnknownPropertyValue))
                        {
                            // UnknownPropertyValue is just a placeholder for plugins to use.
                            // If one is actually created, discard it.
                            pv = null;
                        }
                    }
                    break;
                }
            }

            if (pv != null)
            {
                if (!pv.Parse(itemFactory, text, tokens))
                {
                    pv = null;
                }
            }

            return(pv);
        }