Converts child tags of raw-content tags to a raw text.

Used in tokenize().

@param Token[] $tokens

@return Token[]
498338
protected function processRawContentTagTokens(array $tokens) : array
    {
        $rawTagName = null;
        return array_reduce($tokens, function (array $tokens, $token) use (&$rawTagName) {
            if (!isset($rawTagName)) {
                // If not in a raw-content tag and current tag is a raw-content, store a tag name.
                if ($token instanceof TagToken) {
                    $tagName = $token->getTagName();
                    $tagDef = $this->tagDefs->get($tagName);
                    if ($tagDef->rawContent()) {
                        $rawTagName = $tagName;
                    }
                }
            } elseif ($token instanceof TagToken && $token->getTagName() === $rawTagName) {
                // If in a raw-content tag and current tag is closing for it, unset the stored tag name.
                $rawTagName = null;
            } else {
                // If in a raw-content tag, return current token as a text token.
                $text = $token->getRawText();
                $token = new TextToken($text);
            }

            // Append current token.
            return array_merge($tokens, [$token]);
        }, []);
    }
432636
private function detectIndent(Tokens $tokens, $index)
	{
		while (true) {
			$whitespaceIndex = $tokens->getPrevTokenOfKind($index, [[T_WHITESPACE]]);

			if ($whitespaceIndex === null) {
				return '';
			}

			$whitespaceToken = $tokens[$whitespaceIndex];

			if (strpos($whitespaceToken->getContent(), "\n") !== false) {
				break;
			}

			$prevToken = $tokens[$whitespaceIndex - 1];

			if ($prevToken->isGivenKind([T_OPEN_TAG, T_COMMENT]) && substr($prevToken->getContent(), -1) === "\n") {
				break;
			}

			$index = $whitespaceIndex;
		}

		$explodedContent = explode("\n", $whitespaceToken->getContent());

		return end($explodedContent);
	}
236128
protected function generateNamespaceContext(array & $tokens)
	{
		$namespaceContext = new NamespaceContext();
		
		for($size = count($tokens), $i = 0; $i < $size; $i++)
		{
			if(is_array($tokens[$i]))
			{
				switch($tokens[$i][0])
				{
					case T_NAMESPACE:
						
						$namespace = '';
						
						for($i++; $i < $size; $i++)
						{
							if(is_array($tokens[$i]))
							{
								switch($tokens[$i][0])
								{
									case T_WHITESPACE:
									case T_COMMENT:
									case T_DOC_COMMENT:
										continue 2;
									case T_NS_SEPARATOR:
									case T_STRING:
										$namespace .= $tokens[$i][1];
										continue 2;
								}
							}
							
							break;
						}
						
						$namespaceContext = new NamespaceContext($namespace);
						
						break;
					case T_USE:
						do
						{
							$i++;
							$this->readImport($tokens, $i, $namespaceContext);
						}
						while($tokens[$i] == ',');
						
						break;
					case T_CLASS:
					case T_INTERFACE:
					case T_TRAIT:
						// Abort namespace detection as soon as code declaring a type is reached.
						break 2;
				}
			}
		}
		
		return $namespaceContext;
	}
740503
public static function create(array $tokens, $content) {
        HashMap::assert($tokens, 'tokens');
        $tableAlias = Table::alias($tokens);

        $attributeValueMap = array_map(function($token) use ($content, $tableAlias) {
            $key   = empty($token['alias']['name']) ? $token['base_expr'] : $token['alias']['name'];
            $value = $content[str_replace($tableAlias . '.', '', $token['base_expr'])];
            return [$key => $value];
        }, $tokens['SELECT']);

        return [ array_reduce($attributeValueMap, 'array_merge', []) ];
    }
316077
public static function parseSeries(array $tokens): array
    {
        foreach ($tokens as $token) {
            if ($token->isString()) {
                throw SyntaxErrorException::stringAsFunctionArgument();
            }
        }

        $joined = trim(implode('', array_map(function (Token $token) {
            return $token->getValue();
        }, $tokens)));

        $int = function ($string) {
            if (!is_numeric($string)) {
                throw SyntaxErrorException::stringAsFunctionArgument();
            }

            return (int) $string;
        };

        switch (true) {
            case 'odd' === $joined:
                return [2, 1];
            case 'even' === $joined:
                return [2, 0];
            case 'n' === $joined:
                return [1, 0];
            case false === strpos($joined, 'n'):
                return [0, $int($joined)];
        }

        $split = explode('n', $joined);
        $first = isset($split[0]) ? $split[0] : null;

        return [
            $first ? ('-' === $first || '+' === $first ? $int($first.'1') : $int($first)) : 1,
            isset($split[1]) && $split[1] ? $int($split[1]) : 0,
        ];
    }
