Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

psych_parser.c
Go to the documentation of this file.
1 #include <psych.h>
2
3 VALUE cPsychParser;
4 VALUE ePsychSyntaxError;
5
6 static ID id_read;
7 static ID id_path;
8 static ID id_empty;
9 static ID id_start_stream;
10 static ID id_end_stream;
11 static ID id_start_document;
12 static ID id_end_document;
13 static ID id_alias;
14 static ID id_scalar;
15 static ID id_start_sequence;
16 static ID id_end_sequence;
17 static ID id_start_mapping;
18 static ID id_end_mapping;
19
20 #define PSYCH_TRANSCODE(_str, _yaml_enc, _internal_enc) \
21 do { \
22 rb_enc_associate_index((_str), (_yaml_enc)); \
23 if(_internal_enc) \
24 (_str) = rb_str_export_to_enc((_str), (_internal_enc)); \
25 } while (0)
26
27 static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
28 {
29 VALUE io = (VALUE)data;
30 VALUE string = rb_funcall(io, id_read, 1, INT2NUM(size));
31
32 *read = 0;
33
34 if(! NIL_P(string)) {
35 void * str = (void *)StringValuePtr(string);
36 *read = (size_t)RSTRING_LEN(string);
37 memcpy(buf, str, *read);
38 }
39
40 return 1;
41 }
42
43 static void dealloc(void * ptr)
44 {
45 yaml_parser_t * parser;
46
47 parser = (yaml_parser_t *)ptr;
48 yaml_parser_delete(parser);
49 xfree(parser);
50 }
51
52 static VALUE allocate(VALUE klass)
53 {
54 yaml_parser_t * parser;
55
56 parser = xmalloc(sizeof(yaml_parser_t));
57 yaml_parser_initialize(parser);
58
59 return Data_Wrap_Struct(klass, 0, dealloc, parser);
60 }
61
62 static VALUE make_exception(yaml_parser_t * parser, VALUE path)
63 {
64 size_t line, column;
65
66 line = parser->context_mark.line + 1;
67 column = parser->context_mark.column + 1;
68
69 return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
70 path,
71 INT2NUM(line),
72 INT2NUM(column),
73 INT2NUM(parser->problem_offset),
74 parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
75 parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
76 }
77
78 #ifdef HAVE_RUBY_ENCODING_H
79 static VALUE transcode_string(VALUE src, int * parser_encoding)
80 {
81 int utf8 = rb_utf8_encindex();
82 int utf16le = rb_enc_find_index("UTF-16LE");
83 int utf16be = rb_enc_find_index("UTF-16BE");
84 int source_encoding = rb_enc_get_index(src);
85
86 if (source_encoding == utf8) {
87 *parser_encoding = YAML_UTF8_ENCODING;
88 return src;
89 }
90
91 if (source_encoding == utf16le) {
92 *parser_encoding = YAML_UTF16LE_ENCODING;
93 return src;
94 }
95
96 if (source_encoding == utf16be) {
97 *parser_encoding = YAML_UTF16BE_ENCODING;
98 return src;
99 }
100
101 src = rb_str_export_to_enc(src, rb_utf8_encoding());
102 RB_GC_GUARD(src);
103
104 *parser_encoding = YAML_UTF8_ENCODING;
105 return src;
106 }
107
108 static VALUE transcode_io(VALUE src, int * parser_encoding)
109 {
110 VALUE io_external_encoding;
111 int io_external_enc_index;
112
113 io_external_encoding = rb_funcall(src, rb_intern("external_encoding"), 0);
114
115 /* if no encoding is returned, assume ascii8bit. */
116 if (NIL_P(io_external_encoding)) {
117 io_external_enc_index = rb_ascii8bit_encindex();
118 } else {
119 io_external_enc_index = rb_to_encoding_index(io_external_encoding);
120 }
121
122 /* Treat US-ASCII as utf_8 */
123 if (io_external_enc_index == rb_usascii_encindex()) {
124 *parser_encoding = YAML_UTF8_ENCODING;
125 return src;
126 }
127
128 if (io_external_enc_index == rb_utf8_encindex()) {
129 *parser_encoding = YAML_UTF8_ENCODING;
130 return src;
131 }
132
133 if (io_external_enc_index == rb_enc_find_index("UTF-16LE")) {
134 *parser_encoding = YAML_UTF16LE_ENCODING;
135 return src;
136 }
137
138 if (io_external_enc_index == rb_enc_find_index("UTF-16BE")) {
139 *parser_encoding = YAML_UTF16BE_ENCODING;
140 return src;
141 }
142
143 /* Just guess on ASCII-8BIT */
144 if (io_external_enc_index == rb_ascii8bit_encindex()) {
145 *parser_encoding = YAML_ANY_ENCODING;
146 return src;
147 }
148
149 /* If the external encoding is something we don't know how to handle,
150 * fall back to YAML_ANY_ENCODING. */
151 *parser_encoding = YAML_ANY_ENCODING;
152
153 return src;
154 }
155
156 #endif
157
158 static VALUE protected_start_stream(VALUE pointer)
159 {
160 VALUE *args = (VALUE *)pointer;
161 return rb_funcall(args[0], id_start_stream, 1, args[1]);
162 }
163
164 static VALUE protected_start_document(VALUE pointer)
165 {
166 VALUE *args = (VALUE *)pointer;
167 return rb_funcall3(args[0], id_start_document, 3, args + 1);
168 }
169
170 static VALUE protected_end_document(VALUE pointer)
171 {
172 VALUE *args = (VALUE *)pointer;
173 return rb_funcall(args[0], id_end_document, 1, args[1]);
174 }
175
176 static VALUE protected_alias(VALUE pointer)
177 {
178 VALUE *args = (VALUE *)pointer;
179 return rb_funcall(args[0], id_alias, 1, args[1]);
180 }
181
182 static VALUE protected_scalar(VALUE pointer)
183 {
184 VALUE *args = (VALUE *)pointer;
185 return rb_funcall3(args[0], id_scalar, 6, args + 1);
186 }
187
188 static VALUE protected_start_sequence(VALUE pointer)
189 {
190 VALUE *args = (VALUE *)pointer;
191 return rb_funcall3(args[0], id_start_sequence, 4, args + 1);
192 }
193
194 static VALUE protected_end_sequence(VALUE handler)
195 {
196 return rb_funcall(handler, id_end_sequence, 0);
197 }
198
199 static VALUE protected_start_mapping(VALUE pointer)
200 {
201 VALUE *args = (VALUE *)pointer;
202 return rb_funcall3(args[0], id_start_mapping, 4, args + 1);
203 }
204
205 static VALUE protected_end_mapping(VALUE handler)
206 {
207 return rb_funcall(handler, id_end_mapping, 0);
208 }
209
210 static VALUE protected_empty(VALUE handler)
211 {
212 return rb_funcall(handler, id_empty, 0);
213 }
214
215 static VALUE protected_end_stream(VALUE handler)
216 {
217 return rb_funcall(handler, id_end_stream, 0);
218 }
219
220 /*
221 * call-seq:
222 * parser.parse(yaml)
223 *
224 * Parse the YAML document contained in +yaml+. Events will be called on
225 * the handler set on the parser instance.
226 *
227 * See Psych::Parser and Psych::Parser#handler
228 */
229 static VALUE parse(int argc, VALUE *argv, VALUE self)
230 {
231 VALUE yaml, path;
232 yaml_parser_t * parser;
233 yaml_event_t event;
234 int done = 0;
235 int tainted = 0;
236 int state = 0;
237 int parser_encoding = YAML_ANY_ENCODING;
238 #ifdef HAVE_RUBY_ENCODING_H
239 int encoding = rb_utf8_encindex();
240 rb_encoding * internal_enc = rb_default_internal_encoding();
241 #endif
242 VALUE handler = rb_iv_get(self, "@handler");
243
244 if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
245 if(rb_respond_to(yaml, id_path))
246 path = rb_funcall(yaml, id_path, 0);
247 else
248 path = rb_str_new2("<unknown>");
249 }
250
251 Data_Get_Struct(self, yaml_parser_t, parser);
252
253 yaml_parser_delete(parser);
254 yaml_parser_initialize(parser);
255
256 if (OBJ_TAINTED(yaml)) tainted = 1;
257
258 if (rb_respond_to(yaml, id_read)) {
259 #ifdef HAVE_RUBY_ENCODING_H
260 yaml = transcode_io(yaml, &parser_encoding);
261 yaml_parser_set_encoding(parser, parser_encoding);
262 #endif
263 yaml_parser_set_input(parser, io_reader, (void *)yaml);
264 if (RTEST(rb_obj_is_kind_of(yaml, rb_cIO))) tainted = 1;
265 } else {
266 StringValue(yaml);
267 #ifdef HAVE_RUBY_ENCODING_H
268 yaml = transcode_string(yaml, &parser_encoding);
269 yaml_parser_set_encoding(parser, parser_encoding);
270 #endif
271 yaml_parser_set_input_string(
272 parser,
273 (const unsigned char *)RSTRING_PTR(yaml),
274 (size_t)RSTRING_LEN(yaml)
275 );
276 }
277
278 while(!done) {
279 if(!yaml_parser_parse(parser, &event)) {
280 VALUE exception;
281
282 exception = make_exception(parser, path);
283 yaml_parser_delete(parser);
284 yaml_parser_initialize(parser);
285
286 rb_exc_raise(exception);
287 }
288
289 switch(event.type) {
290 case YAML_STREAM_START_EVENT:
291 {
292 VALUE args[2];
293
294 args[0] = handler;
295 args[1] = INT2NUM((long)event.data.stream_start.encoding);
296 rb_protect(protected_start_stream, (VALUE)args, &state);
297 }
298 break;
299 case YAML_DOCUMENT_START_EVENT:
300 {
301 VALUE args[4];
302 /* Get a list of tag directives (if any) */
303 VALUE tag_directives = rb_ary_new();
304 /* Grab the document version */
305 VALUE version = event.data.document_start.version_directive ?
306 rb_ary_new3(
307 (long)2,
308 INT2NUM((long)event.data.document_start.version_directive->major),
309 INT2NUM((long)event.data.document_start.version_directive->minor)
310 ) : rb_ary_new();
311
312 if(event.data.document_start.tag_directives.start) {
313 yaml_tag_directive_t *start =
314 event.data.document_start.tag_directives.start;
315 yaml_tag_directive_t *end =
316 event.data.document_start.tag_directives.end;
317 for(; start != end; start++) {
318 VALUE handle = Qnil;
319 VALUE prefix = Qnil;
320 if(start->handle) {
321 handle = rb_str_new2((const char *)start->handle);
322 if (tainted) OBJ_TAINT(handle);
323 #ifdef HAVE_RUBY_ENCODING_H
324 PSYCH_TRANSCODE(handle, encoding, internal_enc);
325 #endif
326 }
327
328 if(start->prefix) {
329 prefix = rb_str_new2((const char *)start->prefix);
330 if (tainted) OBJ_TAINT(prefix);
331 #ifdef HAVE_RUBY_ENCODING_H
332 PSYCH_TRANSCODE(prefix, encoding, internal_enc);
333 #endif
334 }
335
336 rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
337 }
338 }
339 args[0] = handler;
340 args[1] = version;
341 args[2] = tag_directives;
342 args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse;
343 rb_protect(protected_start_document, (VALUE)args, &state);
344 }
345 break;
346 case YAML_DOCUMENT_END_EVENT:
347 {
348 VALUE args[2];
349
350 args[0] = handler;
351 args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse;
352 rb_protect(protected_end_document, (VALUE)args, &state);
353 }
354 break;
355 case YAML_ALIAS_EVENT:
356 {
357 VALUE args[2];
358 VALUE alias = Qnil;
359 if(event.data.alias.anchor) {
360 alias = rb_str_new2((const char *)event.data.alias.anchor);
361 if (tainted) OBJ_TAINT(alias);
362 #ifdef HAVE_RUBY_ENCODING_H
363 PSYCH_TRANSCODE(alias, encoding, internal_enc);
364 #endif
365 }
366
367 args[0] = handler;
368 args[1] = alias;
369 rb_protect(protected_alias, (VALUE)args, &state);
370 }
371 break;
372 case YAML_SCALAR_EVENT:
373 {
374 VALUE args[7];
375 VALUE anchor = Qnil;
376 VALUE tag = Qnil;
377 VALUE plain_implicit, quoted_implicit, style;
378 VALUE val = rb_str_new(
379 (const char *)event.data.scalar.value,
380 (long)event.data.scalar.length
381 );
382 if (tainted) OBJ_TAINT(val);
383
384 #ifdef HAVE_RUBY_ENCODING_H
385 PSYCH_TRANSCODE(val, encoding, internal_enc);
386 #endif
387
388 if(event.data.scalar.anchor) {
389 anchor = rb_str_new2((const char *)event.data.scalar.anchor);
390 if (tainted) OBJ_TAINT(anchor);
391 #ifdef HAVE_RUBY_ENCODING_H
392 PSYCH_TRANSCODE(anchor, encoding, internal_enc);
393 #endif
394 }
395
396 if(event.data.scalar.tag) {
397 tag = rb_str_new2((const char *)event.data.scalar.tag);
398 if (tainted) OBJ_TAINT(tag);
399 #ifdef HAVE_RUBY_ENCODING_H
400 PSYCH_TRANSCODE(tag, encoding, internal_enc);
401 #endif
402 }
403
404 plain_implicit =
405 event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
406
407 quoted_implicit =
408 event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
409
410 style = INT2NUM((long)event.data.scalar.style);
411
412 args[0] = handler;
413 args[1] = val;
414 args[2] = anchor;
415 args[3] = tag;
416 args[4] = plain_implicit;
417 args[5] = quoted_implicit;
418 args[6] = style;
419 rb_protect(protected_scalar, (VALUE)args, &state);
420 }
421 break;
422 case YAML_SEQUENCE_START_EVENT:
423 {
424 VALUE args[5];
425 VALUE anchor = Qnil;
426 VALUE tag = Qnil;
427 VALUE implicit, style;
428 if(event.data.sequence_start.anchor) {
429 anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
430 if (tainted) OBJ_TAINT(anchor);
431 #ifdef HAVE_RUBY_ENCODING_H
432 PSYCH_TRANSCODE(anchor, encoding, internal_enc);
433 #endif
434 }
435
436 tag = Qnil;
437 if(event.data.sequence_start.tag) {
438 tag = rb_str_new2((const char *)event.data.sequence_start.tag);
439 if (tainted) OBJ_TAINT(tag);
440 #ifdef HAVE_RUBY_ENCODING_H
441 PSYCH_TRANSCODE(tag, encoding, internal_enc);
442 #endif
443 }
444
445 implicit =
446 event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
447
448 style = INT2NUM((long)event.data.sequence_start.style);
449
450 args[0] = handler;
451 args[1] = anchor;
452 args[2] = tag;
453 args[3] = implicit;
454 args[4] = style;
455
456 rb_protect(protected_start_sequence, (VALUE)args, &state);
457 }
458 break;
459 case YAML_SEQUENCE_END_EVENT:
460 rb_protect(protected_end_sequence, handler, &state);
461 break;
462 case YAML_MAPPING_START_EVENT:
463 {
464 VALUE args[5];
465 VALUE anchor = Qnil;
466 VALUE tag = Qnil;
467 VALUE implicit, style;
468 if(event.data.mapping_start.anchor) {
469 anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
470 if (tainted) OBJ_TAINT(anchor);
471 #ifdef HAVE_RUBY_ENCODING_H
472 PSYCH_TRANSCODE(anchor, encoding, internal_enc);
473 #endif
474 }
475
476 if(event.data.mapping_start.tag) {
477 tag = rb_str_new2((const char *)event.data.mapping_start.tag);
478 if (tainted) OBJ_TAINT(tag);
479 #ifdef HAVE_RUBY_ENCODING_H
480 PSYCH_TRANSCODE(tag, encoding, internal_enc);
481 #endif
482 }
483
484 implicit =
485 event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
486
487 style = INT2NUM((long)event.data.mapping_start.style);
488
489 args[0] = handler;
490 args[1] = anchor;
491 args[2] = tag;
492 args[3] = implicit;
493 args[4] = style;
494
495 rb_protect(protected_start_mapping, (VALUE)args, &state);
496 }
497 break;
498 case YAML_MAPPING_END_EVENT:
499 rb_protect(protected_end_mapping, handler, &state);
500 break;
501 case YAML_NO_EVENT:
502 rb_protect(protected_empty, handler, &state);
503 break;
504 case YAML_STREAM_END_EVENT:
505 rb_protect(protected_end_stream, handler, &state);
506 done = 1;
507 break;
508 }
509 yaml_event_delete(&event);
510 if (state) rb_jump_tag(state);
511 }
512
513 return self;
514 }
515
516 /*
517 * call-seq:
518 * parser.mark # => #<Psych::Parser::Mark>
519 *
520 * Returns a Psych::Parser::Mark object that contains line, column, and index
521 * information.
522 */
523 static VALUE mark(VALUE self)
524 {
525 VALUE mark_klass;
526 VALUE args[3];
527 yaml_parser_t * parser;
528
529 Data_Get_Struct(self, yaml_parser_t, parser);
530 mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
531 args[0] = INT2NUM(parser->mark.index);
532 args[1] = INT2NUM(parser->mark.line);
533 args[2] = INT2NUM(parser->mark.column);
534
535 return rb_class_new_instance(3, args, mark_klass);
536 }
537
538 void Init_psych_parser()
539 {
540 #if 0
541 mPsych = rb_define_module("Psych");
542 #endif
543
544 cPsychParser = rb_define_class_under(mPsych, "Parser", rb_cObject);
545 rb_define_alloc_func(cPsychParser, allocate);
546
547 /* Any encoding: Let the parser choose the encoding */
548 rb_define_const(cPsychParser, "ANY", INT2NUM(YAML_ANY_ENCODING));
549
550 /* UTF-8 Encoding */
551 rb_define_const(cPsychParser, "UTF8", INT2NUM(YAML_UTF8_ENCODING));
552
553 /* UTF-16-LE Encoding with BOM */
554 rb_define_const(cPsychParser, "UTF16LE", INT2NUM(YAML_UTF16LE_ENCODING));
555
556 /* UTF-16-BE Encoding with BOM */
557 rb_define_const(cPsychParser, "UTF16BE", INT2NUM(YAML_UTF16BE_ENCODING));
558
559 rb_require("psych/syntax_error");
560 ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
561
562 rb_define_method(cPsychParser, "parse", parse, -1);
563 rb_define_method(cPsychParser, "mark", mark, 0);
564
565 id_read = rb_intern("read");
566 id_path = rb_intern("path");
567 id_empty = rb_intern("empty");
568 id_start_stream = rb_intern("start_stream");
569 id_end_stream = rb_intern("end_stream");
570 id_start_document = rb_intern("start_document");
571 id_end_document = rb_intern("end_document");
572 id_alias = rb_intern("alias");
573 id_scalar = rb_intern("scalar");
574 id_start_sequence = rb_intern("start_sequence");
575 id_end_sequence = rb_intern("end_sequence");
576 id_start_mapping = rb_intern("start_mapping");
577 id_end_mapping = rb_intern("end_mapping");
578 }
579 /* vim: set noet sws=4 sw=4: */
data
VALUE data
Definition: tcltklib.c:3368
id_empty
static ID id_empty
Definition: psych_parser.c:8
id_start_document
static ID id_start_document
Definition: psych_parser.c:11
rb_const_get_at
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1882
rb_enc_get_index
int rb_enc_get_index(VALUE obj)
Definition: encoding.c:690
yaml_parser_parse
yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event)
Parse the input stream and produce the next parsing event.
Definition: parser.c:170
yaml_event_s
The event structure.
Definition: yaml.h:384
yaml_event_delete
yaml_event_delete(yaml_event_t *event)
Free any memory allocated for an event object.
Definition: api.c:979
rb_class_new_instance
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1775
id_path
static ID id_path
Definition: psych_parser.c:7
YAML_UTF16BE_ENCODING
The UTF-16-BE encoding with BOM.
Definition: yaml.h:105
yaml_parser_set_encoding
yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding)
Set the source encoding.
Definition: api.c:336
YAML_SEQUENCE_START_EVENT
A SEQUENCE-START event.
Definition: yaml.h:373
rb_usascii_str_new2
#define rb_usascii_str_new2
yaml_event_s::document_start
struct yaml_event_s::@20::@22 document_start
The document parameters (for YAML_DOCUMENT_START_EVENT).
rb_const_get
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1876
id_end_stream
static ID id_end_stream
Definition: psych_parser.c:10
yaml_parser_set_input_string
yaml_parser_set_input_string(yaml_parser_t *parser, const unsigned char *input, size_t size)
Set a string input.
Definition: api.c:283
YAML_MAPPING_START_EVENT
A MAPPING-START event.
Definition: yaml.h:378
rb_iv_get
VALUE rb_iv_get(VALUE, const char *)
Definition: variable.c:2583
rb_define_alloc_func
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
yaml_parser_s
The parser structure.
Definition: yaml.h:1081
OBJ_TAINTED
#define OBJ_TAINTED(x)
rb_default_internal_encoding
rb_encoding * rb_default_internal_encoding(void)
Definition: encoding.c:1373
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:822
rb_require
VALUE rb_require(const char *)
Definition: load.c:1024
path
gz path
Definition: zlib.c:2279
rb_usascii_encindex
int rb_usascii_encindex(void)
Definition: encoding.c:1192
RSTRING_PTR
#define RSTRING_PTR(str)
NIL_P
NIL_P(eventloop_thread)
Definition: tcltklib.c:4068
rb_protect
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:771
xfree
#define xfree
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:774
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:545
id_scalar
static ID id_scalar
Definition: psych_parser.c:14
id_start_sequence
static ID id_start_sequence
Definition: psych_parser.c:15
Qtrue
return Qtrue
Definition: tcltklib.c:9610
YAML_ANY_ENCODING
Let the parser choose the encoding.
Definition: yaml.h:99
Init_psych_parser
void Init_psych_parser()
Definition: psych_parser.c:538
yaml_parser_delete
yaml_parser_delete(yaml_parser_t *parser)
Destroy a parser.
Definition: api.c:214
rb_ary_new3
VALUE rb_ary_new3(long n,...)
Definition: array.c:432
yaml_parser_s::context
const char * context
The error context.
Definition: yaml.h:1099
alias
const char * alias
Definition: nkf.c:1151
rb_str_new2
#define rb_str_new2
yaml_tag_directive_s::prefix
yaml_char_t * prefix
The tag prefix.
Definition: yaml.h:93
id_start_mapping
static ID id_start_mapping
Definition: psych_parser.c:17
state
int state
Definition: tcltklib.c:1462
parse
static VALUE parse(int argc, VALUE *argv, VALUE self)
Definition: psych_parser.c:229
rb_utf8_encoding
rb_encoding * rb_utf8_encoding(void)
Definition: encoding.c:1168
protected_end_mapping
static VALUE protected_end_mapping(VALUE handler)
Definition: psych_parser.c:205
args
VALUE VALUE args
Definition: tcltklib.c:2561
psych.h
yaml_parser_s::mark
yaml_mark_t mark
The mark of the current position.
Definition: yaml.h:1171
YAML_UTF16LE_ENCODING
The UTF-16-LE encoding with BOM.
Definition: yaml.h:103
cPsychParser
VALUE cPsychParser
Definition: psych_parser.c:3
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Definition: eval.c:527
id_alias
static ID id_alias
Definition: psych_parser.c:13
transcode_io
static VALUE transcode_io(VALUE src, int *parser_encoding)
Definition: psych_parser.c:108
id_end_mapping
static ID id_end_mapping
Definition: psych_parser.c:18
done
*q done
Definition: tcltklib.c:2929
ePsychSyntaxError
VALUE ePsychSyntaxError
Definition: psych_parser.c:4
rb_to_encoding_index
int rb_to_encoding_index(VALUE enc)
Definition: encoding.c:146
Data_Wrap_Struct
return Data_Wrap_Struct(CLASS_OF(interp), 0, ip_free, slave)
protected_end_stream
static VALUE protected_end_stream(VALUE handler)
Definition: psych_parser.c:215
Qfalse
return Qfalse
Definition: tcltklib.c:6779
Qnil
#define Qnil
Definition: tcltklib.c:1896
StringValuePtr
#define StringValuePtr(v)
protected_end_document
static VALUE protected_end_document(VALUE pointer)
Definition: psych_parser.c:170
protected_end_sequence
static VALUE protected_end_sequence(VALUE handler)
Definition: psych_parser.c:194
val
#define val
Definition: tcltklib.c:1949
str
static VALUE char * str
Definition: tcltklib.c:3547
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:424
rb_ascii8bit_encindex
int rb_ascii8bit_encindex(void)
Definition: encoding.c:1162
ID
unsigned long ID
Definition: ripper.y:105
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2202
RSTRING_LEN
#define RSTRING_LEN(str)
dealloc
static void dealloc(void *ptr)
Definition: psych_parser.c:43
xmalloc
#define xmalloc
YAML_DOCUMENT_START_EVENT
A DOCUMENT-START event.
Definition: yaml.h:363
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
PSYCH_TRANSCODE
#define PSYCH_TRANSCODE(_str, _yaml_enc, _internal_enc)
Definition: psych_parser.c:20
protected_start_sequence
static VALUE protected_start_sequence(VALUE pointer)
Definition: psych_parser.c:188
YAML_MAPPING_END_EVENT
A MAPPING-END event.
Definition: yaml.h:380
argv
VALUE * argv
Definition: tcltklib.c:1971
yaml_parser_set_input
yaml_parser_set_input(yaml_parser_t *parser, yaml_read_handler_t *handler, void *data)
Set a generic input handler.
Definition: api.c:320
memcpy
memcpy(buf+1, str, len)
RTEST
#define RTEST(v)
rb_str_export_to_enc
VALUE rb_str_export_to_enc(VALUE, rb_encoding *)
Definition: string.c:632
StringValue
#define StringValue(v)
yaml_tag_directive_s::handle
yaml_char_t * handle
The tag handle.
Definition: yaml.h:91
protected_start_mapping
static VALUE protected_start_mapping(VALUE pointer)
Definition: psych_parser.c:199
YAML_SEQUENCE_END_EVENT
A SEQUENCE-END event.
Definition: yaml.h:375
rb_scan_args
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1570
RB_GC_GUARD
#define RB_GC_GUARD(v)
id_read
static ID id_read
Definition: psych_parser.c:6
argc
int argc
Definition: tcltklib.c:1970
yaml_event_s::mapping_start
struct yaml_event_s::@20::@27 mapping_start
The mapping parameters (for YAML_MAPPING_START_EVENT).
yaml_tag_directive_s
The tag directive data.
Definition: yaml.h:89
rb_utf8_encindex
int rb_utf8_encindex(void)
Definition: encoding.c:1177
protected_empty
static VALUE protected_empty(VALUE handler)
Definition: psych_parser.c:210
id_end_sequence
static ID id_end_sequence
Definition: psych_parser.c:16
io_reader
static int io_reader(void *data, unsigned char *buf, size_t size, size_t *read)
Definition: psych_parser.c:27
yaml_parser_s::context_mark
yaml_mark_t context_mark
The context position.
Definition: yaml.h:1101
rb_jump_tag
void rb_jump_tag(int tag)
Definition: eval.c:666
ptr
return ptr
Definition: tcltklib.c:784
YAML_UTF8_ENCODING
The default UTF-8 encoding.
Definition: yaml.h:101
rb_cIO
RUBY_EXTERN VALUE rb_cIO
Definition: ripper.y:1442
end
gz end
Definition: zlib.c:2272
yaml_parser_s::problem_offset
size_t problem_offset
The byte about which the problem occured.
Definition: yaml.h:1093
yaml_event_s::alias
struct yaml_event_s::@20::@24 alias
The alias parameters (for YAML_ALIAS_EVENT).
YAML_DOCUMENT_END_EVENT
A DOCUMENT-END event.
Definition: yaml.h:365
src
VALUE src
Definition: tcltklib.c:7953
id_end_document
static ID id_end_document
Definition: psych_parser.c:12
size
int size
Definition: encoding.c:52
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:582
YAML_SCALAR_EVENT
A SCALAR event.
Definition: yaml.h:370
rb_funcall3
VALUE rb_funcall3(VALUE, ID, int, const VALUE *)
Calls a method.
Definition: vm_eval.c:820
yaml_parser_initialize
yaml_parser_initialize(yaml_parser_t *parser)
Initialize a parser.
Definition: api.c:171
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
YAML_STREAM_END_EVENT
A STREAM-END event.
Definition: yaml.h:360
yaml_event_s::data
union yaml_event_s::@20 data
The event data.
klass
klass
Definition: tcltklib.c:3504
INT2NUM
#define INT2NUM(x)
yaml_mark_s::line
size_t line
The position line.
Definition: yaml.h:150
make_exception
static VALUE make_exception(yaml_parser_t *parser, VALUE path)
Definition: psych_parser.c:62
mPsych
VALUE mPsych
Definition: psych.c:21
Data_Get_Struct
#define Data_Get_Struct(obj, type, sval)
rb_respond_to
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1564
mark
static VALUE mark(VALUE self)
Definition: psych_parser.c:523
io
gz io
Definition: zlib.c:2263
yaml_event_s::stream_start
struct yaml_event_s::@20::@21 stream_start
The stream parameters (for YAML_STREAM_START_EVENT).
rb_str_new
VALUE rb_str_new(const char *, long)
Definition: string.c:425
yaml_mark_s::index
size_t index
The position index.
Definition: yaml.h:147
allocate
static VALUE allocate(VALUE klass)
Definition: psych_parser.c:52
parser
struct parser_params * parser
Definition: ripper.c:4507
YAML_STREAM_START_EVENT
A STREAM-START event.
Definition: yaml.h:358
yaml_parser_s::problem
const char * problem
Error description.
Definition: yaml.h:1091
protected_start_document
static VALUE protected_start_document(VALUE pointer)
Definition: psych_parser.c:164
VALUE
unsigned long VALUE
Definition: ripper.y:104
rb_enc_find_index
int rb_enc_find_index(const char *name)
Definition: encoding.c:635
version
static void version(void)
Definition: nkf.c:898
id_start_stream
static ID id_start_stream
Definition: psych_parser.c:9
OBJ_TAINT
#define OBJ_TAINT(x)
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:617
yaml_event_s::sequence_start
struct yaml_event_s::@20::@26 sequence_start
The sequence parameters (for YAML_SEQUENCE_START_EVENT).
rb_intern
#define rb_intern(str)
yaml_mark_s::column
size_t column
The position column.
Definition: yaml.h:153
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344
yaml_event_s::type
yaml_event_type_t type
The event type.
Definition: yaml.h:387
protected_start_stream
static VALUE protected_start_stream(VALUE pointer)
Definition: psych_parser.c:158
yaml_event_s::scalar
struct yaml_event_s::@20::@25 scalar
The scalar parameters (for YAML_SCALAR_EVENT).
YAML_ALIAS_EVENT
An ALIAS event.
Definition: yaml.h:368
protected_alias
static VALUE protected_alias(VALUE pointer)
Definition: psych_parser.c:176
YAML_NO_EVENT
An empty event.
Definition: yaml.h:355
protected_scalar
static VALUE protected_scalar(VALUE pointer)
Definition: psych_parser.c:182
transcode_string
static VALUE transcode_string(VALUE src, int *parser_encoding)
Definition: psych_parser.c:79
OnigEncodingTypeST
Definition: ripper.y:161