diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-05-26 23:14:40 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-05-26 23:14:40 +0000 |
commit | 41973ef1ab2935818a07b5899c1961e9c8c85214 (patch) | |
tree | 4c787ed51e8d3b7d00f11c61e2274c267c8a1981 /src/parse/language.h | |
parent | 83146f43df1f1330c10cedad4e97e90c7f2c1243 (diff) | |
download | libcss-41973ef1ab2935818a07b5899c1961e9c8c85214.tar.gz libcss-41973ef1ab2935818a07b5899c1961e9c8c85214.tar.bz2 |
More refactoring groundwork. This actually compiles and passes the testsuite.
svn path=/trunk/libcss/; revision=7556
Diffstat (limited to 'src/parse/language.h')
-rw-r--r-- | src/parse/language.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/parse/language.h b/src/parse/language.h index cd7dd74..0b1d56f 100644 --- a/src/parse/language.h +++ b/src/parse/language.h @@ -8,18 +8,75 @@ #ifndef css_parse_language_h_ #define css_parse_language_h_ +#include <parserutils/utils/stack.h> #include <parserutils/utils/vector.h> #include <libcss/functypes.h> #include <libcss/types.h> +#include "lex/lex.h" #include "parse/parse.h" +#include "parse/propstrings.h" -typedef struct css_language css_language; +/** + * Context for a CSS language parser + */ +typedef struct css_language { + css_stylesheet *sheet; /**< The stylesheet to parse for */ + +#define STACK_CHUNK 32 + parserutils_stack *context; /**< Context stack */ + + enum { + BEFORE_CHARSET, + BEFORE_RULES, + HAD_RULE + } state; /**< State flag, for at-rule handling */ + + /** \todo These should be statically allocated */ + /** Interned strings */ + lwc_string *strings[LAST_KNOWN]; + + css_allocator_fn alloc; /**< Memory (de)allocation function */ + void *pw; /**< Client's private data */ +} css_language; css_error css_language_create(css_stylesheet *sheet, css_parser *parser, css_allocator_fn alloc, void *pw, void **language); css_error css_language_destroy(css_language *language); +/****************************************************************************** + * Helper functions * + ******************************************************************************/ + +/** + * Consume all leading whitespace tokens + * + * \param vector The vector to consume from + * \param ctx The vector's context + */ +static inline void consumeWhitespace(const parserutils_vector *vector, int *ctx) +{ + const css_token *token = NULL; + + while ((token = parserutils_vector_peek(vector, *ctx)) != NULL && + token->type == CSS_TOKEN_S) + token = parserutils_vector_iterate(vector, ctx); +} + +/** + * Determine if a token is a character + * + * \param token The token to consider + * \param c The character to match (lowercase ASCII only) + * \return True if the token matches, false otherwise + */ +static inline bool tokenIsChar(const css_token *token, uint8_t c) +{ + return token != NULL && token->type == CSS_TOKEN_CHAR && + lwc_string_length(token->ilower) == 1 && + lwc_string_data(token->ilower)[0] == c; +} + #endif |