summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-26 23:45:42 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-26 23:45:42 -0700
commit70467fb3e4611559138d016e61e0388ae1c52a56 (patch)
tree71975e8d71e151d3f21029944adb44c5b286a85e
parenta59a8c0fc75f6c0339facdd90302eb352e9d8ea6 (diff)
downloadpsych-70467fb3e4611559138d016e61e0388ae1c52a56.zip
scalar supports anchors
-rw-r--r--ext/psych/parser.c6
-rw-r--r--lib/psych/parser/handler.rb2
-rw-r--r--test/psych/test_parser.rb7
3 files changed, 12 insertions, 3 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 6fd6cb4..1503520 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -79,11 +79,15 @@ static VALUE parse_string(VALUE self, VALUE string)
(long)event.data.scalar.length
);
+ VALUE anchor = event.data.scalar.anchor ?
+ rb_str_new2((const char *)event.data.scalar.anchor) :
+ Qnil;
+
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);
+ rb_funcall(handler, rb_intern("scalar"), 3, val, anchor, tag);
}
break;
case YAML_STREAM_END_EVENT:
diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb
index a36e8fa..a0152e7 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 tag, value
+ def scalar value, anchor = nil, tag = nil
end
###
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb
index 90c19b2..4ab7860 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -30,7 +30,12 @@ module Psych
def test_scalar_with_tag
@parser.parse("---\n!!str foo\n")
- assert_called :scalar, ['tag:yaml.org,2002:str', 'foo']
+ assert_called :scalar, ['foo', 'tag:yaml.org,2002:str']
+ end
+
+ def test_scalar_with_anchor
+ @parser.parse("---\n&A foo\n")
+ assert_called :scalar, ['foo', 'A']
end
def test_alias