[json-glib] [parser] Return the right expected token



commit bd604338b25884edbd86cf531505259948484323
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Sep 22 15:34:18 2009 +0100

    [parser] Return the right expected token
    
    When parsing a value embedded in a Json Object or Array we need to
    return the right expected token so that the generated syntax error
    will be correct.

 json-glib/json-parser.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index 35747d3..419f695 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -337,6 +337,7 @@ json_parse_value (JsonParser   *parser,
                   guint         token,
                   JsonNode    **node)
 {
+  JsonNode *current_node = parser->priv->current_node;
   gboolean is_negative = FALSE;
 
   if (token == '-')
@@ -383,8 +384,19 @@ json_parse_value (JsonParser   *parser,
       break;
 
     default:
-      *node = NULL;
-      return G_TOKEN_RIGHT_BRACE;
+      {
+        JsonNodeType cur_type;
+
+        *node = NULL;
+
+        cur_type = json_node_get_node_type (current_node);
+        if (cur_type == JSON_NODE_ARRAY)
+          return G_TOKEN_RIGHT_BRACE;
+        else if (cur_type == JSON_NODE_OBJECT)
+          return G_TOKEN_RIGHT_CURLY;
+        else
+          return G_TOKEN_SYMBOL;
+      }
     }
 
   return G_TOKEN_NONE;



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