From 3342c8e3bafba86ff1154db940891a3405cb1c30 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 1 Aug 2018 15:38:49 +0100 Subject: HACKS for testing Media Queries parsing. Top level stylesheets need to have their media query passed in. So we need a way to parse standalone media queries. This was hacked together to explore doing that. However, it encounteded an issue where it seems the parseAtRule() function in src/parse/parse.c doesn't handle the full grammar for media queries. --- src/parse/language.c | 1 - src/parse/parse.c | 19 +++++++++++++++++++ src/parse/parse.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/parse') diff --git a/src/parse/language.c b/src/parse/language.c index faafcfd..54fac9a 100644 --- a/src/parse/language.c +++ b/src/parse/language.c @@ -532,7 +532,6 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector) css_mq_query *media = NULL; /* any0 = media query */ - error = css__mq_parse_media_list( c->strings, vector, &ctx, &media); if (error != CSS_OK) diff --git a/src/parse/parse.c b/src/parse/parse.c index 4cc1c98..d58e328 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -219,6 +219,25 @@ css_error css__parser_create_for_inline_style(const char *charset, initial, parser); } +/** + * Create a CSS parser for a media query + * + * \param charset Charset of data, if known, or NULL + * \param cs_source Source of charset information, or CSS_CHARSET_DEFAULT + * \param parser Pointer to location to receive parser instance + * \return CSS_OK on success, + * CSS_BADPARM on bad parameters, + * CSS_NOMEM on memory exhaustion + */ +css_error css__parser_create_for_media_query(const char *charset, + css_charset_source cs_source, css_parser **parser) +{ + parser_state initial = { sAtRule, 0 }; + + return css__parser_create_internal(charset, cs_source, + initial, parser); +} + /** * Destroy a CSS parser * diff --git a/src/parse/parse.h b/src/parse/parse.h index 833aa51..e65f055 100644 --- a/src/parse/parse.h +++ b/src/parse/parse.h @@ -61,6 +61,8 @@ css_error css__parser_create(const char *charset, css_charset_source cs_source, css_parser **parser); css_error css__parser_create_for_inline_style(const char *charset, css_charset_source cs_source, css_parser **parser); +css_error css__parser_create_for_media_query(const char *charset, + css_charset_source cs_source, css_parser **parser); css_error css__parser_destroy(css_parser *parser); css_error css__parser_setopt(css_parser *parser, css_parser_opttype type, -- cgit v1.2.3