Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created July 11, 2018 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/b5197dec7acc1c40b07fe4e482bbe45d to your computer and use it in GitHub Desktop.
Save zoffixznet/b5197dec7acc1c40b07fe4e482bbe45d to your computer and use it in GitHub Desktop.
use nqp;
use NQPHLL:from<NQP>;
BEGIN $*LANG.refine_slang: 'MAIN',
role {
token scope_declarator:sym('I HAZ A') {
<sym> <scoped('my')>
}
token scope_declarator:sym('WE HAZ A') {
<sym> <scoped('our')>
}
token multi_declarator:sym<LOTZA> {
:my $*LINE_NO := HLL::Compiler.lineof(self.orig(), self.from(), :cache(1));
<sym><.kok> :my $*MULTINESS := 'multi';
[ <?before '('> { $*W.throw($/, 'X::Anon::Multi', multiness => $*MULTINESS) } ]?
[ <declarator> || <routine_def('sub')> || <.malformed('multi')> ]
}
token initializer:sym<ITZ> {
<sym> <.ws> <EXPR('e=')>
}
token term:sym<multi_declarator> {
<?before 'multi'|'proto'|'only'|'LOTZA'> <multi_declarator>
}
},
role {
sub lookup-key(Mu \h, \k) {
nqp::atkey(nqp::findmethod(h, 'hash')(h), k)
}
method scope_declarator:sym('I HAZ A')(Mu $/) {
$/.make: lookup-key($/, 'scoped').ast
}
method scope_declarator:sym('WE HAZ A')(Mu $/) {
$/.make: lookup-key($/, 'scoped').ast
}
method multi_declarator:sym<LOTZA>(Mu $/) {
my \declarator = lookup-key($/, 'declarator');
$/.make: declarator ?? declarator.ast !! lookup-key($/, 'routine_def').ast;
}
method initializer:sym<ITZ>(Mu $/) {
$/.make: lookup-key($/, 'EXPR').ast
}
}
{
our sub HAI(|args) { say |args }
WE HAZ A $CHEEZBURGER ITZ 'HELLA FRICKIN EPIC';
HAI $CHEEZBURGER;
{
LOTZA sub HALLO { say 'HALLO' };
HALLO;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment