[gtk+] cssprovider: Rework declaration parsing loop
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssprovider: Rework declaration parsing loop
- Date: Wed, 18 May 2011 20:26:43 +0000 (UTC)
commit 22bda2b92f805c76fb280c843590de326d363d4d
Author: Benjamin Otte <otte redhat com>
Date: Sat Apr 9 18:18:02 2011 +0200
cssprovider: Rework declaration parsing loop
The new loop can cope better with invalid identifiers and manages to
resume parsing properly.
gtk/gtkcssprovider.c | 46 +++++++++++++++++++++++++++++++---------------
1 files changed, 31 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 0845ed4..8bb594d 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1588,6 +1588,16 @@ gtk_css_provider_take_error (GtkCssProvider *provider,
}
static void
+gtk_css_provider_error_literal (GtkCssProvider *provider,
+ GQuark domain,
+ gint code,
+ const char *message)
+{
+ gtk_css_provider_take_error (provider,
+ g_error_new_literal (domain, code, message));
+}
+
+static void
gtk_css_provider_error (GtkCssProvider *provider,
GQuark domain,
gint code,
@@ -2348,15 +2358,32 @@ parse_rule (GtkCssProvider *css_provider,
/* Declarations parsing */
css_provider_push_scope (css_provider, SCOPE_DECLARATION);
- g_scanner_get_next_token (scanner);
- while (scanner->token == G_TOKEN_IDENTIFIER)
+ g_scanner_get_next_token (scanner);
+
+ while (scanner->token != G_TOKEN_RIGHT_CURLY &&
+ !g_scanner_eof (scanner))
{
gchar *value_str = NULL;
GtkStylePropertyParser parse_func = NULL;
GParamSpec *pspec = NULL;;
gchar *prop;
+ if (scanner->token == ';')
+ {
+ g_scanner_get_next_token (scanner);
+ continue;
+ }
+
+ if (scanner->token != G_TOKEN_IDENTIFIER)
+ {
+ gtk_css_provider_error_literal (css_provider,
+ GTK_CSS_PROVIDER_ERROR,
+ GTK_CSS_PROVIDER_ERROR_PROPERTY_NAME,
+ "Expected a valid property name");
+ goto find_end_of_declaration;
+ }
+
prop = g_strdup (scanner->value.v_identifier);
if (!gtk_style_properties_lookup_property (prop, &parse_func, &pspec) &&
@@ -2491,22 +2518,11 @@ parse_rule (GtkCssProvider *css_provider,
}
find_end_of_declaration:
- while (scanner->token != ';' &&
- scanner->token != G_TOKEN_RIGHT_CURLY &&
- scanner->token != G_TOKEN_EOF)
+ while (scanner->token != G_TOKEN_RIGHT_CURLY &&
+ !g_scanner_eof (scanner))
g_scanner_get_next_token (scanner);
-
- if (scanner->token == G_TOKEN_RIGHT_CURLY ||
- scanner->token == G_TOKEN_EOF)
- break;
-
- g_scanner_get_next_token (scanner);
}
- if (scanner->token != G_TOKEN_RIGHT_CURLY &&
- scanner->token != G_TOKEN_EOF)
- return G_TOKEN_RIGHT_CURLY;
-
css_provider_pop_scope (css_provider);
return G_TOKEN_NONE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]