psych 3.1.0 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/LICENSE +21 -0
  4. data/README.md +2 -5
  5. data/Rakefile +8 -15
  6. data/ext/psych/depend +2 -0
  7. data/ext/psych/extconf.rb +6 -2
  8. data/ext/psych/psych.c +6 -3
  9. data/ext/psych/psych_parser.c +20 -33
  10. data/ext/psych/psych_yaml_tree.c +0 -12
  11. data/ext/psych/yaml/api.c +22 -22
  12. data/ext/psych/yaml/config.h +76 -6
  13. data/ext/psych/yaml/dumper.c +1 -1
  14. data/ext/psych/yaml/emitter.c +44 -10
  15. data/ext/psych/yaml/loader.c +206 -106
  16. data/ext/psych/yaml/parser.c +6 -1
  17. data/ext/psych/yaml/scanner.c +45 -25
  18. data/ext/psych/yaml/yaml.h +43 -29
  19. data/ext/psych/yaml/yaml_private.h +4 -4
  20. data/lib/psych/class_loader.rb +10 -8
  21. data/lib/psych/core_ext.rb +1 -1
  22. data/lib/psych/exception.rb +2 -2
  23. data/lib/psych/handler.rb +1 -1
  24. data/lib/psych/handlers/document_stream.rb +1 -1
  25. data/lib/psych/handlers/recorder.rb +1 -1
  26. data/lib/psych/json/stream.rb +2 -2
  27. data/lib/psych/json/tree_builder.rb +1 -1
  28. data/lib/psych/nodes/node.rb +4 -4
  29. data/lib/psych/nodes/scalar.rb +1 -1
  30. data/lib/psych/nodes.rb +7 -7
  31. data/lib/psych/scalar_scanner.rb +25 -39
  32. data/lib/psych/syntax_error.rb +1 -1
  33. data/lib/psych/tree_builder.rb +1 -1
  34. data/lib/psych/versions.rb +3 -3
  35. data/lib/psych/visitors/json_tree.rb +1 -1
  36. data/lib/psych/visitors/to_ruby.rb +53 -20
  37. data/lib/psych/visitors/visitor.rb +17 -3
  38. data/lib/psych/visitors/yaml_tree.rb +83 -47
  39. data/lib/psych/visitors.rb +6 -6
  40. data/lib/psych.rb +222 -122
  41. data/psych.gemspec +10 -16
  42. metadata +12 -43
  43. data/.travis.yml +0 -22
  44. data/CHANGELOG.rdoc +0 -583
@@ -16,7 +16,7 @@
16
16
  #define PUT(emitter,value) \
17
17
  (FLUSH(emitter) \
18
18
  && (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \
19
- emitter->column ++, \
19
+ emitter->column++, \
20
20
  1))
21
21
 
22
22
  /*
@@ -495,6 +495,7 @@ static int
495
495
  yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
496
496
  yaml_event_t *event)
497
497
  {
498
+ emitter->open_ended = 0;
498
499
  if (event->type == YAML_STREAM_START_EVENT)
499
500
  {
500
501
  if (!emitter->encoding) {
@@ -597,13 +598,20 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
597
598
  if (!yaml_emitter_write_indent(emitter))
598
599
  return 0;
599
600
  }
601
+ emitter->open_ended = 0;
600
602
 
601
603
  if (event->data.document_start.version_directive) {
602
604
  implicit = 0;
603
605
  if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0))
604
606
  return 0;
605
- if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
606
- return 0;
607
+ if (event->data.document_start.version_directive->minor == 1) {
608
+ if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
609
+ return 0;
610
+ }
611
+ else {
612
+ if (!yaml_emitter_write_indicator(emitter, "1.2", 1, 0, 0))
613
+ return 0;
614
+ }
607
615
  if (!yaml_emitter_write_indent(emitter))
608
616
  return 0;
609
617
  }
@@ -644,19 +652,25 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
644
652
 
645
653
  emitter->state = YAML_EMIT_DOCUMENT_CONTENT_STATE;
646
654
 
655
+ emitter->open_ended = 0;
647
656
  return 1;
648
657
  }
649
658
 
650
659
  else if (event->type == YAML_STREAM_END_EVENT)
651
660
  {
652
- if (emitter->open_ended)
661
+
662
+ /**
663
+ * This can happen if a block scalar with trailing empty lines
664
+ * is at the end of the stream
665
+ */
666
+ if (emitter->open_ended == 2)
653
667
  {
654
668
  if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
655
669
  return 0;
670
+ emitter->open_ended = 0;
656
671
  if (!yaml_emitter_write_indent(emitter))
657
672
  return 0;
658
673
  }
