public function test_expanders_that_takes_other_expanders_as_arguments() { $pattern = "@type@.expander(expander(\"test\"), expander(1))"; $expanders = $this->parser->getAST($pattern)->getExpanders(); $firstExpander = new Expander("expander"); $firstExpander->addArgument("test"); $secondExpander = new Expander("expander"); $secondExpander->addArgument(1); $this->assertEquals($expanders[0]->getArguments(), array($firstExpander, $secondExpander)); }
/** * @param Expander $expanderNode * @throws InvalidExpanderTypeException * @throws UnknownExpanderException * @return PatternExpander */ public function initialize(Expander $expanderNode) { if (!array_key_exists($expanderNode->getName(), $this->expanderDefinitions)) { throw new UnknownExpanderException(sprintf("Unknown expander \"%s\"", $expanderNode->getName())); } $reflection = new \ReflectionClass($this->expanderDefinitions[$expanderNode->getName()]); if ($expanderNode->hasArguments()) { $arguments = array(); foreach ($expanderNode->getArguments() as $argument) { $arguments[] = $argument instanceof Expander ? $this->initialize($argument) : $argument; } $expander = $reflection->newInstanceArgs($arguments); } else { $expander = $reflection->newInstance(); } if (!$expander instanceof PatternExpander) { throw new InvalidExpanderTypeException(); } return $expander; }
/** * Add arguments to expander * * @param AST\Expander $expander */ private function addArgumentValues(AST\Expander $expander) { while (($argument = $this->getNextArgumentValue()) !== null) { $argument = $argument === self::NULL_VALUE ? null : $argument; $expander->addArgument($argument); if (!$this->lexer->isNextToken(Lexer::T_COMMA)) { break; } $this->lexer->moveNext(); if ($this->lexer->isNextToken(Lexer::T_CLOSE_PARENTHESIS)) { $this->unexpectedSyntaxError($this->lexer->lookahead, "string, number, boolean or null argument"); } } }