static MediaQuery Consume_MediaQuery(DataConsumer <CssToken> Stream = null) {/* Docs: https://drafts.csswg.org/mediaqueries-4/#mq-syntax */ if (Stream is null) { throw new CssParserException(CssErrors.STREAM_IS_NULL); } if (Stream.Next.Type != ECssTokenType.Ident) { throw new CssSyntaxErrorException(CssErrors.EXPECTING_IDENT, Stream); } EMediaQueryModifier modifier = 0x0; EMediaType mediaType = 0x0; LinkedList <IMediaCondition> conditionList = new LinkedList <IMediaCondition>(); /* First check for media modifier */ if (Stream.Next.Type != ECssTokenType.Ident) { throw new CssSyntaxErrorException(CssErrors.EXPECTING_IDENT, Stream); } if (Lookup.TryEnum((Stream.Next as IdentToken).Value, out EMediaQueryModifier mod)) { Stream.Consume();// consume this token modifier = mod; } /* Skip 'and' keyword if present */ if (ParserCommon.Is_Combinator(Stream.Next)) { Stream.Consume(); } /* Set the media type */ if (Stream.Next.Type != ECssTokenType.Ident) { throw new CssSyntaxErrorException(CssErrors.EXPECTING_IDENT, Stream); } if (!Lookup.TryEnum((Stream.Next as IdentToken).Value, out EMediaType type)) { throw new CssParserException(String.Format(CultureInfo.InvariantCulture, CssErrors.INVALID_MEDIA_TYPE, (Stream.Next as IdentToken).Value), Stream); } else { Stream.Consume(); } /* Skip thew first combinator keyword if present */ Consume_All_Whitespace(Stream); if (ParserCommon.Is_Combinator(Stream.Next)) { Stream.Consume(); } /* Now consume media conditions until we cant anymore */ do { Consume_All_Whitespace(Stream); if (Stream.Next.Type != ECssTokenType.Parenth_Open) {/* This isn't invalid, it just signals that we have no more features to consume */ break; } var condition = Consume_Media_Condition(Stream); conditionList.AddLast(condition); }while (Stream.Next.Type != ECssTokenType.EOF); return(new MediaQuery(modifier, mediaType, conditionList)); }
public MediaQuery(EMediaQueryModifier modifier, EMediaType mediaType, LinkedList <IMediaCondition> conditions) { Modifier = modifier; MediaType = mediaType; Conditions = conditions; }