summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/psych/parser.c9
-rw-r--r--lib/psych/parser/handler.rb5
-rw-r--r--test/psych/test_parser.rb7
3 files changed, 20 insertions, 1 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index c7237e5..4ae3625 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -72,6 +72,15 @@ static VALUE parse_string(VALUE self, VALUE string)
Qnil
);
break;
+ case YAML_SCALAR_EVENT:
+ {
+ VALUE val = rb_str_new(
+ event.data.scalar.value,
+ event.data.scalar.length
+ );
+ rb_funcall(handler, rb_intern("scalar"), 1, val);
+ }
+ 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 00573df..599dfe2 100644
--- a/lib/psych/parser/handler.rb
+++ b/lib/psych/parser/handler.rb
@@ -25,6 +25,11 @@ module Psych
end
###
+ # Called when a scalar +value+ is found
+ def scalar value
+ 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 83e5482..7d6335b 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -23,6 +23,11 @@ module Psych
@parser = Psych::Parser.new EventCatcher.new
end
+ def test_scalar
+ @parser.parse("--- foo\n")
+ assert_called :scalar, ['foo']
+ end
+
def test_alias
@parser.parse(<<-eoyml)
%YAML 1.1
@@ -71,7 +76,7 @@ module Psych
def assert_called call, with = nil, parser = @parser
if with
assert(
- parser.handler.calls.any? { |x| x == [call, with] },
+ parser.handler.calls.any? { |x| x.compact == [call, with] },
"#{[call,with].inspect} not in #{parser.handler.calls.inspect}"
)
else