Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move add_package_declarator to World
  • Loading branch information
lizmat committed Apr 28, 2015
1 parent f4ff0a8 commit 59b8935
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
33 changes: 0 additions & 33 deletions src/Perl6/Grammar.nqp
Expand Up @@ -1082,39 +1082,6 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
{ $*W.mop_up_and_check($/) }
}

method add_package_declarator(str $pdecl) {
# Compute name of grammar/action entry.
my $canname := 'package_declarator:sym<' ~ $pdecl ~ '>';

# Add to grammar if needed.
unless nqp::can(self, $canname) {
my role PackageDeclarator[$meth_name, $declarator] {
token ::($meth_name) {
:my $*OUTERPACKAGE := $*PACKAGE;
:my $*PKGDECL := $declarator;
:my $*LINE_NO := HLL::Compiler.lineof(self.orig(), self.from(), :cache(1));
$<sym>=[$declarator] <.end_keyword> <package_def>
}
}
self.HOW.mixin(self, PackageDeclarator.HOW.curry(PackageDeclarator, $canname, $pdecl));

# This also becomes the current MAIN. Also place it in %?LANG.
%*LANG<MAIN> := self.WHAT;
$*W.install_lexical_symbol($*W.cur_lexpad(), '%?LANG', $*W.p6ize_recursive(%*LANG));
}

# Add action method if needed.
unless nqp::can($*ACTIONS, $canname) {
my role PackageDeclaratorAction[$meth] {
method ::($meth)($/) {
make $<package_def>.ast;
}
};
%*LANG<MAIN-actions> := $*ACTIONS.HOW.mixin($*ACTIONS,
PackageDeclaratorAction.HOW.curry(PackageDeclaratorAction, $canname));
}
}

rule statementlist($*statement_level = 0) {
:my %*LANG := self.shallow_copy(nqp::getlexdyn('%*LANG'));
:my %*HOW := self.shallow_copy(nqp::getlexdyn('%*HOW'));
Expand Down
37 changes: 36 additions & 1 deletion src/Perl6/World.nqp
Expand Up @@ -523,7 +523,7 @@ class Perl6::World is HLL::World {
}
%*HOW{$pdecl} := $meta;
%*HOWUSE{$pdecl} := nqp::hash('DECLARE', $meta);
$/.CURSOR.add_package_declarator($pdecl);
self.add_package_declarator($/,$pdecl);
}
}
elsif $key eq 'COMPOSE' {
Expand All @@ -546,6 +546,41 @@ class Perl6::World is HLL::World {
}
}

method add_package_declarator($/, str $pdecl) {
my $cursor := $/.CURSOR;

# Compute name of grammar/action entry.
my $canname := 'package_declarator:sym<' ~ $pdecl ~ '>';

# Add to grammar if needed.
unless nqp::can($cursor, $canname) {
my role PackageDeclarator[$meth_name, $declarator] {
token ::($meth_name) {
:my $*OUTERPACKAGE := $*PACKAGE;
:my $*PKGDECL := $declarator;
:my $*LINE_NO := HLL::Compiler.lineof($cursor.orig(), $cursor.from(), :cache(1));
$<sym>=[$declarator] <.end_keyword> <package_def>
}
}
$cursor.HOW.mixin($cursor, PackageDeclarator.HOW.curry(PackageDeclarator, $canname, $pdecl));

# This also becomes the current MAIN. Also place it in %?LANG.
%*LANG<MAIN> := $cursor.WHAT;
self.install_lexical_symbol(self.cur_lexpad(), '%?LANG', self.p6ize_recursive(%*LANG));
}

# Add action method if needed.
unless nqp::can($*ACTIONS, $canname) {
my role PackageDeclaratorAction[$meth] {
method ::($meth)($/) {
make $<package_def>.ast;
}
};
%*LANG<MAIN-actions> := $*ACTIONS.HOW.mixin($*ACTIONS,
PackageDeclaratorAction.HOW.curry(PackageDeclaratorAction, $canname));
}
}

method do_import($/, $module, $package_source_name, $arglist?) {
if nqp::existskey($module, 'EXPORT') {
my $EXPORT := self.stash_hash($module<EXPORT>);
Expand Down

0 comments on commit 59b8935

Please sign in to comment.