[gtk+/wip/otte/tokenizer: 29/78] css: Consume whitespace tokens automatically



commit 90e423b34d5de45e27f3e58fea4fd3ab474383b1
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 18 03:54:27 2016 +0100

    css: Consume whitespace tokens automatically
    
    Exception: The selector parsing code uses the peek_token() vfunc to
    actually get the real tokens, whitepsace included.

 gtk/gtkcssarrayvalue.c         |    3 --
 gtk/gtkcssbordervalue.c        |    4 ---
 gtk/gtkcsscalcvalue.c          |    9 ------
 gtk/gtkcsscolorvalue.c         |   10 -------
 gtk/gtkcsscornervalue.c        |    1 -
 gtk/gtkcssdeclaration.c        |    2 -
 gtk/gtkcsspalettevalue.c       |    3 --
 gtk/gtkcssrepeatvalue.c        |    2 -
 gtk/gtkcssrule.c               |    8 +++---
 gtk/gtkcssselector.c           |   44 +++++++++++++++++++-----------
 gtk/gtkcssshadowsvalue.c       |    2 -
 gtk/gtkcssshadowvalue.c        |    6 ----
 gtk/gtkcssstylepropertyimpl.c  |    2 -
 gtk/gtkcssstylerule.c          |    1 -
 gtk/gtkcsstokensource.c        |   57 ++++++++++++++++-----------------------
 gtk/gtkcsstokensourceprivate.h |    5 +--
 gtk/gtkcsswin32sizevalue.c     |    4 ---
 gtk/gtkstyleproperty.c         |    4 ---
 18 files changed, 57 insertions(+), 110 deletions(-)
