Skip to content

Commit

Permalink
Pod: allow empty config value
Browse files Browse the repository at this point in the history
Previously a Pod block such as

  =begin pod :config('')
  =end pod

or

  =begin pod :config[]
  =end pod

would throw a compiler error (coercing NQPMu to Str). This is because,
first, an empty quoted string was treated like nothing when compiling
the list of values of the :config key above, and second, an empty value
list was unexpected on the caller site.

This commit makes empty quoted strings recognized and empty value lists
supported, so that

  =begin pod :x('') :y( )
  =end pod

parses successfully and gives

  dd $=pod.head.config
  #= Hash %!config = {:x(""), :y($[])}

Fixes #3098 and closes #3101
  • Loading branch information
taboege committed Aug 6, 2019
1 parent 84b3e9f commit 7c3b257
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Perl6/Pod.nqp
Expand Up @@ -486,7 +486,7 @@ class Perl6::Pod {
$quoted := nqp::null();
}

if nqp::chars($quoted) {
if nqp::chars($quote) || nqp::chars($quoted) {
$word := nqp::concat($word, $quoted);
}
elsif nqp::chars($unquoted) {
Expand All @@ -498,7 +498,7 @@ class Perl6::Pod {
@pieces.push($delim) if ($keep eq 'delimiters');
$word := '';
}
if !nqp::chars($line) && nqp::chars($word) {
if !nqp::chars($line) && (nqp::chars($quote) || nqp::chars($word)) {
@pieces.push($word);
$word := '';
}
Expand Down Expand Up @@ -526,14 +526,15 @@ class Perl6::Pod {
# break into an array
my @arr := string2array($st);

if nqp::elems(@arr) > 1 {
return serialize_object('Array', |@arr).compile_time_value;
}
else {
if nqp::elems(@arr) == 1 {
# convert a single-element list to a single value
my $val := @arr[0];
return $val;
}
else {
# 0 or 2 or more elements are an array
return serialize_object('Array', |@arr).compile_time_value;
}
}

sub make-config-hash($st) {
Expand Down

0 comments on commit 7c3b257

Please sign in to comment.