Permalink
Browse files

Fix heredoc interpolation space oddity (thou++)

  • Loading branch information...
1 parent 1735ca0 commit ba002dd52d818a3ca7797c52ac6c50ee1d3b4621 @sorear committed Jun 27, 2011
Showing with 89 additions and 1 deletion.
  1. +3 −1 lib/CLRBackend.cs
  2. +77 −0 src/niecza
  3. +9 −0 test2.pl
View
@@ -4712,7 +4712,9 @@ public class CLRBackend {
root.clrType, "BOOT");
if (argv != null) {
Kernel.RunLoop(root.name, argv, Builtins.eval_result);
- CLRBackend.last_repl_frame = Kernel.GetLastMainlineFrame();
+ try {
+ CLRBackend.last_repl_frame = Kernel.GetLastMainlineFrame();
+ } catch (Exception) {}
}
}
View
@@ -113,6 +113,83 @@ class Op::ROify is Op {
}
augment class NieczaActions {
+sub mkstringycat($/, *@strings) {
+ my @a;
+ for @strings -> $s {
+ my $i = ($s !~~ Op) ?? ::Op::StringLiteral.new(|node($/),
+ text => $s) !! $s;
+
+ # this *might* belong in an optimization pass
+ if @a && @a[*-1] ~~ ::Op::StringLiteral &&
+ $i ~~ ::Op::StringLiteral {
+ @a[*-1] = ::Op::StringLiteral.new(|node($/),
+ text => (@a[*-1].text ~ $i.text));
+ } else {
+ push @a, $i;
+ }
+ }
+ if @a == 0 {
+ return ::Op::StringLiteral.new(|node($/), text => "");
+ } elsif @a == 1 {
+ return (@a[0] ~~ ::Op::StringLiteral) ?? @a[0] !!
+ mkcall($/, '&prefix:<~>', @a[0]);
+ } else {
+ return mkcall($/, '&infix:<~>', @a);
+ }
+}
+method process_nibble($/, @bits, $prefix?) {
+ my @acc;
+ for @bits -> $n {
+ my $ast = $n.ast;
+
+ if $ast ~~ CClass {
+ $n.CURSOR.sorry("Cannot use a character class in a string");
+ $ast = "";
+ }
+
+ if $ast !~~ Op && defined($prefix) && $prefix ne "" {
+ my $start_nl = !$n.from || ("\r\n".index(
+ substr($/.orig, $n.from-1, 1).defined));
+ $ast = $ast.split(/ ^^ [ <?{ $start_nl }> || <?after <[\r\n]> > ]
+ <before \h>[ $prefix || \h+ ]/).join("");
+ }
+
+ push @acc, $ast;
+ }
+
+ my $post = $/.CURSOR.postprocessor;
+ make mkstringycat($/, @acc);
+
+ if $post eq 'null' {
+ # already OK
+ }
+ # actually quotewords is a bit trickier than this...
+ elsif $post eq 'words' || $post eq 'quotewords' {
+ my $sl = $/.ast;
+ if !$sl.^isa(::Op::StringLiteral) {
+ make ::Op::CallMethod.new(|node($/), :name<words>, receiver => $sl);
+ }
+ else {
+ my @tok = $sl.text.words;
+ @tok = map { ::Op::StringLiteral.new(|node($/), text => $_) }, @tok;
+
+ make ((@tok == 1) ?? @tok[0] !! ::Op::Paren.new(|node($/),
+ inside => ::Op::SimpleParcel.new(|node($/), items => @tok)));
+ }
+ }
+ elsif $post eq 'path' {
+ # TODO could stand to be a lot fancier.
+ make ::Op::CallMethod(|node($/), receiver => $/.ast, :name<IO>);
+ }
+ elsif $post eq 'run' {
+ make mkcall($/, 'rungather', $/.ast);
+ }
+ else {
+ $/.CURSOR.sorry("Unhandled postprocessor $post");
+ }
+
+ $/.ast;
+}
method package_var($/, $slot, $name, $path, :$list, :$hash) {
$/.CURSOR.trymop({
View
@@ -125,6 +125,15 @@
lives_ok { my %x; %x<a> = Mu }, "hash element creation autoviv supports Mu";
}
+# regression test from thou
+{
+ my $x = 'Bar';
+ my $in = qq:to [A] ;
+ Foo $x
+A
+ is $in.substr(0,8), ' Foo Bar', "spaces preserved after heredoc interpolation";
+}
+
#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
# {

0 comments on commit ba002dd

Please sign in to comment.