Skip to content

Commit a79e4ab

Browse files
committed
canonicalize operator names to legal perl
Operator names containing < or > are now enclosed in « and ».
1 parent 687a357 commit a79e4ab

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/HLL/Actions.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class HLL::Actions {
8585
$ast.op( ~$<OPER><O><op> );
8686
}
8787
if $key eq 'LIST' { $key := 'infix'; }
88-
my $name := nqp::lc($key) ~ ':<' ~ $<OPER><sym> ~ '>';
88+
my $name := nqp::lc($key) ~ ':' ~ ($<OPER><sym> ~~ /<[ < > ]>/ ?? '«' ~ $<OPER><sym> ~ '»' !! '<' ~ $<OPER><sym> ~ '>');
8989
$ast.name('&' ~ $name);
9090
unless $ast.op {
9191
$ast.op('call');

src/NQP/Actions.nqp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ class NQP::Actions is HLL::Actions {
4242
method deflongname($/) {
4343
make $<colonpair>
4444
?? ~$<identifier> ~ ':' ~ $<colonpair>.made.named
45-
~ '<' ~ colonpair_str($<colonpair>.made) ~ '>'
45+
~ colonpair_str($<colonpair>.made)
4646
!! ~$/;
4747
}
4848

4949
sub colonpair_str($ast) {
50+
my $s;
5051
if nqp::istype($ast, QAST::Op) {
5152
my @parts;
5253
for $ast.list { @parts.push($_.value) }
53-
join(' ', @parts)
54+
$s := join(' ', @parts)
5455
} else {
55-
$ast.value
56+
$s := $ast.value
5657
}
58+
$s ~~ /<[ < > ]>/ ?? '«' ~ $s ~ '»' !! '<' ~ $s ~ '>';
5759
}
5860

5961
method comp_unit($/) {
@@ -1866,14 +1868,15 @@ class NQP::RegexActions is QRegex::P6Regex::Actions {
18661868
elsif $name eq 'sym' {
18671869
my str $fullrxname := %*RX<name>;
18681870
my str $rxname := "";
1869-
my int $loc := nqp::index($fullrxname, ':sym<');
1871+
my int $loc := nqp::index($fullrxname, ':sym');
18701872
if $loc >= 0 {
18711873
$rxname := nqp::substr($fullrxname, $loc + 5 );
18721874
$rxname := nqp::substr( $rxname, 0, nqp::chars($rxname) - 1);
18731875
}
18741876
else {
18751877
$loc := nqp::index($fullrxname, ':');
18761878
my $angleloc := nqp::index($fullrxname, '<', $loc);
1879+
$angleloc := nqp::index($fullrxname, '«', $loc) if $angleloc < 0;
18771880
$rxname := nqp::substr($fullrxname, $loc + 1, $angleloc - $loc - 1) unless $loc < 0;
18781881
}
18791882
if $loc >= 0 {

src/QRegex/P6Regex/Actions.nqp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,15 @@ class QRegex::P6Regex::Actions is HLL::Actions {
539539
}
540540
elsif $name eq 'sym' {
541541
my $rxname := "";
542-
my $loc := nqp::index(%*RX<name>, ':sym<');
542+
my $loc := nqp::index(%*RX<name>, ':sym');
543543
if $loc >= 0 {
544544
$rxname := nqp::substr(%*RX<name>, $loc + 5 );
545545
$rxname := nqp::substr( $rxname, 0, nqp::chars($rxname) - 1);
546546
}
547547
else {
548548
$loc := nqp::index(%*RX<name>, ':');
549549
my $angleloc := nqp::index(%*RX<name>, '<', $loc);
550+
$angleloc := nqp::index(%*RX<name>, '«', $loc) if $angleloc < 0;
550551
$rxname := nqp::substr(%*RX<name>, $loc + 1, $angleloc - $loc - 1) unless $loc < 0;
551552
}
552553
if $loc >= 0 {

0 commit comments

Comments
 (0)