original_string: private static function computeRegexp(array $tokens, int $index, int $firstOptional): string
      {
          $token = $tokens[$index];
          if ('text' === $token[0]) {
              // Text tokens
              return preg_quote($token[1], self::REGEX_DELIMITER);
          } else {
              // Variable tokens
              if (0 === $index && 0 === $firstOptional) {
                  // When the only token is an optional variable token, the separator is required
                  return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
              } else {
                  $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
                  if ($index >= $firstOptional) {
                      // Enclose each optional token in a subpattern to make it optional.
                      // "?:" means it is non-capturing, i.e. the portion of the subject string that
                      // matched the optional subpattern is not passed back.
                      $regexp = "(?:$regexp";
                      $nbTokens = \count($tokens);
                      if ($nbTokens - 1 == $index) {
                          // Close the optional subpatterns
                          $regexp .= str_repeat(')?', $nbTokens - $firstOptional - (0 === $firstOptional ? 1 : 0));
                      }
                  }
  
                  return $regexp;
              }
          }
      }
code: private static function computeRegexp(array $tokens, int $index, int $firstOptional): string
      {
          $token = $tokens[$index];
          if ('text' === $token[0]) {
              // Text tokens
              return preg_quote($token[1], self::REGEX_DELIMITER);
          } else {
              // Variable tokens
              if (0 === $index && 0 === $firstOptional) {
                  // When the only token is an optional variable token, the separator is required
                  return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
              } else {
                  $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
                  if ($index >= $firstOptional) {
                      // Enclose each optional token in a subpattern to make it optional.
                      // "?:" means it is non-capturing, i.e. the portion of the subject string that
                      // matched the optional subpattern is not passed back.
                      $regexp = "(?:$regexp";
                      $nbTokens = \count($tokens);
                      if ($nbTokens - 1 == $index) {
                          // Close the optional subpatterns
                          $regexp .= str_repeat(')?', $nbTokens - $firstOptional - (0 === $firstOptional ? 1 : 0));
                      }
                  }
  
                  return $regexp;
              }
          }
      }
code_tokens: private static function computeRegexp ( array $ tokens , int $ index , int $ firstOptional ) : string { $ token = $ tokens [ $ index ] ; if ( 'text' === $ token [ 0 ] ) { // Text tokens return preg_quote ( $ token [ 1 ] , self :: REGEX_DELIMITER ) ; } else { // Variable tokens if ( 0 === $ index && 0 === $ firstOptional ) { // When the only token is an optional variable token, the separator is required return sprintf ( '%s(?P<%s>%s)?' , preg_quote ( $ token [ 1 ] , self :: REGEX_DELIMITER ) , $ token [ 3 ] , $ token [ 2 ] ) ; } else { $ regexp = sprintf ( '%s(?P<%s>%s)' , preg_quote ( $ token [ 1 ] , self :: REGEX_DELIMITER ) , $ token [ 3 ] , $ token [ 2 ] ) ; if ( $ index >= $ firstOptional ) { // Enclose each optional token in a subpattern to make it optional. // "?:" means it is non-capturing, i.e. the portion of the subject string that // matched the optional subpattern is not passed back. $ regexp = "(?:$regexp" ; $ nbTokens = \ count ( $ tokens ) ; if ( $ nbTokens - 1 == $ index ) { // Close the optional subpatterns $ regexp .= str_repeat ( ')?' , $ nbTokens - $ firstOptional - ( 0 === $ firstOptional ? 1 : 0 ) ) ; } } return $ regexp ; } } }
docstring: Computes the regexp used to match a specific token. It can be static text or a subpattern.
  
  @param array $tokens        The route tokens
  @param int   $index         The index of the current token
  @param int   $firstOptional The index of the first optional token
  
  @return string The regexp pattern for a single token
docstring_tokens: Computes the regexp used to match a specific token . It can be static text or a subpattern .