Skip to content

Instantly share code, notes, and snippets.

@Skarsnik

Skarsnik/code.p6 Secret

Created February 17, 2016 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skarsnik/cdcfcb15e766913970c8 to your computer and use it in GitHub Desktop.
Save Skarsnik/cdcfcb15e766913970c8 to your computer and use it in GitHub Desktop.
sub build-tree(mxml_node_t $node, $parent, $cpt = 0) {
say "build tree";
#say $node;
given $node.type {
when MXML_ELEMENT {
say "ELEMENT";
say '--' x $cpt ~ $node.value.element.name ~ " : " ~ $node.value.element.num_attrs;
say $node.child;
if $node.child !=== Pointer {
say "=has child=";
my $child = $node.child;
repeat {
say '--' x $cpt ~ "BUILD-TREE-CHILD";
build-tree($child.deref, 'foo', $cpt + 1);
} while $child = $child.deref.next
}
}
when MXML_TEXT {
say "Text";
say '--' x $cpt ~ $node.value.text.string;
}
}
}
...
NativeCall::Types::Pointer[MiniXML::Raw::mxml_node_t]<0xb830080>
=has child=
BUILD-TREE-CHILD
build tree
ELEMENT
--p : 1
NativeCall::Types::Pointer[MiniXML::Raw::mxml_node_t]<0xb830140>
=has child=
root@testperl6:~/piko/perl6-MiniXML#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment