psych 2.0.12 → 5.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +24 -0
- data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
- data/README.md +80 -0
- data/ext/psych/depend +14 -0
- data/ext/psych/extconf.rb +43 -28
- data/ext/psych/psych.c +6 -4
- data/ext/psych/psych.h +0 -3
- data/ext/psych/psych_emitter.c +165 -132
- data/ext/psych/psych_parser.c +298 -331
- data/ext/psych/psych_to_ruby.c +0 -5
- data/ext/psych/psych_yaml_tree.c +0 -13
- data/lib/psych/class_loader.rb +11 -8
- data/lib/psych/coder.rb +1 -0
- data/lib/psych/core_ext.rb +3 -19
- data/lib/psych/exception.rb +17 -2
- data/lib/psych/handler.rb +8 -2
- data/lib/psych/handlers/document_stream.rb +2 -1
- data/lib/psych/handlers/recorder.rb +2 -1
- data/lib/psych/json/ruby_events.rb +1 -0
- data/lib/psych/json/stream.rb +3 -2
- data/lib/psych/json/tree_builder.rb +2 -1
- data/lib/psych/json/yaml_events.rb +1 -0
- data/lib/psych/nodes/alias.rb +3 -0
- data/lib/psych/nodes/document.rb +3 -0
- data/lib/psych/nodes/mapping.rb +3 -0
- data/lib/psych/nodes/node.rb +25 -5
- data/lib/psych/nodes/scalar.rb +4 -1
- data/lib/psych/nodes/sequence.rb +3 -0
- data/lib/psych/nodes/stream.rb +3 -0
- data/lib/psych/nodes.rb +8 -7
- data/lib/psych/omap.rb +1 -0
- data/lib/psych/parser.rb +14 -0
- data/lib/psych/scalar_scanner.rb +41 -49
- data/lib/psych/set.rb +1 -0
- data/lib/psych/stream.rb +1 -0
- data/lib/psych/streaming.rb +1 -0
- data/lib/psych/syntax_error.rb +2 -1
- data/lib/psych/tree_builder.rb +48 -7
- data/lib/psych/versions.rb +10 -0
- data/lib/psych/visitors/depth_first.rb +1 -0
- data/lib/psych/visitors/emitter.rb +1 -0
- data/lib/psych/visitors/json_tree.rb +2 -1
- data/lib/psych/visitors/to_ruby.rb +64 -33
- data/lib/psych/visitors/visitor.rb +18 -3
- data/lib/psych/visitors/yaml_tree.rb +128 -149
- data/lib/psych/visitors.rb +7 -6
- data/lib/psych/y.rb +1 -0
- data/lib/psych.rb +360 -95
- metadata +36 -169
- data/.autotest +0 -18
- data/.gemtest +0 -0
- data/.travis.yml +0 -11
- data/CHANGELOG.rdoc +0 -562
- data/Manifest.txt +0 -112
- data/README.rdoc +0 -71
- data/Rakefile +0 -74
- data/ext/psych/yaml/api.c +0 -1415
- data/ext/psych/yaml/config.h +0 -10
- data/ext/psych/yaml/dumper.c +0 -394
- data/ext/psych/yaml/emitter.c +0 -2329
- data/ext/psych/yaml/loader.c +0 -459
- data/ext/psych/yaml/parser.c +0 -1370
- data/ext/psych/yaml/reader.c +0 -469
- data/ext/psych/yaml/scanner.c +0 -3583
- data/ext/psych/yaml/writer.c +0 -141
- data/ext/psych/yaml/yaml.h +0 -1971
- data/ext/psych/yaml/yaml_private.h +0 -664
- data/lib/psych/deprecated.rb +0 -85
- data/test/psych/handlers/test_recorder.rb +0 -25
- data/test/psych/helper.rb +0 -114
- data/test/psych/json/test_stream.rb +0 -109
- data/test/psych/nodes/test_enumerable.rb +0 -43
- data/test/psych/test_alias_and_anchor.rb +0 -96
- data/test/psych/test_array.rb +0 -57
- data/test/psych/test_boolean.rb +0 -36
- data/test/psych/test_class.rb +0 -36
- data/test/psych/test_coder.rb +0 -184
- data/test/psych/test_date_time.rb +0 -38
- data/test/psych/test_deprecated.rb +0 -214
- data/test/psych/test_document.rb +0 -46
- data/test/psych/test_emitter.rb +0 -93
- data/test/psych/test_encoding.rb +0 -259
- data/test/psych/test_exception.rb +0 -157
- data/test/psych/test_hash.rb +0 -94
- data/test/psych/test_json_tree.rb +0 -65
- data/test/psych/test_marshalable.rb +0 -54
- data/test/psych/test_merge_keys.rb +0 -180
- data/test/psych/test_nil.rb +0 -18
- data/test/psych/test_null.rb +0 -19
- data/test/psych/test_numeric.rb +0 -45
- data/test/psych/test_object.rb +0 -44
- data/test/psych/test_object_references.rb +0 -71
- data/test/psych/test_omap.rb +0 -75
- data/test/psych/test_parser.rb +0 -339
- data/test/psych/test_psych.rb +0 -168
- data/test/psych/test_safe_load.rb +0 -97
- data/test/psych/test_scalar.rb +0 -11
- data/test/psych/test_scalar_scanner.rb +0 -106
- data/test/psych/test_serialize_subclasses.rb +0 -38
- data/test/psych/test_set.rb +0 -49
- data/test/psych/test_stream.rb +0 -93
- data/test/psych/test_string.rb +0 -226
- data/test/psych/test_struct.rb +0 -49
- data/test/psych/test_symbol.rb +0 -25
- data/test/psych/test_tainted.rb +0 -130
- data/test/psych/test_to_yaml_properties.rb +0 -63
- data/test/psych/test_tree_builder.rb +0 -79
- data/test/psych/test_yaml.rb +0 -1288
- data/test/psych/test_yamldbm.rb +0 -193
- data/test/psych/test_yamlstore.rb +0 -85
- data/test/psych/visitors/test_depth_first.rb +0 -49
- data/test/psych/visitors/test_emitter.rb +0 -144
- data/test/psych/visitors/test_to_ruby.rb +0 -326
- data/test/psych/visitors/test_yaml_tree.rb +0 -173
data/ext/psych/psych_parser.c
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#include <psych.h>
|
2
2
|
|
3
3
|
VALUE cPsychParser;
|
4
|
-
VALUE ePsychSyntaxError;
|
5
4
|
|
6
5
|
static ID id_read;
|
7
6
|
static ID id_path;
|
@@ -16,6 +15,7 @@ static ID id_start_sequence;
|
|
16
15
|
static ID id_end_sequence;
|
17
16
|
static ID id_start_mapping;
|
18
17
|
static ID id_end_mapping;
|
18
|
+
static ID id_event_location;
|
19
19
|
|
20
20
|
#define PSYCH_TRANSCODE(_str, _yaml_enc, _internal_enc) \
|
21
21
|
do { \
|
@@ -27,14 +27,14 @@ static ID id_end_mapping;
|
|
27
27
|
static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
|
28
28
|
{
|
29
29
|
VALUE io = (VALUE)data;
|
30
|
-
VALUE string = rb_funcall(io, id_read, 1,
|
30
|
+
VALUE string = rb_funcall(io, id_read, 1, SIZET2NUM(size));
|
31
31
|
|
32
32
|
*read = 0;
|
33
33
|
|
34
34
|
if(! NIL_P(string)) {
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
void * str = (void *)StringValuePtr(string);
|
36
|
+
*read = (size_t)RSTRING_LEN(string);
|
37
|
+
memcpy(buf, str, *read);
|
38
38
|
}
|
39
39
|
|
40
40
|
return 1;
|
@@ -70,30 +70,36 @@ static const rb_data_type_t psych_parser_type = {
|
|
70
70
|
static VALUE allocate(VALUE klass)
|
71
71
|
{
|
72
72
|
yaml_parser_t * parser;
|
73
|
+
VALUE obj = TypedData_Make_Struct(klass, yaml_parser_t, &psych_parser_type, parser);
|
73
74
|
|
74
|
-
parser = xmalloc(sizeof(yaml_parser_t));
|
75
75
|
yaml_parser_initialize(parser);
|
76
76
|
|
77
|
-
return
|
77
|
+
return obj;
|
78
78
|
}
|
79
79
|
|
80
80
|
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
|
81
81
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
if (parser->error == YAML_MEMORY_ERROR) {
|
83
|
+
return rb_eNoMemError;
|
84
|
+
} else {
|
85
|
+
size_t line, column;
|
86
|
+
VALUE ePsychSyntaxError;
|
87
|
+
|
88
|
+
line = parser->context_mark.line + 1;
|
89
|
+
column = parser->context_mark.column + 1;
|
90
|
+
|
91
|
+
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
92
|
+
|
93
|
+
return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
|
94
|
+
path,
|
95
|
+
SIZET2NUM(line),
|
96
|
+
SIZET2NUM(column),
|
97
|
+
SIZET2NUM(parser->problem_offset),
|
98
|
+
parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
|
99
|
+
parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
|
100
|
+
}
|
94
101
|
}
|
95
102
|
|
96
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
97
103
|
static VALUE transcode_string(VALUE src, int * parser_encoding)
|
98
104
|
{
|
99
105
|
int utf8 = rb_utf8_encindex();
|
@@ -102,18 +108,18 @@ static VALUE transcode_string(VALUE src, int * parser_encoding)
|
|
102
108
|
int source_encoding = rb_enc_get_index(src);
|
103
109
|
|
104
110
|
if (source_encoding == utf8) {
|
105
|
-
|
106
|
-
|
111
|
+
*parser_encoding = YAML_UTF8_ENCODING;
|
112
|
+
return src;
|
107
113
|
}
|
108
114
|
|
109
115
|
if (source_encoding == utf16le) {
|
110
|
-
|
111
|
-
|
116
|
+
*parser_encoding = YAML_UTF16LE_ENCODING;
|
117
|
+
return src;
|
112
118
|
}
|
113
119
|
|
114
120
|
if (source_encoding == utf16be) {
|
115
|
-
|
116
|
-
|
121
|
+
*parser_encoding = YAML_UTF16BE_ENCODING;
|
122
|
+
return src;
|
117
123
|
}
|
118
124
|
|
119
125
|
src = rb_str_export_to_enc(src, rb_utf8_encoding());
|
@@ -132,36 +138,36 @@ static VALUE transcode_io(VALUE src, int * parser_encoding)
|
|
132
138
|
|
133
139
|
/* if no encoding is returned, assume ascii8bit. */
|
134
140
|
if (NIL_P(io_external_encoding)) {
|
135
|
-
|
141
|
+
io_external_enc_index = rb_ascii8bit_encindex();
|
136
142
|
} else {
|
137
|
-
|
143
|
+
io_external_enc_index = rb_to_encoding_index(io_external_encoding);
|
138
144
|
}
|
139
145
|
|
140
146
|
/* Treat US-ASCII as utf_8 */
|
141
147
|
if (io_external_enc_index == rb_usascii_encindex()) {
|
142
|
-
|
143
|
-
|
148
|
+
*parser_encoding = YAML_UTF8_ENCODING;
|
149
|
+
return src;
|
144
150
|
}
|
145
151
|
|
146
152
|
if (io_external_enc_index == rb_utf8_encindex()) {
|
147
|
-
|
148
|
-
|
153
|
+
*parser_encoding = YAML_UTF8_ENCODING;
|
154
|
+
return src;
|
149
155
|
}
|
150
156
|
|
151
157
|
if (io_external_enc_index == rb_enc_find_index("UTF-16LE")) {
|
152
|
-
|
153
|
-
|
158
|
+
*parser_encoding = YAML_UTF16LE_ENCODING;
|
159
|
+
return src;
|
154
160
|
}
|
155
161
|
|
156
162
|
if (io_external_enc_index == rb_enc_find_index("UTF-16BE")) {
|
157
|
-
|
158
|
-
|
163
|
+
*parser_encoding = YAML_UTF16BE_ENCODING;
|
164
|
+
return src;
|
159
165
|
}
|
160
166
|
|
161
167
|
/* Just guess on ASCII-8BIT */
|
162
168
|
if (io_external_enc_index == rb_ascii8bit_encindex()) {
|
163
|
-
|
164
|
-
|
169
|
+
*parser_encoding = YAML_ANY_ENCODING;
|
170
|
+
return src;
|
165
171
|
}
|
166
172
|
|
167
173
|
/* If the external encoding is something we don't know how to handle,
|
@@ -171,8 +177,6 @@ static VALUE transcode_io(VALUE src, int * parser_encoding)
|
|
171
177
|
return src;
|
172
178
|
}
|
173
179
|
|
174
|
-
#endif
|
175
|
-
|
176
180
|
static VALUE protected_start_stream(VALUE pointer)
|
177
181
|
{
|
178
182
|
VALUE *args = (VALUE *)pointer;
|
@@ -235,297 +239,260 @@ static VALUE protected_end_stream(VALUE handler)
|
|
235
239
|
return rb_funcall(handler, id_end_stream, 0);
|
236
240
|
}
|
237
241
|
|
238
|
-
|
239
|
-
|
240
|
-
*
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
* See Psych::Parser and Psych::Parser#handler
|
246
|
-
*/
|
247
|
-
static VALUE parse(int argc, VALUE *argv, VALUE self)
|
242
|
+
static VALUE protected_event_location(VALUE pointer)
|
243
|
+
{
|
244
|
+
VALUE *args = (VALUE *)pointer;
|
245
|
+
return rb_funcall3(args[0], id_event_location, 4, args + 1);
|
246
|
+
}
|
247
|
+
|
248
|
+
static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path)
|
248
249
|
{
|
249
|
-
VALUE yaml, path;
|
250
250
|
yaml_parser_t * parser;
|
251
251
|
yaml_event_t event;
|
252
252
|
int done = 0;
|
253
|
-
int tainted = 0;
|
254
253
|
int state = 0;
|
255
254
|
int parser_encoding = YAML_ANY_ENCODING;
|
256
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
257
255
|
int encoding = rb_utf8_encindex();
|
258
256
|
rb_encoding * internal_enc = rb_default_internal_encoding();
|
259
|
-
#endif
|
260
|
-
VALUE handler = rb_iv_get(self, "@handler");
|
261
|
-
|
262
|
-
if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
|
263
|
-
if(rb_respond_to(yaml, id_path))
|
264
|
-
path = rb_funcall(yaml, id_path, 0);
|
265
|
-
else
|
266
|
-
path = rb_str_new2("<unknown>");
|
267
|
-
}
|
268
257
|
|
269
258
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
270
259
|
|
271
260
|
yaml_parser_delete(parser);
|
272
261
|
yaml_parser_initialize(parser);
|
273
262
|
|
274
|
-
if (OBJ_TAINTED(yaml)) tainted = 1;
|
275
|
-
|
276
263
|
if (rb_respond_to(yaml, id_read)) {
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
#endif
|
281
|
-
yaml_parser_set_input(parser, io_reader, (void *)yaml);
|
282
|
-
if (RTEST(rb_obj_is_kind_of(yaml, rb_cIO))) tainted = 1;
|
264
|
+
yaml = transcode_io(yaml, &parser_encoding);
|
265
|
+
yaml_parser_set_encoding(parser, parser_encoding);
|
266
|
+
yaml_parser_set_input(parser, io_reader, (void *)yaml);
|
283
267
|
} else {
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
(size_t)RSTRING_LEN(yaml)
|
293
|
-
);
|
268
|
+
StringValue(yaml);
|
269
|
+
yaml = transcode_string(yaml, &parser_encoding);
|
270
|
+
yaml_parser_set_encoding(parser, parser_encoding);
|
271
|
+
yaml_parser_set_input_string(
|
272
|
+
parser,
|
273
|
+
(const unsigned char *)RSTRING_PTR(yaml),
|
274
|
+
(size_t)RSTRING_LEN(yaml)
|
275
|
+
);
|
294
276
|
}
|
295
277
|
|
296
278
|
while(!done) {
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
}
|
515
|
-
break;
|
516
|
-
case YAML_MAPPING_END_EVENT:
|
517
|
-
rb_protect(protected_end_mapping, handler, &state);
|
518
|
-
break;
|
519
|
-
case YAML_NO_EVENT:
|
520
|
-
rb_protect(protected_empty, handler, &state);
|
521
|
-
break;
|
522
|
-
case YAML_STREAM_END_EVENT:
|
523
|
-
rb_protect(protected_end_stream, handler, &state);
|
524
|
-
done = 1;
|
525
|
-
break;
|
526
|
-
}
|
527
|
-
yaml_event_delete(&event);
|
528
|
-
if (state) rb_jump_tag(state);
|
279
|
+
VALUE event_args[5];
|
280
|
+
VALUE start_line, start_column, end_line, end_column;
|
281
|
+
|
282
|
+
if(parser->error || !yaml_parser_parse(parser, &event)) {
|
283
|
+
VALUE exception;
|
284
|
+
|
285
|
+
exception = make_exception(parser, path);
|
286
|
+
yaml_parser_delete(parser);
|
287
|
+
yaml_parser_initialize(parser);
|
288
|
+
|
289
|
+
rb_exc_raise(exception);
|
290
|
+
}
|
291
|
+
|
292
|
+
start_line = SIZET2NUM(event.start_mark.line);
|
293
|
+
start_column = SIZET2NUM(event.start_mark.column);
|
294
|
+
end_line = SIZET2NUM(event.end_mark.line);
|
295
|
+
end_column = SIZET2NUM(event.end_mark.column);
|
296
|
+
|
297
|
+
event_args[0] = handler;
|
298
|
+
event_args[1] = start_line;
|
299
|
+
event_args[2] = start_column;
|
300
|
+
event_args[3] = end_line;
|
301
|
+
event_args[4] = end_column;
|
302
|
+
rb_protect(protected_event_location, (VALUE)event_args, &state);
|
303
|
+
|
304
|
+
switch(event.type) {
|
305
|
+
case YAML_STREAM_START_EVENT:
|
306
|
+
{
|
307
|
+
VALUE args[2];
|
308
|
+
|
309
|
+
args[0] = handler;
|
310
|
+
args[1] = INT2NUM(event.data.stream_start.encoding);
|
311
|
+
rb_protect(protected_start_stream, (VALUE)args, &state);
|
312
|
+
}
|
313
|
+
break;
|
314
|
+
case YAML_DOCUMENT_START_EVENT:
|
315
|
+
{
|
316
|
+
VALUE args[4];
|
317
|
+
/* Get a list of tag directives (if any) */
|
318
|
+
VALUE tag_directives = rb_ary_new();
|
319
|
+
/* Grab the document version */
|
320
|
+
VALUE version = event.data.document_start.version_directive ?
|
321
|
+
rb_ary_new3(
|
322
|
+
(long)2,
|
323
|
+
INT2NUM(event.data.document_start.version_directive->major),
|
324
|
+
INT2NUM(event.data.document_start.version_directive->minor)
|
325
|
+
) : rb_ary_new();
|
326
|
+
|
327
|
+
if(event.data.document_start.tag_directives.start) {
|
328
|
+
yaml_tag_directive_t *start =
|
329
|
+
event.data.document_start.tag_directives.start;
|
330
|
+
yaml_tag_directive_t *end =
|
331
|
+
event.data.document_start.tag_directives.end;
|
332
|
+
for(; start != end; start++) {
|
333
|
+
VALUE handle = Qnil;
|
334
|
+
VALUE prefix = Qnil;
|
335
|
+
if(start->handle) {
|
336
|
+
handle = rb_str_new2((const char *)start->handle);
|
337
|
+
PSYCH_TRANSCODE(handle, encoding, internal_enc);
|
338
|
+
}
|
339
|
+
|
340
|
+
if(start->prefix) {
|
341
|
+
prefix = rb_str_new2((const char *)start->prefix);
|
342
|
+
PSYCH_TRANSCODE(prefix, encoding, internal_enc);
|
343
|
+
}
|
344
|
+
|
345
|
+
rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
|
346
|
+
}
|
347
|
+
}
|
348
|
+
args[0] = handler;
|
349
|
+
args[1] = version;
|
350
|
+
args[2] = tag_directives;
|
351
|
+
args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse;
|
352
|
+
rb_protect(protected_start_document, (VALUE)args, &state);
|
353
|
+
}
|
354
|
+
break;
|
355
|
+
case YAML_DOCUMENT_END_EVENT:
|
356
|
+
{
|
357
|
+
VALUE args[2];
|
358
|
+
|
359
|
+
args[0] = handler;
|
360
|
+
args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse;
|
361
|
+
rb_protect(protected_end_document, (VALUE)args, &state);
|
362
|
+
}
|
363
|
+
break;
|
364
|
+
case YAML_ALIAS_EVENT:
|
365
|
+
{
|
366
|
+
VALUE args[2];
|
367
|
+
VALUE alias = Qnil;
|
368
|
+
if(event.data.alias.anchor) {
|
369
|
+
alias = rb_str_new2((const char *)event.data.alias.anchor);
|
370
|
+
PSYCH_TRANSCODE(alias, encoding, internal_enc);
|
371
|
+
}
|
372
|
+
|
373
|
+
args[0] = handler;
|
374
|
+
args[1] = alias;
|
375
|
+
rb_protect(protected_alias, (VALUE)args, &state);
|
376
|
+
}
|
377
|
+
break;
|
378
|
+
case YAML_SCALAR_EVENT:
|
379
|
+
{
|
380
|
+
VALUE args[7];
|
381
|
+
VALUE anchor = Qnil;
|
382
|
+
VALUE tag = Qnil;
|
383
|
+
VALUE plain_implicit, quoted_implicit, style;
|
384
|
+
VALUE val = rb_str_new(
|
385
|
+
(const char *)event.data.scalar.value,
|
386
|
+
(long)event.data.scalar.length
|
387
|
+
);
|
388
|
+
|
389
|
+
PSYCH_TRANSCODE(val, encoding, internal_enc);
|
390
|
+
|
391
|
+
if(event.data.scalar.anchor) {
|
392
|
+
anchor = rb_str_new2((const char *)event.data.scalar.anchor);
|
393
|
+
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
394
|
+
}
|
395
|
+
|
396
|
+
if(event.data.scalar.tag) {
|
397
|
+
tag = rb_str_new2((const char *)event.data.scalar.tag);
|
398
|
+
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
399
|
+
}
|
400
|
+
|
401
|
+
plain_implicit =
|
402
|
+
event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
|
403
|
+
|
404
|
+
quoted_implicit =
|
405
|
+
event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
|
406
|
+
|
407
|
+
style = INT2NUM(event.data.scalar.style);
|
408
|
+
|
409
|
+
args[0] = handler;
|
410
|
+
args[1] = val;
|
411
|
+
args[2] = anchor;
|
412
|
+
args[3] = tag;
|
413
|
+
args[4] = plain_implicit;
|
414
|
+
args[5] = quoted_implicit;
|
415
|
+
args[6] = style;
|
416
|
+
rb_protect(protected_scalar, (VALUE)args, &state);
|
417
|
+
}
|
418
|
+
break;
|
419
|
+
case YAML_SEQUENCE_START_EVENT:
|
420
|
+
{
|
421
|
+
VALUE args[5];
|
422
|
+
VALUE anchor = Qnil;
|
423
|
+
VALUE tag = Qnil;
|
424
|
+
VALUE implicit, style;
|
425
|
+
if(event.data.sequence_start.anchor) {
|
426
|
+
anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
|
427
|
+
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
428
|
+
}
|
429
|
+
|
430
|
+
tag = Qnil;
|
431
|
+
if(event.data.sequence_start.tag) {
|
432
|
+
tag = rb_str_new2((const char *)event.data.sequence_start.tag);
|
433
|
+
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
434
|
+
}
|
435
|
+
|
436
|
+
implicit =
|
437
|
+
event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
|
438
|
+
|
439
|
+
style = INT2NUM(event.data.sequence_start.style);
|
440
|
+
|
441
|
+
args[0] = handler;
|
442
|
+
args[1] = anchor;
|
443
|
+
args[2] = tag;
|
444
|
+
args[3] = implicit;
|
445
|
+
args[4] = style;
|
446
|
+
|
447
|
+
rb_protect(protected_start_sequence, (VALUE)args, &state);
|
448
|
+
}
|
449
|
+
break;
|
450
|
+
case YAML_SEQUENCE_END_EVENT:
|
451
|
+
rb_protect(protected_end_sequence, handler, &state);
|
452
|
+
break;
|
453
|
+
case YAML_MAPPING_START_EVENT:
|
454
|
+
{
|
455
|
+
VALUE args[5];
|
456
|
+
VALUE anchor = Qnil;
|
457
|
+
VALUE tag = Qnil;
|
458
|
+
VALUE implicit, style;
|
459
|
+
if(event.data.mapping_start.anchor) {
|
460
|
+
anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
|
461
|
+
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
462
|
+
}
|
463
|
+
|
464
|
+
if(event.data.mapping_start.tag) {
|
465
|
+
tag = rb_str_new2((const char *)event.data.mapping_start.tag);
|
466
|
+
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
467
|
+
}
|
468
|
+
|
469
|
+
implicit =
|
470
|
+
event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
|
471
|
+
|
472
|
+
style = INT2NUM(event.data.mapping_start.style);
|
473
|
+
|
474
|
+
args[0] = handler;
|
475
|
+
args[1] = anchor;
|
476
|
+
args[2] = tag;
|
477
|
+
args[3] = implicit;
|
478
|
+
args[4] = style;
|
479
|
+
|
480
|
+
rb_protect(protected_start_mapping, (VALUE)args, &state);
|
481
|
+
}
|
482
|
+
break;
|
483
|
+
case YAML_MAPPING_END_EVENT:
|
484
|
+
rb_protect(protected_end_mapping, handler, &state);
|
485
|
+
break;
|
486
|
+
case YAML_NO_EVENT:
|
487
|
+
rb_protect(protected_empty, handler, &state);
|
488
|
+
break;
|
489
|
+
case YAML_STREAM_END_EVENT:
|
490
|
+
rb_protect(protected_end_stream, handler, &state);
|
491
|
+
done = 1;
|
492
|
+
break;
|
493
|
+
}
|
494
|
+
yaml_event_delete(&event);
|
495
|
+
if (state) rb_jump_tag(state);
|
529
496
|
}
|
530
497
|
|
531
498
|
return self;
|
@@ -546,15 +513,16 @@ static VALUE mark(VALUE self)
|
|
546
513
|
|
547
514
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
548
515
|
mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
|
549
|
-
args[0] =
|
550
|
-
args[1] =
|
551
|
-
args[2] =
|
516
|
+
args[0] = SIZET2NUM(parser->mark.index);
|
517
|
+
args[1] = SIZET2NUM(parser->mark.line);
|
518
|
+
args[2] = SIZET2NUM(parser->mark.column);
|
552
519
|
|
553
520
|
return rb_class_new_instance(3, args, mark_klass);
|
554
521
|
}
|
555
522
|
|
556
523
|
void Init_psych_parser(void)
|
557
524
|
{
|
525
|
+
#undef rb_intern
|
558
526
|
#if 0
|
559
527
|
mPsych = rb_define_module("Psych");
|
560
528
|
#endif
|
@@ -575,23 +543,22 @@ void Init_psych_parser(void)
|
|
575
543
|
rb_define_const(cPsychParser, "UTF16BE", INT2NUM(YAML_UTF16BE_ENCODING));
|
576
544
|
|
577
545
|
rb_require("psych/syntax_error");
|
578
|
-
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
579
546
|
|
580
|
-
|
547
|
+
rb_define_private_method(cPsychParser, "_native_parse", parse, 3);
|
581
548
|
rb_define_method(cPsychParser, "mark", mark, 0);
|
582
549
|
|
583
|
-
id_read
|
584
|
-
id_path
|
585
|
-
id_empty
|
586
|
-
id_start_stream
|
587
|
-
id_end_stream
|
588
|
-
id_start_document
|
589
|
-
id_end_document
|
590
|
-
id_alias
|
591
|
-
id_scalar
|
592
|
-
id_start_sequence
|
593
|
-
id_end_sequence
|
594
|
-
id_start_mapping
|
595
|
-
id_end_mapping
|
550
|
+
id_read = rb_intern("read");
|
551
|
+
id_path = rb_intern("path");
|
552
|
+
id_empty = rb_intern("empty");
|
553
|
+
id_start_stream = rb_intern("start_stream");
|
554
|
+
id_end_stream = rb_intern("end_stream");
|
555
|
+
id_start_document = rb_intern("start_document");
|
556
|
+
id_end_document = rb_intern("end_document");
|
557
|
+
id_alias = rb_intern("alias");
|
558
|
+
id_scalar = rb_intern("scalar");
|
559
|
+
id_start_sequence = rb_intern("start_sequence");
|
560
|
+
id_end_sequence = rb_intern("end_sequence");
|
561
|
+
id_start_mapping = rb_intern("start_mapping");
|
562
|
+
id_end_mapping = rb_intern("end_mapping");
|
563
|
+
id_event_location = rb_intern("event_location");
|
596
564
|
}
|
597
|
-
/* vim: set noet sws=4 sw=4: */
|