Exemplo n.º 1
0
        public void Url_ParseTest()
        {
            TokenStream   tokens;
            string        text = "url(www.microsoft.com)";
            ITextProvider tp   = new StringTextProvider(text);

            tokens = Helpers.MakeTokenStream(tp);
            UrlItem u = new UrlItem();

            Assert.IsTrue(u.Parse(new ItemFactory(tp, null), tp, tokens));

            text   = "url('www.microsoft.com')";
            tp     = new StringTextProvider(text);
            tokens = Helpers.MakeTokenStream(tp);
            u      = new UrlItem();
            Assert.IsTrue(u.Parse(new ItemFactory(tp, null), tp, tokens));

            text   = "url()";
            tp     = new StringTextProvider(text);
            tokens = Helpers.MakeTokenStream(tp);
            u      = new UrlItem();
            Assert.IsTrue(u.Parse(new ItemFactory(tp, null), tp, tokens));
        }
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            ParseAtAndKeyword(itemFactory, text, tokens);

            if (tokens.CurrentToken.TokenType == CssTokenType.Identifier)
            {
                Namespace = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.ItemNamespace);
            }

            if (tokens.CurrentToken.IsString())
            {
                String = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.String);
            }
            else if (tokens.CurrentToken.TokenType == CssTokenType.Url)
            {
                Url = new UrlItem();

                if (Url.Parse(itemFactory, text, tokens))
                {
                    Url.Context = CssClassifierContextCache.FromTypeEnum(CssClassifierContextType.UrlString);
                    Children.Add(Url);
                }
                else
                {
                    Url = null;
                }
            }

            if (String == null && Url == null)
            {
                Children.AddParseError(ParseErrorType.UrlNamespaceMissing);
            }

            CheckSemicolon(tokens);

            return(Children.Count > 0);
        }
Exemplo n.º 3
0
        protected virtual void ParseUrl(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            if (tokens.CurrentToken.IsString())
            {
                FileNames.Add(Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.ImportUrl));
            }
            else if (tokens.CurrentToken.TokenType == CssTokenType.Url)
            {
                UrlItem url = new UrlItem
                {
                    Context = CssClassifierContextCache.FromTypeEnum(CssClassifierContextType.ImportUrl)
                };

                if (url.Parse(itemFactory, text, tokens))
                {
                    FileNames.Add(url);
                    Children.Add(url);
                }
            }
            else
            {
                Children.AddParseError(ParseErrorType.UrlImportMissing);
            }
        }