[gtk+/wip/otte/tokenizer: 40/78] css: Move blocks handling to the token sources that need it
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/tokenizer: 40/78] css: Move blocks handling to the token sources that need it
- Date: Fri, 25 Nov 2016 22:35:04 +0000 (UTC)
commit 920a88512bc8809245b108ae6b75fcc72fcfeec9
Author: Benjamin Otte <otte redhat com>
Date: Sun Mar 20 01:46:11 2016 +0100
css: Move blocks handling to the token sources that need it
They need different ways of handling blocks, so they better do it
themselves instead of having a generic way that always gets it wrong.
gtk/gtkcssrule.c | 43 ++++++++++++++++------
gtk/gtkcsstokensource.c | 76 +++++++++++++++-------------------------
gtk/gtkcsstokensourceprivate.h | 3 --
3 files changed, 59 insertions(+), 63 deletions(-)
---
diff --git a/gtk/gtkcssrule.c b/gtk/gtkcssrule.c
index 70ed6d8..cffd975 100644
--- a/gtk/gtkcssrule.c
+++ b/gtk/gtkcssrule.c
@@ -33,7 +33,7 @@ typedef struct _GtkCssTokenSourceAt GtkCssTokenSourceAt;
struct _GtkCssTokenSourceAt {
GtkCssTokenSource parent;
GtkCssTokenSource *source;
- guint inside_curly_block :1;
+ GSList *blocks;
guint done :1;
};
@@ -42,6 +42,8 @@ gtk_css_token_source_at_finalize (GtkCssTokenSource *source)
{
GtkCssTokenSourceAt *at = (GtkCssTokenSourceAt *) source;
+ g_slist_free (at->blocks);
+
gtk_css_token_source_unref (at->source);
}
@@ -55,20 +57,37 @@ gtk_css_token_source_at_consume_token (GtkCssTokenSource *source,
if (at->done)
return;
- if (gtk_css_token_get_pending_block (source))
+ token = gtk_css_token_source_peek_token (at->source);
+ switch (token->type)
{
- gtk_css_token_source_consume_token_as (at->source, consumer);
- return;
+ case GTK_CSS_TOKEN_FUNCTION:
+ case GTK_CSS_TOKEN_OPEN_PARENS:
+ at->blocks = g_slist_prepend (at->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_PARENS));
+ break;
+ case GTK_CSS_TOKEN_OPEN_SQUARE:
+ at->blocks = g_slist_prepend (at->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_SQUARE));
+ break;
+ case GTK_CSS_TOKEN_OPEN_CURLY:
+ at->blocks = g_slist_prepend (at->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_CURLY));
+ break;
+ case GTK_CSS_TOKEN_CLOSE_PARENS:
+ case GTK_CSS_TOKEN_CLOSE_SQUARE:
+ case GTK_CSS_TOKEN_CLOSE_CURLY:
+ if (at->blocks && GPOINTER_TO_UINT (at->blocks->data) == token->type)
+ {
+ at->blocks = g_slist_remove (at->blocks, at->blocks->data);
+ if (token->type == GTK_CSS_TOKEN_CLOSE_CURLY && at->blocks == NULL)
+ at->done = TRUE;
+ }
+ break;
+ case GTK_CSS_TOKEN_SEMICOLON:
+ if (at->blocks == NULL)
+ at->done = TRUE;
+ break;
+ default:
+ break;
}
- token = gtk_css_token_source_peek_token (at->source);
- if (gtk_css_token_is (token, GTK_CSS_TOKEN_SEMICOLON))
- at->done = TRUE;
- else if (at->inside_curly_block && gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_CURLY))
- at->done = TRUE;
- else if (gtk_css_token_is (token, GTK_CSS_TOKEN_OPEN_CURLY))
- at->inside_curly_block = TRUE;
-
gtk_css_token_source_consume_token_as (at->source, consumer);
}
diff --git a/gtk/gtkcsstokensource.c b/gtk/gtkcsstokensource.c
index 9ed2675..f1fadfe 100644
--- a/gtk/gtkcsstokensource.c
+++ b/gtk/gtkcsstokensource.c
@@ -126,6 +126,7 @@ struct _GtkCssTokenSourcePart {
GtkCssTokenSource parent;
GtkCssTokenSource *source;
GtkCssTokenType end_type;
+ GSList *blocks; /* of GPOINTER_TO_UINT(GtkCssTokenType) */
};
static void
@@ -134,6 +135,7 @@ gtk_css_token_source_part_finalize (GtkCssTokenSource *source)
GtkCssTokenSourcePart *part = (GtkCssTokenSourcePart *) source;
gtk_css_token_source_unref (part->source);
+ g_slist_free (part->blocks);
}
static void
@@ -143,11 +145,32 @@ gtk_css_token_source_part_consume_token (GtkCssTokenSource *source,
GtkCssTokenSourcePart *part = (GtkCssTokenSourcePart *) source;
const GtkCssToken *token;
- if (!gtk_css_token_get_pending_block (source))
+ token = gtk_css_token_source_peek_token (part->source);
+
+ if (part->blocks)
+ {
+ if (token->type == GPOINTER_TO_UINT (part->blocks->data))
+ part->blocks = g_slist_remove (part->blocks, part->blocks->data);
+ }
+ else if (gtk_css_token_is (token, part->end_type))
{
- token = gtk_css_token_source_peek_token (part->source);
- if (gtk_css_token_is (token, part->end_type))
- return;
+ return;
+ }
+
+ switch (token->type)
+ {
+ case GTK_CSS_TOKEN_FUNCTION:
+ case GTK_CSS_TOKEN_OPEN_PARENS:
+ part->blocks = g_slist_prepend (part->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_PARENS));
+ break;
+ case GTK_CSS_TOKEN_OPEN_SQUARE:
+ part->blocks = g_slist_prepend (part->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_SQUARE));
+ break;
+ case GTK_CSS_TOKEN_OPEN_CURLY:
+ part->blocks = g_slist_prepend (part->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_CURLY));
+ break;
+ default:
+ break;
}
gtk_css_token_source_consume_token_as (part->source, consumer);
@@ -161,7 +184,7 @@ gtk_css_token_source_part_peek_token (GtkCssTokenSource *source)
const GtkCssToken *token;
token = gtk_css_token_source_peek_token (part->source);
- if (!gtk_css_token_get_pending_block (source) &&
+ if (part->blocks == NULL &&
gtk_css_token_is (token, part->end_type))
return &eof_token;
@@ -257,41 +280,7 @@ void
gtk_css_token_source_consume_token_as (GtkCssTokenSource *source,
GObject *consumer)
{
- const GtkCssToken *token;
-
- if (source->blocks)
- {
- token = gtk_css_token_source_peek_token (source);
- if (gtk_css_token_is (token, GPOINTER_TO_UINT (source->blocks->data)))
- source->blocks = g_slist_remove (source->blocks, source->blocks->data);
- }
-
source->klass->consume_token (source, consumer);
-
- token = gtk_css_token_source_peek_token (source);
- switch (token->type)
- {
- case GTK_CSS_TOKEN_FUNCTION:
- case GTK_CSS_TOKEN_OPEN_PARENS:
- source->blocks = g_slist_prepend (source->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_PARENS));
- break;
- case GTK_CSS_TOKEN_OPEN_SQUARE:
- source->blocks = g_slist_prepend (source->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_SQUARE));
- break;
- case GTK_CSS_TOKEN_OPEN_CURLY:
- source->blocks = g_slist_prepend (source->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_CURLY));
- break;
- default:
- break;
- }
-
- source->klass->consume_token (source, consumer);
-
- if (source->blocks)
- {
- if (token_type == GPOINTER_TO_UINT (source->blocks->data))
- source->blocks = g_slist_remove (source->blocks, source->blocks->data);
- }
}
const GtkCssToken *
@@ -521,15 +510,6 @@ gtk_css_token_source_consume_url (GtkCssTokenSource *source)
}
}
-GtkCssTokenType
-gtk_css_token_get_pending_block (GtkCssTokenSource *source)
-{
- if (!source->blocks)
- return GTK_CSS_TOKEN_EOF;
-
- return GPOINTER_TO_UINT(source->blocks->data);
-}
-
void
gtk_css_token_source_emit_error (GtkCssTokenSource *source,
const GError *error)
diff --git a/gtk/gtkcsstokensourceprivate.h b/gtk/gtkcsstokensourceprivate.h
index 7b82762..def15bc 100644
--- a/gtk/gtkcsstokensourceprivate.h
+++ b/gtk/gtkcsstokensourceprivate.h
@@ -33,7 +33,6 @@ struct _GtkCssTokenSource
const GtkCssTokenSourceClass *klass;
gint ref_count;
GObject *consumer;
- GSList *blocks; /* of GPOINTER_TO_UINT(GtkCssTokenType) */
};
struct _GtkCssTokenSourceClass
@@ -65,8 +64,6 @@ void gtk_css_token_source_consume_token_as (GtkCssTokenSour
const GtkCssToken * gtk_css_token_source_peek_token (GtkCssTokenSource *source);
const GtkCssToken * gtk_css_token_source_get_token (GtkCssTokenSource *source);
-GtkCssTokenType gtk_css_token_get_pending_block (GtkCssTokenSource *source);
-
void gtk_css_token_source_consume_all (GtkCssTokenSource *source);
char * gtk_css_token_source_consume_to_string (GtkCssTokenSource *source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]