psych 2.0.14-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +16 -0
  5. data/CHANGELOG.rdoc +576 -0
  6. data/Manifest.txt +114 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +123 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +38 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +555 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +597 -0
  16. data/ext/psych/psych_parser.h +6 -0
  17. data/ext/psych/psych_to_ruby.c +43 -0
  18. data/ext/psych/psych_to_ruby.h +8 -0
  19. data/ext/psych/psych_yaml_tree.c +24 -0
  20. data/ext/psych/psych_yaml_tree.h +8 -0
  21. data/ext/psych/yaml/LICENSE +19 -0
  22. data/ext/psych/yaml/api.c +1415 -0
  23. data/ext/psych/yaml/config.h +10 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2329 -0
  26. data/ext/psych/yaml/loader.c +459 -0
  27. data/ext/psych/yaml/parser.c +1370 -0
  28. data/ext/psych/yaml/reader.c +469 -0
  29. data/ext/psych/yaml/scanner.c +3576 -0
  30. data/ext/psych/yaml/writer.c +141 -0
  31. data/ext/psych/yaml/yaml.h +1971 -0
  32. data/ext/psych/yaml/yaml_private.h +664 -0
  33. data/lib/psych.jar +0 -0
  34. data/lib/psych.rb +504 -0
  35. data/lib/psych/class_loader.rb +101 -0
  36. data/lib/psych/coder.rb +94 -0
  37. data/lib/psych/core_ext.rb +35 -0
  38. data/lib/psych/deprecated.rb +85 -0
  39. data/lib/psych/exception.rb +13 -0
  40. data/lib/psych/handler.rb +249 -0
  41. data/lib/psych/handlers/document_stream.rb +22 -0
  42. data/lib/psych/handlers/recorder.rb +39 -0
  43. data/lib/psych/json/ruby_events.rb +19 -0
  44. data/lib/psych/json/stream.rb +16 -0
  45. data/lib/psych/json/tree_builder.rb +12 -0
  46. data/lib/psych/json/yaml_events.rb +29 -0
  47. data/lib/psych/nodes.rb +77 -0
  48. data/lib/psych/nodes/alias.rb +18 -0
  49. data/lib/psych/nodes/document.rb +60 -0
  50. data/lib/psych/nodes/mapping.rb +56 -0
  51. data/lib/psych/nodes/node.rb +55 -0
  52. data/lib/psych/nodes/scalar.rb +67 -0
  53. data/lib/psych/nodes/sequence.rb +81 -0
  54. data/lib/psych/nodes/stream.rb +37 -0
  55. data/lib/psych/omap.rb +4 -0
  56. data/lib/psych/parser.rb +51 -0
  57. data/lib/psych/scalar_scanner.rb +149 -0
  58. data/lib/psych/set.rb +4 -0
  59. data/lib/psych/stream.rb +37 -0
  60. data/lib/psych/streaming.rb +27 -0
  61. data/lib/psych/syntax_error.rb +21 -0
  62. data/lib/psych/tree_builder.rb +96 -0
  63. data/lib/psych/versions.rb +3 -0
  64. data/lib/psych/visitors.rb +6 -0
  65. data/lib/psych/visitors/depth_first.rb +26 -0
  66. data/lib/psych/visitors/emitter.rb +51 -0
  67. data/lib/psych/visitors/json_tree.rb +24 -0
  68. data/lib/psych/visitors/to_ruby.rb +404 -0
  69. data/lib/psych/visitors/visitor.rb +19 -0
  70. data/lib/psych/visitors/yaml_tree.rb +605 -0
  71. data/lib/psych/y.rb +9 -0
  72. data/lib/psych_jars.rb +5 -0
  73. data/test/psych/handlers/test_recorder.rb +25 -0
  74. data/test/psych/helper.rb +121 -0
  75. data/test/psych/json/test_stream.rb +109 -0
  76. data/test/psych/nodes/test_enumerable.rb +43 -0
  77. data/test/psych/test_alias_and_anchor.rb +96 -0
  78. data/test/psych/test_array.rb +57 -0
  79. data/test/psych/test_boolean.rb +36 -0
  80. data/test/psych/test_class.rb +36 -0
  81. data/test/psych/test_coder.rb +206 -0
  82. data/test/psych/test_date_time.rb +38 -0
  83. data/test/psych/test_deprecated.rb +214 -0
  84. data/test/psych/test_document.rb +46 -0
  85. data/test/psych/test_emitter.rb +93 -0
  86. data/test/psych/test_encoding.rb +259 -0
  87. data/test/psych/test_exception.rb +157 -0
  88. data/test/psych/test_hash.rb +94 -0
  89. data/test/psych/test_json_tree.rb +65 -0
  90. data/test/psych/test_merge_keys.rb +180 -0
  91. data/test/psych/test_nil.rb +18 -0
  92. data/test/psych/test_null.rb +19 -0
  93. data/test/psych/test_numeric.rb +45 -0
  94. data/test/psych/test_object.rb +44 -0
  95. data/test/psych/test_object_references.rb +71 -0
  96. data/test/psych/test_omap.rb +75 -0
  97. data/test/psych/test_parser.rb +339 -0
  98. data/test/psych/test_psych.rb +168 -0
  99. data/test/psych/test_safe_load.rb +97 -0
  100. data/test/psych/test_scalar.rb +11 -0
  101. data/test/psych/test_scalar_scanner.rb +106 -0
  102. data/test/psych/test_serialize_subclasses.rb +38 -0
  103. data/test/psych/test_set.rb +49 -0
  104. data/test/psych/test_stream.rb +93 -0
  105. data/test/psych/test_string.rb +226 -0
  106. data/test/psych/test_struct.rb +49 -0
  107. data/test/psych/test_symbol.rb +25 -0
  108. data/test/psych/test_tainted.rb +130 -0
  109. data/test/psych/test_to_yaml_properties.rb +63 -0
  110. data/test/psych/test_tree_builder.rb +79 -0
  111. data/test/psych/test_yaml.rb +1292 -0
  112. data/test/psych/test_yamldbm.rb +193 -0
  113. data/test/psych/test_yamlstore.rb +85 -0
  114. data/test/psych/visitors/test_depth_first.rb +49 -0
  115. data/test/psych/visitors/test_emitter.rb +144 -0
  116. data/test/psych/visitors/test_to_ruby.rb +333 -0
  117. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  118. metadata +240 -0
