diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-30 00:10:31 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-30 00:10:31 +0000 |
commit | 0df90074c740c2c106051b44fcebaf36b103485b (patch) | |
tree | a9d4d69de81bafe49c1e5d6370b1b5c5f4a6cde2 /ext | |
parent | 302b6f6e0264dc7f03cfb1a55829ef60af1e96b0 (diff) |
* ext/psych/parser.c (parse): parse method can take an option file
name for use in exception messages.
* test/psych/test_parser.rb: corresponding tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/psych/parser.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 987fd7ad40..70a5865edb 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -84,8 +84,9 @@ static VALUE make_exception(yaml_parser_t * parser, VALUE path) * * See Psych::Parser and Psych::Parser#handler */ -static VALUE parse(VALUE self, VALUE yaml) +static VALUE parse(int argc, VALUE *argv, VALUE self) { + VALUE yaml, path; yaml_parser_t * parser; yaml_event_t event; int done = 0; @@ -96,6 +97,13 @@ static VALUE parse(VALUE self, VALUE yaml) #endif VALUE handler = rb_iv_get(self, "@handler"); + if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) { + if(rb_respond_to(yaml, id_path)) + path = rb_funcall(yaml, id_path, 0); + else + path = rb_str_new2("<unknown>"); + } + Data_Get_Struct(self, yaml_parser_t, parser); if (OBJ_TAINTED(yaml)) tainted = 1; @@ -114,12 +122,7 @@ static VALUE parse(VALUE self, VALUE yaml) while(!done) { if(!yaml_parser_parse(parser, &event)) { - VALUE path, exception; - - if(rb_respond_to(yaml, id_path)) - path = rb_funcall(yaml, id_path, 0); - else - path = rb_str_new2("<unknown>"); + VALUE exception; exception = make_exception(parser, path); yaml_parser_delete(parser); @@ -392,7 +395,7 @@ void Init_psych_parser() rb_require("psych/syntax_error"); ePsychSyntaxError = rb_define_class_under(mPsych, "SyntaxError", rb_eSyntaxError); - rb_define_method(cPsychParser, "parse", parse, 1); + rb_define_method(cPsychParser, "parse", parse, -1); rb_define_method(cPsychParser, "mark", mark, 0); rb_define_method(cPsychParser, "external_encoding=", set_external_encoding, 1); |