659
-
660
674
  if (!yaml_emitter_flush(emitter))
661
675
  return 0;
662
676
 
@@ -698,9 +712,12 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter,
698
712
  if (!event->data.document_end.implicit) {
699
713
  if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
700
714
  return 0;
715
+ emitter->open_ended = 0;
701
716
  if (!yaml_emitter_write_indent(emitter))
702
717
  return 0;
703
718
  }
719
+ else if (!emitter->open_ended)
720
+ emitter->open_ended = 1;
704
721
  if (!yaml_emitter_flush(emitter))
705
722
  return 0;
706
723
 
@@ -1006,6 +1023,8 @@ yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event))
1006
1023
  {
1007
1024
  if (!yaml_emitter_process_anchor(emitter))
1008
1025
  return 0;
1026
+ if (emitter->simple_key_context)
1027
+ if (!PUT(emitter, ' ')) return 0;
1009
1028
  emitter->state = POP(emitter, emitter->states);
1010
1029
 
1011
1030
  return 1;
@@ -1333,7 +1352,10 @@ static int
1333
1352
  yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter,
1334
1353
  yaml_version_directive_t version_directive)
1335
1354
  {
1336
- if (version_directive.major != 1 || version_directive.minor != 1) {
1355
+ if (version_directive.major != 1 || (
1356
+ version_directive.minor != 1
1357
+ && version_directive.minor != 2
1358
+ )) {
1337
1359
  return yaml_emitter_set_emitter_error(emitter,
1338
1360
  "incompatible %YAML directive");
1339
1361
  }
@@ -1803,7 +1825,6 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter,
1803
1825
 
1804
1826
  emitter->whitespace = is_whitespace;
1805
1827
  emitter->indention = (emitter->indention && is_indention);
1806
- emitter->open_ended = 0;
1807
1828
 
1808
1829
  return 1;
1809
1830
  }
@@ -1904,7 +1925,17 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
1904
1925
 
1905
1926
  STRING_ASSIGN(string, value, length);
1906
1927
 
1907
- if (!emitter->whitespace) {
1928
+ /**
1929
+ * Avoid trailing spaces for empty values in block mode.
1930
+ * In flow mode, we still want the space to prevent ambiguous things
1931
+ * like {a:}.
1932
+ * Currently, the emitter forbids any plain empty scalar in flow mode
1933
+ * (e.g. it outputs {a: ''} instead), so emitter->flow_level will
1934
+ * never be true here.
1935
+ * But if the emitter is ever changed to allow emitting empty values,
1936
+ * the check for flow_level is already here.
1937
+ */
1938
+ if (!emitter->whitespace && (length || emitter->flow_level)) {
1908
1939
  if (!PUT(emitter, ' ')) return 0;
1909
1940
  }
1910
1941
 
@@ -2004,6 +2035,9 @@ yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter,
2004
2035
  }
2005
2036
  }
2006
2037
 
2038
+ if (breaks)
2039
+ if (!yaml_emitter_write_indent(emitter)) return 0;
2040
+
2007
2041
  if (!yaml_emitter_write_indicator(emitter, "'", 0, 0, 0))
