Skip to content

Commit

Permalink
Strip Slip wrapping quoteword if one only word
Browse files Browse the repository at this point in the history
When using word quoting with interpolation, interpolated words are
wrapped in a Slip. This is desirable when there are multiple words, as
the interpolated values in the Slip get integrated into the surrounding
List, but is problematic when there is only one word total (prior to
interpolation).

If there is only one word-related op in the resulting QAST tree, strip
the Slip. This fixes the issue when using both qqww and << >>.

Also added "val" sub variant that handles both Slips and Lists, as it
was there was not a good candidate for dealing with the List returned by
the "words" method (on the << >> path).

Addresses [Issue #1204](#1204)
  • Loading branch information
jstuder-gh committed Dec 30, 2017
1 parent 08c97d6 commit ad684de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/Perl6/Actions.nqp
Expand Up @@ -9774,7 +9774,17 @@ class Perl6::QActions is HLL::Actions does STDActions {
}
}
walk($past);
+@($result) == 1 ?? $result[0] !! QAST::Stmts.new( $result )

# Strip out list op and possible Slip if only one resulting word
nqp::if(
+@($result) == 1,
nqp::if(
nqp::istype($result[0], QAST::Op) && $result[0].name eq 'Slip',
$result[0][0],
$result[0]
),
QAST::Stmts.new( $result )
)
}

method postprocess_heredoc($/, $past) {
Expand Down
13 changes: 10 additions & 3 deletions src/core/allomorphs.pm
Expand Up @@ -159,9 +159,16 @@ multi sub val(Mu) {
Mu
}

# needed to preserve slip-ness
multi sub val(Slip:D $maybevals) {
val(|$maybevals).Slip
# if Slip, preserve slipness
multi sub val(List:D $maybevals) {
nqp::stmts(
(my $output := val(|$maybevals)),
nqp::if(
nqp::istype($maybevals, Slip),
$output.Slip,
$output
)
)
}

multi sub val(Pair:D \ww-thing) is raw {
Expand Down

0 comments on commit ad684de

Please sign in to comment.