666717
public static function findClassInNextTokens($tokens, $i)
    {
        $classname = '';
        for ($j = $i; TokenUtils::isTokenType($tokens[$j],
            array(T_NS_SEPARATOR, T_STRING)); $j++) {
            $classname .= self::tokenStr($tokens[$j]);
        }
        if ($classname && !in_array($classname, self::IGNORED_KEYWORDS)) {
            return new FoundClass($classname, $i, $j - 1);
        }

        return null;
    }
809189
public static function replaceTokens($data, $tokens)
    {
        if (is_string($data)) {
            return preg_replace_callback('/%(\w+)%/', function ($matches) use ($tokens) {
                $token = strtoupper($matches[1]);
                if (isset($tokens[$token])) {
                    return $tokens[$token];
                }

                return getenv($token) ?: $matches[0];
            }, $data);
        }

        if (is_array($data)) {
            array_walk($data, function (&$value) use ($tokens) {
                $value = static::replaceTokens($value, $tokens);
            });
        }

        return $data;
    }
563281
protected function getContent(array $tokens, int $start, int $end): string
    {
        $content = '';
        for ($i = $start; $i <= $end; $i++) {
            $content .= $tokens[$i]['content'];
        }

        return $content;
    }
187807
protected function extractClassNames(array $tokens) : array {
    $classes = [];
    $namespace = $this->extractNamespace($tokens);
    foreach ($tokens as $id => $token) {
      if ($token[0] == T_CLASS) {
        $classes[] = $namespace ? $namespace . '\\' . $tokens[$id+2][1] : $tokens[$id+2][1];
      }
    }
    return $classes;
  }
639330
public function replaceTokens($text, $tokens = [])
    {
        // Obtain Token Mappings:
        
        $mappings = $this->getTokenMappings();
        
        // Iterate Token Mappings:
        
        foreach ($mappings as $name => $spec) {
            
            // Ignore Custom Mappings:
            
            if (isset($spec['custom']) && $spec['custom']) {
                continue;
            }
            
            // Check Property Defined:
                
            if (!isset($spec['property'])) {
                throw new Exception(sprintf('Property is undefined for token mapping "%s"', $name));
            }
            
            // Obtain Value for Token:
            
            $value = isset($tokens[$name]) ? $tokens[$name] : $this->getPropertyValue($spec['property']);
            
            // Perform Token Replacement:
            
            $text = str_ireplace("{{$name}}", $value, $text);
            
        }
        
        // Answer Processed Text:
        
        return $text;
    }
1132206
public function generateUrl(array $tokens = [])
    {
        $path = $this->path;

        foreach ($tokens as $key => $value) {
            $path = str_replace(":{$key}", $value, $path);
        }

        return $path;
    }
968484
public static function tokenPreviousCharacterIsWhiteSpace($token, &$originalTokens)
    {
        return (isset($originalTokens[$token['i'] - 1])
            && $originalTokens[$token['i'] - 1][Tokenizer::TOKEN_TYPE] !== Tokenizer::TOKEN_TYPE_WHITESPACE);
    }
159501
public static function create(array $tokens, array $content) {
        $content = self::orderBy($tokens, $content);

        return array_map(function($entry) use ($tokens) {
            $row = SelectSingleResult::create($tokens, $entry);
            return array_pop($row);
        }, $content);
    }
49025
public static function create(array $tokens) {
        HashMap::assert($tokens, 'tokens');

        $columns = array_map(function($token) {
            $segments = explode('=', $token['base_expr']);
            return trim($segments[0]);
        }, $tokens['SET']);

        $values = array_map(function($token) {
            $segments = explode('=', $token['base_expr']);
            return Value::create(trim($segments[1]));
        }, $tokens['SET']);

        return array_combine($columns, $values);
    }
1200352
public function parse($tokens = null, $additional = [], $embedded = false)
    {
        if (is_string($tokens)) {
            $tokens = $this->tokenize($tokens, $additional, $embedded);
        } elseif (!$tokens instanceof TokenIterator) {
            // Todo: Own Exceptions
            throw new \InvalidArgumentException('$tokens must be string or TokenIterator');
        }

        return $this->_process($tokens);
    }
475682
public static function alias(array $tokens) {
        $column     = self::column($tokens, new MetaData());
        $tableAlias = Table::alias($tokens);

        return empty($tableAlias) ? $column : $tableAlias . '.' . $column;
    }
866388
public function serializeNodes(array $nodes, $language, TokenInterface $token)
    {
        $return = [];

        foreach ($nodes as $node) {
            $nodeData = $this->serializeNode($node, $language, $token);

            if ($nodeData) {
                $return[] = $nodeData;
            }
        }

        return $return;
    }