diff --git a/src/NQP/Actions.pm b/src/NQP/Actions.pm index 5668d0c..62ae55d 100644 --- a/src/NQP/Actions.pm +++ b/src/NQP/Actions.pm @@ -718,6 +718,10 @@ method prefix:sym($/) { ); } +method infix:sym<~~>($/) { + make PAST::Op.new( :pasttype, :name, :node($/) ); +} + class NQP::RegexActions is Regex::P6Regex::Actions { diff --git a/src/NQP/Grammar.pm b/src/NQP/Grammar.pm index 564ac4a..19affcf 100644 --- a/src/NQP/Grammar.pm +++ b/src/NQP/Grammar.pm @@ -480,6 +480,7 @@ token infix:sym«ge» { ')> } token infix:sym«lt» { ')> } token infix:sym«gt» { ')> } token infix:sym«=:=» { ')> } +token infix:sym<~~> { ')> } token infix:sym<&&> { ')> } @@ -505,6 +506,11 @@ token infix:sym<,> { ')> } token prefix:sym { \s ')> } token prefix:sym { \s } +method smartmatch($/) { + # swap rhs into invocant position + my $t := $/[0]; $/[0] := $/[1]; $/[1] := $t; +} + grammar NQP::Regex is Regex::P6Regex::Grammar { token metachar:sym<:my> { diff --git a/t/nqp/45-smartmatch.t b/t/nqp/45-smartmatch.t new file mode 100644 index 0000000..1bbce06 --- /dev/null +++ b/t/nqp/45-smartmatch.t @@ -0,0 +1,12 @@ +#! nqp + +P6metaclass.register('Integer'); +P6metaclass.register('ResizablePMCArray'); + +plan(4); +ok(3 ~~ Integer, "smartmatch of Integer works"); +ok(!(4.5 ~~ Integer), "negative smartmatch of Integer works"); + +ok( ~~ ResizablePMCArray, "smartmatch of RPA works"); +ok(!(3 ~~ ResizablePMCArray), "negative smartmatch of RPA works"); +