|
|
@ -3,20 +3,32 @@ |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
|
|
|
namespace groove { |
|
|
|
namespace groove { |
|
|
|
|
|
|
|
std::unordered_map<Syntax, RulesList> Highlighter::Syntaxes = { |
|
|
|
std::vector<std::pair<std::regex, ncurses::Colors>> Highlighter::list = { |
|
|
|
std::make_pair(Syntax::CPP, |
|
|
|
make_pair("([+-.<>,;=!:&*])", ncurses::Colors::CYAN), |
|
|
|
RulesList { |
|
|
|
make_pair("([\\{\\}\\[\\]\\(\\)])", ncurses::Colors::GREEN), |
|
|
|
make_pair("([+-.<>,;=!:&*])", ncurses::Colors::CYAN), |
|
|
|
make_pair("(^|\\s)(while|if|try|catch|void|this|else|using|namespace|private|public|protected|friend|class|char|bool|unsigned|long|short|int|return)\\s+\\*?", ncurses::Colors::MAGENTA), |
|
|
|
make_pair("([\\{\\}\\[\\]\\(\\)])", ncurses::Colors::GREEN), |
|
|
|
make_pair("([a-zA-Z_][a-zA-Z_0-9]+)::", ncurses::Colors::GREEN), |
|
|
|
make_pair("(^|\\s)(while|if|try|catch|void|this|else|using|namespace|private|public|protected|friend|class|char|bool|unsigned|long|short|int|return):?(\\s+|$)\\*?", ncurses::Colors::MAGENTA), |
|
|
|
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::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("\\.([a-zA-Z_][a-zA-Z_0-9]+)", ncurses::Colors::CYAN), |
|
|
|
make_pair("\\\".*\\\"", ncurses::Colors::ORANGE), |
|
|
|
make_pair("([_a-zA-Z][a-zA-Z0-9_-]+)\\(", ncurses::Colors::CYAN), |
|
|
|
make_pair("/\\*.*\\*//*", ncurses::Colors::COMMENTS), |
|
|
|
make_pair("\\\".*\\\"", ncurses::Colors::ORANGE), |
|
|
|
make_pair("(//.*)", ncurses::Colors::ORANGE) |
|
|
|
make_pair("/\\*.*\\*//*", ncurses::Colors::COMMENTS), |
|
|
|
|
|
|
|
make_pair("(//.*)", ncurses::Colors::ORANGE) |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
std::make_pair(Syntax::DEFAULT, |
|
|
|
|
|
|
|
RulesList { |
|
|
|
|
|
|
|
make_pair("([.,;!\\*])", ncurses::Colors::MAGENTA), |
|
|
|
|
|
|
|
make_pair("([\\{\\}\\[\\]\\(\\)])", ncurses::Colors::GREEN), |
|
|
|
|
|
|
|
make_pair("\\\".*\\\"", ncurses::Colors::ORANGE), |
|
|
|
|
|
|
|
make_pair("/\\*.*\\*//*", ncurses::Colors::COMMENTS), |
|
|
|
|
|
|
|
}) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RulesList Highlighter::list = RulesList(); |
|
|
|
|
|
|
|
|
|
|
|
std::unordered_map<long, std::pair<long, ncurses::Colors>> groove::Highlighter::get() { |
|
|
|
std::unordered_map<long, std::pair<long, ncurses::Colors>> groove::Highlighter::get() { |
|
|
|
std::unordered_map<long, std::pair<long, ncurses::Colors>> list; |
|
|
|
std::unordered_map<long, std::pair<long, ncurses::Colors>> list; |
|
|
|
|
|
|
|
|
|
|
@ -26,7 +38,7 @@ namespace groove { |
|
|
|
return list; |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (auto& keyword : Highlighter::list) { |
|
|
|
for (auto &keyword : Highlighter::list) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
std::sregex_iterator next(this->line.begin(), this->line.end(), keyword.first); |
|
|
|
std::sregex_iterator next(this->line.begin(), this->line.end(), keyword.first); |
|
|
|
std::sregex_iterator end; |
|
|
|
std::sregex_iterator end; |
|
|
@ -37,7 +49,7 @@ namespace groove { |
|
|
|
} |
|
|
|
} |
|
|
|
next++; |
|
|
|
next++; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (std::regex_error& e) { |
|
|
|
} catch (std::regex_error &e) { |
|
|
|
// Syntax error in the regular expression
|
|
|
|
// Syntax error in the regular expression
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -47,3 +59,5 @@ namespace groove { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|