parser: Add gtk_css_parser_has_token()

This is ithe first step towards converting the parsing code to use
tokens. For now, the topken type is just a magic enum value that only
works as-needed.
This commit is contained in:
Benjamin Otte 2019-03-23 18:21:59 +01:00
parent 32e256e5ab
commit 904a9d0c98
3 changed files with 74 additions and 5 deletions

View File

@ -461,11 +461,78 @@ _gtk_css_parser_try_ident (GtkCssParser *parser,
}
gboolean
_gtk_css_parser_is_string (GtkCssParser *parser)
gtk_css_parser_has_token (GtkCssParser *parser,
GtkCssTokenType type)
{
g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
return *parser->data == '"' || *parser->data == '\'';
switch (type)
{
case GTK_CSS_TOKEN_STRING:
return *parser->data == '"' || *parser->data == '\'';
case GTK_CSS_TOKEN_OPEN_CURLY:
return *parser->data == '{';
case GTK_CSS_TOKEN_CLOSE_CURLY:
return *parser->data == '}';
case GTK_CSS_TOKEN_OPEN_PARENS:
return *parser->data == '(';
case GTK_CSS_TOKEN_CLOSE_PARENS:
return *parser->data == ')';
case GTK_CSS_TOKEN_COMMA:
return *parser->data == ',';
case GTK_CSS_TOKEN_COLON:
return *parser->data == ':';
case GTK_CSS_TOKEN_SEMICOLON:
return *parser->data == ';';
case GTK_CSS_TOKEN_AT_KEYWORD:
return *parser->data == '@';
case GTK_CSS_TOKEN_EOF:
return *parser->data == 0;
case GTK_CSS_TOKEN_IDENT:
return *parser->data != 0 &&
strchr (NMSTART "-", *parser->data) != NULL;
default:
case GTK_CSS_TOKEN_FUNCTION:
case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
case GTK_CSS_TOKEN_HASH_ID:
case GTK_CSS_TOKEN_URL:
case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
case GTK_CSS_TOKEN_DIMENSION:
case GTK_CSS_TOKEN_WHITESPACE:
case GTK_CSS_TOKEN_OPEN_SQUARE:
case GTK_CSS_TOKEN_CLOSE_SQUARE:
case GTK_CSS_TOKEN_CDC:
case GTK_CSS_TOKEN_CDO:
case GTK_CSS_TOKEN_DELIM:
case GTK_CSS_TOKEN_SIGNED_INTEGER:
case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
case GTK_CSS_TOKEN_SIGNED_NUMBER:
case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
case GTK_CSS_TOKEN_PERCENTAGE:
case GTK_CSS_TOKEN_INCLUDE_MATCH:
case GTK_CSS_TOKEN_DASH_MATCH:
case GTK_CSS_TOKEN_PREFIX_MATCH:
case GTK_CSS_TOKEN_SUFFIX_MATCH:
case GTK_CSS_TOKEN_SUBSTRING_MATCH:
case GTK_CSS_TOKEN_COLUMN:
case GTK_CSS_TOKEN_BAD_STRING:
case GTK_CSS_TOKEN_BAD_URL:
case GTK_CSS_TOKEN_COMMENT:
g_assert_not_reached ();
return FALSE;
}
}
char *
@ -838,7 +905,7 @@ gtk_css_parser_resync_internal (GtkCssParser *parser,
if (gtk_css_parser_new_line (parser))
continue;
if (_gtk_css_parser_is_string (parser))
if (gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_STRING))
{
/* Hrm, this emits errors, and i suspect it shouldn't... */
char *free_me = _gtk_css_parser_read_string (parser);

View File

@ -21,6 +21,7 @@
#include <gtk/gtkcssprovider.h>
#include <gtk/css/gtkcss.h>
#include "gtk/css/gtkcsstokenizerprivate.h"
G_BEGIN_DECLS
@ -53,7 +54,8 @@ gboolean _gtk_css_parser_begins_with (GtkCssParser *parser
char c);
gboolean _gtk_css_parser_has_prefix (GtkCssParser *parser,
const char *prefix);
gboolean _gtk_css_parser_is_string (GtkCssParser *parser);
gboolean gtk_css_parser_has_token (GtkCssParser *parser,
GtkCssTokenType token_type);
/* IMPORTANT:
* _try_foo() functions do not modify the data pointer if they fail, nor do they

View File

@ -782,7 +782,7 @@ parse_import (GtkCssScanner *scanner)
return FALSE;
}
if (_gtk_css_parser_is_string (scanner->parser))
if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_STRING))
{
char *uri;