Created
November 21, 2015 00:39
-
-
Save peschwa/7202b9f622de517cd881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nqp; | |
use QAST:from<NQP>; | |
use NQPHLL:from<NQP>; | |
sub EXPORT(|) { | |
my role SuperscriptPotentiation { | |
token postfix:sym<superscript> { | |
<[²³]>+ | |
} | |
} | |
my role SuperscriptPotentiationActions { | |
method postfix:sym<superscript>(Mu $/) { | |
my $exp; | |
my $i = 0; | |
my \chars = nqp::split('', $/.Str); | |
my $iter := nqp::iterator(chars); | |
while $iter { | |
my $val := nqp::shift($iter); | |
$exp += unival($val) * ($i + 1) | |
} | |
#say QAST::IVal.new(:value($exp.Int)).dump; | |
my $block = QAST::Op.new( | |
:op<call>, :name('infix:<**>'), | |
QAST::IVal.new(:value(2)), | |
QAST::IVal.new(:value($exp.Int))); | |
$/.'!make'($block); | |
} | |
} | |
my Mu $MAIN-grammar = nqp::atkey(%*LANG, 'MAIN'); | |
my Mu $MAIN-actions = nqp::atkey(%*LANG, 'MAIN-actions'); | |
nqp::bindkey(%*LANG, 'MAIN', $MAIN-grammar.HOW.mixin($MAIN-grammar, SuperscriptPotentiation)); | |
nqp::bindkey(%*LANG, 'MAIN-actions', $MAIN-actions.HOW.mixin($MAIN-actions, SuperscriptPotentiationActions)); | |
{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment