Skip to content

Commit

Permalink
Stub support for no <pragma>; statements
Browse files Browse the repository at this point in the history
  • Loading branch information
niner authored and Stefan Seifert committed Jul 3, 2022
1 parent 376dd56 commit 8f3cfb8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Raku/Actions.nqp
Expand Up @@ -340,6 +340,17 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
self.attach: $/, self.r('Statement', 'Control').new(body => $<block>.ast);
}

method statement_control:sym<no>($/) {
my $ast := $<arglist><EXPR>
?? self.r('Statement', 'No').new(
module-name => $<module_name>.ast,
argument => $<arglist><EXPR>.ast
)
!! self.r('Statement', 'No').new(module-name => $<module_name>.ast);
$ast.ensure-begin-performed($*R, $*CU.context);
self.attach: $/, $ast;
}

method statement_control:sym<use>($/) {
my $ast := $<arglist><EXPR>
?? self.r('Statement', 'Use').new(
Expand Down
6 changes: 6 additions & 0 deletions src/Raku/Grammar.nqp
Expand Up @@ -812,6 +812,12 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
rule statement_control:sym<CATCH> { <sym> <block> }
rule statement_control:sym<CONTROL> { <sym> <block> }
token statement_control:sym<no> {
<sym> <.ws>
<module_name=.longname> [ <.spacey> <arglist> ]?
<.ws>
}
token statement_control:sym<use> {
# TODO this is massively simplified
<sym> <.ws>
Expand Down
66 changes: 66 additions & 0 deletions src/Raku/ast/statements.rakumod
Expand Up @@ -1096,6 +1096,72 @@ class RakuAST::Statement::Control is RakuAST::Statement::ExceptionHandler is Rak
}
}

# A no statement.
class RakuAST::Statement::No is RakuAST::Statement is RakuAST::BeginTime
is RakuAST::ImplicitLookups {
has RakuAST::Name $.module-name;
has RakuAST::Expression $.argument;

method new(RakuAST::Name :$module-name!, RakuAST::Expression :$argument) {
my $obj := nqp::create(self);
nqp::bindattr($obj, RakuAST::Statement::No, '$!module-name', $module-name);
nqp::bindattr($obj, RakuAST::Statement::No, '$!argument',
$argument // RakuAST::Expression);
$obj
}

method PRODUCE-IMPLICIT-LOOKUPS() {
self.IMPL-WRAP-LIST([
RakuAST::Type::Setting.new(RakuAST::Name.from-identifier('Nil')),
])
}

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
# Evaluate the argument to the module load, if any.
my $arglist := $!argument
?? self.IMPL-BEGIN-TIME-EVALUATE($!argument, $resolver, $context).List.FLATTENABLE_LIST
!! Nil;

# See if it's a pragma of some kind.
unless self.IMPL-DO-PRAGMA($resolver, $arglist) {
nqp::die("Don't know how to 'no " ~ $!module-name.canonicalize ~ "' just yet");
}
}

method IMPL-DO-PRAGMA(RakuAST::Resolver $resolver, Mu $arglist) {
return False unless $!module-name.is-identifier;
my str $name := self.IMPL-UNWRAP-LIST($!module-name.parts)[0].name;
if $name eq 'lib' {
$resolver.build-exception('X::Pragma::CannotWhat', :what<no>, :$name).throw;
}
elsif $name eq 'MONKEY-SEE-NO-EVAL' {
True
}
elsif $name eq 'MONKEY-GUTS' {
True
}
elsif $name eq 'nqp' {
True
}
elsif $name eq 'fatal' {
True
}
else {
False
}
}

method IMPL-TO-QAST(RakuAST::IMPL::QASTContext $context) {
my @lookups := self.IMPL-UNWRAP-LIST(self.get-implicit-lookups);
@lookups[0].IMPL-TO-QAST($context)
}

method visit-children(Code $visitor) {
$visitor($!module-name);
self.visit-labels($visitor);
}
}

# A use statement.
class RakuAST::Statement::Use is RakuAST::Statement is RakuAST::BeginTime
is RakuAST::ImplicitLookups {
Expand Down

0 comments on commit 8f3cfb8

Please sign in to comment.