Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

when encountering an error during compilation, show the source text i…

…f available
  • Loading branch information...
commit 5e85657e3b601f947bebfd1919f515312565865f 1 parent 434dfc3
@moritz moritz authored
Showing with 17 additions and 2 deletions.
  1. +17 −2 src/QAST/Compiler.nqp
View
19 src/QAST/Compiler.nqp
@@ -189,6 +189,19 @@ class QAST::Compiler is HLL::Compiler {
};
}
+ method source_for_node($node) {
+ my $source := $node.node
+ ?? ~ nqp::escape($node.node.Str)
+ !! '';
+ if nqp::chars($source) > 103 {
+ $source := nqp::substr($source, 0, 100) ~ '...';
+ }
+ if nqp::chars($source) {
+ $source := qq[ (source text: "$source")];
+ }
+ $source;
+ }
+
method post($source, *%adverbs) {
# Wrap $source in a QAST::Block if it's not already a viable root node.
$source := QAST::Block.new($source)
@@ -399,7 +412,8 @@ class QAST::Compiler is HLL::Compiler {
CATCH { $err := $! }
}
if $err {
- nqp::die("Error while compiling block " ~ $node.name ~ ": $err");
+ my $source := self.source_for_node($node);
+ nqp::die("Error while compiling block " ~ $node.name ~ "$source: $err");
}
}
@@ -671,7 +685,8 @@ class QAST::Compiler is HLL::Compiler {
CATCH { $err := $! }
}
if $err {
- nqp::die("Error while compiling op " ~ $node.op ~ ": $err");
+ my $source := self.source_for_node($node);
+ nqp::die("Error while compiling op " ~ $node.op ~ "$source: $err");
}
$result
}
Please sign in to comment.
Something went wrong with that request. Please try again.