2008
2042
  return 0;
2009
2043
 
@@ -2203,7 +2237,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
2203
2237
  else if (string.start == string.pointer)
2204
2238
  {
2205
2239
  chomp_hint = "+";
2206
- emitter->open_ended = 1;
2240
+ emitter->open_ended = 2;
2207
2241
  }
2208
2242
  else
2209
2243
  {
@@ -2213,7 +2247,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
2213
2247
  if (IS_BREAK(string))
2214
2248
  {
2215
2249
  chomp_hint = "+";
2216
- emitter->open_ended = 1;
2250
+ emitter->open_ended = 2;
2217
2251
  }
2218
2252
  }
2219
2253
  }
@@ -37,27 +37,47 @@ yaml_parser_register_anchor(yaml_parser_t *parser,
37
37
  static void
38
38
  yaml_parser_delete_aliases(yaml_parser_t *parser);
39
39
 
40
+ /*
41
+ * Document loading context.
42
+ */
43
+ struct loader_ctx {
44
+ int *start;
45
+ int *end;
46
+ int *top;
47
+ };
48
+
40
49
  /*
41
50
  * Composer functions.
42
51
  */
52
+ static int
53
+ yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx);
54
+
55
+ static int
56
+ yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event);
43
57
 
44
58
  static int
45
- yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event);
59
+ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
60
+ struct loader_ctx *ctx);
46
61
 
47
62
  static int
48
- yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event);
63
+ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
64
+ struct loader_ctx *ctx);
49
65
 
50
66
  static int
51
- yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event);
67
+ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
68
+ struct loader_ctx *ctx);
52
69
 
53
70
  static int
54
- yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event);
71
+ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
72
+ struct loader_ctx *ctx);
55
73
 
56
74
  static int
57
- yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event);
75
+ yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event,
76
+ struct loader_ctx *ctx);
58
77
 
59
78
  static int
60
- yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event);
79
+ yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
80
+ struct loader_ctx *ctx);
61
81
 
62
82
  /*
63
83
  * Load the next document of the stream.
@@ -162,59 +182,78 @@ yaml_parser_delete_aliases(yaml_parser_t *parser)
162
182
  */
163
183
 
164
184
  static int
165
- yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event)
185
+ yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event)
166
186
  {
167
- yaml_event_t event;
187
+ struct loader_ctx ctx = { NULL, NULL, NULL };
168
188
 
169
- assert(first_event->type == YAML_DOCUMENT_START_EVENT);
189
+ assert(event->type == YAML_DOCUMENT_START_EVENT);
170
190
  /* DOCUMENT-START is expected. */
171
191
 
172
192
  parser->document->version_directive
173
- = first_event->data.document_start.version_directive;
193
+ = event->data.document_start.version_directive;
174
194
  parser->document->tag_directives.start
175
- = first_event->data.document_start.tag_directives.start;
195
+ = event->data.document_start.tag_directives.start;
176
196
  parser->document->tag_directives.end
177
- = first_event->data.document_start.tag_directives.end;
197
+ = event->data.document_start.tag_directives.end;
178
198
  parser->document->start_implicit
179
- = first_event->data.document_start.implicit;
180
- parser->document->start_mark = first_event->start_mark;
181
-
182
- if (!yaml_parser_parse(parser, &event)) return 0;
183
-
184
- if (!yaml_parser_load_node(parser, &event)) return 0;
185
-
186
- if (!yaml_parser_parse(parser, &event)) return 0;
187
- assert(event.type == YAML_DOCUMENT_END_EVENT);
188
- /* DOCUMENT-END is expected. */
199
+ = event->data.document_start.implicit;
200
+ parser->document->start_mark = event->start_mark;
189
201
 
190
- parser->document->end_implicit = event.data.document_end.implicit;
191
- parser->document->end_mark = event.end_mark;
202
+ if (!STACK_INIT(parser, ctx, int*)) return 0;
203
+ if (!yaml_parser_load_nodes(parser, &ctx)) {
204
+ STACK_DEL(parser, ctx);
205
+ return 0;
206
+ }
207
+ STACK_DEL(parser, ctx);
192
208
 
193
209
  return 1;
194
210
  }
