ruby-changes:21851
From: tenderlove <ko1@a...>
Date: Wed, 30 Nov 2011 09:10:43 +0900 (JST)
Subject: [ruby-changes:21851] tenderlove:r33900 (trunk): * ext/psych/parser.c (parse): parse method can take an option file
tenderlove 2011-11-30 09:10:31 +0900 (Wed, 30 Nov 2011) New Revision: 33900 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33900 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/psych/parser.c trunk/test/psych/test_parser.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33899) +++ ChangeLog (revision 33900) @@ -1,3 +1,9 @@ +Wed Nov 30 09:09:37 2011 Aaron Patterson <aaron@t...> + + * 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. + Tue Nov 29 09:07:59 2011 Eric Hodel <drbrain@s...> * lib/mkmf.rb: Fix indentations of constants at end of module. Index: ext/psych/parser.c =================================================================== --- ext/psych/parser.c (revision 33899) +++ ext/psych/parser.c (revision 33900) @@ -84,8 +84,9 @@ * * 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 @@ #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,13 +122,8 @@ while(!done) { if(!yaml_parser_parse(parser, &event)) { - VALUE path, exception; + VALUE exception; - if(rb_respond_to(yaml, id_path)) - path = rb_funcall(yaml, id_path, 0); - else - path = rb_str_new2("<unknown>"); - exception = make_exception(parser, path); yaml_parser_delete(parser); yaml_parser_initialize(parser); @@ -392,7 +395,7 @@ 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); Index: test/psych/test_parser.rb =================================================================== --- test/psych/test_parser.rb (revision 33899) +++ test/psych/test_parser.rb (revision 33900) @@ -32,6 +32,13 @@ @handler.parser = @parser end + def test_filename + ex = assert_raises(Psych::SyntaxError) do + @parser.parse '--- `', 'omg!' + end + assert_match 'omg!', ex.message + end + def test_line_numbers assert_equal 0, @parser.mark.line @parser.parse "---\n- hello\n- world" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/