/** * @{inheritdoc} */ public function parse(TokenStream $stream, Token $token) { if ($stream->nextIf(['trans', 'transchoice']) && $stream->expect('(')) { $out = 'echo ' . ($token->test('trans') ? '__' : '_c'); while (!$stream->test(T_CLOSE_TAG)) { $out .= $this->parser->parseExpression(); } return $out; } }
/** * @{inheritdoc} */ public function parse(TokenStream $stream, Token $token) { $control = in_array($token->getType(), $this->control); if ($control || in_array($token->getType(), $this->controlEnd)) { $out = ''; while (!$stream->test(T_CLOSE_TAG)) { $out .= $this->parser->parseExpression(); } if ($control) { $out .= ':'; } return $out; } }
/** * Tests the current token for a condition or throws an exception otherwise. * * @param array|integer $type * @param array|string|null $value * @param string|null $message * @throws SyntaxErrorException * @return Token|null */ public function expect($type, $value = null, $message = null) { $token = $this->tokens[$this->current]; if (!$token->test($type, $value)) { throw new SyntaxErrorException(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s) on line %s', $message ? "{$message}. " : "", $token, $token->getValue(), Token::getName($type), $value ? sprintf(' with value "%s"', $value) : '', $token->getLine())); } return $token; }