protected function scan($regex, $type)
    {
        if (preg_match($regex, $this->input, $matches)) {
            $this->consume($matches[0]);

            return $this->token($type, isset($matches[1]) && mb_strlen($matches[1]) > 0 ? $matches[1] : '');
        }
    }