Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement a default DOC INIT phaser
  • Loading branch information
Tadeusz Sośnierz committed Aug 8, 2011
1 parent 9ca7ef7 commit ff8d46f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -219,6 +219,44 @@ class Perl6::Actions is HLL::Actions {
make $outer;
}

method install_doc_phaser($/) {
# Add a default DOC INIT phaser
if %*COMPILING<%?OPTIONS><doc> {
my $block := $*ST.push_lexpad($/);
# loading and importing
# TODO: Skip importing and use a symbol_lookup when the
# Pod::foo modules bug gets fixed
my $module := $*ST.load_module('Pod::To::Text', $*GLOBALish);
if pir::exists($module, 'EXPORT') {
my $EXPORT := $module<EXPORT>.WHO;
if pir::exists($EXPORT, 'DEFAULT') {
$*ST.import($EXPORT<DEFAULT>);
}
}

#my $pod2text := $*ST.symbol_lookup(
# ['Pod','To','Text','&pod2text'], $/
#);
my $pod2text := PAST::Op.new(
:pasttype<call>, :node($/), :name<&pod2text>,
);

$pod2text.push(PAST::Var.new(:name<$=POD>, :node($/)));

$block.push(
PAST::Op.new(
:pasttype<call>, :node($/),
:name('&print'), $pod2text,
),
);
$*ST.pop_lexpad();
$*ST.add_phaser(
$/, make_simple_code_object($block, 'Block'), 'INIT'
);
}
}


method pod_content_toplevel($/) {
my $child := $<pod_block>.ast;
# make sure we don't push the same thing twice
Expand Down
4 changes: 4 additions & 0 deletions src/Perl6/Grammar.pm
Expand Up @@ -296,6 +296,8 @@ grammar Perl6::Grammar is HLL::Grammar {
# TODO: Also Semantic blocks one day
}

token install_doc_phaser { <?> }

## Top-level rules

token comp_unit {
Expand Down Expand Up @@ -388,6 +390,8 @@ grammar Perl6::Grammar is HLL::Grammar {

<.finishpad>
<statementlist>

<.install_doc_phaser>

[ $ || <.panic: 'Confused'> ]

Expand Down

0 comments on commit ff8d46f

Please sign in to comment.