[gtk+/wip/otte/tokenizer: 59/78] css: Split integer tokens into ones with sign and ones without



commit ca5075c26d7163c8fc8640efff75179d8086f5f9
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 26 22:54:54 2016 +0100

    css: Split integer tokens into ones with sign and ones without
    
    And with that newfound power, fix the an+b parser.
    I hate that part of the spec.

 gtk/gtkcsscolorvalue.c       |    3 +-
 gtk/gtkcssdimensionvalue.c   |    9 ++-
 gtk/gtkcsseasevalue.c        |    2 +-
 gtk/gtkcssnumbervalue.c      |    9 ++-
 gtk/gtkcssselector.c         |  175 ++++++++++++++++++++++++++++++++++--------
 gtk/gtkcsstokenizer.c        |   52 +++++++++----
 gtk/gtkcsstokenizerprivate.h |    9 ++-
 gtk/gtkcsstokensource.c      |    6 +-
 gtk/gtkcsswin32sizevalue.c   |    9 ++-
 9 files changed, 210 insertions(+), 64 deletions(-)
---
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c
index 8f31ae0..d2347db 100644
--- a/gtk/gtkcsscolorvalue.c
+++ b/gtk/gtkcsscolorvalue.c
@@ -1109,7 +1109,8 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source)
                 }
               gtk_css_token_source_consume_token (source);
             }
-          else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+          else if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) ||
+                   gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
             {
               id = token->number.number;
               gtk_css_token_source_consume_token (source);
diff --git a/gtk/gtkcssdimensionvalue.c b/gtk/gtkcssdimensionvalue.c
index 22365c4..4cc667b 100644
--- a/gtk/gtkcssdimensionvalue.c
+++ b/gtk/gtkcssdimensionvalue.c
@@ -331,8 +331,10 @@ gtk_css_dimension_value_token_parse (GtkCssTokenSource      *source,
   double d;
   GtkCssUnit unit;
 
-  if ((gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER) ||
-       gtk_css_token_is (token, GTK_CSS_TOKEN_NUMBER)) &&
+  if ((gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) ||
+       gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER) ||
+       gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_NUMBER) ||
+       gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_NUMBER)) &&
       ((flags & (GTK_CSS_PARSE_NUMBER | GTK_CSS_NUMBER_AS_PIXELS)) ||
        (token->number.number == 0.0 && (flags & (GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_ANGLE)))))
     {
@@ -359,7 +361,8 @@ gtk_css_dimension_value_token_parse (GtkCssTokenSource      *source,
       d = token->number.number;
       unit = GTK_CSS_PERCENT;
     }
-  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER_DIMENSION) ||
+  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION) ||
+           gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION) ||
            gtk_css_token_is (token, GTK_CSS_TOKEN_DIMENSION))
     {
       static const struct {
diff --git a/gtk/gtkcsseasevalue.c b/gtk/gtkcsseasevalue.c
index 842a4d9..b342b4b 100644
--- a/gtk/gtkcsseasevalue.c
+++ b/gtk/gtkcsseasevalue.c
@@ -359,7 +359,7 @@ token_parse_steps (GtkCssTokenSource *source,
   token = gtk_css_token_source_get_token (source);
   if (nth_argument == 0)
     {
-      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
         {
           gtk_css_token_source_error (source, "Expected a positive integer for number of steps");
           gtk_css_token_source_consume_all (source);
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 8151dd8..a9f44db 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -161,10 +161,13 @@ _gtk_css_number_value_parse (GtkCssParser           *parser,
 gboolean
 gtk_css_number_value_check_token (const GtkCssToken *token)
 {
-  return gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER)
-      || gtk_css_token_is (token, GTK_CSS_TOKEN_NUMBER)
+  return gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER)
+      || gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER)
+      || gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_NUMBER)
+      || gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_NUMBER)
       || gtk_css_token_is (token, GTK_CSS_TOKEN_DIMENSION)
-      || gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER_DIMENSION)
+      || gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION)
+      || gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION)
       || gtk_css_token_is (token, GTK_CSS_TOKEN_PERCENTAGE)
       || gtk_css_token_is_function (token, "calc")
       || gtk_css_token_is_function (token, "-gtk-win32-size")
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index c7cc832..34c80dc 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -1341,6 +1341,25 @@ token_parse_selector_class (GtkCssTokenSource *source,
 }
 
 static gboolean
+string_has_number (const char *string,
+                   const char *prefix,
+                   int        *number)
+{
+  gsize len = strlen (prefix);
+  char *end;
+
+  if (g_ascii_strncasecmp (string, prefix, len) != 0)
+    return FALSE;
+
+  errno = 0;
+  *number = strtoul (string + len, &end, 10);
+  if (*end != '\0' || errno != 0)
+    return FALSE;
+
+  return TRUE;
+}
+
+static gboolean
 parse_plus_b (GtkCssTokenSource *source,
               gboolean           negate,
               gint              *b)
@@ -1370,15 +1389,24 @@ parse_plus_b (GtkCssTokenSource *source,
     }
 
   token = gtk_css_token_source_get_token (source);
-  if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+  if (!has_seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER))
     {
-      if (has_seen_sign && token->number.number >= 0)
-        {
-          *b = token->number.number;
-          if (negate)
-            *b = - *b;
-          return TRUE;
-        }
+      *b = token->number.number;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
+    }
+  else if (has_seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
+    {
+      *b = token->number.number;
+      if (negate)
+        *b = - *b;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
+    }
+  else if (!has_seen_sign)
+    {
+      *b = 0;
+      return TRUE;
     }
   
   gtk_css_token_source_error (source, "Not a valid an+b type");
@@ -1386,7 +1414,49 @@ parse_plus_b (GtkCssTokenSource *source,
 }
 
 gboolean
+parse_n_plus_b (GtkCssTokenSource *source,
+                gint               before,
+                gint              *a,
+                gint              *b)
+{
+  const GtkCssToken *token;
+
+  token = gtk_css_token_source_get_token (source);
+
+  if (gtk_css_token_is_ident (token, "n"))
+    {
+      *a = before;
+      gtk_css_token_source_consume_token (source);
+      return parse_plus_b (source, FALSE, b);
+    }
+  else if (gtk_css_token_is_ident (token, "n-"))
+    {
+      *a = before;
+      gtk_css_token_source_consume_token (source);
+      return parse_plus_b (source, TRUE, b);
+    }
+  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT) &&
+           string_has_number (token->string.string, "n-", b))
+    {
+      *a = before;
+      *b = -*b;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
+    }
+  else
+    {
+      *b = before;
+      *a = 0;
+      return TRUE;
+    }
+  
+  gtk_css_token_source_error (source, "Not a valid an+b type");
+  return FALSE;
+}
+                
+gboolean
 parse_a_n_plus_b (GtkCssTokenSource *source,
+                  gint               seen_sign,
                   gint              *a,
                   gint              *b)
 {
@@ -1394,66 +1464,105 @@ parse_a_n_plus_b (GtkCssTokenSource *source,
 
   token = gtk_css_token_source_get_token (source);
 
-  if (gtk_css_token_is_ident (token, "even"))
+  if (!seen_sign && gtk_css_token_is_ident (token, "even"))
     {
       *a = 2;
       *b = 0;
       gtk_css_token_source_consume_token (source);
       return TRUE;
     }
-  else if (gtk_css_token_is_ident (token, "odd"))
+  else if (!seen_sign && gtk_css_token_is_ident (token, "odd"))
     {
       *a = 2;
       *b = 1;
       gtk_css_token_source_consume_token (source);
       return TRUE;
     }
-  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+  else if (!seen_sign && gtk_css_token_is_delim (token, '+'))
     {
-      *a = 0;
-      *b = token->number.number;
       gtk_css_token_source_consume_token (source);
-      return TRUE;
+      return parse_a_n_plus_b (source, 1, a, b);
+    }
+  else if (!seen_sign && gtk_css_token_is_delim (token, '-'))
+    {
+      gtk_css_token_source_consume_token (source);
+      return parse_a_n_plus_b (source, -1, a, b);
     }
-  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER_DIMENSION) &&
+  else if ((!seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER)) ||
+           gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
+    {
+      int x = token->number.number * (seen_sign ? seen_sign : 1);
+      gtk_css_token_source_consume_token (source);
+
+      return parse_n_plus_b (source, x , a, b);
+    }
+  else if (((!seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION)) ||
+            gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION)) &&
            g_ascii_strcasecmp (token->dimension.dimension, "n") == 0)
     {
-      *a = token->dimension.value;
+      *a = token->dimension.value * (seen_sign ? seen_sign : 1);
       gtk_css_token_source_consume_token (source);
       return parse_plus_b (source, FALSE, b);
     }