---
diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c
index 7477485..8348243 100644
--- a/gtk/gtkcssarrayvalue.c
+++ b/gtk/gtkcssarrayvalue.c
@@ -389,7 +389,6 @@ gtk_css_array_value_token_parse (GtkCssTokenSource *source,
   values = g_ptr_array_new ();
 
   while (TRUE) {
-    gtk_css_token_source_consume_whitespace (source);
     value = parse_func (source);
 
     if (value == NULL)
@@ -400,11 +399,9 @@ gtk_css_array_value_token_parse (GtkCssTokenSource *source,
       }
 
     g_ptr_array_add (values, value);
-    gtk_css_token_source_consume_whitespace (source);
     if (!gtk_css_token_is (gtk_css_token_source_get_token (source), GTK_CSS_TOKEN_COMMA))
       break;
     gtk_css_token_source_consume_token (source);
-    gtk_css_token_source_consume_whitespace (source);
   }
 
   result = _gtk_css_array_value_new_from_array ((GtkCssValue **) values->pdata, values->len);
diff --git a/gtk/gtkcssbordervalue.c b/gtk/gtkcssbordervalue.c
index 5f9d236..3964374 100644
--- a/gtk/gtkcssbordervalue.c
+++ b/gtk/gtkcssbordervalue.c
@@ -221,7 +221,6 @@ gtk_css_border_value_token_parse (GtkCssTokenSource      *source,
     {
       result->fill = TRUE;
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
       token = gtk_css_token_source_get_token (source);
     }
 
@@ -233,7 +232,6 @@ gtk_css_border_value_token_parse (GtkCssTokenSource      *source,
         {
           result->fill = TRUE;
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
           i--;
           break;
         }
@@ -241,7 +239,6 @@ gtk_css_border_value_token_parse (GtkCssTokenSource      *source,
       if (allow_auto && gtk_css_token_is_ident (token, "auto"))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
           continue;
         }
 
@@ -254,7 +251,6 @@ gtk_css_border_value_token_parse (GtkCssTokenSource      *source,
           _gtk_css_value_unref (result);
           return NULL;
         }
-      gtk_css_token_source_consume_whitespace (source);
     }
 
   if (i <= 0)
diff --git a/gtk/gtkcsscalcvalue.c b/gtk/gtkcsscalcvalue.c
index 4c9d79d..84d0bc4 100644
--- a/gtk/gtkcsscalcvalue.c
+++ b/gtk/gtkcsscalcvalue.c
@@ -506,7 +506,6 @@ gtk_css_calc_value_token_parse_value (GtkCssTokenSource      *source,
   else if (gtk_css_token_is (token, GTK_CSS_TOKEN_OPEN_PARENS))
     {
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
 
       result = gtk_css_calc_value_token_parse_sum (source, flags);
       if (result == NULL)
@@ -522,7 +521,6 @@ gtk_css_calc_value_token_parse_value (GtkCssTokenSource      *source,
         }
 
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
 
       return result;
     }
@@ -531,8 +529,6 @@ gtk_css_calc_value_token_parse_value (GtkCssTokenSource      *source,
       result = gtk_css_number_value_token_parse (source, flags);
       if (result == NULL)
         return NULL;
-
-      gtk_css_token_source_consume_whitespace (source);
     }
 
   return result;
@@ -561,7 +557,6 @@ gtk_css_calc_value_token_parse_product (GtkCssTokenSource      *source,
       if (gtk_css_token_is_delim (token, '*'))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           value = gtk_css_calc_value_token_parse_product (source, actual_flags);
           if (value == NULL)
@@ -577,7 +572,6 @@ gtk_css_calc_value_token_parse_product (GtkCssTokenSource      *source,
       else if (gtk_css_token_is_delim (token, '/'))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           value = gtk_css_calc_value_token_parse_product (source, GTK_CSS_PARSE_NUMBER);
           if (value == NULL)
@@ -626,7 +620,6 @@ gtk_css_calc_value_token_parse_sum (GtkCssTokenSource      *source,
       if (gtk_css_token_is_delim (token, '+'))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           next = gtk_css_calc_value_token_parse_product (source, flags);
           if (next == NULL)
@@ -635,7 +628,6 @@ gtk_css_calc_value_token_parse_sum (GtkCssTokenSource      *source,
       else if (gtk_css_token_is_delim (token, '-'))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           temp = gtk_css_calc_value_token_parse_product (source, flags);
           if (temp == NULL)
@@ -681,7 +673,6 @@ gtk_css_calc_value_token_parse (GtkCssTokenSource      *source,
       return NULL;
     }
   gtk_css_token_source_consume_token (source);
-  gtk_css_token_source_consume_whitespace (source);
 
   value = gtk_css_calc_value_token_parse_sum (source, flags);
   if (value == NULL)
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c
index 37923e9..6246475 100644
--- a/gtk/gtkcsscolorvalue.c
+++ b/gtk/gtkcsscolorvalue.c
@@ -863,7 +863,6 @@ _gtk_css_color_value_parse (GtkCssParser *parser)
 static gboolean
 parse_comma (GtkCssTokenSource *source)
 {
-  gtk_css_token_source_consume_whitespace (source);
   if (!gtk_css_token_is (gtk_css_token_source_get_token (source), GTK_CSS_TOKEN_COMMA))
     {
       gtk_css_token_source_error (source, "Expected ','");
@@ -872,7 +871,6 @@ parse_comma (GtkCssTokenSource *source)
     }
 
   gtk_css_token_source_consume_token (source);
-  gtk_css_token_source_consume_whitespace (source);
   return TRUE;
 }
 
@@ -968,7 +966,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           GdkRGBA rgba;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           token = gtk_css_token_source_get_token (source);
           if (gtk_css_token_is (token, GTK_CSS_TOKEN_PERCENTAGE))
@@ -1013,7 +1010,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           GtkCssValue *child;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           child = gtk_css_color_value_token_parse (source);
           if (child == NULL)
@@ -1028,7 +1024,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           GtkCssValue *child;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           child = gtk_css_color_value_token_parse (source);
           if (child == NULL)
@@ -1044,7 +1039,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           double d;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           child = gtk_css_color_value_token_parse (source);
           if (child == NULL)
@@ -1066,7 +1060,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           double d;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           child = gtk_css_color_value_token_parse (source);
           if (child == NULL)
@@ -1088,7 +1081,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           double d;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           child1 = gtk_css_color_value_token_parse (source);
           if (child1 == NULL)
@@ -1116,7 +1108,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           int id;
 
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
 
           theme = gtk_win32_theme_token_parse (source);
           if (theme == NULL)
@@ -1157,7 +1148,6 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
           gtk_win32_theme_unref (theme);
         }
       
-      gtk_css_token_source_consume_whitespace (source);
       token = gtk_css_token_source_get_token (source);
       if (!gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_PARENS))
         {
diff --git a/gtk/gtkcsscornervalue.c b/gtk/gtkcsscornervalue.c
index 52ba36e..fde6f37 100644
--- a/gtk/gtkcsscornervalue.c
+++ b/gtk/gtkcsscornervalue.c
@@ -164,7 +164,6 @@ gtk_css_corner_value_token_parse (GtkCssTokenSource *source)
   if (x == NULL)
     return NULL;
 
-  gtk_css_token_source_consume_whitespace (source);
   if (gtk_css_token_is (gtk_css_token_source_get_token (source), GTK_CSS_TOKEN_EOF))
     y = _gtk_css_value_ref (x);
   else
diff --git a/gtk/gtkcssdeclaration.c b/gtk/gtkcssdeclaration.c
index de40941..c95f2da 100644
--- a/gtk/gtkcssdeclaration.c
+++ b/gtk/gtkcssdeclaration.c
@@ -71,7 +71,6 @@ gtk_css_declaration_new_parse (GtkCssStyleDeclaration *style,
 
   gtk_css_token_source_set_consumer (source, G_OBJECT (decl));
 
-  gtk_css_token_source_consume_whitespace (source);
   priv->style = style;
   token = gtk_css_token_source_get_token (source);
   if (!gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT))
@@ -96,7 +95,6 @@ gtk_css_declaration_new_parse (GtkCssStyleDeclaration *style,
                                      "The '%s' property has been renamed to '%s'",
                                      name, _gtk_style_property_get_name (priv->prop));
   gtk_css_token_source_consume_token (source);
-  gtk_css_token_source_consume_whitespace (source);
   g_free (name);
 
   token = gtk_css_token_source_get_token (source);
diff --git a/gtk/gtkcsspalettevalue.c b/gtk/gtkcsspalettevalue.c
index 595dea5..46f1ad1 100644
--- a/gtk/gtkcsspalettevalue.c
+++ b/gtk/gtkcsspalettevalue.c
@@ -270,7 +270,6 @@ gtk_css_palette_value_token_parse (GtkCssTokenSource *source)
         }
       ident = g_strdup (token->string.string);
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
       
       color = gtk_css_color_value_token_parse (source);
       if (color == NULL)
@@ -283,12 +282,10 @@ gtk_css_palette_value_token_parse (GtkCssTokenSource *source)
       gtk_css_palette_value_add_color (result, ident, color);
       g_free (ident);
 
-      gtk_css_token_source_consume_whitespace (source);
       token = gtk_css_token_source_get_token (source);
       if (!gtk_css_token_is (token, GTK_CSS_TOKEN_COMMA))
         break;
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
   }
 
   return result;
diff --git a/gtk/gtkcssrepeatvalue.c b/gtk/gtkcssrepeatvalue.c
index a9b523b..5942f9a 100644
--- a/gtk/gtkcssrepeatvalue.c
+++ b/gtk/gtkcssrepeatvalue.c
@@ -249,7 +249,6 @@ gtk_css_background_repeat_value_token_parse (GtkCssTokenSource *source)
     }
 
   gtk_css_token_source_consume_token (source);
-  gtk_css_token_source_consume_whitespace (source);
   token = gtk_css_token_source_get_token (source);
   if (gtk_css_background_repeat_value_from_token (token, &y))
     gtk_css_token_source_consume_token (source);
@@ -381,7 +380,6 @@ gtk_css_border_repeat_value_token_parse (GtkCssTokenSource *source)
     }
 
   gtk_css_token_source_consume_token (source);
-  gtk_css_token_source_consume_whitespace (source);
   token = gtk_css_token_source_get_token (source);
   if (gtk_css_border_repeat_value_from_token (token, &y))
     gtk_css_token_source_consume_token (source);
diff --git a/gtk/gtkcssrule.c b/gtk/gtkcssrule.c
index 7693b7f..ef65c61 100644
--- a/gtk/gtkcssrule.c
+++ b/gtk/gtkcssrule.c
@@ -61,7 +61,7 @@ gtk_css_token_source_at_consume_token (GtkCssTokenSource *source,
       return;
     }
 
-  token = gtk_css_token_source_get_token (at->source);
+  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))
@@ -73,7 +73,7 @@ gtk_css_token_source_at_consume_token (GtkCssTokenSource *source,
 }
 
 const GtkCssToken *
