-
-
Save alabamenhu/1b502c4ad8b4fa26c30f858e32e44938 to your computer and use it in GitHub Desktop.
Slang term
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
#unit module BX; | |
sub EXPORT(|) { | |
use QAST:from<NQP>; | |
use nqp; | |
role RevAccept { | |
multi method ACCEPTS (\a) { a.ACCEPTS(self) } | |
} | |
sub xpslang-xp (Str $a) { $a does RevAccept } | |
role BX::Grammar { | |
token term:sym<xpath> { <sym> '|' $<xpathS>=.+? '|' } | |
} | |
role BX::Actions { | |
sub lk(Mu \h, \k) { | |
nqp::atkey(nqp::findmethod(h, 'hash')(h), k) | |
} | |
method term:sym<xpath>(Mu $/) { | |
my $xpath := lk($/, 'xpathS'); | |
my $block := QAST::Op.new( | |
:op<call>, | |
:name<&xpslang-xp>, | |
QAST::SVal.new(:value($xpath.Str)) | |
); | |
$/.make($block); | |
} | |
} | |
$ = $*LANG.define_slang( | |
'MAIN', | |
$*LANG.slang_grammar('MAIN').^mixin(BX::Grammar), | |
$*LANG.actions.^mixin(BX::Actions) | |
); | |
Map.new: "&xpslang-xp" => &xpslang-xp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment