Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ignore \n and \r\n during heredoc dedenting.
We probably make the optimizer a little extra constant folding work
with this solution, but it's unintrusive and uses the already complex
enough heredoc handling logic to do the heavy lifting.
  • Loading branch information
jnthn committed Nov 12, 2015
1 parent 8d4da82 commit 74fcb36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Perl6/Actions.nqp
Expand Up @@ -8461,10 +8461,24 @@ class Perl6::QActions is HLL::Actions does STDActions {
method backslash:sym<c>($/) { make $<charspec>.ast }
method backslash:sym<e>($/) { make "\c[27]" }
method backslash:sym<f>($/) { make "\c[12]" }
method backslash:sym<n>($/) { make nqp::unbox_s($*W.find_symbol(['$?NL'])); }
method backslash:sym<n>($/) {
my str $nl := nqp::unbox_s($*W.find_symbol(['$?NL']));
if nqp::can($/.CURSOR, 'parsing_heredoc') {
# In heredocs, we spit out a QAST::SVal here to prevent newlines
# being taken literally and affecting the dedent.
make QAST::SVal.new( :value($nl) );
}
else {
make $nl;
}
}
method backslash:sym<o>($/) { make self.ints_to_string( $<octint> ?? $<octint> !! $<octints><octint> ) }
method backslash:sym<r>($/) { make "\r" }
method backslash:sym<rn>($/) { make "\r\n" }
method backslash:sym<rn>($/) {
make nqp::can($/.CURSOR, 'parsing_heredoc')
?? QAST::SVal.new( :value("\r\n") )
!! "\r\n";
}
method backslash:sym<t>($/) { make "\t" }
method backslash:sym<x>($/) { make self.ints_to_string( $<hexint> ?? $<hexint> !! $<hexints><hexint> ) }
method backslash:sym<0>($/) { make "\c[0]" }
Expand Down
1 change: 1 addition & 0 deletions src/Perl6/Grammar.nqp
Expand Up @@ -152,6 +152,7 @@ role STD {
role herestop {
token starter { <!> }
token stopper { ^^ {} $<ws>=(\h*) $*DELIM \h* $$ [\r\n | \v]? }
method parsing_heredoc() { 1 }
}

method heredoc () {
Expand Down

0 comments on commit 74fcb36

Please sign in to comment.