195
211
 
196
212
  /*
197
- * Compose a node.
213
+ * Compose a node tree.
198
214
  */
199
215
 
200
216
  static int
201
- yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event)
217
+ yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx)
202
218
  {
203
- switch (first_event->type) {
204
- case YAML_ALIAS_EVENT:
205
- return yaml_parser_load_alias(parser, first_event);
206
- case YAML_SCALAR_EVENT:
207
- return yaml_parser_load_scalar(parser, first_event);
208
- case YAML_SEQUENCE_START_EVENT:
209
- return yaml_parser_load_sequence(parser, first_event);
210
- case YAML_MAPPING_START_EVENT:
211
- return yaml_parser_load_mapping(parser, first_event);
212
- default:
213
- assert(0); /* Could not happen. */
214
- return 0;
215
- }
219
+ yaml_event_t event;
216
220
 
217
- return 0;
221
+ do {
222
+ if (!yaml_parser_parse(parser, &event)) return 0;
223
+
224
+ switch (event.type) {
225
+ case YAML_ALIAS_EVENT:
226
+ if (!yaml_parser_load_alias(parser, &event, ctx)) return 0;
227
+ break;
228
+ case YAML_SCALAR_EVENT:
229
+ if (!yaml_parser_load_scalar(parser, &event, ctx)) return 0;
230
+ break;
231
+ case YAML_SEQUENCE_START_EVENT:
232
+ if (!yaml_parser_load_sequence(parser, &event, ctx)) return 0;
233
+ break;
234
+ case YAML_SEQUENCE_END_EVENT:
235
+ if (!yaml_parser_load_sequence_end(parser, &event, ctx))
236
+ return 0;
237
+ break;
238
+ case YAML_MAPPING_START_EVENT:
239
+ if (!yaml_parser_load_mapping(parser, &event, ctx)) return 0;
240
+ break;
241
+ case YAML_MAPPING_END_EVENT:
242
+ if (!yaml_parser_load_mapping_end(parser, &event, ctx))
243
+ return 0;
244
+ break;
245
+ default:
246
+ assert(0); /* Could not happen. */
247
+ return 0;
248
+ case YAML_DOCUMENT_END_EVENT:
249
+ break;
250
+ }
251
+ } while (event.type != YAML_DOCUMENT_END_EVENT);
252
+
253
+ parser->document->end_implicit = event.data.document_end.implicit;
254
+ parser->document->end_mark = event.end_mark;
255
+
256
+ return 1;
218
257
  }
219
258
 
220
259
  /*
@@ -252,27 +291,80 @@ yaml_parser_register_anchor(yaml_parser_t *parser,
252
291
  return 1;
253
292
  }
254
293
 
294
+ /*
295
+ * Compose node into its parent in the stree.
296
+ */
297
+
298
+ static int
299
+ yaml_parser_load_node_add(yaml_parser_t *parser, struct loader_ctx *ctx,
300
+ int index)
301
+ {
302
+ struct yaml_node_s *parent;
303
+ int parent_index;
304
+
305
+ if (STACK_EMPTY(parser, *ctx)) {
306
+ /* This is the root node, there's no tree to add it to. */
307
+ return 1;
308
+ }
309
+
310
+ parent_index = *((*ctx).top - 1);
311
+ parent = &parser->document->nodes.start[parent_index-1];
312
+
313
+ switch (parent->type) {
314
+ case YAML_SEQUENCE_NODE:
315
+ if (!STACK_LIMIT(parser, parent->data.sequence.items, INT_MAX-1))
316
+ return 0;
317
+ if (!PUSH(parser, parent->data.sequence.items, index))
318
+ return 0;
319
+ break;
320
+ case YAML_MAPPING_NODE: {
321
+ yaml_node_pair_t pair;
322
+ if (!STACK_EMPTY(parser, parent->data.mapping.pairs)) {
323
+ yaml_node_pair_t *p = parent->data.mapping.pairs.top - 1;
324
+ if (p->key != 0 && p->value == 0) {
325
+ p->value = index;
326
+ break;
327
+ }
328
+ }
329
+
330
+ pair.key = index;
331
+ pair.value = 0;
332
+ if (!STACK_LIMIT(parser, parent->data.mapping.pairs, INT_MAX-1))
333
+ return 0;
334
+ if (!PUSH(parser, parent->data.mapping.pairs, pair))
335
+ return 0;
336
+
337
+ break;
338
+ }
339
+ default:
340
+ assert(0); /* Could not happen. */
341
+ return 0;
342
+ }
343
+ return 1;
344
+ }
345
+
255
346
  /*
256
347
  * Compose a node corresponding to an alias.
257
348
  */
