[gtk/wip/otte/css: 171/225] cssparser: Add gtk_css_parser_try_token()



commit 6ee11e6b9a605ca5a53ff698e67f92dc6dbf615f
Author: Benjamin Otte <otte redhat com>
Date:   Sun Mar 24 14:36:55 2019 +0100

    cssparser: Add gtk_css_parser_try_token()

 gtk/gtkcssarrayvalue.c            |  2 +-
 gtk/gtkcssfontfeaturesvalue.c     |  2 +-
 gtk/gtkcssfontvariationsvalue.c   |  2 +-
 gtk/gtkcssimagelinear.c           |  6 +--
 gtk/gtkcssparser.c                | 82 +++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssparserprivate.h         |  2 +
 gtk/gtkcssprovider.c              |  2 +-
 gtk/gtkcssshadowsvalue.c          |  2 +-
 gtk/gtkcssshorthandpropertyimpl.c |  6 +--
 9 files changed, 95 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c
index ca65df9698..29fd305791 100644
--- a/gtk/gtkcssarrayvalue.c
+++ b/gtk/gtkcssarrayvalue.c
@@ -421,7 +421,7 @@ _gtk_css_array_value_parse (GtkCssParser *parser,
       }
 
     g_ptr_array_add (values, value);
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   result = _gtk_css_array_value_new_from_array ((GtkCssValue **) values->pdata, values->len);
   g_ptr_array_free (values, TRUE);
diff --git a/gtk/gtkcssfontfeaturesvalue.c b/gtk/gtkcssfontfeaturesvalue.c
index 262539e216..d116157229 100644
--- a/gtk/gtkcssfontfeaturesvalue.c
+++ b/gtk/gtkcssfontfeaturesvalue.c
@@ -263,7 +263,7 @@ gtk_css_font_features_value_parse (GtkCssParser *parser)
 
     gtk_css_font_features_value_add_feature (result, name, val);
     g_free (name);
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   return result;
 }
diff --git a/gtk/gtkcssfontvariationsvalue.c b/gtk/gtkcssfontvariationsvalue.c
index 56fb5162f1..c8d0ab02a0 100644
--- a/gtk/gtkcssfontvariationsvalue.c
+++ b/gtk/gtkcssfontvariationsvalue.c
@@ -260,7 +260,7 @@ gtk_css_font_variations_value_parse (GtkCssParser *parser)
 
     gtk_css_font_variations_value_add_axis (result, name, coord);
     g_free (name);
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   return result;
 }
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index 20ddb6e9cd..9ca1b88bd9 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -322,7 +322,7 @@ gtk_css_image_linear_parse (GtkCssImage  *image,
           return FALSE;
         }
 
-      if (!_gtk_css_parser_try (parser, ",", TRUE))
+      if (!gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA))
         {
           _gtk_css_parser_error (parser, "Expected a comma");
           return FALSE;
@@ -334,7 +334,7 @@ gtk_css_image_linear_parse (GtkCssImage  *image,
       if (linear->angle == NULL)
         return FALSE;
 
-      if (!_gtk_css_parser_try (parser, ",", TRUE))
+      if (!gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA))
         {
           _gtk_css_parser_error (parser, "Expected a comma");
           return FALSE;
@@ -368,7 +368,7 @@ gtk_css_image_linear_parse (GtkCssImage  *image,
 
     g_array_append_val (linear->stops, stop);
 
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   if (linear->stops->len < 2)
     {
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index fb6ce4450f..295b3c1cde 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -315,6 +315,88 @@ gtk_css_parser_try_ident (GtkCssParser *parser,
   return TRUE;
 }
 
+gboolean
+gtk_css_parser_try_token (GtkCssParser    *parser,
+                          GtkCssTokenType  type)
+{
+  g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
+
+  switch (type)
+  {
+    case GTK_CSS_TOKEN_OPEN_CURLY:
+      if (*parser->data != '{')
+        return FALSE;
+      parser->data += 1;
+      _gtk_css_parser_skip_whitespace (parser);
+      return TRUE;
+
+    case GTK_CSS_TOKEN_CLOSE_CURLY:
+      if (*parser->data != '}')
+        return FALSE;
+      parser->data += 1;
+      _gtk_css_parser_skip_whitespace (parser);
+      return TRUE;
+
+    case GTK_CSS_TOKEN_COMMA:
+      if (*parser->data != ',')
+        return FALSE;
+      parser->data += 1;
+      _gtk_css_parser_skip_whitespace (parser);
+      return TRUE;
+
+    case GTK_CSS_TOKEN_COLON:
+      if (*parser->data != ':')
+        return FALSE;
+      parser->data += 1;
+      _gtk_css_parser_skip_whitespace (parser);
+      return TRUE;
+
+    case GTK_CSS_TOKEN_SEMICOLON:
+      if (*parser->data != ';')
+        return FALSE;
+      parser->data += 1;
+      _gtk_css_parser_skip_whitespace (parser);
+      return TRUE;
+
+    default:
+    case GTK_CSS_TOKEN_STRING:
+    case GTK_CSS_TOKEN_AT_KEYWORD:
+    case GTK_CSS_TOKEN_IDENT:
+    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_EOF:
+    case GTK_CSS_TOKEN_WHITESPACE:
+    case GTK_CSS_TOKEN_OPEN_PARENS:
+    case GTK_CSS_TOKEN_CLOSE_PARENS:
+    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;
+    }
+}
+
 static guint
 get_xdigit (char c)
 {
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index ff90e1c662..22973526c5 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -67,6 +67,8 @@ gboolean        gtk_css_parser_has_function       (GtkCssParser          *parser
  */
 gboolean        gtk_css_parser_try_ident          (GtkCssParser          *parser,
                                                    const char            *ident);
+gboolean        gtk_css_parser_try_token          (GtkCssParser          *parser,
+                                                   GtkCssTokenType        token_type);
 gboolean        _gtk_css_parser_try               (GtkCssParser          *parser,
                                                    const char            *string,
                                                    gboolean               skip_whitespace);
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 635a92263f..1e1f987692 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1021,7 +1021,7 @@ parse_declaration (GtkCssScanner *scanner,
 
   property = _gtk_style_property_lookup (name);
 
-  if (!_gtk_css_parser_try (scanner->parser, ":", TRUE))
+  if (!gtk_css_parser_try_token (scanner->parser, GTK_CSS_TOKEN_COLON))
     {
       gtk_css_provider_invalid_token (scanner->provider, scanner, "':'");
       _gtk_css_parser_resync (scanner->parser, TRUE, '}');
diff --git a/gtk/gtkcssshadowsvalue.c b/gtk/gtkcssshadowsvalue.c
index b920c0737e..88ab7261a8 100644
--- a/gtk/gtkcssshadowsvalue.c
+++ b/gtk/gtkcssshadowsvalue.c
@@ -256,7 +256,7 @@ _gtk_css_shadows_value_parse (GtkCssParser *parser,
       }
 
     g_ptr_array_add (values, value);
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   result = gtk_css_shadows_value_new ((GtkCssValue **) values->pdata, values->len);
   g_ptr_array_free (values, TRUE);
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 6f8028cc48..e0712380b9 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -595,7 +595,7 @@ parse_background (GtkCssShorthandProperty  *shorthand,
           g_ptr_array_add (arrays[i], step_values[i]);
           step_values[i] = NULL;
         }
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   for (i = 0; i < 6; i++)
     {
@@ -699,7 +699,7 @@ parse_transition (GtkCssShorthandProperty  *shorthand,
           g_ptr_array_add (arrays[i], step_values[i]);
           step_values[i] = NULL;
         }
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   for (i = 0; i < 4; i++)
     {
@@ -816,7 +816,7 @@ parse_animation (GtkCssShorthandProperty  *shorthand,
           g_ptr_array_add (arrays[i], step_values[i]);
           step_values[i] = NULL;
         }
-  } while (_gtk_css_parser_try (parser, ",", TRUE));
+  } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
   for (i = 0; i < 7; i++)
     {


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