colorize_regex_factory: transform boost::regex_error in Kakoune::runtime_error

This commit is contained in:
Maxime Coste 2012-08-07 00:32:21 +02:00
parent c166bc92e3
commit 661c9db925

View File

@ -96,30 +96,37 @@ HighlighterAndId colorize_regex_factory(Window& window,
if (params.size() < 2) if (params.size() < 2)
throw runtime_error("wrong parameter count"); throw runtime_error("wrong parameter count");
Regex ex(params[0].begin(), params[0].end(), try
boost::regex::perl | boost::regex::optimize);
static Regex color_spec_ex(LR"((\d+):(\w+)(,(\w+))?)");
ColorSpec colors;
for (auto it = params.begin() + 1; it != params.end(); ++it)
{ {
boost::match_results<String::iterator> res; static Regex color_spec_ex(LR"((\d+):(\w+)(,(\w+))?)");
if (not boost::regex_match(it->begin(), it->end(), res, color_spec_ex)) ColorSpec colors;
throw runtime_error("wrong colorspec: '" + *it + for (auto it = params.begin() + 1; it != params.end(); ++it)
"' expected <capture>:<fgcolor>[,<bgcolor>]"); {
boost::match_results<String::iterator> res;
if (not boost::regex_match(it->begin(), it->end(), res, color_spec_ex))
throw runtime_error("wrong colorspec: '" + *it +
"' expected <capture>:<fgcolor>[,<bgcolor>]");
int capture = str_to_int(String(res[1].first, res[1].second)); int capture = str_to_int(String(res[1].first, res[1].second));
Color fg_color = parse_color(String(res[2].first, res[2].second)); Color fg_color = parse_color(String(res[2].first, res[2].second));
Color bg_color = res[4].matched ? Color bg_color = res[4].matched ?
parse_color(String(res[4].first, res[4].second)) parse_color(String(res[4].first, res[4].second))
: Color::Default; : Color::Default;
colors[capture] = { fg_color, bg_color }; colors[capture] = { fg_color, bg_color };
}
String id = "colre'" + params[0] + "'";
Regex ex(params[0].begin(), params[0].end(),
boost::regex::perl | boost::regex::optimize);
return HighlighterAndId(id, std::bind(colorize_regex, _1, ex,
std::move(colors)));
}
catch (boost::regex_error& err)
{
throw runtime_error(String("regex error: ") + err.what());
} }
String id = "colre'" + params[0] + "'";
return HighlighterAndId(id, std::bind(colorize_regex, _1, ex,
std::move(colors)));
} }
void expand_tabulations(Window& window, DisplayBuffer& display_buffer) void expand_tabulations(Window& window, DisplayBuffer& display_buffer)