protected function matchTokenTextAtCursor(int $type)
    {
        $result = preg_match($this->getTokenPattern($type), $this->getTextAtCursor(), $matches);
        PregHelper::assertMatchResult(
            $result,
            RegExpException::class,
            "Failed to match token text due to regular expression error"
        );
        if (1 === $result) {
            $text = $matches[0];
            if (strlen($text) == 0) {
                throw new LengthException("Matched token text is empty");
            }
        } else {
            $text = null;
        }
        return $text;
    }