Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExpressionParser.php

function ExpressionParser::parseSubscriptExpressionArray

1 call to ExpressionParser::parseSubscriptExpressionArray()
ExpressionParser::parseSubscriptExpression in vendor/twig/twig/src/ExpressionParser.php

File

vendor/twig/twig/src/ExpressionParser.php, line 971

Class

ExpressionParser
Parses expressions.

Namespace

Twig

Code

private function parseSubscriptExpressionArray(Node $node) : AbstractExpression {
    $stream = $this->parser
        ->getStream();
    $token = $stream->getCurrent();
    $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 = $this->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 = $this->parseExpression();
        }
        $filter = $this->getFilter('slice', $token->getLine());
        $arguments = new Nodes([
            $attribute,
            $length,
        ]);
        $filter = new $filter->getNodeClass()($node, $filter, $arguments, $token->getLine());
        $stream->expect(Token::PUNCTUATION_TYPE, ']');
        return $filter;
    }
    $stream->expect(Token::PUNCTUATION_TYPE, ']');
    return new GetAttrExpression($node, $attribute, $arguments, Template::ARRAY_CALL, $lineno);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal