ReturnNode example

public function parse(Token $token): ReturnNode
    {
        $stream = $this->parser->getStream();
        $nodes = [];

        if (!$stream->test(Token::BLOCK_END_TYPE)) {
            $nodes['expr'] = $this->parser->getExpressionParser()->parseExpression();
        }

        $stream->expect(Token::BLOCK_END_TYPE);

        return new ReturnNode($nodes[]$token->getLine()$this->getTag());
    }

    public function getTag(): string
    {
        return 'return';
    }
}
Home | Imprint | This part of the site doesn't use cookies.