Вход Регистрация
Файл: upload/core/vendor/twig/twig/src/ExpressionParser/Infix/SquareBracketExpressionParser.php
Строк: 119
<?php

/*
 * This file is part of Twig.
 *
 * (c) Fabien Potencier
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace TwigExpressionParserInfix;

use 
TwigExpressionParserAbstractExpressionParser;
use 
TwigExpressionParserExpressionParserDescriptionInterface;
use 
TwigExpressionParserInfixAssociativity;
use 
TwigExpressionParserInfixExpressionParserInterface;
use 
TwigNodeExpressionAbstractExpression;
use 
TwigNodeExpressionArrayExpression;
use 
TwigNodeExpressionConstantExpression;
use 
TwigNodeExpressionGetAttrExpression;
use 
TwigNodeNodes;
use 
TwigParser;
use 
TwigTemplate;
use 
TwigToken;

/**
 * @internal
 */
final class SquareBracketExpressionParser extends AbstractExpressionParser implements InfixExpressionParserInterfaceExpressionParserDescriptionInterface
{
    public function 
parse(Parser $parserAbstractExpression $exprToken $token): AbstractExpression
    
{
        
$stream $parser->getStream();
        
$lineno $token->getLine();
        
$arguments = new ArrayExpression([], $lineno);

        
// slice?
        
$slice false;
        if (
$stream->test(Token::PUNCTUATION_TYPE':')) {
            
$slice true;
            
$attribute = new ConstantExpression(0$token->getLine());
        } else {
            
$attribute $parser->parseExpression();
        }

        if (
$stream->nextIf(Token::PUNCTUATION_TYPE':')) {
            
$slice true;
        }

        if (
$slice) {
            if (
$stream->test(Token::PUNCTUATION_TYPE']')) {
                
$length = new ConstantExpression(null$token->getLine());
            } else {
                
$length $parser->parseExpression();
            }

            
$filter $parser->getFilter('slice'$token->getLine());
            
$arguments = new Nodes([$attribute$length]);
            
$filter = new ($filter->getNodeClass())($expr$filter$arguments$token->getLine());

            
$stream->expect(Token::PUNCTUATION_TYPE']');

            return 
$filter;
        }

        
$stream->expect(Token::PUNCTUATION_TYPE']');

        return new 
GetAttrExpression($expr$attribute$argumentsTemplate::ARRAY_CALL$lineno);
    }

    public function 
getName(): string
    
{
        return 
'[';
    }

    public function 
getDescription(): string
    
{
        return 
'Array access';
    }

    public function 
getPrecedence(): int
    
{
        return 
512;
    }

    public function 
getAssociativity(): InfixAssociativity
    
{
        return 
InfixAssociativity::Left;
    }
}
Онлайн: 1
Реклама