Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable Str(Any) as a term.
You can't do much useful with it yet, but this does at least get the
parsing of it straightened out.
  • Loading branch information
jnthn committed Jan 24, 2015
1 parent 994dd52 commit 57fe1fe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/Perl6/Actions.nqp
Expand Up @@ -4431,7 +4431,13 @@ class Perl6::Actions is HLL::Actions does STDActions {
my $past;
if $*longname.contains_indirect_lookup() {
if $<args> {
$/.CURSOR.panic("Combination of indirect name lookup and call not (yet?) allowed");
$/.CURSOR.panic("Combination of indirect name lookup and call not supported");
}
elsif $<arglist> {
$/.CURSOR.panic("Combination of indirect name lookup and type arguments not supported");
}
elsif $<accept> || $<accept_any> {
$/.CURSOR.panic("Combination of indirect name lookup and coercion type construction not supported");
}
$past := self.make_indirect_lookup($*longname.components())
}
Expand Down Expand Up @@ -4535,11 +4541,21 @@ class Perl6::Actions is HLL::Actions does STDActions {
else {
$past := instantiated_type(@name, $/);
}

# Names ending in :: really want .WHO.
if $*longname.get_who {
$past := QAST::Op.new( :op('who'), $past );
}

# If needed, try to form a coercion type.
if $<accept> || $<accept_any> {
unless nqp::istype($past, QAST::WVal) {
$/.CURSOR.panic("Target type too complex to form a coercion type");
}
my $type := $*W.create_coercion_type($/, $past.value,
$<accept> ?? $<accept>.ast !! $*W.find_symbol(['Any']));
$past := QAST::WVal.new( :value($type) );
}
}

$past.node($/);
Expand Down Expand Up @@ -5865,7 +5881,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
if $<typename> {
$/.CURSOR.panic("Cannot put 'of' constraint on a coercion type");
}
$type := %*HOW<coercion>.new_type($type,
$type := $*W.create_coercion_type($/, $type,
$<accept> ?? $<accept>.ast !! $*W.find_symbol(['Any']));
}
elsif $<typename> {
Expand Down
12 changes: 10 additions & 2 deletions src/Perl6/Grammar.nqp
Expand Up @@ -3184,8 +3184,16 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
|| <?{ nqp::eqat($<longname>.Str, '::', 0) || $*W.is_name($*longname.components()) }>
<.unsp>?
[
<?{ $*W.is_type($*longname.components()) }>
<?[[]> :dba('type parameter') '[' ~ ']' <arglist>
<?[[]> <?{ $*W.is_type($*longname.components()) }>
:dba('type parameter') '[' ~ ']' <arglist>
]?
<.unsp>?
[
<?[(]> <?{ $*W.is_type($*longname.components()) }>
'(' <.ws> [
|| <accept=.typename> <!{ nqp::isconcrete($<accept>.ast) }>
|| $<accept_any>=<?>
] <.ws> ')'
]?
|| <args(1)>
{
Expand Down
10 changes: 10 additions & 0 deletions src/Perl6/World.nqp
Expand Up @@ -1837,6 +1837,16 @@ class Perl6::World is HLL::World {
$val
}

# Gets a coercion type (possibly freshly created, possibly an
# interned one).
method create_coercion_type($/, $target, $constraint) {
self.ex-handle($/, {
my $type := %*HOW<coercion>.new_type($target, $constraint);
if nqp::isnull(nqp::getobjsc($type)) { self.add_object($type); }
$type
})
}

method suggest_typename($name) {
my %seen;
%seen{$name} := 1;
Expand Down

0 comments on commit 57fe1fe

Please sign in to comment.