diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-06 14:30:34 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-06 14:30:34 -0800 |
commit | 7aad593c5e6e37e5b5f218b51a91cc005d10a3ac (patch) | |
tree | 06a8c5ed0b26677fdeca0e71aee213a2768ce195 | |
parent | 9d431140d6159e97b964b623cfb4370ba0b8203d (diff) | |
download | psych-7aad593c5e6e37e5b5f218b51a91cc005d10a3ac.zip |
* 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.
-rw-r--r-- | CHANGELOG.rdoc | 6 | ||||
-rw-r--r-- | Rakefile | 2 | ||||
-rw-r--r-- | ext/psych/parser.c | 19 | ||||
-rw-r--r-- | test/psych/test_parser.rb | 7 |
4 files changed, 25 insertions, 9 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 2c8c51d..d1184d4 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,9 @@ +Wed Nov 30 09:09:37 2011 Aaron Patterson <aaron@tenderlovemaking.com> + + * 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 22 04:46:22 2011 Aaron Patterson <aaron@tenderlovemaking.com> * ext/psych/lib/psych.rb: remove autoload from psych @@ -11,7 +11,7 @@ end gem 'rake-compiler', '>= 0.4.1' require "rake/extensiontask" -Hoe.plugin :debugging, :doofus, :git, :gemspec, :isolate +Hoe.plugin :doofus, :git, :gemspec, :isolate $hoe = Hoe.spec 'psych' do developer 'Aaron Patterson', 'aaron@tenderlovemaking.com' diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 987fd7a..70a5865 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); diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index decb241..b607514 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -32,6 +32,13 @@ module Psych @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" |