@@ -0,0 +1,459 @@
1
+
2
+ #include "yaml_private.h"
3
+
4
+ /*
5
+ * API functions.
6
+ */
7
+
8
+ YAML_DECLARE(int)
9
+ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
10
+
11
+ /*
12
+ * Error handling.
13
+ */
14
+
15
+ static int
16
+ yaml_parser_set_composer_error(yaml_parser_t *parser,
17
+ const char *problem, yaml_mark_t problem_mark);
18
+
19
+ static int
20
+ yaml_parser_set_composer_error_context(yaml_parser_t *parser,
21
+ const char *context, yaml_mark_t context_mark,
22
+ const char *problem, yaml_mark_t problem_mark);
23
+
24
+
25
+ /*
26
+ * Alias handling.
27
+ */
28
+
29
+ static int
30
+ yaml_parser_register_anchor(yaml_parser_t *parser,
31
+ int index, yaml_char_t *anchor);
32
+
33
+ /*
34
+ * Clean up functions.
35
+ */
36
+
37
+ static void
38
+ yaml_parser_delete_aliases(yaml_parser_t *parser);
39
+
40
+ /*
41
+ * Composer functions.
42
+ */
43
+
44
+ static int
45
+ yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event);
46
+
47
+ static int
48
+ yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event);
49
+
50
+ static int
51
+ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event);
52
+
53
+ static int
54
+ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event);
55
+
56
+ static int
57
+ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event);
58
+
59
+ static int
60
+ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event);
61
+
62
+ /*
63
+ * Load the next document of the stream.
64
+ */
65
+
66
+ YAML_DECLARE(int)
67
+ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
68
+ {
69
+ yaml_event_t event;
70
+
71
+ assert(parser); /* Non-NULL parser object is expected. */
72
+ assert(document); /* Non-NULL document object is expected. */
73
+
74
+ memset(document, 0, sizeof(yaml_document_t));
75
+ if (!STACK_INIT(parser, document->nodes, INITIAL_STACK_SIZE))
76
+ goto error;
77
+
78
+ if (!parser->stream_start_produced) {
79
+ if (!yaml_parser_parse(parser, &event)) goto error;
80
+ assert(event.type == YAML_STREAM_START_EVENT);
81
+ /* STREAM-START is expected. */
82
+ }
83
+
84
+ if (parser->stream_end_produced) {
85
+ return 1;
86
+ }
87
+
88
+ if (!yaml_parser_parse(parser, &event)) goto error;
89
+ if (event.type == YAML_STREAM_END_EVENT) {
90
+ return 1;
91
+ }
92
+
93
+ if (!STACK_INIT(parser, parser->aliases, INITIAL_STACK_SIZE))
94
+ goto error;
95
+
96
+ parser->document = document;
97
+
98
+ if (!yaml_parser_load_document(parser, &event)) goto error;
99
+
100
+ yaml_parser_delete_aliases(parser);
101
+ parser->document = NULL;
102
+
103
+ return 1;
104
+
105
+ error:
106
+
107
+ yaml_parser_delete_aliases(parser);
108
+ yaml_document_delete(document);
109
+ parser->document = NULL;
110
+
111
+ return 0;
112
+ }
113
+
114
+ /*
115
+ * Set composer error.
116
+ */
117
+
118
+ static int
119
+ yaml_parser_set_composer_error(yaml_parser_t *parser,
120
+ const char *problem, yaml_mark_t problem_mark)
121
+ {
122
+ parser->error = YAML_COMPOSER_ERROR;
123
+ parser->problem = problem;
124
+ parser->problem_mark = problem_mark;
125
+
126
+ return 0;
127
+ }
128
+
129
+ /*
130
+ * Set composer error with context.
131
+ */
132
+
133
+ static int
134
+ yaml_parser_set_composer_error_context(yaml_parser_t *parser,
135
+ const char *context, yaml_mark_t context_mark,
136
+ const char *problem, yaml_mark_t problem_mark)
137
+ {
138
+ parser->error = YAML_COMPOSER_ERROR;
139
+ parser->context = context;
140
+ parser->context_mark = context_mark;
141
+ parser->problem = problem;
142
+ parser->problem_mark = problem_mark;
143
+
144
+ return 0;
145
+ }
146
+
147
+ /*
148
+ * Delete the stack of aliases.
149
+ */
150
+
151
+ static void
152
+ yaml_parser_delete_aliases(yaml_parser_t *parser)
153
+ {
154
+ while (!STACK_EMPTY(parser, parser->aliases)) {
155
+ yaml_free(POP(parser, parser->aliases).anchor);
156
+ }
157
+ STACK_DEL(parser, parser->aliases);
158
+ }
159
+
160
+ /*
161
+ * Compose a document object.
162
+ */
163
+
164
+ static int
165
+ yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event)
166
+ {
167
+ yaml_event_t event;
168
+
169
+ assert(first_event->type == YAML_DOCUMENT_START_EVENT);
170
+ /* DOCUMENT-START is expected. */
171
+
172
+ parser->document->version_directive
173
+ = first_event->data.document_start.version_directive;
174
+ parser->document->tag_directives.start
175
+ = first_event->data.document_start.tag_directives.start;
176
+ parser->document->tag_directives.end
177
+ = first_event->data.document_start.tag_directives.end;
178
+ 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. */
189
+
190
+ parser->document->end_implicit = event.data.document_end.implicit;
191
+ parser->document->end_mark = event.end_mark;
192
+
193
+ return 1;
194
+ }
195
+
196
+ /*
197
+ * Compose a node.
198
+ */
199
+
200
+ static int
201
+ yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event)
202
+ {
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
+ }
216
+
217
+ return 0;
218
+ }
219
+
220
+ /*
221
+ * Add an anchor.
222
+ */
223
+
224
+ static int
225
+ yaml_parser_register_anchor(yaml_parser_t *parser,
226
+ int index, yaml_char_t *anchor)
227
+ {
228
+ yaml_alias_data_t data;
229
+ yaml_alias_data_t *alias_data;
230
+
231
+ if (!anchor) return 1;
232
+
233
+ data.anchor = anchor;
234
+ data.index = index;
235
+ data.mark = parser->document->nodes.start[index-1].start_mark;
236
+
237
+ for (alias_data = parser->aliases.start;
238
+ alias_data != parser->aliases.top; alias_data ++) {
239
+ if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
240
+ yaml_free(anchor);
241
+ return yaml_parser_set_composer_error_context(parser,
242
+ "found duplicate anchor; first occurence",
243
+ alias_data->mark, "second occurence", data.mark);
244
+ }
245
+ }
246
+
247
+ if (!PUSH(parser, parser->aliases, data)) {
248
+ yaml_free(anchor);
249
+ return 0;
250
+ }
251
+
252
+ return 1;
253
+ }
254
+
255
+ /*
256
+ * Compose a node corresponding to an alias.
257
+ */
258
+
259
+ static int
260
+ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
261
+ {
262
+ yaml_char_t *anchor = first_event->data.alias.anchor;
263
+ yaml_alias_data_t *alias_data;
264
+
265
+ for (alias_data = parser->aliases.start;
266
+ alias_data != parser->aliases.top; alias_data ++) {
267
+ if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
268
+ yaml_free(anchor);
269
+ return alias_data->index;
270
+ }
271
+ }
272
+
273
+ yaml_free(anchor);
274
+ return yaml_parser_set_composer_error(parser, "found undefined alias",
275
+ first_event->start_mark);
276
+ }
277
+
278
+ /*
279
+ * Compose a scalar node.
280
+ */
281
+
282
+ static int
283
+ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
284
+ {
285
+ yaml_node_t node;
286
+ ptrdiff_t node_index;
287
+ int index;
288
+ yaml_char_t *tag = first_event->data.scalar.tag;
289
+
290
+ if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
291
+
292
+ if (!tag || strcmp((char *)tag, "!") == 0) {
293
+ yaml_free(tag);
294
+ tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SCALAR_TAG);
295
+ if (!tag) goto error;
296
+ }
297
+
298
+ SCALAR_NODE_INIT(node, tag, first_event->data.scalar.value,
299
+ first_event->data.scalar.length, first_event->data.scalar.style,
300
+ first_event->start_mark, first_event->end_mark);
301
+
302
+ if (!PUSH(parser, parser->document->nodes, node)) goto error;
303
+
304
+ node_index = parser->document->nodes.top - parser->document->nodes.start;
305
+ #if PTRDIFF_MAX > INT_MAX
306
+ if (node_index > INT_MAX) goto error;
307
+ #endif
308
+ index = (int)node_index;
309
+
310
+ if (!yaml_parser_register_anchor(parser, index,
311
+ first_event->data.scalar.anchor)) return 0;
312
+
313
+ return index;
314
+
315
+ error:
316
+ yaml_free(tag);
317
+ yaml_free(first_event->data.scalar.anchor);
318
+ yaml_free(first_event->data.scalar.value);
319
+ return 0;
320
+ }
321
+
322
+ /*
323
+ * Compose a sequence node.
324
+ */
325
+
326
+ static int
327
+ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
328
+ {
329
+ yaml_event_t event;
330
+ yaml_node_t node;
331
+ struct {
332
+ yaml_node_item_t *start;
333
+ yaml_node_item_t *end;
334
+ yaml_node_item_t *top;
335
+ } items = { NULL, NULL, NULL };
336
+ int index, item_index;
337
+ ptrdiff_t node_index;
338
+ yaml_char_t *tag = first_event->data.sequence_start.tag;
339
+
340
+ if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
341
+
342
+ if (!tag || strcmp((char *)tag, "!") == 0) {
343
+ yaml_free(tag);
344
+ tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG);
345
+ if (!tag) goto error;
346
+ }
347
+
348
+ if (!STACK_INIT(parser, items, INITIAL_STACK_SIZE)) goto error;
349
+
350
+ SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
351
+ first_event->data.sequence_start.style,
352
+ first_event->start_mark, first_event->end_mark);
353
+
354
+ if (!PUSH(parser, parser->document->nodes, node)) goto error;
355
+
356
+ node_index = parser->document->nodes.top - parser->document->nodes.start;
357
+ #if PTRDIFF_MAX > INT_MAX
358
+ if (node_index > INT_MAX) goto error;
359
+ #endif
360
+ index = (int)node_index;
361
+
362
+ if (!yaml_parser_register_anchor(parser, index,
363
+ first_event->data.sequence_start.anchor)) return 0;
364
+
365
+ if (!yaml_parser_parse(parser, &event)) return 0;
366
+
367
+ while (event.type != YAML_SEQUENCE_END_EVENT) {
368
+ if (!STACK_LIMIT(parser,
369
+ parser->document->nodes.start[index-1].data.sequence.items,
370
+ INT_MAX-1)) return 0;
371
+ item_index = yaml_parser_load_node(parser, &event);
372
+ if (!item_index) return 0;
373
+ if (!PUSH(parser,
374
+ parser->document->nodes.start[index-1].data.sequence.items,
375
+ item_index)) return 0;
376
+ if (!yaml_parser_parse(parser, &event)) return 0;
377
+ }
378
+
379
+ parser->document->nodes.start[index-1].end_mark = event.end_mark;
380
+
381
+ return index;
382
+
383
+ error:
384
+ yaml_free(tag);
385
+ yaml_free(first_event->data.sequence_start.anchor);
386
+ return 0;
387
+ }
388
+
389
+ /*
390
+ * Compose a mapping node.
391
+ */
392
+
393
+ static int
394
+ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
395
+ {
396
+ yaml_event_t event;
397
+ yaml_node_t node;
398
+ struct {
399
+ yaml_node_pair_t *start;
400
+ yaml_node_pair_t *end;
401
+ yaml_node_pair_t *top;
402
+ } pairs = { NULL, NULL, NULL };
403
+ int index;
404
+ ptrdiff_t node_index;
405
+ yaml_node_pair_t pair;
406
+ yaml_char_t *tag = first_event->data.mapping_start.tag;
407
+
408
+ if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
409
+
410
+ if (!tag || strcmp((char *)tag, "!") == 0) {
411
+ yaml_free(tag);
412
+ tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG);
413
+ if (!tag) goto error;
414
+ }
415
+
416
+ if (!STACK_INIT(parser, pairs, INITIAL_STACK_SIZE)) goto error;
417
+
418
+ MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
419
+ first_event->data.mapping_start.style,
420
+ first_event->start_mark, first_event->end_mark);
421
+
422
+ if (!PUSH(parser, parser->document->nodes, node)) goto error;
423
+
424
+ node_index = parser->document->nodes.top - parser->document->nodes.start;
425
+ #if PTRDIFF_MAX > INT_MAX
426
+ if (node_index > INT_MAX) goto error;
427
+ #endif
428
+ index = (int)node_index;
429
+
430
+ if (!yaml_parser_register_anchor(parser, index,
431
+ first_event->data.mapping_start.anchor)) return 0;
432
+
433
+ if (!yaml_parser_parse(parser, &event)) return 0;
434
+
435
+ while (event.type != YAML_MAPPING_END_EVENT) {
436
+ if (!STACK_LIMIT(parser,
437
+ parser->document->nodes.start[index-1].data.mapping.pairs,
438
+ INT_MAX-1)) return 0;
439
+ pair.key = yaml_parser_load_node(parser, &event);
440
+ if (!pair.key) return 0;
441
+ if (!yaml_parser_parse(parser, &event)) return 0;
442
+ pair.value = yaml_parser_load_node(parser, &event);
443
+ if (!pair.value) return 0;
444
+ if (!PUSH(parser,
445
+ parser->document->nodes.start[index-1].data.mapping.pairs,
446
+ pair)) return 0;
447
+ if (!yaml_parser_parse(parser, &event)) return 0;
448
+ }
449
+
450
+ parser->document->nodes.start[index-1].end_mark = event.end_mark;
451
+
452
+ return index;
453
+
454
+ error:
455
+ yaml_free(tag);
456
+ yaml_free(first_event->data.mapping_start.anchor);
457
+ return 0;
458
+ }
459
+