Skip to content

Instantly share code, notes, and snippets.

@Tux
Created April 7, 2015 06:50
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 Tux/8dc3bcb1cd82a7c23d3b to your computer and use it in GitHub Desktop.
Save Tux/8dc3bcb1cd82a7c23d3b to your computer and use it in GitHub Desktop.
sub EXPORT(|) {
sub atkeyish(Mu \h, \k) {
nqp::atkey(nqp::findmethod(h, 'hash')(h), k)
}
my role Tuxic {
token term:sym<identifier> {
:my $pos;
<identifier> <!{ $*W.is_type([atkeyish($/, 'identifier').Str]) }> <?before <.unsp>|\s*'('> \s* <![:]>
{ $pos := $/.CURSOR.pos }
<args>
{ self.add_mystery(atkeyish($/, 'identifier'), atkeyish($/, 'args').from, nqp::substr(atkeyish($/, 'args').Str, 0, 1)) }
}
token methodop {
[
| <longname>
| <?[$@&]> <variable> { self.check_variable(atkeyish($/, 'variable')) }
| <?['"]>
[ <!{$*QSIGIL}> || <!before '"' <-["]>*? [\s|$] > ] # dwim on "$foo."
<quote>
[ <?before '(' | '.(' | '\\'> || <.panic: "Quoted method name requires parenthesized arguments. If you meant to concatenate two strings, use '~'."> ]
] \s* <.unsp>?
[
[
| <?before \s*'('> \s* <args>
| ':' <?before \s | '{'> <!{ $*QSIGIL }> <args=.arglist>
]
|| <!{ $*QSIGIL }> <?>
|| <?{ $*QSIGIL }> <?[.]> <?>
] <.unsp>?
}
}
nqp::bindkey(%*LANG, 'MAIN', %*LANG<MAIN>.HOW.mixin(%*LANG<MAIN>, Tuxic));
{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment