This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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