-  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER_DIMENSION) &&
+  else if (((!seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION)) ||
+            gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION)) &&
            g_ascii_strcasecmp (token->dimension.dimension, "n-") == 0)
     {
-      *a = token->dimension.value;
+      *a = token->dimension.value * (seen_sign ? seen_sign : 1);
       gtk_css_token_source_consume_token (source);
       return parse_plus_b (source, TRUE, b);
     }
-  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER_DIMENSION) &&
-           g_ascii_strncasecmp (token->dimension.dimension, "n-", 2) == 0)
+  else if (((!seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION)) ||
+            gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION)) &&
+           string_has_number (token->dimension.dimension, "n-", b))
     {
-      char *end;
-      *a = token->dimension.value;
-      errno = 0;
-      *b = strtoul (token->dimension.dimension + 2, &end, 10);
-      if (*end == '\0' && errno == 0)
-        {
-          gtk_css_token_source_consume_token (source);
-          return TRUE;
-        }
+      *a = token->dimension.value * (seen_sign ? seen_sign : 1);
+      *b = -*b;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
     }
-  else if (gtk_css_token_is_ident (token, "-n"))
+  else if (!seen_sign && gtk_css_token_is_ident (token, "-n"))
     {
       *a = -1;
       gtk_css_token_source_consume_token (source);
       return parse_plus_b (source, FALSE, b);
     }
-  else if (gtk_css_token_is_ident (token, "-n-"))
+  else if (!seen_sign && gtk_css_token_is_ident (token, "-n-"))
     {
       *a = -1;
       gtk_css_token_source_consume_token (source);
       return parse_plus_b (source, TRUE, b);
     }
+  else if (!seen_sign &&
+           gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT) &&
+           string_has_number (token->string.string, "-n-", b))
+    {
+      *a = -1;
+      *b = -*b;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
+    }
+  else if (gtk_css_token_is_ident (token, "n") ||
+           gtk_css_token_is_ident (token, "n-"))
+    {
+      return parse_n_plus_b (source, seen_sign ? seen_sign : 1, a, b);
+    }
+  else if (gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT) &&
+           string_has_number (token->string.string, "n-", b))
+    {
+      *a = seen_sign ? seen_sign : 1;
+      *b = -*b;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
+    }
+  else if (!seen_sign && gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT) &&
+           string_has_number (token->string.string, "-n-", b))
+    {
+      *a = -1;
+      *b = -*b;
+      gtk_css_token_source_consume_token (source);
+      return TRUE;
+    }
   
   gtk_css_token_source_error (source, "Not a valid an+b type");
   return FALSE;
@@ -1527,7 +1636,7 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
       if (gtk_css_token_is_function (token, "nth-child"))
         {
           gtk_css_token_source_consume_token (source);
-          if (parse_a_n_plus_b (source, &a, &b))
+          if (parse_a_n_plus_b (source, 0, &a, &b))
             {
               selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_POSITION
                                                       : &GTK_CSS_SELECTOR_PSEUDOCLASS_POSITION,
@@ -1555,7 +1664,7 @@ token_parse_selector_pseudo_class (GtkCssTokenSource *source,
       else if (gtk_css_token_is_function (token, "nth-last-child"))
         {
           gtk_css_token_source_consume_token (source);
-          if (parse_a_n_plus_b (source, &a, &b))
+          if (parse_a_n_plus_b (source, 0, &a, &b))
             {
               selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_POSITION
                                                       : &GTK_CSS_SELECTOR_PSEUDOCLASS_POSITION,
diff --git a/gtk/gtkcsstokenizer.c b/gtk/gtkcsstokenizer.c
index 35fb51b..884ed66 100644
--- a/gtk/gtkcsstokenizer.c
+++ b/gtk/gtkcsstokenizer.c
@@ -59,7 +59,8 @@ gtk_css_token_clear (GtkCssToken *token)
       g_free (token->string.string);
       break;
 
-    case GTK_CSS_TOKEN_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
     case GTK_CSS_TOKEN_DIMENSION:
       g_free (token->dimension.dimension);
       break;
@@ -80,8 +81,10 @@ gtk_css_token_clear (GtkCssToken *token)
     case GTK_CSS_TOKEN_CDC:
     case GTK_CSS_TOKEN_CDO:
     case GTK_CSS_TOKEN_DELIM:
-    case GTK_CSS_TOKEN_INTEGER:
-    case GTK_CSS_TOKEN_NUMBER:
+    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:
@@ -121,13 +124,16 @@ gtk_css_token_initv (GtkCssToken     *token,
       token->delim.delim = va_arg (args, gunichar);
       break;
 
-    case GTK_CSS_TOKEN_INTEGER:
-    case GTK_CSS_TOKEN_NUMBER:
+    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:
       token->number.number = va_arg (args, double);
       break;
 
-    case GTK_CSS_TOKEN_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
     case GTK_CSS_TOKEN_DIMENSION:
       token->dimension.value = va_arg (args, double);
       token->dimension.dimension = va_arg (args, char *);
@@ -228,11 +234,14 @@ gtk_css_token_is_finite (const GtkCssToken *token)
     case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
     case GTK_CSS_TOKEN_HASH_ID:
     case GTK_CSS_TOKEN_DELIM:
-    case GTK_CSS_TOKEN_INTEGER:
-    case GTK_CSS_TOKEN_NUMBER:
+    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_BAD_STRING:
     case GTK_CSS_TOKEN_BAD_URL:
-    case GTK_CSS_TOKEN_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
     case GTK_CSS_TOKEN_DIMENSION:
       return FALSE;
     }
@@ -304,8 +313,13 @@ gtk_css_token_print (const GtkCssToken *token,
       g_string_append_unichar (string, token->delim.delim);
       break;
 
-    case GTK_CSS_TOKEN_INTEGER:
-    case GTK_CSS_TOKEN_NUMBER:
+    case GTK_CSS_TOKEN_SIGNED_INTEGER:
+    case GTK_CSS_TOKEN_SIGNED_NUMBER:
+      if (token->number.number >= 0)
+        g_string_append_c (string, '+');
+      /* fall through */
+    case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
+    case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
       g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE, token->number.number);
       g_string_append (string, buf);
       break;
@@ -316,7 +330,11 @@ gtk_css_token_print (const GtkCssToken *token,
       g_string_append_c (string, '%');
       break;
 
-    case GTK_CSS_TOKEN_INTEGER_DIMENSION:
+    case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
+      if (token->dimension.value >= 0)
+        g_string_append_c (string, '+');
+      /* fall through */
+    case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
     case GTK_CSS_TOKEN_DIMENSION:
       g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE, token->dimension.value);
       g_string_append (string, buf);
@@ -942,16 +960,18 @@ gtk_css_tokenizer_read_numeric (GtkCssTokenizer *tokenizer,
 {
   int sign = 1, exponent_sign = 1;
   gint64 integer, fractional = 0, fractional_length = 1, exponent = 0;
-  gboolean is_int = TRUE;
+  gboolean is_int = TRUE, has_sign = FALSE;
   const char *data = tokenizer->data;
 
   if (*data == '-')
     {
+      has_sign = TRUE;
       sign = -1;
       data++;
     }
   else if (*data == '+')
     {
+      has_sign = TRUE;
       data++;
     }
 
@@ -1011,7 +1031,8 @@ gtk_css_tokenizer_read_numeric (GtkCssTokenizer *tokenizer,
   if (gtk_css_tokenizer_has_identifier (tokenizer))
     {
       gtk_css_token_init (token,
-                          is_int ? GTK_CSS_TOKEN_INTEGER_DIMENSION : GTK_CSS_TOKEN_DIMENSION,
+                          is_int ? (has_sign ? GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION : 
GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION)
+                                 : GTK_CSS_TOKEN_DIMENSION,
                           sign * (integer + ((double) fractional / fractional_length)) * pow (10, 
exponent_sign * exponent),
                           gtk_css_tokenizer_read_name (tokenizer));
     }
@@ -1025,7 +1046,8 @@ gtk_css_tokenizer_read_numeric (GtkCssTokenizer *tokenizer,
   else
     {
       gtk_css_token_init (token,
-                          is_int ? GTK_CSS_TOKEN_INTEGER : GTK_CSS_TOKEN_NUMBER,
+                          is_int ? (has_sign ? GTK_CSS_TOKEN_SIGNED_INTEGER : GTK_CSS_TOKEN_SIGNLESS_INTEGER)
+                                 : (has_sign ? GTK_CSS_TOKEN_SIGNED_NUMBER : GTK_CSS_TOKEN_SIGNLESS_NUMBER),
                           sign * (integer + ((double) fractional / fractional_length)) * pow (10, 
exponent_sign * exponent));
     }
 }
diff --git a/gtk/gtkcsstokenizerprivate.h b/gtk/gtkcsstokenizerprivate.h
index 1f178af..9ea56f2 100644
--- a/gtk/gtkcsstokenizerprivate.h
+++ b/gtk/gtkcsstokenizerprivate.h
@@ -57,11 +57,14 @@ typedef enum {
   GTK_CSS_TOKEN_HASH_ID,
   GTK_CSS_TOKEN_URL,
   /* number */
-  GTK_CSS_TOKEN_INTEGER,
-  GTK_CSS_TOKEN_NUMBER,
+  GTK_CSS_TOKEN_SIGNED_INTEGER,
+  GTK_CSS_TOKEN_SIGNLESS_INTEGER,
+  GTK_CSS_TOKEN_SIGNED_NUMBER,
+  GTK_CSS_TOKEN_SIGNLESS_NUMBER,
   GTK_CSS_TOKEN_PERCENTAGE,
   /* dimension */
-  GTK_CSS_TOKEN_INTEGER_DIMENSION,
+  GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION,
+  GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION,
   GTK_CSS_TOKEN_DIMENSION
 } GtkCssTokenType;
 
diff --git a/gtk/gtkcsstokensource.c b/gtk/gtkcsstokensource.c
index f1fadfe..ef2435d 100644
--- a/gtk/gtkcsstokensource.c
+++ b/gtk/gtkcsstokensource.c
@@ -415,8 +415,10 @@ gtk_css_token_source_consume_number (GtkCssTokenSource *source,
   GtkCssValue *value;
 
   token = gtk_css_token_source_get_token (source);
-  if (gtk_css_token_is (token, GTK_CSS_TOKEN_NUMBER) ||
-      gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+  if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_NUMBER) ||
+      gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_NUMBER) ||
+      gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) ||
+      gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
     {
       *number = token->number.number;
       gtk_css_token_source_consume_token (source);
diff --git a/gtk/gtkcsswin32sizevalue.c b/gtk/gtkcsswin32sizevalue.c
index 405ac4a..24eef60 100644
--- a/gtk/gtkcsswin32sizevalue.c
+++ b/gtk/gtkcsswin32sizevalue.c
@@ -465,7 +465,8 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
             }
           gtk_css_token_source_consume_token (source);
         }
-      else if (gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+      else if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) ||
+               gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
         {
           result->val.size.id = token->number.number;
           gtk_css_token_source_consume_token (source);
@@ -486,7 +487,8 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
     case GTK_WIN32_PART_BORDER_BOTTOM:
     case GTK_WIN32_PART_BORDER_LEFT:
       token = gtk_css_token_source_get_token (source);
-      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) &&
+          !gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
         {
           _gtk_css_value_unref (result);
           gtk_css_token_source_error (source, "Expected an integer part ID");
@@ -507,7 +509,8 @@ gtk_css_win32_size_value_token_parse (GtkCssTokenSource      *source,
       gtk_css_token_source_consume_token (source);
 
       token = gtk_css_token_source_get_token (source);
-      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_INTEGER))
+      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) &&
+          !gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
         {
           _gtk_css_value_unref (result);
           gtk_css_token_source_error (source, "Expected an integer state ID");


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