-gtk_css_token_source_at_get_token (GtkCssTokenSource *source)
+gtk_css_token_source_at_peek_token (GtkCssTokenSource *source)
 {
   GtkCssTokenSourceAt *at = (GtkCssTokenSourceAt *) source;
   static GtkCssToken eof_token = { GTK_CSS_TOKEN_EOF };
@@ -81,7 +81,7 @@ gtk_css_token_source_at_get_token (GtkCssTokenSource *source)
   if (at->done)
     return &eof_token;
 
-  return gtk_css_token_source_get_token (at->source);
+  return gtk_css_token_source_peek_token (at->source);
 }
 
 static void
@@ -96,7 +96,7 @@ gtk_css_token_source_at_error (GtkCssTokenSource *source,
 static const GtkCssTokenSourceClass GTK_CSS_TOKEN_SOURCE_AT = {
   gtk_css_token_source_at_finalize,
   gtk_css_token_source_at_consume_token,
-  gtk_css_token_source_at_get_token,
+  gtk_css_token_source_at_peek_token,
   gtk_css_token_source_at_error
 };
 
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index fd537d3..c7cc832 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -1315,7 +1315,12 @@ token_parse_selector_class (GtkCssTokenSource *source,
   const GtkCssToken *token;
 
   gtk_css_token_source_consume_token (source);
-  token = gtk_css_token_source_get_token (source);
+  for (token = gtk_css_token_source_peek_token (source);
+       gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT);
+       token = gtk_css_token_source_peek_token (source))
+    {
+      gtk_css_token_source_consume_token (source);
+    }
 
   if (gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT))
     {
@@ -1343,7 +1348,6 @@ parse_plus_b (GtkCssTokenSource *source,
   const GtkCssToken *token;
   gboolean has_seen_sign;
 
-  gtk_css_token_source_consume_whitespace (source);
   token = gtk_css_token_source_get_token (source);
 
   if (negate)
@@ -1355,13 +1359,11 @@ parse_plus_b (GtkCssTokenSource *source,
       if (gtk_css_token_is_delim (token, '+'))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
           has_seen_sign = TRUE;
         }
       else if (gtk_css_token_is_delim (token, '-'))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
           negate = TRUE;
           has_seen_sign = TRUE;
         }
@@ -1456,6 +1458,7 @@ parse_a_n_plus_b (GtkCssTokenSource *source,
   gtk_css_token_source_error (source, "Not a valid an+b type");
   return FALSE;
 }
+
 GtkCssSelector *
 token_parse_selector_pseudo_class (GtkCssTokenSource *source,
                                    GtkCssSelector    *selector,
@@ -1464,7 +1467,12 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
   const GtkCssToken *token;
 
   gtk_css_token_source_consume_token (source);
-  token = gtk_css_token_source_get_token (source);
+  for (token = gtk_css_token_source_peek_token (source);
+       gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT);
+       token = gtk_css_token_source_peek_token (source))
+    {
+      gtk_css_token_source_consume_token (source);
+    }
 
   if (gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT))
     {
@@ -1534,7 +1542,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
                 _gtk_css_selector_free (selector);
               return NULL;
             }
-          gtk_css_token_source_consume_whitespace (source);
           token = gtk_css_token_source_get_token (source);
           if (!gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_PARENS))
             {
@@ -1563,7 +1570,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
                 _gtk_css_selector_free (selector);
               return NULL;
             }
-          gtk_css_token_source_consume_whitespace (source);
           token = gtk_css_token_source_get_token (source);
           if (!gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_PARENS))
             {
@@ -1622,7 +1628,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
                   return NULL;
                 }
 
-              gtk_css_token_source_consume_whitespace (source);
               token = gtk_css_token_source_get_token (source);
               if (gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_PARENS))
                 {
@@ -1641,7 +1646,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
       else if (gtk_css_token_is_function (token, "dir"))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
           token = gtk_css_token_source_get_token (source);
           if (gtk_css_token_is_ident (token, "ltr"))
             {
@@ -1667,7 +1671,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
               selector = NULL;
               return NULL;
             }
-          gtk_css_token_source_consume_whitespace (source);
           token = gtk_css_token_source_get_token (source);
           if (!gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_PARENS))
             {
@@ -1681,7 +1684,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
       else if (gtk_css_token_is_function (token, "drop"))
         {
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
           token = gtk_css_token_source_get_token (source);
           if (gtk_css_token_is_ident (token, "active"))
             {
@@ -1699,7 +1701,6 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
               selector = NULL;
               return NULL;
             }
-          gtk_css_token_source_consume_whitespace (source);
           token = gtk_css_token_source_get_token (source);
           if (!gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_PARENS))
             {
@@ -1737,7 +1738,12 @@ token_parse_simple_selector (GtkCssTokenSource *source,
   const GtkCssToken *token;
 
   do {
-      token = gtk_css_token_source_get_token (source);
+      for (token = gtk_css_token_source_peek_token (source);
+           gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT);
+           token = gtk_css_token_source_peek_token (source))
+        {
+          gtk_css_token_source_consume_token (source);
+        }
 
       if (!parsed_something && gtk_css_token_is_delim (token, '*'))
         {
@@ -1800,8 +1806,14 @@ gtk_css_selector_token_parse (GtkCssTokenSource *source)
           return NULL;
         }
 
-      seen_whitespace = gtk_css_token_source_consume_whitespace (source);
-      token = gtk_css_token_source_get_token (source);
+      for (token = gtk_css_token_source_peek_token (source);
+           gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT) || 
+           gtk_css_token_is (token, GTK_CSS_TOKEN_WHITESPACE);
+           token = gtk_css_token_source_peek_token (source))
+        {
+          seen_whitespace |= gtk_css_token_is (token, GTK_CSS_TOKEN_WHITESPACE);
+          gtk_css_token_source_consume_token (source);
+        }
 
       if (gtk_css_token_is_delim (token, '+'))
         {
@@ -1834,7 +1846,7 @@ gtk_css_selector_token_parse (GtkCssTokenSource *source)
           return NULL;
         }
 
-      gtk_css_token_source_consume_whitespace (source);
+      token = gtk_css_token_source_get_token (source);
     }
 
   return selector;
diff --git a/gtk/gtkcssshadowsvalue.c b/gtk/gtkcssshadowsvalue.c
index 87ce81e..fcc8106 100644
--- a/gtk/gtkcssshadowsvalue.c
+++ b/gtk/gtkcssshadowsvalue.c
@@ -269,12 +269,10 @@ gtk_css_shadows_value_token_parse (GtkCssTokenSource *source,
         }
 
       g_ptr_array_add (values, value);
-      gtk_css_token_source_consume_whitespace (source);
       token = gtk_css_token_source_get_token (source);
       if (!gtk_css_token_is (token, GTK_CSS_TOKEN_COMMA))
         break;
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
     }
 
   result = gtk_css_shadows_value_new ((GtkCssValue **) values->pdata, values->len);
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 3202584..51e2ab9 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -319,14 +319,12 @@ gtk_css_shadow_value_token_parse (GtkCssTokenSource *source,
         {
           inset = TRUE;
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
         }
       else if (values[COLOR] == NULL && gtk_css_color_value_check_token (token))
         {
           values[COLOR] = gtk_css_color_value_token_parse (source);
           if (values[COLOR] == NULL)
             goto fail;
-          gtk_css_token_source_consume_whitespace (source);
         }
       else if (values[HOFFSET] == NULL && gtk_css_number_value_check_token (token))
         {
@@ -335,14 +333,12 @@ gtk_css_shadow_value_token_parse (GtkCssTokenSource *source,
                                                               | GTK_CSS_NUMBER_AS_PIXELS);
           if (values[HOFFSET] == NULL)
             goto fail;
-          gtk_css_token_source_consume_whitespace (source);
 
           values[VOFFSET] = gtk_css_number_value_token_parse (source,
                                                               GTK_CSS_PARSE_LENGTH
                                                               | GTK_CSS_NUMBER_AS_PIXELS);
           if (values[VOFFSET] == NULL)
             goto fail;
-          gtk_css_token_source_consume_whitespace (source);
 
           if (gtk_css_number_value_check_token (gtk_css_token_source_get_token (source)))
             {
@@ -352,7 +348,6 @@ gtk_css_shadow_value_token_parse (GtkCssTokenSource *source,
                                                                  | GTK_CSS_NUMBER_AS_PIXELS);
               if (values[RADIUS] == NULL)
                 goto fail;
-              gtk_css_token_source_consume_whitespace (source);
             }
           else
             values[RADIUS] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
@@ -365,7 +360,6 @@ gtk_css_shadow_value_token_parse (GtkCssTokenSource *source,
                                                                | GTK_CSS_NUMBER_AS_PIXELS);
             if (values[SPREAD] == NULL)
               goto fail;
-            gtk_css_token_source_consume_whitespace (source);
           }
         else
           values[SPREAD] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 9bbc81d..1edb142 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -296,7 +296,6 @@ font_family_token_parse_one (GtkCssTokenSource *source)
       GString *string = g_string_new (token->string.string);
 
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
       for (token = gtk_css_token_source_get_token (source);
            gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT);
            token = gtk_css_token_source_get_token (source))
@@ -304,7 +303,6 @@ font_family_token_parse_one (GtkCssTokenSource *source)
           g_string_append_c (string, ' ');
           g_string_append (string, token->string.string);
           gtk_css_token_source_consume_token (source);
-          gtk_css_token_source_consume_whitespace (source);
         }
 
       return _gtk_css_string_value_new_take (g_string_free (string, FALSE));
diff --git a/gtk/gtkcssstylerule.c b/gtk/gtkcssstylerule.c
index c7d3645..eb43332 100644
--- a/gtk/gtkcssstylerule.c
+++ b/gtk/gtkcssstylerule.c
@@ -83,7 +83,6 @@ gtk_css_style_rule_parse_selectors (GtkCssStyleRule   *rule,
        !gtk_css_token_is (token, GTK_CSS_TOKEN_EOF);
        token = gtk_css_token_source_get_token (source))
     {
-      gtk_css_token_source_consume_whitespace (source);
       child_source = gtk_css_token_source_new_for_part (source, GTK_CSS_TOKEN_COMMA);
       selector = gtk_css_selector_token_parse (child_source);
       gtk_css_token_source_unref (child_source);
diff --git a/gtk/gtkcsstokensource.c b/gtk/gtkcsstokensource.c
index baec8fb..58d9586 100644
--- a/gtk/gtkcsstokensource.c
+++ b/gtk/gtkcsstokensource.c
@@ -49,7 +49,7 @@ gtk_css_token_source_tokenizer_consume_token (GtkCssTokenSource *source,
 }
 
 static const GtkCssToken *
-gtk_css_token_source_tokenizer_get_token (GtkCssTokenSource   *source)
+gtk_css_token_source_tokenizer_peek_token (GtkCssTokenSource   *source)
 {
   GtkCssTokenSourceTokenizer *tok = (GtkCssTokenSourceTokenizer *) source;
 
@@ -87,7 +87,7 @@ gtk_css_token_source_tokenizer_error (GtkCssTokenSource *source,
 const GtkCssTokenSourceClass GTK_CSS_TOKEN_SOURCE_TOKENIZER = {
   gtk_css_token_source_tokenizer_finalize,
   gtk_css_token_source_tokenizer_consume_token,
-  gtk_css_token_source_tokenizer_get_token,
+  gtk_css_token_source_tokenizer_peek_token,
   gtk_css_token_source_tokenizer_error,
 };
 
@@ -128,7 +128,7 @@ gtk_css_token_source_part_consume_token (GtkCssTokenSource *source,
 
   if (!gtk_css_token_get_pending_block (source))
     {
-      token = gtk_css_token_source_get_token (part->source);
+      token = gtk_css_token_source_peek_token (part->source);
       if (gtk_css_token_is (token, part->end_type))
         return;
     }
@@ -137,13 +137,13 @@ gtk_css_token_source_part_consume_token (GtkCssTokenSource *source,
 }
 
 static const GtkCssToken *
-gtk_css_token_source_part_get_token (GtkCssTokenSource *source)
+gtk_css_token_source_part_peek_token (GtkCssTokenSource *source)
 {
   GtkCssTokenSourcePart *part = (GtkCssTokenSourcePart *) source;
   static const GtkCssToken eof_token = { GTK_CSS_TOKEN_EOF };
   const GtkCssToken *token;
 
-  token = gtk_css_token_source_get_token (part->source);
+  token = gtk_css_token_source_peek_token (part->source);
   if (!gtk_css_token_get_pending_block (source) &&
       gtk_css_token_is (token, part->end_type))
     return &eof_token;
@@ -163,7 +163,7 @@ gtk_css_token_source_part_error (GtkCssTokenSource *source,
 const GtkCssTokenSourceClass GTK_CSS_TOKEN_SOURCE_PART = {
   gtk_css_token_source_part_finalize,
   gtk_css_token_source_part_consume_token,
-  gtk_css_token_source_part_get_token,
+  gtk_css_token_source_part_peek_token,
   gtk_css_token_source_part_error,
 };
 
@@ -235,14 +235,14 @@ gtk_css_token_source_consume_token_as (GtkCssTokenSource *source,
   
   if (source->blocks)
     {
-      token = gtk_css_token_source_get_token (source);
+      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_get_token (source);
+  token = gtk_css_token_source_peek_token (source);
   switch (token->type)
     {
     case GTK_CSS_TOKEN_FUNCTION:
@@ -269,16 +269,22 @@ gtk_css_token_source_consume_token_as (GtkCssTokenSource *source,
 }
 
 const GtkCssToken *
+gtk_css_token_source_peek_token (GtkCssTokenSource *source)
+{
+  return source->klass->peek_token (source);
+}
+
+const GtkCssToken *
 gtk_css_token_source_get_token (GtkCssTokenSource *source)
 {
   const GtkCssToken *token;
 
-  for (token = source->klass->get_token (source);
-       gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT);
-       token = source->klass->get_token (source))
+  for (token = gtk_css_token_source_peek_token (source);
+       gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT) ||
+       gtk_css_token_is (token, GTK_CSS_TOKEN_WHITESPACE);
+       token = gtk_css_token_source_peek_token (source))
     {
-      /* use vfunc here to avoid infloop */
-      source->klass->consume_token (source, source->consumer);
+      gtk_css_token_source_consume_token (source);
     }
 
   return token;
@@ -305,10 +311,12 @@ gtk_css_token_source_consume_to_string (GtkCssTokenSource *source)
 
   string = g_string_new (NULL);
 
-  for (token = gtk_css_token_source_get_token (source);
+  for (token = gtk_css_token_source_peek_token (source);
        !gtk_css_token_is (token, GTK_CSS_TOKEN_EOF);
-       token = gtk_css_token_source_get_token (source))
+       token = gtk_css_token_source_peek_token (source))
     {
+      if (gtk_css_token_is (token, GTK_CSS_TOKEN_COMMENT))
+        continue;
       gtk_css_token_print (token, string);
       gtk_css_token_source_consume_token (source);
     }
@@ -317,23 +325,6 @@ gtk_css_token_source_consume_to_string (GtkCssTokenSource *source)
 }
 
 gboolean
-gtk_css_token_source_consume_whitespace (GtkCssTokenSource *source)
-{
-  const GtkCssToken *token;
-  gboolean seen_whitespace = FALSE;
-
-  for (token = gtk_css_token_source_get_token (source);
-       gtk_css_token_is (token, GTK_CSS_TOKEN_WHITESPACE);
-       token = gtk_css_token_source_get_token (source))
-    {
-      seen_whitespace = TRUE;
-      gtk_css_token_source_consume_token (source);
-    }
-
-  return seen_whitespace;
-}
-
-gboolean
 gtk_css_token_source_consume_function (GtkCssTokenSource      *source,
                                        guint                   min_args,
                                        guint                   max_args,
@@ -354,13 +345,11 @@ gtk_css_token_source_consume_function (GtkCssTokenSource      *source,
 
   for (arg = 0; arg < max_args; arg++)
     {
-      gtk_css_token_source_consume_whitespace (func_source);
       if (!parse_func (func_source, arg, data))
         {
           gtk_css_token_source_consume_all (func_source);
           break;
         }
-      gtk_css_token_source_consume_whitespace (func_source);
       token = gtk_css_token_source_get_token (func_source);
       if (gtk_css_token_is (token, GTK_CSS_TOKEN_EOF))
         {
diff --git a/gtk/gtkcsstokensourceprivate.h b/gtk/gtkcsstokensourceprivate.h
index 6c81221..9efc060 100644
--- a/gtk/gtkcsstokensourceprivate.h
+++ b/gtk/gtkcsstokensourceprivate.h
@@ -41,7 +41,7 @@ struct _GtkCssTokenSourceClass
   void                  (* finalize)                            (GtkCssTokenSource      *source);
   void                  (* consume_token)                       (GtkCssTokenSource      *source,
                                                                  GObject                *consumer);
-  const GtkCssToken *   (* get_token)                           (GtkCssTokenSource      *source);
+  const GtkCssToken *   (* peek_token)                          (GtkCssTokenSource      *source);
   void                  (* error)                               (GtkCssTokenSource      *source,
                                                                  const GError           *error);
 };
@@ -60,13 +60,13 @@ GtkCssTokenSource *     gtk_css_token_source_alloc              (gsize
 void                    gtk_css_token_source_consume_token      (GtkCssTokenSource      *source);
 void                    gtk_css_token_source_consume_token_as   (GtkCssTokenSource      *source,
                                                                  GObject                *consumer);
+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);
-gboolean                gtk_css_token_source_consume_whitespace (GtkCssTokenSource      *source);
 
 gboolean                gtk_css_token_source_consume_function   (GtkCssTokenSource      *source,
                                                                  guint                   min_args,
@@ -89,7 +89,6 @@ void                    gtk_css_token_source_deprecated         (GtkCssTokenSour
 GObject *               gtk_css_token_source_get_consumer       (GtkCssTokenSource      *source);
 void                    gtk_css_token_source_set_consumer       (GtkCssTokenSource      *source,
                                                                  GObject                *consumer);
-                                                                 
 
 
 G_END_DECLS
diff --git a/gtk/gtkcsswin32sizevalue.c b/gtk/gtkcsswin32sizevalue.c
index 82fa5c6..405ac4a 100644
--- a/gtk/gtkcsswin32sizevalue.c
+++ b/gtk/gtkcsswin32sizevalue.c
@@ -436,7 +436,6 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
   if (theme == NULL)
     return NULL;
 
-  gtk_css_token_source_consume_whitespace (source);
   token = gtk_css_token_source_get_token (source);
   if (!gtk_css_token_is (token, GTK_CSS_TOKEN_COMMA))
     {
@@ -446,7 +445,6 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
       return NULL;
     }
   gtk_css_token_source_consume_token (source);
-  gtk_css_token_source_consume_whitespace (source);
 
   result = gtk_css_win32_size_value_new (1.0, theme, type);
   gtk_win32_theme_unref (theme);
@@ -497,7 +495,6 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
         }
       result->val.part.part = token->number.number;
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
 
       token = gtk_css_token_source_get_token (source);
       if (!gtk_css_token_is (token, GTK_CSS_TOKEN_COMMA))
@@ -508,7 +505,6 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
           return NULL;
         }
       gtk_css_token_source_consume_token (source);
-      gtk_css_token_source_consume_whitespace (source);
 
       token = gtk_css_token_source_get_token (source);
       if (!gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 75279aa..6b57ec8 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -187,15 +187,11 @@ gtk_style_property_token_parse (GtkStyleProperty  *property,
 
   klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
 
-  gtk_css_token_source_consume_whitespace (source);
-
   value = klass->token_parse (property, source);
 
   if (value == NULL)
     return NULL;
 
-  gtk_css_token_source_consume_whitespace (source);
-
   if (!gtk_css_token_is (gtk_css_token_source_get_token (source),
                          GTK_CSS_TOKEN_EOF))
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]