Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'heredoc_trim_fix' of https://github.com/timo/rakudo int…
…o nom
  • Loading branch information
moritz committed Jul 12, 2013
2 parents 8e07625 + 3f1c71d commit 663f6b5
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/Perl6/Actions.nqp
Expand Up @@ -21,11 +21,47 @@ role STDActions {
$origast.push($*W.add_string_constant($dedented));
}
else {
$origast.push(QAST::Op.new(
:op('callmethod'), :name('indent'),
$doc.MATCH.ast,
QAST::IVal.new( :value($indent) )));
# we need to remove spaces from the beginnings of only textual lines,
# so we have to track after each concatenation if the spaces at the
# beginning of our chunk belong to a fresh line or come after an
# interpolation or something
my $in-fresh-line := 1;

sub descend($node) {
if nqp::istype($node, QAST::Want) {
if +@($node) == 3 && $node[1] eq "Ss" {
my $strval := $node[0].compile_time_value;
if !$in-fresh-line {
if $strval ~~ /\n/ {
my $strbox := nqp::box_s(nqp::x(" ", -$indent) ~ nqp::unbox_s($strval), $*W.find_symbol(["Str"]));
$strval := nqp::unbox_s($strbox.indent($indent));
$in-fresh-line := 1;
return $*W.add_string_constant($strval);
}
} else {
$strval := nqp::unbox_s($strval.indent($indent));
return $*W.add_string_constant($strval);
}
}
} elsif nqp::istype($node, QAST::Op) && $node.op eq 'call' && $node.name eq '&infix:<~>' {
my @results;
# since we have the $in-fresh-line state, we need to traverse
# and replace the child nodes in order
for @($node) {
nqp::push(@results, descend($node.shift))
}
for @results {
nqp::push($node, $_)
}
return $node;
}
$in-fresh-line := 0;
return $node
}

$origast.push(descend($docast))
}
return $origast;
}
}

Expand Down

0 comments on commit 663f6b5

Please sign in to comment.