Will return a list of all the modifiers for a given token.

@param  array $tokenId The tokenId you are analyzing
@param  array $tokens  The array of the currently created tokens
@return array          An array of tokenId's
435193
public static function modifiers($tokenId, array $tokens) {
		if (!in_array($tokens[$tokenId]['id'], array(T_CLASS, T_FUNCTION, T_VARIABLE))) {
			$token = print_r($tokens[$tokenId], true);
			throw new \Exception('Cannot call modifiers on non class/function/variable' . $token);
		}
		$modifiers = array();
		for ($key = $tokenId - 1; $key >= 0; $key--) {
			$token = $tokens[$key];
			if ($token['id'] === T_WHITESPACE) {
				continue;
			} elseif (in_array($token['id'], static::$modifiers)) {
				$modifiers[] = $key;
			} else {
				break;
			}
		}
		return $modifiers;
	}
727138
public function createToken(array $tokenData, $userId = null)
    {
        $userId = $this->_checkUserId($userId);
        return $this->getTokenLibrary()->createToken($tokenData, $userId);
    }
383803
public function peekWhileTokens(array $tokenNames)
    {
        while ($token = $this->peek()) {
            if (!in_array($token->getName(), $tokenNames, true)) {
                break;
            }
        }

        return $token;
    }
169231
protected function replaceTokens($string, array $tokens)
    {
        foreach ($tokens as $key => $value) {
            $string = str_replace('{{ '.$key.' }}', $value, $string);
        }

        return $string;
    }
1212675
protected function createSegments(array $tokens) : array
    {
        // Stack of opened tags.
        $active = new TagStack();

        return array_reduce($tokens, function (array $segments, $token) use ($active) {
            if ($token instanceof TagToken) {
                /** @var TagToken $token */
                if ($token->isOpening()) {
                    // If tag token is opening, add tag to the stack.
                    $active->push(Tag::createFromToken($token));
                } else {
                    // If tag token is closing, find matching tag in the stack.
                    $tagName = $token->getTagName();
                    $isFound = $active->removeLast($tagName);
                    if (!$isFound) {
                        // If not found, return tag token as a text.
                        $text = $token->getRawText();
                        $tags = $active->asArray();
                        $segments[] = new TextSegment($text, $tags);
                    }
                }
            } else {
                // Return text segment with currently active tags.
                /** @var TextToken $token */
                $text = $token->getRawText();
                $tags = $active->asArray();
                $segments[] = new TextSegment($text, $tags);
            }

            return $segments;
        }, []);
    }
503731
public function parse(array $tokens)
    {
        $parser = new Parser($this->symbolContainer);

        if ($this->customGrammarChecker !== null) {
            $parser->setCustomGrammarChecker($this->customGrammarChecker);
        }

        $rootNode = $parser->parse($tokens);

        return $rootNode;
    }
550231
private function registerNamespace(int $tokenID)
    {
        $namespace = '';
        $localID = $tokenID + 1;

        do {
            $token = $this->tokens[$localID++];
            if ($token[self::TOKEN_CODE] == '{') {
                break;
            }

            $namespace .= $token[self::TOKEN_CODE];
        } while (
            isset($this->tokens[$localID])
            && $this->tokens[$localID][self::TOKEN_CODE] != '{'
            && $this->tokens[$localID][self::TOKEN_CODE] != ';'
        );

        //Whitespaces
        $namespace = trim($namespace);

        $uses = [];
        if (isset($this->namespaces[$namespace])) {
            $uses = $this->namespaces[$namespace];
        }

        if ($this->tokens[$localID][self::TOKEN_CODE] == ';') {
            $endingID = count($this->tokens) - 1;
        } else {
            $endingID = $this->endingToken($tokenID);
        }

        $this->namespaces[$namespace] = [
            self::O_TOKEN => $tokenID,
            self::C_TOKEN => $endingID,
            self::N_USES  => $uses,
        ];
    }
