Skip to content
Browse files

beginnings of a QAST dumper

  • Loading branch information...
1 parent ec4648d commit 2cba446ea98d31b327e157e89a405193c1c8125a @moritz moritz committed Nov 17, 2012
Showing with 47 additions and 0 deletions.
  1. +1 −0 src/QAST/IVal.nqp
  2. +1 −0 src/QAST/NVal.nqp
  3. +36 −0 src/QAST/Node.nqp
  4. +2 −0 src/QAST/Op.nqp
  5. +3 −0 src/QAST/SVal.nqp
  6. +4 −0 src/QAST/Var.nqp
View
1 src/QAST/IVal.nqp
@@ -9,4 +9,5 @@ class QAST::IVal is QAST::Node {
method evaluate_unquotes(@unquotes) {
self
}
+ method dump_extra_node_info() { ~$!value }
}
View
1 src/QAST/NVal.nqp
@@ -9,4 +9,5 @@ class QAST::NVal is QAST::Node {
method evaluate_unquotes(@unquotes) {
self
}
+ method dump_extra_node_info() { ~$!value }
}
View
36 src/QAST/Node.nqp
@@ -114,4 +114,40 @@ class QAST::Node {
method evaluate_unquotes(@unquotes) {
nqp::die(self.HOW.name(self) ~ " does not support evaluating unquotes");
}
+
+ method dump($indent?) {
+ unless nqp::defined($indent) {
+ $indent := 0;
+ }
+ my @chunks := [
+ nqp::x(' ', $indent), '- ', self.HOW.name(self),
+ ];
+ my $extra := self.dump_extra_node_info();
+ if nqp::chars($extra) {
+ nqp::push(@chunks, "($extra)");
+ }
+ if (self.node) {
+ nqp::push(@chunks, ' ');
+ nqp::push(@chunks, pir::escape__SS(self.node));
+ }
+ nqp::push(@chunks, "\n");
+ self.dump_children($indent + 2, @chunks);
+ return nqp::join('', @chunks);
+ }
+
+ method dump_children(int $indent, @onto) {
+ for @!array {
+ if nqp::istype($_, QAST::Node) {
+ nqp::push(@onto, $_.dump($indent));
+ }
+ else {
+ nqp::push(@onto, nqp::x(' ', $indent));
+ nqp::push(@onto, '- ');
+ nqp::push(@onto, ~$_);
+ nqp::push(@onto, "\n");
+ }
+ }
+ }
+
+ method dump_extra_node_info() { '' }
}
View
2 src/QAST/Op.nqp
@@ -28,4 +28,6 @@ class QAST::Op is QAST::Node {
}
$result
}
+
+ method dump_extra_node_info() { "$!op $!name"; }
}
View
3 src/QAST/SVal.nqp
@@ -9,4 +9,7 @@ class QAST::SVal is QAST::Node {
method evaluate_unquotes(@unquotes) {
self
}
+ method dump_extra_node_info() {
+ pir::escape__SS($!value);
+ }
}
View
4 src/QAST/Var.nqp
@@ -18,4 +18,8 @@ class QAST::Var is QAST::Node {
method evaluate_unquotes(@unquotes) {
self
}
+
+ method dump_extra_node_info() {
+ "$!scope $!name";
+ }
}

0 comments on commit 2cba446

Please sign in to comment.
Something went wrong with that request. Please try again.