258
349
 
259
350
  static int
260
- yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
351
+ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
352
+ struct loader_ctx *ctx)
261
353
  {
262
- yaml_char_t *anchor = first_event->data.alias.anchor;
354
+ yaml_char_t *anchor = event->data.alias.anchor;
263
355
  yaml_alias_data_t *alias_data;
264
356
 
265
357
  for (alias_data = parser->aliases.start;
266
358
  alias_data != parser->aliases.top; alias_data ++) {
267
359
  if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
268
360
  yaml_free(anchor);
269
- return alias_data->index;
361
+ return yaml_parser_load_node_add(parser, ctx, alias_data->index);
270
362
  }
271
363
  }
272
364
 
273
365
  yaml_free(anchor);
274
366
  return yaml_parser_set_composer_error(parser, "found undefined alias",
275
- first_event->start_mark);
367
+ event->start_mark);
276
368
  }
277
369
 
278
370
  /*
@@ -280,11 +372,12 @@ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
280
372
  */
281
373
 
282
374
  static int
283
- yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
375
+ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
376
+ struct loader_ctx *ctx)
284
377
  {
285
378
  yaml_node_t node;
286
379
  int index;
287
- yaml_char_t *tag = first_event->data.scalar.tag;
380
+ yaml_char_t *tag = event->data.scalar.tag;
288
381
 
289
382
  if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
290
383
 
@@ -294,23 +387,23 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
294
387
  if (!tag) goto error;
295
388
  }
296
389
 
297
- SCALAR_NODE_INIT(node, tag, first_event->data.scalar.value,
298
- first_event->data.scalar.length, first_event->data.scalar.style,
299
- first_event->start_mark, first_event->end_mark);
390
+ SCALAR_NODE_INIT(node, tag, event->data.scalar.value,
391
+ event->data.scalar.length, event->data.scalar.style,
392
+ event->start_mark, event->end_mark);
300
393
 
301
394
  if (!PUSH(parser, parser->document->nodes, node)) goto error;
302
395
 
303
- index = parser->document->nodes.top - parser->document->nodes.start;
396
+ index = (int)(parser->document->nodes.top - parser->document->nodes.start);
304
397
 
305
398
  if (!yaml_parser_register_anchor(parser, index,
306
- first_event->data.scalar.anchor)) return 0;
399
+ event->data.scalar.anchor)) return 0;
307
400
 
308
- return index;
401
+ return yaml_parser_load_node_add(parser, ctx, index);
309
402
 
310
403
  error:
311
404
  yaml_free(tag);
312
- yaml_free(first_event->data.scalar.anchor);
313
- yaml_free(first_event->data.scalar.value);
405
+ yaml_free(event->data.scalar.anchor);
406
+ yaml_free(event->data.scalar.value);
314
407
  return 0;
315
408
  }
316
409
 
@@ -319,17 +412,17 @@ error:
319
412
  */
