summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/psych/parser.c11
-rw-r--r--lib/psych.rb8
-rw-r--r--lib/psych/parser/handler.rb5
-rw-r--r--test/psych/test_parser.rb22
4 files changed, 40 insertions, 6 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 1503520..79444e9 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -87,7 +87,16 @@ static VALUE parse_string(VALUE self, VALUE string)
rb_str_new2((const char *)event.data.scalar.tag) :
Qnil;
- rb_funcall(handler, rb_intern("scalar"), 3, val, anchor, tag);
+ VALUE plain_implicit =
+ event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
+
+ VALUE quoted_implicit =
+ event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
+
+ VALUE style = INT2NUM((long)event.data.scalar.style);
+
+ rb_funcall(handler, rb_intern("scalar"), 6,
+ val, anchor, tag, plain_implicit, quoted_implicit, style);
}
break;
case YAML_STREAM_END_EVENT:
diff --git a/lib/psych.rb b/lib/psych.rb
index df00156..a695b0a 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -11,6 +11,14 @@ module Psych
UTF16LE_ENCODING = 3
UTF16BE_ENCODING = 4
+ # Scalar Styles
+ ANY_SCALAR_STYLE = 0
+ PLAIN_SCALAR_STYLE = 1
+ SINGLE_QUOTED_SCALAR_STYLE = 2
+ DOUBLE_QUOTED_SCALAR_STYLE = 3
+ LITERAL_SCALAR_STYLE = 4
+ FOLDED_SCALAR_STYLE = 5
+
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 a0152e7..9cb8281 100644
--- a/lib/psych/parser/handler.rb
+++ b/lib/psych/parser/handler.rb
@@ -25,8 +25,9 @@ module Psych
end
###
- # Called when a scalar +value+ is found
- def scalar value, anchor = nil, tag = nil
+ # Called when a scalar +value+ is found. The scalar may have an
+ # +anchor+, a +tag+, be implicitly +plain+ or implicitly +quoted+
+ def scalar value, anchor = nil, tag = nil, plain = true, quoted = true, style = 0
end
###
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb
index 4ab7860..85ddb8a 100644
--- a/test/psych/test_parser.rb
+++ b/test/psych/test_parser.rb
@@ -20,22 +20,38 @@ module Psych
end
def setup
+ warn "#{name}" if ENV['TESTOPTS'] == '-v'
@parser = Psych::Parser.new EventCatcher.new
end
+ def test_literal_scalar
+ @parser.parse(<<-eoyml)
+%YAML 1.1
+---
+"literal\n\
+ \ttext\n"
+ eoyml
+ assert_called :scalar, ['literal text ', false, true, 3]
+ end
+
def test_scalar
@parser.parse("--- foo\n")
- assert_called :scalar, ['foo']
+ assert_called :scalar, ['foo', true, false, 1]
end
def test_scalar_with_tag
@parser.parse("---\n!!str foo\n")
- assert_called :scalar, ['foo', 'tag:yaml.org,2002:str']
+ assert_called :scalar, ['foo', 'tag:yaml.org,2002:str', false, false, 1]
end
def test_scalar_with_anchor
@parser.parse("---\n&A foo\n")
- assert_called :scalar, ['foo', 'A']
+ assert_called :scalar, ['foo', 'A', true, false, 1]
+ end
+
+ def test_scalar_plain_implicit
+ @parser.parse("---\n&A foo\n")
+ assert_called :scalar, ['foo', 'A', true, false, 1]
end
def test_alias