Ejemplo n.º 1
0
        public static CssMedium Parse(String str, IFeatureValidatorFactory factory)
        {
            var source = new StringSource(str);
            var result = source.ParseMedium(factory);

            return(source.IsDone ? result : null);
        }
Ejemplo n.º 2
0
        public static IEnumerable <CssMedium> ParseMedia(this StringSource source, IFeatureValidatorFactory factory)
        {
            var current = source.SkipSpacesAndComments();
            var media   = new List <CssMedium>();

            while (!source.IsDone)
            {
                if (media.Count > 0)
                {
                    if (current != Symbols.Comma)
                    {
                        return(null);
                    }

                    source.SkipCurrentAndSpaces();
                }

                var medium = source.ParseMedium(factory);

                if (medium == null)
                {
                    return(null);
                }

                media.Add(medium);
                current = source.SkipSpacesAndComments();
            }

            return(media);
        }
Ejemplo n.º 3
0
        public static CssMedium ParseMedium(this StringSource source, IFeatureValidatorFactory factory)
        {
            source.SkipSpacesAndComments();
            var ident     = source.ParseIdent();
            var inverse   = false;
            var exclusive = false;
            var type      = String.Empty;

            if (ident != null)
            {
                if (ident.Isi(CssKeywords.Not))
                {
                    inverse = true;
                    source.SkipSpacesAndComments();
                    ident = source.ParseIdent();
                }
                else if (ident.Isi(CssKeywords.Only))
                {
                    exclusive = true;
                    source.SkipSpacesAndComments();
                    ident = source.ParseIdent();
                }
            }

            if (ident != null)
            {
                type = ident;
                source.SkipSpacesAndComments();
                var position = source.Index;
                ident = source.ParseIdent();

                if (ident == null || !ident.Isi(CssKeywords.And))
                {
                    source.BackTo(position);
                    return(new CssMedium(type, inverse, exclusive));
                }

                source.SkipSpacesAndComments();
            }

            var features = new List <IMediaFeature>();

            do
            {
                var start = source.Current;
                source.SkipCurrentAndSpaces();
                var feature = ParseFeature(source);
                var end     = source.Current;

                if (feature == null ||
                    start != Symbols.RoundBracketOpen ||
                    end != Symbols.RoundBracketClose)
                {
                    return(null);
                }

                var validator = factory?.Create(feature.Name);
                feature.AssociateValidator(validator);
                features.Add(feature);
                source.SkipCurrentAndSpaces();
                var position = source.Index;
                ident = source.ParseIdent();

                if (ident == null || !ident.Isi(CssKeywords.And))
                {
                    source.BackTo(position);
                    break;
                }

                source.SkipSpacesAndComments();
            }while (!source.IsDone);

            return(new CssMedium(type, inverse, exclusive, features));
        }