[DEV] Update the parsing of many languages (pyton, cmake) is now good

This commit is contained in:
2014-10-09 21:23:19 +02:00
parent 67a08dd775
commit a201439665
24 changed files with 170 additions and 91 deletions

View File

@@ -691,7 +691,7 @@ void appl::Buffer::removeSelection() {
void appl::Buffer::tryFindHighlightType() {
etk::FSNode file(m_fileName);
std::string type = appl::highlightManager::getTypeExtention(file.fileGetExtention());
std::string type = appl::highlightManager::getTypeFile(file.getNameFile());
if (type.size() == 0) {
return;
}

View File

@@ -390,31 +390,13 @@ void MainWindows::displayProperty() {
} else {
#ifdef SDGSDFGSDFGSDFGSDFGSTERGDHFGHFDS
std::string menuDescription = "<title>Properties</title>\n";
menuDescription += "<group>\n";
menuDescription += " <title>Editor</title>\n";
menuDescription += " <menu>\n";
menuDescription += " <title>Editor Interface</title>\n";
menuDescription += " <short-title>Editor</short-title>\n";
menuDescription += " <widget>appl-text-viewer</widget>\n";
menuDescription += " </menu>\n";
menuDescription += "<group title='Editor'>\n";
menuDescription += " <menu title='Editor Interface' short-title='Editor' widget='appl-text-viewer'>\n";
menuDescription += "</group>\n";
menuDescription += "<group>\n";
menuDescription += " <title>Gui</title>\n";
menuDescription += " <menu>\n";
menuDescription += " <title>Font selection</title>\n";
menuDescription += " <short-title>Font</short-title>\n";
menuDescription += " <widget></widget>\n";
menuDescription += " </menu>\n";
menuDescription += " <menu>\n";
menuDescription += " <title>Color selection</title>\n";
menuDescription += " <short-title>Color</short-title>\n";
menuDescription += " <widget></widget>\n";
menuDescription += " </menu>\n";
menuDescription += " <menu>\n";
menuDescription += " <title>Theme selection</title>\n";
menuDescription += " <short-title>Theme</short-title>\n";
menuDescription += " <widget></widget>\n";
menuDescription += " </menu>\n";
menuDescription += "<group title='Gui'>\n";
menuDescription += " <menu title='Font selection' short-title='Font' widget=''>\n";
menuDescription += " <menu title='Color selection' short-title='Color' widget=''>\n";
menuDescription += " <menu title='Theme selection' short-title='Theme' widget=''>\n";
menuDescription += "</group>\n";
tmpWidget->setMenu(menuDescription);

View File

@@ -114,13 +114,28 @@ appl::Highlight::~Highlight() {
m_listExtentions.clear();
}
bool appl::Highlight::hasExtention(const std::string& _ext) {
bool appl::Highlight::isCompatible(const std::string& _name) {
for (auto &it : m_listExtentions) {
APPL_VERBOSE(" check : " << it << "=?=" << _ext);
if ( it == "*." + _ext
|| it == _ext) {
return true;
APPL_VERBOSE(" check : " << it << "=?=" << _name);
std::regex expression;
try {
expression.assign(it, std::regex_constants::optimize | std::regex_constants::ECMAScript);
} catch (std::regex_error e) {
APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << it);
continue;
}
std::smatch resultMatch;
std::regex_search(_name.begin(), _name.end(), resultMatch, expression, std::regex_constants::match_continuous);
if (resultMatch.size() <= 0) {
continue;
}
if (resultMatch[0].first != _name.begin()) {
continue;
}
if (resultMatch[0].second != _name.end()) {
continue;
}
return true;
}
return false;
}

View File

@@ -48,7 +48,7 @@ namespace appl {
return m_typeName;
}
public:
bool hasExtention(const std::string& _ext);
bool isCompatible(const std::string& _name);
bool fileNameCompatible(const std::string& _fileName);
void display();
void parse(int64_t _start,

View File

@@ -70,19 +70,19 @@ void appl::highlightManager::unInit() {
hlList.clear();
}
std::string appl::highlightManager::getTypeExtention(const std::string& _extention) {
if (_extention.size() == 0) {
std::string appl::highlightManager::getTypeFile(const std::string& _fileName) {
if (_fileName.size() == 0) {
return "";
}
APPL_DEBUG("Try to find type for extention : '" << _extention << "' in " << s_list().size() << " types");
APPL_DEBUG("Try to find type for extention : '" << _fileName << "' in " << s_list().size() << " types");
std::vector<std::shared_ptr<Highlight>>& hlList = s_list();
for (auto &it : hlList) {
if (it == nullptr) {
continue;
}
APPL_DEBUG(" check : " << it->getTypeName());
if (it->hasExtention(_extention) == true) {
APPL_DEBUG("Find type for extention : " << _extention
if (it->isCompatible(_fileName) == true) {
APPL_DEBUG("Find type for extention : " << _fileName
<< " type : " << it->getTypeName());
return it->getTypeName();
}

View File

@@ -27,10 +27,10 @@ namespace appl {
void unInit();
/**
* @brief Un-Init the Highlight manager
* @param[in] extention of the file
* @param[in] _fileName name of the file
* @return type of highlight
*/
std::string getTypeExtention(const std::string& _extention);
std::string getTypeFile(const std::string& _fileName);
/**
* @brief Get filename with type.
* @param[in] _type Type name of the highlight.