320
413
 
321
414
  static int
322
- yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
415
+ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
416
+ struct loader_ctx *ctx)
323
417
  {
324
- yaml_event_t event;
325
418
  yaml_node_t node;
326
419
  struct {
327
420
  yaml_node_item_t *start;
328
421
  yaml_node_item_t *end;
329
422
  yaml_node_item_t *top;
330
423
  } items = { NULL, NULL, NULL };
331
- int index, item_index;
332
- yaml_char_t *tag = first_event->data.sequence_start.tag;
424
+ int index;
425
+ yaml_char_t *tag = event->data.sequence_start.tag;
333
426
 
334
427
  if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
335
428
 
@@ -342,48 +435,54 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
342
435
  if (!STACK_INIT(parser, items, yaml_node_item_t*)) goto error;
343
436
 
344
437
  SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
345
- first_event->data.sequence_start.style,
346
- first_event->start_mark, first_event->end_mark);
438
+ event->data.sequence_start.style,
439
+ event->start_mark, event->end_mark);
347
440
 
348
441
  if (!PUSH(parser, parser->document->nodes, node)) goto error;
349
442
 
350
- index = parser->document->nodes.top - parser->document->nodes.start;
443
+ index = (int)(parser->document->nodes.top - parser->document->nodes.start);
351
444
 
352
445
  if (!yaml_parser_register_anchor(parser, index,
353
- first_event->data.sequence_start.anchor)) return 0;
354
-
355
- if (!yaml_parser_parse(parser, &event)) return 0;
356
-
357
- while (event.type != YAML_SEQUENCE_END_EVENT) {
358
- if (!STACK_LIMIT(parser,
359
- parser->document->nodes.start[index-1].data.sequence.items,
360
- INT_MAX-1)) return 0;
361
- item_index = yaml_parser_load_node(parser, &event);
362
- if (!item_index) return 0;
363
- if (!PUSH(parser,
364
- parser->document->nodes.start[index-1].data.sequence.items,
365
- item_index)) return 0;
366
- if (!yaml_parser_parse(parser, &event)) return 0;
367
- }
446
+ event->data.sequence_start.anchor)) return 0;
368
447
 
369
- parser->document->nodes.start[index-1].end_mark = event.end_mark;
448
+ if (!yaml_parser_load_node_add(parser, ctx, index)) return 0;
370
449
 
371
- return index;
450
+ if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0;
451
+ if (!PUSH(parser, *ctx, index)) return 0;
452
+
453
+ return 1;
372
454
 
373
455
  error:
374
456
  yaml_free(tag);
375
- yaml_free(first_event->data.sequence_start.anchor);
457
+ yaml_free(event->data.sequence_start.anchor);
376
458
  return 0;
377
459
  }
378
460
 
461
+ static int
462
+ yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event,
463
+ struct loader_ctx *ctx)
464
+ {
465
+ int index;
466
+
467
+ assert(((*ctx).top - (*ctx).start) > 0);
468
+
469
+ index = *((*ctx).top - 1);
470
+ assert(parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE);
471
+ parser->document->nodes.start[index-1].end_mark = event->end_mark;
472
+
473
+ (void)POP(parser, *ctx);
474
+
475
+ return 1;
476
+ }
477
+
379
478
  /*
380
479
  * Compose a mapping node.
381
480
  */
382
481
 
383
482
  static int
384
- yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
483
+ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
484
+ struct loader_ctx *ctx)
385
485
  {
386
- yaml_event_t event;
387
486
  yaml_node_t node;
388
487
  struct {
389
488
  yaml_node_pair_t *start;
@@ -391,8 +490,7 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
391
490
  yaml_node_pair_t *top;
392
491
  } pairs = { NULL, NULL, NULL };
393
492
  int index;
394
- yaml_node_pair_t pair;
395
- yaml_char_t *tag = first_event->data.mapping_start.tag;
493
+ yaml_char_t *tag = event->data.mapping_start.tag;
396
494
 
397
495
  if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
398
496
 
@@ -405,40 +503,42 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
405
503
  if (!STACK_INIT(parser, pairs, yaml_node_pair_t*)) goto error;
406
504
 
407
505
  MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
408
- first_event->data.mapping_start.style,
409
- first_event->start_mark, first_event->end_mark);
506
+ event->data.mapping_start.style,
507
+ event->start_mark, event->end_mark);
410
508
 
