Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow to switch to Perl 5 module by switching to a foreign statementlist
This makes "use v5" work, though this is not the ideal patch for slangs
implemented in Perl 6 itself. We only do it this way for now to have
something at all. jnthn++ for reviewing
  • Loading branch information
FROGGS committed May 18, 2014
1 parent 834a415 commit 3216e73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Perl6/Actions.nqp
Expand Up @@ -1207,7 +1207,10 @@ class Perl6::Actions is HLL::Actions does STDActions {

method statement_control:sym<use>($/) {
my $past := QAST::WVal.new( :value($*W.find_symbol(['Nil'])) );
if $<version> {
if $<statementlist> {
$past := $<statementlist>.ast;
}
elsif $<version> {
# TODO: replace this by code that doesn't always die with
# a useless error message
# my $i := -1;
Expand Down
17 changes: 15 additions & 2 deletions src/Perl6/Grammar.nqp
Expand Up @@ -923,6 +923,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {

# Quasis and unquotes
:my $*IN_QUASI := 0; # whether we're currently in a quasi block
:my $*MAIN := 'MAIN';

# performance improvement stuff
:my $*FAKE_INFIX_FOUND := 0;
Expand Down Expand Up @@ -994,6 +995,9 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
%*LANG{$_.key} := $_.value;
}
}
if $have_outer && $*UNIT_OUTER.symbol('$*MAIN') {
$*MAIN := $*UNIT_OUTER.symbol('$*MAIN')<value>;
}

# Install unless we've no setting, in which case we've likely no
# static lexpad class yet either. Also, UNIT needs a code object.
Expand All @@ -1016,7 +1020,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {

<.finishpad>
<.bom>?
<statementlist(1)>
<statementlist=.LANG($*MAIN, 'statementlist', 1)>

<.install_doc_phaser>

Expand Down Expand Up @@ -1354,10 +1358,18 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*IN_DECL := 'use';
:my $*HAS_SELF := '';
:my $*SCOPE := 'use';
:my $OLD_MAIN := ~$*MAIN;
$<doc>=[ 'DOC' \h+ ]**0..1
<sym> <.ws>
[
| <version>
| <version> [ <?{ ~$<version><vnum>[0] eq '5' }> {
my $module := $*W.load_module($/, 'Perl5', {}, $*GLOBALish);
do_import($/, $module, 'Perl5');
$/.CURSOR.import_EXPORTHOW($module);
} ]?
[ <?{ ~$<version><vnum>[0] eq '6' }> {
$*MAIN := 'MAIN';
} ]?
| <module_name>
{
$longname := $<module_name><longname>;
Expand Down Expand Up @@ -1408,6 +1420,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
}
]
]
[ <?{ $*MAIN ne $OLD_MAIN }> <statementlist=.LANG($*MAIN, 'statementlist', 1)> || <?> ]
<.ws>
}

Expand Down

0 comments on commit 3216e73

Please sign in to comment.