Skip to content

Commit

Permalink
added support for: do EXPR
Browse files Browse the repository at this point in the history
  • Loading branch information
FROGGS committed Jun 2, 2013
1 parent 6a1743a commit bb684f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/Perl5/Actions.nqp
Expand Up @@ -1106,7 +1106,12 @@ class Perl5::Actions is HLL::Actions does STDActions {

method statement_prefix:sym<do>($/) {
$V5DEBUG && say("statement_prefix:sym<do>($/)");
make QAST::Op.new( :op('call'), $<block>.ast );
if $<block> {
make QAST::Op.new( :op('call'), $<block>.ast );
}
else {
make QAST::Op.new( :op('callmethod'), :name('P5do'), $<EXPR>.ast );
}
}

method statement_prefix:sym<eval>($/) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Perl5/Grammar.nqp
Expand Up @@ -2926,7 +2926,7 @@ grammar Perl5::Grammar is HLL::Grammar does STD5 {
<.ws>
}

rule statement_prefix:sym<do> {<sym> <block> }
rule statement_prefix:sym<do> {<sym> [ <?[{]> <block> | <EXPR('q=')> ] }
rule statement_prefix:sym<eval> {<sym> <block> }

#########
Expand Down
22 changes: 21 additions & 1 deletion lib/Perl5/Terms.pm
Expand Up @@ -153,13 +153,32 @@ sub say(*@a) is export { @a.P5Str.say }; # XXX $*MAIN eq 'Perl5' ?? @a.P5Str.say
use Perl5::warnings ();
use MONKEY_TYPING;

sub _P5do( $file ) is hidden_from_backtrace {
my $ret;
if $file {
if $file.IO.e {
try {
$ret = eval slurp $file;
CATCH {
default { warn(CALLER::DYNAMIC::<$!> = .Str) }
}
}
}
}
else {
die 'Null filename used'
}
$ret
}

augment class Any {
method P5Str(Any:U:) is hidden_from_backtrace {
if warnings::enabled('all') || warnings::enabled('uninitialized') {
warn 'Use of uninitialized value in string'
}
''
}
method P5do(Any:) is hidden_from_backtrace { _P5do(self) }
}

augment class Bool {
Expand All @@ -178,7 +197,8 @@ augment class List {
}

augment class Str {
multi method P5Str(Str:D:) { self.Str }
multi method P5Str(Str:D:) { self.Str }
method P5do(Str:) { _P5do(self) }
}

augment class Int {
Expand Down

0 comments on commit bb684f4

Please sign in to comment.