added special case for #include highlighting, because of the lack of negative lookahead in `std::regex`

development
Michael Ochmann 8 years ago
parent 2e039c3f4d
commit d3839314e3
  1. 11
      src/Highlighter.cpp

@ -6,12 +6,13 @@ namespace groove {
std::vector<std::pair<std::regex, ncurses::Colors>> Highlighter::list = {
make_pair("(#[a-z]+ ?)(.*)", ncurses::Colors::ORANGE),
make_pair("([+-.<>,;=!:])", ncurses::Colors::CYAN),
make_pair("([+-.<>,;=!:&*])", ncurses::Colors::CYAN),
make_pair("([\\{\\}\\[\\]\\(\\)])", ncurses::Colors::GREEN),
make_pair("(while|if|try|catch|void|this|else|namespace|private|public|protected|class|char|bool|unsigned|long|short|int|return)\\*?", ncurses::Colors::MAGENTA),
make_pair("(^|\\s)(while|if|try|catch|void|this|else|using|namespace|private|public|protected|friend|class|char|bool|unsigned|long|short|int|return)\\*?", ncurses::Colors::MAGENTA),
make_pair("([a-zA-Z_][a-zA-Z_0-9]+)::", ncurses::Colors::GREEN),
make_pair("::([a-zA-Z_][a-zA-Z_0-9]+)", ncurses::Colors::CYAN),
make_pair("\\.([a-zA-Z_][a-zA-Z_0-9]+)", ncurses::Colors::CYAN),
make_pair("([_a-zA-Z][a-zA-Z0-9_-]+)\\(", ncurses::Colors::CYAN),
make_pair("\\\".*\\\"", ncurses::Colors::ORANGE),
make_pair("/\\*.*\\*//*", ncurses::Colors::ORANGE),
make_pair("(//.*)", ncurses::Colors::ORANGE)
@ -20,6 +21,12 @@ namespace groove {
std::unordered_map<long, std::pair<long, ncurses::Colors>> groove::Highlighter::get() {
std::unordered_map<long, std::pair<long, ncurses::Colors>> list;
if (this->line.size() > 0 && this->line.at(0) == '#') {
list.emplace(0, std::make_pair(this->line.size(), ncurses::Colors::ORANGE));
return list;
}
for (auto& keyword : Highlighter::list) {
try {
std::sregex_iterator next(this->line.begin(), this->line.end(), keyword.first);

Loading…
Cancel
Save