summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/psych/parser.c20
-rw-r--r--lib/psych/parser/handler.rb5
-rw-r--r--test/psych/test_parser.rb14
3 files changed, 33 insertions, 6 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index b984739..ef95056 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -31,13 +31,31 @@ static VALUE parse_string(VALUE self, VALUE string)
break;
case YAML_DOCUMENT_START_EVENT:
{
+ // Grab the document version
VALUE version = event.data.document_start.version_directive ?
rb_ary_new3(
(long)2,
INT2NUM((long)event.data.document_start.version_directive->major),
INT2NUM((long)event.data.document_start.version_directive->minor)
) : rb_ary_new();
- rb_funcall(handler, rb_intern("start_document"), 1, version);
+
+ // Get a list of tag directives (if any)
+ VALUE tag_directives = rb_ary_new();
+ if(event.data.document_start.tag_directives.start) {
+ yaml_tag_directive_t *start =
+ event.data.document_start.tag_directives.start;
+ yaml_tag_directive_t *end =
+ event.data.document_start.tag_directives.end;
+ for(; start != end; start++) {
+ VALUE pair = rb_ary_new3((long)2,
+ start->handle ? rb_str_new2(start->handle) : Qnil,
+ start->prefix ? rb_str_new2(start->prefix) : Qnil
+ );
+ rb_ary_push(tag_directives, pair);
+ }
+ }
+ rb_funcall(handler, rb_intern("start_document"), 2,
+ version, tag_directives);
}
break;
case YAML_STREAM_END_EVENT:
diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb
index c3e6f1d..a140b09 100644
--- a/lib/psych/parser/handler.rb
+++ b/lib/psych/parser/handler.rb
@@ -9,8 +9,9 @@ module Psych
end
###
- # Called when the document starts with the declared +version+
- def start_document version = []
+ # Called when the document starts with the declared +version+ and
+ # +tag_directives+
+ def start_document version = [], tag_directives = []
end
###
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb
index 748d67b..4a12015 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -33,14 +33,22 @@ module Psych
assert_called :start_stream
end
- def test_start_document
+ def test_start_document_version
@parser.parse("%YAML 1.1\n---\n\"foo\"\n")
- assert_called :start_document, [[1,1]]
+ assert_called :start_document, [[1,1], []]
+ end
+
+ def test_start_document_tag
+ @parser.parse("%TAG !yaml! tag:yaml.org,2002\n---\n!yaml!str \"foo\"\n")
+ assert_called :start_document, [[], [['!yaml!', 'tag:yaml.org,2002']]]
end
def assert_called call, with = nil, parser = @parser
if with
- assert parser.handler.calls.any? { |x| x == [call, with] }
+ assert(
+ parser.handler.calls.any? { |x| x == [call, with] },
+ "#{[call,with].inspect} not in #{parser.handler.calls.inspect}"
+ )
else
assert parser.handler.calls.any? { |x| x.first == call }
end