psych 3.1.0 → 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 +4 -4
- data/CONTRIBUTING.md +24 -0
- data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
- data/README.md +22 -17
- data/ext/psych/depend +14 -0
- data/ext/psych/extconf.rb +42 -28
- data/ext/psych/psych.c +6 -4
- data/ext/psych/psych_emitter.c +155 -121
- data/ext/psych/psych_parser.c +274 -302
- data/ext/psych/psych_to_ruby.c +0 -1
- data/ext/psych/psych_yaml_tree.c +0 -13
- data/lib/psych/class_loader.rb +10 -8
- data/lib/psych/core_ext.rb +1 -1
- data/lib/psych/exception.rb +16 -2
- data/lib/psych/handler.rb +1 -1
- data/lib/psych/handlers/document_stream.rb +1 -1
- data/lib/psych/handlers/recorder.rb +1 -1
- data/lib/psych/json/stream.rb +2 -2
- data/lib/psych/json/tree_builder.rb +1 -1
- data/lib/psych/nodes/node.rb +5 -5
- data/lib/psych/nodes/scalar.rb +1 -1
- data/lib/psych/nodes.rb +7 -7
- data/lib/psych/parser.rb +13 -0
- data/lib/psych/scalar_scanner.rb +39 -47
- data/lib/psych/syntax_error.rb +1 -1
- data/lib/psych/tree_builder.rb +3 -3
- data/lib/psych/versions.rb +3 -3
- data/lib/psych/visitors/json_tree.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +60 -26
- data/lib/psych/visitors/visitor.rb +17 -3
- data/lib/psych/visitors/yaml_tree.rb +103 -71
- data/lib/psych/visitors.rb +6 -6
- data/lib/psych.rb +260 -138
- metadata +20 -53
- data/.gitignore +0 -16
- data/.travis.yml +0 -22
- data/CHANGELOG.rdoc +0 -583
- data/Gemfile +0 -3
- data/Mavenfile +0 -7
- data/Rakefile +0 -48
- data/bin/console +0 -7
- data/bin/setup +0 -6
- data/ext/psych/yaml/api.c +0 -1393
- data/ext/psych/yaml/config.h +0 -10
- data/ext/psych/yaml/dumper.c +0 -394
- data/ext/psych/yaml/emitter.c +0 -2324
- data/ext/psych/yaml/loader.c +0 -444
- data/ext/psych/yaml/parser.c +0 -1370
- data/ext/psych/yaml/reader.c +0 -469
- data/ext/psych/yaml/scanner.c +0 -3578
- data/ext/psych/yaml/writer.c +0 -141
- data/ext/psych/yaml/yaml.h +0 -1971
- data/ext/psych/yaml/yaml_private.h +0 -688
- data/psych.gemspec +0 -75
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;
|
@@ -28,14 +27,14 @@ static ID id_event_location;
|
|
28
27
|
static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
|
29
28
|
{
|
30
29
|
VALUE io = (VALUE)data;
|
31
|
-
VALUE string = rb_funcall(io, id_read, 1,
|
30
|
+
VALUE string = rb_funcall(io, id_read, 1, SIZET2NUM(size));
|
32
31
|
|
33
32
|
*read = 0;
|
34
33
|
|
35
34
|
if(! NIL_P(string)) {
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
void * str = (void *)StringValuePtr(string);
|
36
|
+
*read = (size_t)RSTRING_LEN(string);
|
37
|
+
memcpy(buf, str, *read);
|
39
38
|
}
|
40
39
|
|
41
40
|
return 1;
|
@@ -80,18 +79,25 @@ static VALUE allocate(VALUE klass)
|
|
80
79
|
|
81
80
|
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
|
82
81
|
{
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
+
}
|
95
101
|
}
|
96
102
|
|
97
103
|
static VALUE transcode_string(VALUE src, int * parser_encoding)
|
@@ -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,
|
@@ -239,286 +245,254 @@ static VALUE protected_event_location(VALUE pointer)
|
|
239
245
|
return rb_funcall3(args[0], id_event_location, 4, args + 1);
|
240
246
|
}
|
241
247
|
|
242
|
-
|
243
|
-
* call-seq:
|
244
|
-
* parser.parse(yaml)
|
245
|
-
*
|
246
|
-
* Parse the YAML document contained in +yaml+. Events will be called on
|
247
|
-
* the handler set on the parser instance.
|
248
|
-
*
|
249
|
-
* See Psych::Parser and Psych::Parser#handler
|
250
|
-
*/
|
251
|
-
static VALUE parse(int argc, VALUE *argv, VALUE self)
|
248
|
+
static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path)
|
252
249
|
{
|
253
|
-
VALUE yaml, path;
|
254
250
|
yaml_parser_t * parser;
|
255
251
|
yaml_event_t event;
|
256
252
|
int done = 0;
|
257
|
-
int tainted = 0;
|
258
253
|
int state = 0;
|
259
254
|
int parser_encoding = YAML_ANY_ENCODING;
|
260
255
|
int encoding = rb_utf8_encindex();
|
261
256
|
rb_encoding * internal_enc = rb_default_internal_encoding();
|
262
|
-
VALUE handler = rb_iv_get(self, "@handler");
|
263
|
-
|
264
|
-
if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
|
265
|
-
if(rb_respond_to(yaml, id_path))
|
266
|
-
path = rb_funcall(yaml, id_path, 0);
|
267
|
-
else
|
268
|
-
path = rb_str_new2("<unknown>");
|
269
|
-
}
|
270
257
|
|
271
258
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
272
259
|
|
273
260
|
yaml_parser_delete(parser);
|
274
261
|
yaml_parser_initialize(parser);
|
275
262
|
|
276
|
-
if (OBJ_TAINTED(yaml)) tainted = 1;
|
277
|
-
|
278
263
|
if (rb_respond_to(yaml, id_read)) {
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
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
|
+
);
|
292
276
|
}
|
293
277
|
|
294
278
|
while(!done) {
|
295
|
-
|
296
|
-
|
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
|
-
case YAML_NO_EVENT:
|
513
|
-
rb_protect(protected_empty, handler, &state);
|
514
|
-
break;
|
515
|
-
case YAML_STREAM_END_EVENT:
|
516
|
-
rb_protect(protected_end_stream, handler, &state);
|
517
|
-
done = 1;
|
518
|
-
break;
|
519
|
-
}
|
520
|
-
yaml_event_delete(&event);
|
521
|
-
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);
|
522
496
|
}
|
523
497
|
|
524
498
|
return self;
|
@@ -539,9 +513,9 @@ static VALUE mark(VALUE self)
|
|
539
513
|
|
540
514
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
541
515
|
mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
|
542
|
-
args[0] =
|
543
|
-
args[1] =
|
544
|
-
args[2] =
|
516
|
+
args[0] = SIZET2NUM(parser->mark.index);
|
517
|
+
args[1] = SIZET2NUM(parser->mark.line);
|
518
|
+
args[2] = SIZET2NUM(parser->mark.column);
|
545
519
|
|
546
520
|
return rb_class_new_instance(3, args, mark_klass);
|
547
521
|
}
|
@@ -569,9 +543,8 @@ void Init_psych_parser(void)
|
|
569
543
|
rb_define_const(cPsychParser, "UTF16BE", INT2NUM(YAML_UTF16BE_ENCODING));
|
570
544
|
|
571
545
|
rb_require("psych/syntax_error");
|
572
|
-
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
573
546
|
|
574
|
-
|
547
|
+
rb_define_private_method(cPsychParser, "_native_parse", parse, 3);
|
575
548
|
rb_define_method(cPsychParser, "mark", mark, 0);
|
576
549
|
|
577
550
|
id_read = rb_intern("read");
|
@@ -589,4 +562,3 @@ void Init_psych_parser(void)
|
|
589
562
|
id_end_mapping = rb_intern("end_mapping");
|
590
563
|
id_event_location = rb_intern("event_location");
|
591
564
|
}
|
592
|
-
/* vim: set noet sws=4 sw=4: */
|