@@ -8,7 +8,7 @@ static ID i_json_creatable_p, i_json_create, i_create_id,
8
8
i_chr, i_deep_const_get, i_match, i_aset, i_aref,
9
9
i_leftshift, i_new, i_try_convert, i_uminus, i_encode;
10
10
11
- static VALUE sym_max_nesting, sym_allow_nan, sym_symbolize_names, sym_freeze,
11
+ static VALUE sym_max_nesting, sym_allow_nan, sym_allow_trailing_comma, sym_symbolize_names, sym_freeze,
12
12
sym_create_additions, sym_create_id, sym_object_class, sym_array_class,
13
13
sym_decimal_class, sym_match_string;
14
14
@@ -383,6 +383,7 @@ typedef struct JSON_ParserStruct {
383
383
FBuffer fbuffer;
384
384
int max_nesting;
385
385
bool allow_nan;
386
+ bool allow_trailing_comma;
386
387
bool parsing_name;
387
388
bool symbolize_names;
388
389
bool freeze;
@@ -477,6 +478,8 @@ static void raise_parse_error(const char *format, const char *start)
477
478
}
478
479
}
479
480
481
+ action allow_trailing_comma { json->allow_trailing_comma }
482
+
480
483
action parse_name {
481
484
char *np;
482
485
json->parsing_name = true;
@@ -495,7 +498,7 @@ static void raise_parse_error(const char *format, const char *start)
495
498
496
499
main := (
497
500
begin_object
498
- (pair (next_pair)*)? ignore*
501
+ (pair (next_pair)*((ignore* value_separator) when allow_trailing_comma)? )? ignore*
499
502
end_object
500
503
) @exit;
501
504
}%%
@@ -788,13 +791,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
788
791
}
789
792
}
790
793
794
+ action allow_trailing_comma { json->allow_trailing_comma }
795
+
791
796
action exit { fhold; fbreak; }
792
797
793
798
next_element = value_separator ignore* begin_value >parse_value;
794
799
795
800
main := begin_array ignore*
796
801
((begin_value >parse_value ignore*)
797
- (ignore* next_element ignore*)*)?
802
+ (ignore* next_element ignore*)*((value_separator ignore*) when allow_trailing_comma)? )?
798
803
end_array @exit;
799
804
}%%
800
805
@@ -1073,16 +1078,17 @@ static int configure_parser_i(VALUE key, VALUE val, VALUE data)
1073
1078
{
1074
1079
JSON_Parser *json = (JSON_Parser *)data;
1075
1080
1076
- if (key == sym_max_nesting) { json->max_nesting = RTEST(val) ? FIX2INT(val) : 0; }
1077
- else if (key == sym_allow_nan) { json->allow_nan = RTEST(val); }
1078
- else if (key == sym_symbolize_names) { json->symbolize_names = RTEST(val); }
1079
- else if (key == sym_freeze) { json->freeze = RTEST(val); }
1080
- else if (key == sym_create_id) { json->create_id = RTEST(val) ? val : Qfalse; }
1081
- else if (key == sym_object_class) { json->object_class = RTEST(val) ? val : Qfalse; }
1082
- else if (key == sym_array_class) { json->array_class = RTEST(val) ? val : Qfalse; }
1083
- else if (key == sym_decimal_class) { json->decimal_class = RTEST(val) ? val : Qfalse; }
1084
- else if (key == sym_match_string) { json->match_string = RTEST(val) ? val : Qfalse; }
1085
- else if (key == sym_create_additions) {
1081
+ if (key == sym_max_nesting) { json->max_nesting = RTEST(val) ? FIX2INT(val) : 0; }
1082
+ else if (key == sym_allow_nan) { json->allow_nan = RTEST(val); }
1083
+ else if (key == sym_allow_trailing_comma) { json->allow_trailing_comma = RTEST(val); }
1084
+ else if (key == sym_symbolize_names) { json->symbolize_names = RTEST(val); }
1085
+ else if (key == sym_freeze) { json->freeze = RTEST(val); }
1086
+ else if (key == sym_create_id) { json->create_id = RTEST(val) ? val : Qfalse; }
1087
+ else if (key == sym_object_class) { json->object_class = RTEST(val) ? val : Qfalse; }
1088
+ else if (key == sym_array_class) { json->array_class = RTEST(val) ? val : Qfalse; }
1089
+ else if (key == sym_decimal_class) { json->decimal_class = RTEST(val) ? val : Qfalse; }
1090
+ else if (key == sym_match_string) { json->match_string = RTEST(val) ? val : Qfalse; }
1091
+ else if (key == sym_create_additions) {
1086
1092
if (NIL_P(val)) {
1087
1093
json->create_additions = true;
1088
1094
json->deprecated_create_additions = true;
@@ -1358,6 +1364,7 @@ void Init_parser(void)
1358
1364
1359
1365
sym_max_nesting = ID2SYM(rb_intern("max_nesting"));
1360
1366
sym_allow_nan = ID2SYM(rb_intern("allow_nan"));
1367
+ sym_allow_trailing_comma = ID2SYM(rb_intern("allow_trailing_comma"));
1361
1368
sym_symbolize_names = ID2SYM(rb_intern("symbolize_names"));
1362
1369
sym_freeze = ID2SYM(rb_intern("freeze"));
1363
1370
sym_create_additions = ID2SYM(rb_intern("create_additions"));
0 commit comments