summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-26 23:40:46 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-26 23:40:46 -0700
commita59a8c0fc75f6c0339facdd90302eb352e9d8ea6 (patch)
tree3313403dcdaf32fef09c6116d4b626ae430b7fe3
parentfd76e1c22a0c4a639d10c458733dea7a46390492 (diff)
downloadpsych-a59a8c0fc75f6c0339facdd90302eb352e9d8ea6.zip
supporting scalar tags
-rw-r--r--ext/psych/parser.c7
-rw-r--r--lib/psych/parser/handler.rb2
-rw-r--r--test/psych/test_parser.rb11
3 files changed, 16 insertions, 4 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 698eb37..6fd6cb4 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -78,7 +78,12 @@ static VALUE parse_string(VALUE self, VALUE string)
(const char *)event.data.scalar.value,
(long)event.data.scalar.length
);
- rb_funcall(handler, rb_intern("scalar"), 1, val);
+
+ VALUE tag = event.data.scalar.tag ?
+ rb_str_new2((const char *)event.data.scalar.tag) :
+ Qnil;
+
+ rb_funcall(handler, rb_intern("scalar"), 2, tag, val);
}
break;
case YAML_STREAM_END_EVENT:
diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb
index 599dfe2..a36e8fa 100644
--- a/lib/psych/parser/handler.rb
+++ b/lib/psych/parser/handler.rb
@@ -26,7 +26,7 @@ module Psych
###
# Called when a scalar +value+ is found
- def scalar value
+ def scalar tag, value
end
###
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb
index 7d6335b..90c19b2 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -28,6 +28,11 @@ module Psych
assert_called :scalar, ['foo']
end
+ def test_scalar_with_tag
+ @parser.parse("---\n!!str foo\n")
+ assert_called :scalar, ['tag:yaml.org,2002:str', 'foo']
+ end
+
def test_alias
@parser.parse(<<-eoyml)
%YAML 1.1
@@ -75,8 +80,10 @@ module Psych
def assert_called call, with = nil, parser = @parser
if with
- assert(
- parser.handler.calls.any? { |x| x.compact == [call, with] },
+ call = parser.handler.calls.find { |x|
+ x.first == call && x.last.compact == with
+ }
+ assert(call,
"#{[call,with].inspect} not in #{parser.handler.calls.inspect}"
)
else