Skip to content

Commit

Permalink
Introduc // as a definedness prefix operator in 6.e
Browse files Browse the repository at this point in the history
As suggested by Leon Timmermans in:
  https://twitter.com/leon_timmermans/status/1560416910101172225

This also disables the "null regex not allowed" error in 6.e, because
otherwise the // prefix operator wouldn't get past parsing.
  • Loading branch information
lizmat committed Aug 22, 2022
1 parent dbf035d commit eb5bf0d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -3510,7 +3510,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
]
}
token quote:sym</null/> { '/' \s* '/' <.typed_panic: "X::Syntax::Regex::NullRegex"> }
token quote:sym</null/> {
<?{ nqp::getcomp('Raku').language_revision lt 'e' }>
'/' \s* '/' <.typed_panic: "X::Syntax::Regex::NullRegex">
}
token quote:sym</ /> {
:my %*RX;
:my $*INTERPOLATE := 1;
Expand Down Expand Up @@ -4096,6 +4099,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<?before \d+ <?before \. <.?alpha> > <.worry: "Precedence of ^ is looser than method call; please parenthesize"> >?
}
token prefix:sym<> { <sym> <O(|%symbolic_unary)> }
token prefix:sym<//> {
<?{ nqp::getcomp('Raku').language_revision ge 'e' }>
<sym> <O(|%symbolic_unary)>
}
token infix:sym<*> { <sym> <O(|%multiplicative)> }
token infix:sym<×> { <sym> <O(|%multiplicative)> }
Expand Down
3 changes: 3 additions & 0 deletions src/core.e/control.pm6
@@ -1,4 +1,7 @@
multi sub next(\x --> Nil) { THROW(nqp::const::CONTROL_NEXT, x) }
multi sub last(\x --> Nil) { THROW(nqp::const::CONTROL_LAST, x) }

proto sub prefix:<//>($) {*}
multi sub prefix:<//>(\a) { a.defined }

# vim: expandtab shiftwidth=4
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6e.t
Expand Up @@ -387,6 +387,7 @@ my @expected = (
Q{&prefix:<~>},
Q{&prefix:<~^>},
Q{&prefix:<−>},
Q{&prefix:<//>},
Q{&prefix:<⚛>},
Q{&prepend},
Q{&print},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys.t
Expand Up @@ -800,6 +800,7 @@ my @allowed =
Q{&next},
Q{&postcircumfix:<[; ]>},
Q{&postcircumfix:<{; }>},
Q{&prefix:<//>},
Q{&rotor},
Q{&snip},
Q{&term:<nano>},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/04-settingkeys-6e.t
Expand Up @@ -384,6 +384,7 @@ my %allowed = (
Q{&prefix:<~>},
Q{&prefix:<~^>},
Q{&prefix:<−>},
Q{&prefix:<//>},
Q{&prefix:<⚛>},
Q{&prepend},
Q{&print},
Expand Down

0 comments on commit eb5bf0d

Please sign in to comment.