summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/psych/parser.c7
-rw-r--r--lib/psych/parser/handler.rb5
-rw-r--r--test/psych/test_parser.rb20
3 files changed, 27 insertions, 5 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 2efdb09..c7237e5 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -65,6 +65,13 @@ static VALUE parse_string(VALUE self, VALUE string)
event.data.document_end.implicit == 1 ? Qtrue : Qfalse
);
break;
+ case YAML_ALIAS_EVENT:
+ rb_funcall(handler, rb_intern("alias"), 1,
+ event.data.alias.anchor ?
+ rb_str_new2(event.data.alias.anchor) :
+ Qnil
+ );
+ break;
case YAML_STREAM_END_EVENT:
rb_funcall(handler, rb_intern("end_stream"), 0);
done = 1;
diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb
index 5b330a0..00573df 100644
--- a/lib/psych/parser/handler.rb
+++ b/lib/psych/parser/handler.rb
@@ -20,6 +20,11 @@ module Psych
end
###
+ # Called when an alias is found to +anchor+
+ def alias anchor
+ end
+
+ ###
# Called when the YAML stream ends
def end_stream
end
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb
index d32f63a..83e5482 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -23,6 +23,21 @@ module Psych
@parser = Psych::Parser.new EventCatcher.new
end
+ def test_alias
+ @parser.parse(<<-eoyml)
+%YAML 1.1
+---
+!!seq [
+ !!str "Without properties",
+ &A !!str "Anchored",
+ !!str "Tagged",
+ *A,
+ !!str "",
+]
+ eoyml
+ assert_called :alias, ['A']
+ end
+
def test_end_stream
@parser.parse("--- foo\n")
assert_called :end_stream
@@ -38,11 +53,6 @@ module Psych
assert_called :end_document, [true]
end
- def test_end_document_implicit
- @parser.parse("\"foo\"\n")
- assert_called :end_document, [true]
- end
-
def test_end_document_explicit
@parser.parse("\"foo\"\n...")
assert_called :end_document, [false]