summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/psych/parser.c23
-rw-r--r--lib/psych.rb5
-rw-r--r--lib/psych/parser/handler.rb3
-rw-r--r--test/psych/test_parser.rb6
4 files changed, 35 insertions, 2 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 9ba5f16..2d3af66 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -119,8 +119,27 @@ static VALUE parse_string(VALUE self, VALUE string)
}
break;
case YAML_SEQUENCE_END_EVENT:
- rb_funcall(handler, rb_intern("end_sequence"), 0);
- break;
+ rb_funcall(handler, rb_intern("end_sequence"), 0);
+ break;
+ case YAML_MAPPING_START_EVENT:
+ {
+ VALUE anchor = event.data.mapping_start.anchor ?
+ rb_str_new2((const char *)event.data.mapping_start.anchor) :
+ Qnil;
+
+ VALUE tag = event.data.mapping_start.tag ?
+ rb_str_new2((const char *)event.data.mapping_start.tag) :
+ Qnil;
+
+ VALUE implicit =
+ event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
+
+ VALUE style = INT2NUM((long)event.data.mapping_start.style);
+
+ rb_funcall(handler, rb_intern("start_mapping"), 4,
+ anchor, tag, implicit, style);
+ }
+ break;
case YAML_STREAM_END_EVENT:
rb_funcall(handler, rb_intern("end_stream"), 0);
done = 1;
diff --git a/lib/psych.rb b/lib/psych.rb
index 812891e..0151e9f 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -24,6 +24,11 @@ module Psych
BLOCK_SEQUENCE_STYLE = 1
FLOW_SEQUENCE_STYLE = 2
+ # Mapping Styles
+ ANY_MAPPING_STYLE = 0
+ BLOCK_MAPPING_STYLE = 1
+ FLOW_MAPPING_STYLE = 2
+
def self.parse thing
Psych::Parser.new.parse thing
end
diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb
index 4c87fff..1be1dd2 100644
--- a/lib/psych/parser/handler.rb
+++ b/lib/psych/parser/handler.rb
@@ -40,6 +40,9 @@ module Psych
def end_sequence
end
+ def start_mapping anchor = nil, tag = nil, implicit = true, style = BLOCK_MAPPING_STYLE
+ end
+
###
# Called when the YAML stream ends
def end_stream
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb
index 61c2510..7405374 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -24,6 +24,12 @@ module Psych
@parser = Psych::Parser.new EventCatcher.new
end
+ def test_mapping_start
+ @parser.parse("---\n{ key: value }")
+ assert_called :start_mapping
+ assert_called :start_mapping, [true, FLOW_MAPPING_STYLE]
+ end
+
def test_sequence_end
@parser.parse("---\n&A [1, 2]")
assert_called :end_sequence