Exemplo n.º 1
0
        CssValue CreateValue(CssTokenType closing, ref CssToken token, out Boolean important)
        {
            var value = Pool.NewValueBuilder();

            _tokenizer.IsInValue = true;
            token = NextToken();
            var start = token.Position;

            while (token.IsNot(CssTokenType.EndOfFile, CssTokenType.Semicolon, closing))
            {
                value.Apply(token);
                token = NextToken();
            }

            important            = value.IsImportant;
            _tokenizer.IsInValue = false;
            var result = value.ToPool();
            var node   = result as CssNode;

            if (node != null)
            {
                var end = token.Position.Shift(-1);
                node.SourceCode = CreateView(start, end);
            }

            if (!value.IsValid && !_parser.Options.IsToleratingInvalidValues)
            {
                RaiseErrorOccurred(CssParseError.InvalidValue, start);
                result = null;
            }

            return(result);
        }
Exemplo n.º 2
0
 void JumpToEnd(CssToken current)
 {
     while (current.IsNot(CssTokenType.Eof, CssTokenType.Semicolon))
     {
         current = NextToken();
     }
 }
Exemplo n.º 3
0
        ISelector CreateSelector(ref CssToken token)
        {
            var selector = Pool.NewSelectorConstructor();
            var start    = token.Position;

            while (token.IsNot(CssTokenType.EndOfFile, CssTokenType.CurlyBracketOpen, CssTokenType.CurlyBracketClose))
            {
                selector.Apply(token);
                token = NextToken();
            }

            var result = selector.ToPool();
            var node   = result as CssNode;

            if (node != null)
            {
                var end = token.Position.Shift(-1);
                node.SourceCode = CreateView(start, end);
            }

            if (!selector.IsValid && !_parser.Options.IsToleratingInvalidValues)
            {
                RaiseErrorOccurred(CssParseError.InvalidSelector, start);
                result = null;
            }

            return(result);
        }
Exemplo n.º 4
0
 private void JumpToEnd(ref CssToken current)
 {
     while (current.IsNot(CssTokenType.EndOfFile, CssTokenType.Semicolon))
     {
         current = NextToken();
     }
 }
Exemplo n.º 5
0
        MediaFeature CreateFeature(ref CssToken token)
        {
            if (token.Type == CssTokenType.Ident)
            {
                var start   = token.Position;
                var val     = CssValue.Empty;
                var feature = _parser.Options.IsToleratingInvalidConstraints ?
                              new UnknownMediaFeature(token.Data) : Factory.MediaFeatures.Create(token.Data);

                token = NextToken();

                if (token.Type == CssTokenType.Colon)
                {
                    var value = Pool.NewValueBuilder();
                    token = NextToken();

                    while (token.IsNot(CssTokenType.RoundBracketClose, CssTokenType.EndOfFile) || !value.IsReady)
                    {
                        value.Apply(token);
                        token = NextToken();
                    }

                    val = value.ToPool();
                }
                else if (token.Type == CssTokenType.EndOfFile)
                {
                    return(null);
                }

                if (feature != null && feature.TrySetValue(val))
                {
                    var node = feature as CssNode;

                    if (node != null)
                    {
                        var end = token.Position.Shift(-1);
                        node.SourceCode = CreateView(start, end);
                    }

                    return(feature);
                }
            }
            else
            {
                JumpToArgEnd(ref token);
            }

            return(null);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        ISelector CreateSelector(ref CssToken token)
        {
            var selector = Pool.NewSelectorConstructor();
            var start    = token;

            CreateNewNode();

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

            if (!selector.IsValid)
            {
                RaiseErrorOccurred(CssParseError.InvalidSelector, start);
            }

            return(CloseNode(selector.ToPool()));
        }
Exemplo n.º 8
0
        /// <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());
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a list of CssMedium objects.
        /// </summary>
        public List <CssMedium> CreateMedia(ref CssToken token)
        {
            var list = new List <CssMedium>();

            CollectTrivia(ref token);

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

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

                token = NextToken();
                CollectTrivia(ref token);
                list.Add(medium);
            }

            return(list);
        }
Exemplo n.º 10
0
        ISelector CreateSelector(ref CssToken token)
        {
            var selector = Pool.NewSelectorConstructor();
            var start    = token;

            CreateNewNode();

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

            var result = selector.ToPool();

            if (!selector.IsValid && !_parser.Options.IsToleratingInvalidValues)
            {
                RaiseErrorOccurred(CssParseError.InvalidSelector, start);
                result = null;
            }

            return(CloseNode(result));
        }
Exemplo n.º 11
0
        /// <summary>
        /// State that is called once we are in a CSS selector.
        /// </summary>
        protected 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();
        }