Вход Регистрация
Файл: upload/core/vendor/twig/twig/src/ExpressionParser/Infix/BinaryOperatorExpressionParser.php
Строк: 115
<?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 
TwigExpressionParserPrecedenceChange;
use 
TwigNodeExpressionAbstractExpression;
use 
TwigNodeExpressionBinaryAbstractBinary;
use 
TwigParser;
use 
TwigToken;

/**
 * @internal
 */
class BinaryOperatorExpressionParser extends AbstractExpressionParser implements InfixExpressionParserInterfaceExpressionParserDescriptionInterface
{
    public function 
__construct(
        
/** @var class-string<AbstractBinary> */
        
private string $nodeClass,
        private 
string $name,
        private 
int $precedence,
        private 
InfixAssociativity $associativity InfixAssociativity::Left,
        private ?
PrecedenceChange $precedenceChange null,
        private ?
string $description null,
        private array 
$aliases = [],
    ) {
    }

    
/**
     * @return AbstractBinary
     */
    
public function parse(Parser $parserAbstractExpression $leftToken $token): AbstractExpression
    
{
        
$right $parser->parseExpression(InfixAssociativity::Left === $this->getAssociativity() ? $this->getPrecedence() + $this->getPrecedence());

        return new (
$this->nodeClass)($left$right$token->getLine());
    }

    public function 
getAssociativity(): InfixAssociativity
    
{
        return 
$this->associativity;
    }

    public function 
getName(): string
    
{
        return 
$this->name;
    }

    public function 
getDescription(): string
    
{
        return 
$this->description ?? '';
    }

    public function 
getPrecedence(): int
    
{
        return 
$this->precedence;
    }

    public function 
getPrecedenceChange(): ?PrecedenceChange
    
{
        return 
$this->precedenceChange;
    }

    public function 
getAliases(): array
    {
        return 
$this->aliases;
    }
}
Онлайн: 1
Реклама