@@ -19,7 +19,13 @@ typedef enum {
19
19
20
20
const char * jim_error_string (Jim_Error error );
21
21
22
+ typedef enum {
23
+ JIM_ARRAY_SCOPE ,
24
+ JIM_OBJECT_SCOPE ,
25
+ } Jim_Scope_Kind ;
26
+
22
27
typedef struct {
28
+ Jim_Scope_Kind kind ;
23
29
int tail ;
24
30
int key ;
25
31
} Jim_Scope ;
@@ -61,10 +67,11 @@ static size_t jim_strlen(const char *s)
61
67
return count ;
62
68
}
63
69
64
- static void jim_stack_push (Jim * jim )
70
+ static void jim_stack_push (Jim * jim , Jim_Scope_Kind kind )
65
71
{
66
72
if (jim -> error == JIM_OK ) {
67
73
if (jim -> stack_size < JIM_STACK_CAPACITY ) {
74
+ jim -> stack [jim -> stack_size ].kind = kind ;
68
75
jim -> stack [jim -> stack_size ].tail = 0 ;
69
76
jim -> stack [jim -> stack_size ].key = 0 ;
70
77
jim -> stack_size += 1 ;
@@ -309,7 +316,7 @@ void jim_array_begin(Jim *jim)
309
316
if (jim -> error == JIM_OK ) {
310
317
jim_element_begin (jim );
311
318
jim_write_cstr (jim , "[" );
312
- jim_stack_push (jim );
319
+ jim_stack_push (jim , JIM_ARRAY_SCOPE );
313
320
}
314
321
}
315
322
@@ -328,17 +335,16 @@ void jim_object_begin(Jim *jim)
328
335
if (jim -> error == JIM_OK ) {
329
336
jim_element_begin (jim );
330
337
jim_write_cstr (jim , "{" );
331
- jim_stack_push (jim );
338
+ jim_stack_push (jim , JIM_OBJECT_SCOPE );
332
339
}
333
340
}
334
341
335
342
void jim_member_key (Jim * jim , const char * str , const unsigned int * size )
336
343
{
337
- // TODO(#3): jim_member_key does not throw an error when used inside of array scope instead of object scope
338
344
if (jim -> error == JIM_OK ) {
339
345
jim_element_begin (jim );
340
346
Jim_Scope * scope = jim_stack_top (jim );
341
- if (scope ) {
347
+ if (scope && scope -> kind == JIM_OBJECT_SCOPE ) {
342
348
if (!scope -> key ) {
343
349
jim_string_no_element (jim , str , size );
344
350
jim_write_cstr (jim , ":" );
0 commit comments