Permalink
Browse files

Fix handling single-quoted scalars

  • Loading branch information...
1 parent 1aeeec5 commit c09a36b50e9bdc622835767a2f11845bce31110a @bacek bacek committed Jan 30, 2011
Showing with 17 additions and 9 deletions.
  1. +7 −5 lib/YAML/Tiny.pm
  2. +8 −3 t/02_basic.t
  3. +2 −1 t/lib/Test.pm
View
@@ -75,11 +75,12 @@ method read_string($string) {
# A nibbling parser
while +@lines {
+ debug("Current result", |@result);
debug("Handling", @lines[0]);
# Do we have a document header?
if my $match := @lines[0] ~~ /^^\-\-\-\s*[(.+)\s*]?$/ {
- debug("Scalar", $match);
+ debug("Header", $match);
# Handle scalar documents
@lines.shift;
# if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) {
@@ -130,25 +131,26 @@ method read_string($string) {
### }
###
### return $self;
- debug("RESULT", @result);
+ debug("RESULT", |@result);
@result;
}
# Deparse a scalar string to the actual scalar
method _read_scalar($string, $indent, @lines) {
- debug("Scalar", $string);
+ debug("_read_scalar", $string);
# Trim trailing whitespace
$string := subst($string, /\s*$/, '');
# Explitic null/undef
return undef if $string eq '~';
# Single quote
- my $match := $string ~~ /^'(.*?)'[\s+\#.*]?$/;
+ my $match := $string ~~ /^\'(.*?)\'[\s+\#.*]?$/;
if $match {
+ debug("Match", $match);
return '' unless pir::defined($match[0]);
- $string := ~$match[0][0];
+ $string := ~$match[0];
$string := subst($string, /\'\'/, "'", :global<1>);
return $string;
}
View
@@ -168,19 +168,24 @@ yaml_ok(
"---\n- 'foo'\n",
[ [ 'foo' ] ],
'single_quote1',
- todo => 1,
);
yaml_ok(
"---\n- ' '\n",
[ [ ' ' ] ],
'single_spaces',
- todo => 1,
);
yaml_ok(
"---\n- ''\n",
[ [ '' ] ],
'single_null',
- todo => 1,
+);
+
+yaml_ok(
+ "--- ' foo'\n--- 'bar '\n",
+ [ " foo", "bar " ],
+ "leading_trailing_spaces_single",
+ noyamlpm => 1,
+ noyamlperl => 1,
);
# Double quotes
View
@@ -5,7 +5,8 @@ our sub yaml_ok($yaml, $expected, $description, *%adverbs) {
my $parser := YAML::Tiny.new;
try {
my $result := $parser.read_string($yaml);
- #_dumper($result);
+ #print("result: "); _dumper($result);
+ #print("expected: "); _dumper($expected);
is_deeply($expected, $result, $description, todo => %adverbs<todo> ?? $description !! 0);
CATCH {

0 comments on commit c09a36b

Please sign in to comment.