Skip to content

Commit

Permalink
Have package body consistently be a block
Browse files Browse the repository at this point in the history
It's typed that way already in the AST definition, although we don't
yet enforce these type constraints. We could in principle arrange for
something a bit like RakuAST::Blorst (that doesn't apply here since it's
a block or statement list). However, it seems more expedient to define a
unit package (or unit sub main) as sugar for a package or sub with a
block whose content extends to the end of the current file.
  • Loading branch information
jnthn committed Apr 2, 2022
1 parent 05d878f commit 2e01452
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Raku/Actions.nqp
Expand Up @@ -962,7 +962,9 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {

method package_def($/) {
my $package := $*PACKAGE;
$package.replace-body($<block> ?? $<block>.ast !! $<statementlist>.ast);
$package.replace-body: $<block>
?? $<block>.ast
!! self.r('Block').new(body => self.r('Blockoid').new($<statementlist>.ast));
self.attach: $/, $package;
}

Expand Down

0 comments on commit 2e01452

Please sign in to comment.