Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement bracket-delimited categorical sub declarations.
This fixes RT #119919. RT #117737 is related and still behaves the same, which
I would argue as correct in the first place - a bare regexp that matches a
single character is not a useful enough compile-time value to declare an
operator with. I've added a typed exception to be thrown in that case though.
  • Loading branch information
peschwa committed Oct 4, 2015
1 parent 53b8878 commit d0885e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -2498,7 +2498,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
# need to tweak into the grammar.
my $category := $<deflongname><name>.Str;
my $opname := $cf<circumfix>
?? $*W.colonpair_nibble_to_str($/, $cf<circumfix><nibble>)
?? $*W.colonpair_nibble_to_str($/, $cf<circumfix><nibble> // $cf<circumfix><semilist>)
!! '';
my $canname := $category ~ ":sym<" ~ $opname ~ ">";
$/.CURSOR.add_categorical($category, $opname, $canname, $<deflongname>.ast, $*DECLARAND);
Expand Down
30 changes: 28 additions & 2 deletions src/Perl6/World.nqp
Expand Up @@ -2362,7 +2362,18 @@ class Perl6::World is HLL::World {
nqp::push(@pieces, nqp::unbox_s($_.compile_time_value));
}
else {
$/.CURSOR.panic($mkerr());
if nqp::istype($_, QAST::Var) {
my $result;
{
$result := self.compile_time_evaluate($/, $_);
CATCH {
$/.CURSOR.panic($mkerr());
}
}
nqp::push(@pieces, nqp::unbox_s($result));
} else {
$/.CURSOR.panic($mkerr());
}
}
}
return join(' ', @pieces);
Expand All @@ -2371,15 +2382,30 @@ class Perl6::World is HLL::World {
# anyway) and focus on what's inside the val (which could be a
# single thing or a list of things, as done above)
self.nibble_to_str($/, $ast[0], $mkerr);
} else {
$/.CURSOR.panic($mkerr());
}
} elsif nqp::istype($ast, QAST::Var) {
my $result;
{
$result := self.compile_time_evaluate($/, $ast);
CATCH {
$/.CURSOR.panic($mkerr());
}
}
return nqp::unbox_s($result);
} else {
$/.CURSOR.panic($mkerr());
}
}

method colonpair_nibble_to_str($/, $nibble) {
self.nibble_to_str($/, $nibble.ast,
-> { "Colon pair value '$nibble' too complex to use in name" });
-> {
self.throw($/, ['X', 'Syntax', 'Extension', 'TooComplex'],
name => ~$nibble,
);
});
}

# Takes a declarator name and locates the applicable meta-object for it.
Expand Down
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -1418,6 +1418,13 @@ my class X::Syntax::Extension::Null does X::Syntax {
}
}

my class X::Syntax::Extension::TooComplex does X::Syntax {
has $.name;
method message() {
"Colon pair value '$.name' too complex to use in name";
}
}

my class X::Syntax::Extension::SpecialForm does X::Syntax {
has $.category;
has $.opname;
Expand Down

0 comments on commit d0885e5

Please sign in to comment.