1293735
public function forNextTokenId($tokenId)
    {
        $this->sql_select->join('gems__tokens as ct',
                'gems__tokens.gto_id_respondent_track = ct.gto_id_respondent_track AND
                    gems__tokens.gto_id_token != ct.gto_id_token AND
                        ((gems__tokens.gto_round_order < ct.gto_round_order) OR
                            (gems__tokens.gto_round_order = ct.gto_round_order AND gems__tokens.gto_created < ct.gto_created))',
                array());

        $this->sql_select
                ->where('ct.gto_id_token = ?', $tokenId)
                ->order('gems__tokens.gto_round_order DESC')
                ->order('gems__tokens.gto_created DESC');

        return $this;
    }
1077341
private function activeDeclaration(int $tokenID): string
    {
        foreach ($this->declarations as $declarations) {
            foreach ($declarations as $name => $position) {
                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
                    return $name;
                }
            }
        }

        //Can not be detected
        return '';
    }
298426
public function forPreviousTokenId($tokenId) {
        $this->sql_select->join('gems__tokens as ct',
                'gems__tokens.gto_id_respondent_track = ct.gto_id_respondent_track AND
                    gems__tokens.gto_id_token != ct.gto_id_token AND
                        ((gems__tokens.gto_round_order > ct.gto_round_order) OR
                            (gems__tokens.gto_round_order = ct.gto_round_order AND gems__tokens.gto_created > ct.gto_created))',
                array());

        $this->sql_select
                ->where('ct.gto_id_token = ?', $tokenId)
                ->order('gems__tokens.gto_round_order')
                ->order('gems__tokens.gto_created');

        return $this;
    }
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;
    }
729480
protected function updateTokens(array $tokens)
    {
        $this->roles = null;
        $this->contextHash = null;

        if ($this->request === null) {
            return;
        }

        /** @var $token TokenInterface */
        foreach ($tokens as $token) {
            $token->updateCredentials($this->request);
        }

        $sessionDataContainer = $this->objectManager->get(SessionDataContainer::class);
        $sessionDataContainer->setSecurityTokens(array_merge($this->inactiveTokens, $this->activeTokens));
    }
516544
public function getAllDrafts(TokenInterface $token)
    {
        $owner = UserSecurityIdentity::fromToken($token);
        $states = [Revision::STATE_ADDED, Revision::STATE_MODIFIED];

        $result = [];

        try {
            $result = $this->findBy([
                '_owner' => $owner,
                '_state' => $states,
            ]);
        } catch (ConversionException $e) {
            $result = [];
            foreach ($this->getAllDraftsUids($owner, $states) as $data) {
                try {
                    $result[] = $this->find($data['_uid']);
                } catch (ConversionException $e) {
                    $this->_em->getConnection()->executeUpdate(
                        'DELETE FROM revision WHERE uid = :uid',
                        ['uid' => $data['_uid']]
                    );
                }
            }
        } catch (MappingException $e) {
            $result = [];
            foreach ($this->getAllDraftsUids($owner, $states) as $data) {
                $draft = $this->find($data['_uid']);
                if (null !== $draft->getContent()) {
                    $result[] = $draft;
                } else {
                    $this->_em->getConnection()->executeUpdate(
                        'DELETE FROM revision WHERE uid = :uid',
                        ['uid' => $data['_uid']]
                    );
                }
            }
        }

        return $result;
    }
998564
public function get_token_data($tokenId) {
		try {
			$sql = "SELECT *, (max_uses - total_uses) as remaining_uses, "
					. "(NOW() - expiration) as time_remaining "
					. "FROM ". $this->table ." AS t1 INNER JOIN 
						cswal_token_type_table AS t2 ON (t1.token_type_id=t2.token_type_id)
						WHERE auth_token_id=:tokenId";
			try {
				$numrows = $this->db->run_query($sql, array('tokenId'=>$tokenId));

				if($numrows == 1) {
					$tokenData = $this->db->get_single_record();
				}
				elseif($numrows < 1) {
					$tokenData = false;
				}
				else {
					throw new exception("too many records returned (". count($data) .")");
				}
			} catch(Exception $e) {
				throw new exception(__METHOD__ .": Failed to retrieve token data::: ". $e->getMessage());
			}
		}
		catch(exception $e) {
			throw new exception(__METHOD__ .": failed to retrieve tokenId (". $tokenId .")::: ". $e->getMessage());
		}
		return($tokenData);
	}
801227
protected static function _tokenize(array $tokens) {
		$inString = false;
		$results = array();
		$cpt = 0;
		$previousTokenId = null;
		foreach ($tokens as $tokenId => $token) {
			if ($token['content'] === '"') {
				if (!$inString) {
					$token['id'] = T_START_DOUBLE_QUOTE;
					$token['name'] = 'T_START_DOUBLE_QUOTE';
				} else {
					$token['id'] = T_END_DOUBLE_QUOTE;
					$token['name'] = 'T_END_DOUBLE_QUOTE';
				}
				$inString = !$inString;
			}

			$isCurlyBrace = (
				$token['content'] === '$' &&
				isset($tokens[$tokenId + 1]) &&
				$tokens[$tokenId + 1]['content'] === '{'
			);
			if ($isCurlyBrace) {
				$token['id'] = T_DOLLAR_CURLY_BRACES;
				$token['name'] = 'T_DOLLAR_CURLY_BRACES';
			}

			$isArray = (
				!$token['id'] &&
				$token['content'] === '(' &&
				$previousTokenId !== null &&
				$tokens[$previousTokenId]['id'] === T_ARRAY
			);
			if ($isArray) {
				$token['id'] = T_ARRAY_OPEN;
				$token['name'] = 'T_ARRAY_OPEN';
			}

			$isShortArray = (
				!$token['id'] &&
				$token['content'] === '[' &&
				$previousTokenId !== null && (
					$tokens[$previousTokenId]['id'] !== T_VARIABLE &&
					$tokens[$previousTokenId]['id'] !== T_ENCAPSED_AND_WHITESPACE
				)
			);
			if ($isShortArray) {
				$token['id'] = T_SHORT_ARRAY_OPEN;
				$token['name'] = 'T_SHORT_ARRAY_OPEN';
			}

			if ($token['content'] === '(' && !$token['id']) {
				$token['id'] = T_START_BRACKET;
				$token['name'] = 'T_START_BRACKET';
			}

			if ($token['id'] !== T_WHITESPACE) {
				$previousTokenId = $tokenId;
			}

			if ($token['id'] === T_IF) {
				$i = $cpt;
				$spaces = '';
				while ($i-- > 0 && $results[$i]['id'] === T_WHITESPACE) {
					$spaces = $results[$i]['content'] . $spaces;
				}
				if ($i >= 0 && $results[$i]['id'] === T_ELSE) {
					$token['id'] = T_ELSEIF;
					$token['name'] = 'T_ELSEIF';
					$token['content'] = $results[$i]['content'] . $spaces . $token['content'];
					$cpt = $i;
				}
			}

			$results[$cpt++] = $token;
		}

		return $results;
	}
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);
    }
74682
public function apply(array &$tokens)
		{
		$r = 0;
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			$current	= get_class($tokens[$i]);
			$next		= isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false;
			if (($current === "CssRulesetStartToken" && $next === "CssRulesetEndToken") ||
				($current === "CssAtKeyframesRulesetStartToken" && $next === "CssAtKeyframesRulesetEndToken" && !array_intersect(array("from", "0%", "to", "100%"), array_map("strtolower", $tokens[$i]->Selectors)))
				)
				{
				$tokens[$i]		= null;
				$tokens[$i + 1]	= null;
				$i++;
				$r = $r + 2;
				}
			}
		return $r;
		}