Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created February 5, 2018 01:32
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/82387c39102c381ac7895ae0bb310d1c to your computer and use it in GitHub Desktop.
Save zoffixznet/82387c39102c381ac7895ae0bb310d1c to your computer and use it in GitHub Desktop.
sub hunt_loose_adverbs_in_arglist($/, @past) {
# if we have a non-comma-separated list of adverbial pairs in an
# arglist or semiarglist, only the first will be passed as a named
# argument.
# Thus, we need to find chained adverbs. They show up on the parse
# tree as colonpair rules followed by a fake_infix.
# if nqp::getenvhash<COLONPAIR> eq 'trace' { say($/.dump) }
nqp::atkey(nqp::getenvhash(),'ZZ') && nqp::say('ZZ1: ' ~ $/.dump);
if +$/.list == 1 && nqp::istype($/[0].ast, QAST::Op) && $/[0].ast.op eq 'call' && $/[0].ast.name ne 'infix:<,>' {
nqp::die("these adverbs belong to a deeper-nested thing");
}
if $<fake_infix>
|| $<colonpair> && +($/.list) == 0 && +($/.hash) == 1 {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.1');
if +($/.list) == 1 {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.2');
hunt_loose_adverbs_in_arglist($/[0], @past);
}
my $Pair := $*W.find_symbol(['Pair']);
if $<colonpair> && istype($<colonpair>.ast.returns, $Pair) {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.3' ~ $<colonpair>.dump);
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.3' ~ $<colonpair>.ast.dump);
if $*WAS_SKIPPED {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.4');
nqp::push(@past, $<colonpair>.ast);
} else {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.5');
$*WAS_SKIPPED := 1;
}
}
} elsif $<OPER>.Str eq ',' {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.6');
my $*WAS_SKIPPED := 0;
for $/.list {
nqp::atkey(nqp::getenvhash(),'ZZ2') && nqp::say('ZZ2.7');
hunt_loose_adverbs_in_arglist($_, @past);
}
}
}
ZZ1: - 0: :w
- colonpair: :w
- identifier: w
- fake_infix:
- O:
- OPER:
- O:
- colonpair: :h<1>
- coloncircumfix: <1>
- circumfix: <1>
- nibble: 1
- identifier: h
ZZ2.1
ZZ2.2
ZZ1: - colonpair: :w
- identifier: w
ZZ2.1
ZZ2.3- identifier: w
ZZ2.3- QAST::Op(callmethod new) <wanted nosink> :statement_id<2> :w
- QAST::Var(lexical Pair) <wanted> :w
- QAST::Want <wanted>
- QAST::WVal(Str)
- Ss
- QAST::SVal(w)
- QAST::Op(p6bool) <wanted>
- QAST::IVal(1)
- QAST::WVal+{QAST::SpecialArg}(IntStr :named<h>) <wanted> 1
ZZ2.5
ZZ2.3- coloncircumfix: <1>
- circumfix: <1>
- nibble: 1
- identifier: h
ZZ2.3- QAST::Op(callmethod new) <nosink> :h<1>
- QAST::Var(lexical Pair) <wanted> :h<1>
- QAST::Want
- QAST::WVal(Str)
- Ss
- QAST::SVal(h)
- QAST::WVal+{QAST::SpecialArg}(:named<h>) <wanted> 1
ZZ2.4
===SORRY!===
Unknown QAST node type NQPMu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment