Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created July 12, 2016 16:52
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 gfldex/64e429b8fa9a518e461b7a2dc38f94df to your computer and use it in GitHub Desktop.
Save gfldex/64e429b8fa9a518e461b7a2dc38f94df to your computer and use it in GitHub Desktop.
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::.values.grep($node ~~ *).first.^name;$
walk($node.contents, @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