411
509
  if (!PUSH(parser, parser->document->nodes, node)) goto error;
412
510
 
413
- index = parser->document->nodes.top - parser->document->nodes.start;
511
+ index = (int)(parser->document->nodes.top - parser->document->nodes.start);
414
512
 
415
513
  if (!yaml_parser_register_anchor(parser, index,
416
- first_event->data.mapping_start.anchor)) return 0;
514
+ event->data.mapping_start.anchor)) return 0;
417
515
 
418
- if (!yaml_parser_parse(parser, &event)) return 0;
516
+ if (!yaml_parser_load_node_add(parser, ctx, index)) return 0;
419
517
 
420
- while (event.type != YAML_MAPPING_END_EVENT) {
421
- if (!STACK_LIMIT(parser,
422
- parser->document->nodes.start[index-1].data.mapping.pairs,
423
- INT_MAX-1)) return 0;
424
- pair.key = yaml_parser_load_node(parser, &event);
425
- if (!pair.key) return 0;
426
- if (!yaml_parser_parse(parser, &event)) return 0;
427
- pair.value = yaml_parser_load_node(parser, &event);
428
- if (!pair.value) return 0;
429
- if (!PUSH(parser,
430
- parser->document->nodes.start[index-1].data.mapping.pairs,
431
- pair)) return 0;
432
- if (!yaml_parser_parse(parser, &event)) return 0;
433
- }
518
+ if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0;
519
+ if (!PUSH(parser, *ctx, index)) return 0;
434
520
 
435
- parser->document->nodes.start[index-1].end_mark = event.end_mark;
436
-
437
- return index;
521
+ return 1;
438
522
 
439
523
  error:
440
524
  yaml_free(tag);
441
- yaml_free(first_event->data.mapping_start.anchor);
525
+ yaml_free(event->data.mapping_start.anchor);
442
526
  return 0;
443
527
  }
444
528
 
529
+ static int
530
+ yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
531
+ struct loader_ctx *ctx)
532
+ {
533
+ int index;
534
+
535
+ assert(((*ctx).top - (*ctx).start) > 0);
536
+
537
+ index = *((*ctx).top - 1);
538
+ assert(parser->document->nodes.start[index-1].type == YAML_MAPPING_NODE);
539
+ parser->document->nodes.start[index-1].end_mark = event->end_mark;
540
+
541
+ (void)POP(parser, *ctx);
542
+
543
+ return 1;
544
+ }
@@ -1261,7 +1261,10 @@ yaml_parser_process_directives(yaml_parser_t *parser,
1261
1261
  goto error;
1262
1262
  }
1263
1263
  if (token->data.version_directive.major != 1
1264
- || token->data.version_directive.minor != 1) {
1264
+ || (
1265
+ token->data.version_directive.minor != 1
1266
+ && token->data.version_directive.minor != 2
1267
+ )) {
1265
1268
  yaml_parser_set_parser_error(parser,
1266
1269
  "found incompatible YAML document", token->start_mark);
1267
1270
  goto error;
@@ -1316,6 +1319,8 @@ yaml_parser_process_directives(yaml_parser_t *parser,
1316
1319
  STACK_DEL(parser, tag_directives);
1317
1320
  }
1318
1321
 
1322
+ if (!version_directive_ref)
1323
+ yaml_free(version_directive);
1319
1324
  return 1;
1320
1325
 
1321
1326
  error: