Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created April 12, 2018 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/ed56853f44b90fd9a7bf1dfbb86629de to your computer and use it in GitHub Desktop.
Save zoffixznet/ed56853f44b90fd9a7bf1dfbb86629de to your computer and use it in GitHub Desktop.
method can_has_coercerz($/) {
if $<accept> {
$<accept>.ast
}
elsif $<accept_any> {
self.find_symbol: ['Any'], :setting-only
}
elsif $<colonpairs> && ($<colonpairs>.ast<D> || $<colonpairs>.ast<U>) {
my $val := $<longname><colonpair>[0].ast[2];
nqp::atkey(nqp::getenvhash(),'ZZ') && nqp::say("ZZ1:\n" ~ $val.dump);
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say("ZZ2:\n" ~ $<longname><colonpair>[0].dump);
nqp::atkey(nqp::getenvhash(),'ZZ3') && nqp::say("ZZ3:\n" ~ $<longname><colonpair>[0].ast.dump);
if nqp::atkey(nqp::getenvhash(),'ZZ4') {
my $el := $<longname><colonpair>[0];
nqp::say('ZZ4.1: ' ~ $el.dump);
$el := $el;
nqp::say('ZZ4.2: ' ~ $el.dump);
$el := $el<coloncircumfix>;
nqp::say('ZZ4.3: ' ~ $el.dump);
$el := $el<circumfix>;
nqp::say('ZZ4.4: ' ~ $el.dump);
my $target-el := $el<semilist>;
nqp::say('ZZ4.5: ' ~ $el.dump);
$el := (@($el))[1];
nqp::say('ZZ4.5.1: ' ~ $el.dump);
$el := $el<statement>;
nqp::say('ZZ4.6: ' ~ $el.dump);
$el := $el<EXPR>;
nqp::say('ZZ4.7: ' ~ $el.dump);
$el := $el;
nqp::say('ZZ4.8: ' ~ $el.dump);
$el := $el<longname>;
nqp::say('ZZ4.9: ' ~ $el.dump);
}
if nqp::istype($val, QAST::Op) {
if $val.op eq 'call' {
if $val.name && $val.name eq '&circumfix:<[ ]>' {
# XXX TODO: the circumfix:<[ ]> path is a misparse of
# parameterization, e.g. List:D[Int]. When parse is fixed,
# the circumfix branch likely can be removed
nqp::null
}
elsif $val.name && $val.name eq '&infix:<,>' && @($val) == 0 {
# empty coercer source type
self.find_symbol: ['Any'], :setting-only
}
elsif (my $long := try {
# possibly mistyped typename
$<longname><colonpair>[0]<coloncircumfix><circumfix><semilist><statement><EXPR><longname>
}) {
my $longname := $*W.dissect_longname: $long;
try {$*W.find_symbol: $longname; 1}
?? self.throw: $/, ['X', 'Syntax', 'Coercer', 'TooComplex']
!! self.throw: $/, ['X', 'Undeclared'],
:what<Type>, :symbol($longname.name),
:suggestions(self.suggest_typename: $longname.name)
}
else {
self.throw: $/, ['X', 'Syntax', 'Coercer', 'TooComplex']
}
}
elsif $val.op eq 'p6bool' {
nqp::null # not a coercer, but just got a regular DefiniteHOW
}
}
elsif nqp::istype($val, QAST::WVal) {
$val.value
}
else {
self.throw: $/, ['X', 'Syntax', 'Coercer', 'TooComplex']
}
}
else {
nqp::null # we didn't find any coercers
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment