tokens; } /** * Add a token to the result. * * @param string $type token type * @param string $value token string * @param string $pos position of the token in the source string * @param string $length length of the token * @param array|null $data additional token information */ public function addToken($type, $value, $pos, $length, array $data = null) { $this->tokens[] = [ 'type' => $type, 'value' => $value, 'pos' => $pos, 'length' => $length, 'data' => $data ]; } /** * Returns all tokens of the given type. * * @param $type * * @return array */ public function getTokensByType($type) { $result = []; foreach ($this->tokens as $token) { if ($token['type'] == $type) { $result[] = $token; } } return $result; } /** * Check whether the expression contains at least one token of the given type. * * @param int $type * * @return bool */ public function hasTokenOfType($type) { foreach ($this->tokens as $token) { if ($token['type'] == $type) { return true; } } return false; } }