Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement postfix:<ⁿ>
Works for both positive and negative integer powers.
  • Loading branch information
TimToady committed Nov 25, 2015
1 parent d4b93ab commit 2e8830b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -6466,6 +6466,15 @@ Compilation unit '$file' contained the following violations:
QAST::Op.new( :node($/), :op<call>, $hpast )
}

method postfix:sym<>($/) {
my int $power := 0;
for $<dig> {
$power := $power * 10 + nqp::index("⁰¹²³⁴⁵⁶⁷⁸⁹", $_);
}
$power := -$power if $<sign> eq '¯';
make QAST::Op.new(:op<call>, :name('&postfix:<ⁿ>'), $*W.add_constant('Int', 'int', $power));
}

method postfixish($/) {
if $<postfix_prefix_meta_operator> {
my $past := $<OPER>.ast || QAST::Op.new( :name('&postfix' ~ $*W.canonicalize_pair('', $<OPER>.Str)),
Expand Down
1 change: 1 addition & 0 deletions src/Perl6/Grammar.nqp
Expand Up @@ -3994,6 +3994,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token prefix:sym<--> { <sym> <O('%autoincrement')> }
token postfix:sym<++> { <sym> <O('%autoincrement')> }
token postfix:sym<--> { <sym> <O('%autoincrement')> }
token postfix:sym<> { <sign=[⁺¯]>? <dig=[⁰¹²³⁴⁵⁶⁷⁸⁹]>+ <O('%autoincrement')> }

# TODO: report the correct bracket in error message
token postfix:sym«->» {
Expand Down
3 changes: 3 additions & 0 deletions src/core/Numeric.pm
Expand Up @@ -227,6 +227,9 @@ proto sub infix:<**>(Mu $?, Mu $?) is pure { * }
multi sub infix:<**>($x = 1) { $x.Numeric }
multi sub infix:<**>(\a, \b) { a.Numeric ** b.Numeric }

proto sub postfix:<>(Mu $, Mu $) is pure { * }
multi sub postfix:<>(\a, \b) { a ** b }

## relational operators

proto sub infix:«<=>»(Mu $, Mu $?) is pure { * }
Expand Down

0 comments on commit 2e8830b

Please sign in to comment.