private function getAllBlueMacrosFromCrossover($nodes, BlueContext $blueContext) : array { $macros = []; foreach ($nodes as $node) { if ($node instanceof Token) { $macros += $blueContext->getDisabledMacros($node); } else { $macros += $this->getAllBlueMacrosFromCrossover($node, $blueContext); } } return $macros; }
function apply(TokenStream $ts) { $from = $ts->index(); $crossover = $this->pattern->parse($ts); if (null === $crossover || $crossover instanceof Error) { return; } if ($this->expansion) { // infer blue context from matched tokens $context = new BlueContext(); $tokens = $crossover->all(); array_walk_recursive($tokens, function (Token $token) use($context) { $context->inherit($token->context()); }); if (!$this->hasTag('·recursion')) { if ($context->contains($this->id())) { return; } } // already expanded $context->add($this->id()); $ts->unskip(...TokenStream::SKIPPABLE); $to = $ts->index(); $ts->extract($from, $to); $expansion = $this->mutate($this->expansion, $crossover); $this->cycle->next(); // paint blue context of expasion tokens $expansion->each(function (Token $token) use($context) { $token->context()->inherit($context); }); $ts->inject($expansion, $from); } else { $ts->unskip(...TokenStream::SKIPPABLE); $ts->skip(T_WHITESPACE); $to = $ts->index(); $ts->extract($from, $to); } }