[gtk] parser: Add gtk_css_parser_has_token()



commit 904a9d0c98fb823ddd5c44fa18f9ac5d74308f2f
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 23 18:21:59 2019 +0100

    parser: Add gtk_css_parser_has_token()
    
    This is ithe first step towards converting the parsing code to use
    tokens. For now, the topken type is just a magic enum value that only
    works as-needed.

 gtk/gtkcssparser.c        | 73 +++++++++++++++++++++++++++++++++++++++++++++--
 gtk/gtkcssparserprivate.h |  4 ++-
 gtk/gtkcssprovider.c      |  2 +-
 3 files changed, 74 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index b64165efe4..5a786df8c3 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -461,11 +461,78 @@ _gtk_css_parser_try_ident (GtkCssParser *parser,
 }
 
 gboolean
-_gtk_css_parser_is_string (GtkCssParser *parser)
+gtk_css_parser_has_token (GtkCssParser    *parser,
+                          GtkCssTokenType  type)
 {
   g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
 
-  return *parser->data == '"' || *parser->data == '\'';
+  switch (type)
+  {
+    case GTK_CSS_TOKEN_STRING:
+      return *parser->data == '"' || *parser->data == '\'';
+
+    case GTK_CSS_TOKEN_OPEN_CURLY:
+      return *parser->data == '{';
+
+    case GTK_CSS_TOKEN_CLOSE_CURLY:
+      return *parser->data == '}';
+
+    case GTK_CSS_TOKEN_OPEN_PARENS:
+      return *parser->data == '(';
+
+    case GTK_CSS_TOKEN_CLOSE_PARENS:
+      return *parser->data == ')';
+
+    case GTK_CSS_TOKEN_COMMA:
+      return *parser->data == ',';
+
+    case GTK_CSS_TOKEN_COLON:
+      return *parser->data == ':';
+
+    case GTK_CSS_TOKEN_SEMICOLON:
+      return *parser->data == ';';
+
+    case GTK_CSS_TOKEN_AT_KEYWORD:
+      return *parser->data == '@';
+
+    case GTK_CSS_TOKEN_EOF:
+      return *parser->data == 0;
+
+    case GTK_CSS_TOKEN_IDENT:
+      return *parser->data != 0 &&
+             strchr (NMSTART "-", *parser->data) != NULL;
+
+    default:
+    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_WHITESPACE:
+    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;
+    }
 }
 
 char *
@@ -838,7 +905,7 @@ gtk_css_parser_resync_internal (GtkCssParser *parser,
     if (gtk_css_parser_new_line (parser))
       continue;
 
-    if (_gtk_css_parser_is_string (parser))
+    if (gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_STRING))
       {
         /* Hrm, this emits errors, and i suspect it shouldn't... */
         char *free_me = _gtk_css_parser_read_string (parser);
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index f5c4fdddc8..861d5db677 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -21,6 +21,7 @@
 #include <gtk/gtkcssprovider.h>
 
 #include <gtk/css/gtkcss.h>
+#include "gtk/css/gtkcsstokenizerprivate.h"
 
 G_BEGIN_DECLS
 
@@ -53,7 +54,8 @@ gboolean        _gtk_css_parser_begins_with       (GtkCssParser          *parser
                                                    char                   c);
 gboolean        _gtk_css_parser_has_prefix        (GtkCssParser          *parser,
                                                    const char            *prefix);
-gboolean        _gtk_css_parser_is_string         (GtkCssParser          *parser);
+gboolean        gtk_css_parser_has_token          (GtkCssParser          *parser,
+                                                   GtkCssTokenType        token_type);
 
 /* IMPORTANT:
  * _try_foo() functions do not modify the data pointer if they fail, nor do they
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 383568dd98..f91ce9b0d1 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -782,7 +782,7 @@ parse_import (GtkCssScanner *scanner)
       return FALSE;
     }
 
-  if (_gtk_css_parser_is_string (scanner->parser))
+  if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_STRING))
     {
       char *uri;
 


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