Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Get need in place. Sketch out import, though export is a bit too inco…
…mplete for it to really work out yet.
  • Loading branch information
jnthn committed Aug 8, 2011
1 parent bf856cd commit 918e8c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/Perl6/Actions.pm
Expand Up @@ -612,15 +612,14 @@ class Perl6::Actions is HLL::Actions {

method statement_control:sym<need>($/) {
my $past := PAST::Stmts.new( :node($/) );
for $<module_name> {
need($_);
for $<version> {
# XXX TODO: Version checks.
}
make $past;
}

method statement_control:sym<import>($/) {
my $past := PAST::Stmts.new( :node($/) );
import($/);
make $past;
}

Expand Down
34 changes: 28 additions & 6 deletions src/Perl6/Grammar.pm
Expand Up @@ -585,11 +585,29 @@ grammar Perl6::Grammar is HLL::Grammar {
| <version>
| <module_name>
] ** ','
{
for $<module_name> {
$*ST.load_module(~$_<longname>, $*GLOBALish);
}
}
}

token statement_control:sym<import> {
<sym> <.ws>
<module_name> [ <.spacey> <arglist> ]? <.ws>
{
my @name := parse_name(~$<module_name><longname>);
my $module;
my $found := 0;
try { $module := $*ST.find_symbol(@name); $found := 1; }
if $found {
do_import($module.WHO, $<arglist>);
}
else {
$/.CURSOR.panic("Could not find module " ~ ~$<module_name> ~
" to import symbols from");
}
}
}

token statement_control:sym<use> {
Expand Down Expand Up @@ -623,19 +641,23 @@ grammar Perl6::Grammar is HLL::Grammar {
|| {
if $longname {
my $module := $*ST.load_module(~$longname, $*GLOBALish);
if pir::exists($module, 'EXPORT') {
my $EXPORT := $module<EXPORT>.WHO;
if pir::exists($EXPORT, 'DEFAULT') {
$*ST.import($EXPORT<DEFAULT>);
}
}
do_import($module, $<arglist>);
$/.CURSOR.import_EXPORTHOW($module);
}
}
]
]
<.ws>
}

sub do_import($module, $arglist) {
if pir::exists($module, 'EXPORT') {
my $EXPORT := $module<EXPORT>.WHO;
if pir::exists($EXPORT, 'DEFAULT') {
$*ST.import($EXPORT<DEFAULT>);
}
}
}

rule statement_control:sym<require> {
<sym>
Expand Down

0 comments on commit 918e8c6

Please sign in to comment.