Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created Jul 17, 2016
Embed
What would you like to do?
use v6;
subset Pod::FormattingCode::Macro of Pod::FormattingCode where .type eq 'A';
subset Pod::FormattingCode::Bold of Pod::FormattingCode where .type eq 'B';
subset Pod::FormattingCode::Code of Pod::FormattingCode where .type eq 'C';
subset Pod::FormattingCode::Definition of Pod::FormattingCode where .type eq 'D';
subset Pod::FormattingCode::Entity of Pod::FormattingCode where .type eq 'E';
subset Pod::FormattingCode::File of Pod::FormattingCode where .type eq 'F';
subset Pod::FormattingCode::Italic of Pod::FormattingCode where .type eq 'I';
subset Pod::FormattingCode::Link of Pod::FormattingCode where .type eq 'L';
subset Pod::FormattingCode::Note of Pod::FormattingCode where .type eq 'N';
subset Pod::FormattingCode::Placement of Pod::FormattingCode where .type eq 'P';
subset Pod::FormattingCode::Unspace of Pod::FormattingCode where .type eq 'S';
subset Pod::FormattingCode::Terminal of Pod::FormattingCode where .type eq 'T';
subset Pod::FormattingCode::Underline of Pod::FormattingCode where .type eq 'U';
subset Pod::FormattingCode::Verbatim of Pod::FormattingCode where .type eq 'V';
subset Pod::FormattingCode::Index of Pod::FormattingCode where .type eq 'X';
subset Pod::FormattingCode::Comment of Pod::FormattingCode where .type eq 'Z';
multi sub walk(Str :$file) is export {
walk($file.IO);
}
multi sub walk(IO::Path $io) is export {
use MONKEY-SEE-NO-EVAL;
walk(EVAL($io.slurp ~ "\n\$=pod"), [])
}
multi sub walk(Pod::Block $node, @context is copy) {
@context.push: $node;
put (' ' x +@context) ~ $node.^name, ' ', @context>>.Str;
walk($node.contents, @context);
}
multi sub walk(Pod::FormattingCode $node, @context) {
@context.push: $node;
put (' ' x +@context) ~ Pod::FormattingCode::.pairs.first({ $node ~~ $^a.value }).key;
walk($node.contents, @context);
}
multi sub walk([], @context) {}
multi sub walk(@childen, @context) {
@childen.map: { walk($_, @context) }
}
multi sub walk(Str $s, @context) {
$s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment