[gtk+/parser: 31/74] cssprovider: Rework declaration parsing loop
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/parser: 31/74] cssprovider: Rework declaration parsing loop
- Date: Mon, 9 May 2011 15:25:22 +0000 (UTC)
commit 99f81c36bcae5ef988cfa3f1a592c43f8a4d6ad8
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 8973eec..c34cca6 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]