[DEV] correct the regex parsing error in the second highlight pass

This commit is contained in:
Edouard DUPIN 2016-01-15 00:01:58 +01:00
parent c9b86afea0
commit d3d4650d62
6 changed files with 34 additions and 40 deletions

View File

@ -66,7 +66,7 @@
</rule>
<rule name="std type">
<color>type</color>
<regex>\b(std(11)?|boost)::[\w:]*\b</regex>
<regex>\b(std(11)?|boost)::[\w:]*</regex>
</rule>
<rule name="my storage keyword">
<color>storageKeyword</color>

View File

@ -508,13 +508,11 @@ bool appl::TextViewer::onEventInput(const ewol::event::Input& _event) {
markToRedraw();
return true;
}
APPL_VERBOSE("event : " << _event);
// Second call plugin
if (m_pluginManager->onEventInput(*this, _event) == true) {
markToRedraw();
return true;
}
APPL_VERBOSE("event2 : " << _event);
vec2 relativePos = relativePosition(_event.getPos());
// offset for the lineNumber:
relativePos -= vec2(m_lastOffsetDisplay, 0);

View File

@ -217,7 +217,7 @@ void appl::Highlight::parse(int64_t _start,
int64_t currentTime = ewol::getTime();
//try to fond the HL in ALL of we have
for (int64_t jjj=0; jjj<(int64_t)m_listHighlightPass1.size(); jjj++){
enum resultFind ret = HLP_FIND_OK;
bool ret = true;
/*
if (_buffer[elementStart] == '\n') {
HL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='\\n' " << m_listHighlightPass1[jjj].getPaternString());
@ -227,7 +227,7 @@ void appl::Highlight::parse(int64_t _start,
*/
// Stop the search to the end (to get the end of the pattern)
ret = m_listHighlightPass1[jjj].find(elementStart, _buffer.size(), resultat, _buffer);
if (HLP_FIND_ERROR != ret) {
if (ret == true) {
int64_t currentTimeEnd = ewol::getTime();
int64_t deltaTime = currentTimeEnd - currentTime;
HL_DEBUG("Find Pattern in the Buffer : time=" << (float)deltaTime/1000.0f << " ms (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart << " for=" << m_listHighlightPass1[jjj].getPaternString());
@ -282,8 +282,8 @@ void appl::Highlight::parse(int64_t _start,
*/
void appl::Highlight::parse2(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
std::string&_buffer) {
std::vector<appl::HighlightInfo>& _metaData,
std::string& _buffer) {
HL2_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() <<
" == > position search: (" << _start << "," << _stop << ")" );
int64_t elementStart = _start;
@ -296,15 +296,16 @@ void appl::Highlight::parse2(int64_t _start,
}
//HL2_DEBUG("Parse element in the buffer pos=" << elementStart << "," << _buffer.size() << ")" );
//try to fond the HL in ALL of we have
for (int64_t jjj=0; jjj<(int64_t)m_listHighlightPass2.size(); jjj++){
enum resultFind ret;
for (int64_t jjj=0; jjj<int64_t(m_listHighlightPass2.size()); jjj++){
HL2_DEBUG("Parse HL id=" << jjj << " position search: (" <<
elementStart << "," << elementStop << ") in='"
<< _buffer[elementStart] << "' " << m_listHighlightPass2[jjj].getPaternString());
<< /*_buffer[elementStart]*/ std::string(_buffer.begin()+elementStart,_buffer.begin()+elementStop) << "' " << m_listHighlightPass2[jjj].getPaternString());
// Stop the search to the end (to get the end of the pattern)
ret = m_listHighlightPass2[jjj].find(elementStart, elementStop, resultat, _buffer);
if (ret != HLP_FIND_ERROR) {
bool ret = m_listHighlightPass2[jjj].find(elementStart, elementStop, resultat, _buffer);
if (ret == true) {
// find an element:
_metaData.push_back(resultat);
HL2_DEBUG("data='" << std::string(_buffer.begin()+elementStart,_buffer.begin()+resultat.stop) << "'");
elementStart = resultat.stop-1;
break;
}
@ -342,11 +343,10 @@ void appl::Highlight::parseSubElement(const appl::HighlightInfo& _upper,
while (elementStart < elementStop) {
//try to fond the HL in ALL of we have
for (auto &it : itHL->second){
enum resultFind ret;
HL2_DEBUG("Parse HL position search: (" << elementStart << "," << elementStop << ") in='" << _buffer[elementStart] << "' " << it.getPaternString());
// Stop the search to the end (to get the end of the pattern)
ret = it.find(elementStart, elementStop, resultat, _buffer);
if (ret != HLP_FIND_ERROR) {
bool ret = it.find(elementStart, elementStop, resultat, _buffer);
if (ret == true) {
_metaData.push_back(resultat);
elementStart = resultat.stop-1;
break;

View File

@ -114,22 +114,20 @@ void appl::HighlightPattern::parseRules(const std::shared_ptr<const exml::Elemen
}
enum resultFind appl::HighlightPattern::find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::string& _buffer) {
bool appl::HighlightPattern::find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::string& _buffer) {
//APPL_DEBUG(" try to find the element");
_resultat.start = -1;
_resultat.stop = -1;
_resultat.notEnded = false;
_resultat.patern = this;
if (m_hasParsingError == true) {
return HLP_FIND_ERROR;
return false;
}
std::smatch resultMatch;
std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous; // check only the match at the first character.
//APPL_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'");
if ((int64_t)_stop <= (int64_t)_buffer.size()) {
char val = _buffer[_stop];
@ -138,12 +136,14 @@ enum resultFind appl::HighlightPattern::find(int32_t _start,
//after last char ==> not end of line ($ would not work))
flags |= std::regex_constants::match_not_eol;
}
/*
if (!( ('a' <= val && val <= 'z')
|| ('A' <= val && val <= 'Z')
|| ('0' <= val && val <= '9')
|| val == '_')) {
flags |= std::regex_constants::match_not_eow;
}
*/
}
if (_start>0) {
flags |= std::regex_constants::match_prev_avail;
@ -156,15 +156,15 @@ enum resultFind appl::HighlightPattern::find(int32_t _start,
/*
if (true){
//TK_DEBUG("in line : '" << etk::to_string(_buffer) << "'");
TK_DEBUG(" Find " << resultMatch.size() << " elements");
APPL_DEBUG(" Find " << resultMatch.size() << " elements");
for (size_t iii=0; iii<resultMatch.size(); ++iii) {
int32_t posStart = std::distance(_buffer.begin(), resultMatch[iii].first);
int32_t posStop = std::distance(_buffer.begin(), resultMatch[iii].second);
TK_DEBUG(" [" << iii << "] " << posStart << " to " << posStop);
APPL_DEBUG(" [" << iii << "] " << posStart << " to " << posStop);
}
}
*/
return HLP_FIND_OK;
return true;
}
return HLP_FIND_ERROR;
return false;
}

View File

@ -13,18 +13,11 @@
class HighlightPattern;
#include <appl/GlyphPainting.h>
#include <vector>
#include <regex>
#include <exml/exml.h>
enum resultFind {
HLP_FIND_ERROR,
HLP_FIND_OK,
HLP_FIND_OK_NO_END,
};
namespace appl {
class HighlightPattern {
private:
@ -86,14 +79,13 @@ namespace appl {
* @param[in] _stop End of the possibility whe search can continue
* @param[out] _resultat Position where find data
* @param[in] _buffer : Where to search data
* @return HLP_FIND_OK We find a compleate pattern
* @return HLP_FIND_OK_NO_END Xe find a partial pattern (missing end)
* @return HLP_FIND_ERROR Not find the pattern
* @return true We find a compleate pattern
* @return false Not find the pattern
*/
enum resultFind find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::string& _buffer);
bool find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::string& _buffer);
void parseRules(const std::shared_ptr<const exml::Element>& _child, int32_t _level);
};

View File

@ -97,11 +97,14 @@ def create(target, module_name):
"-DPROJECT_NAME=\"\\\""+my_module.name+"\\\"\""
])
my_module.copy_path('../data/icon.*','')
"""
my_module.copy_path('../data/languages/gcov/*.xml','languages/gcov/')
my_module.copy_path('../data/languages/asm/*.xml','languages/asm/')
my_module.copy_path('../data/languages/bash/*.xml','languages/bash/')
my_module.copy_path('../data/languages/boo/*.xml','languages/boo/')
"""
my_module.copy_path('../data/languages/cpp/*.xml','languages/cpp/')
"""
my_module.copy_path('../data/languages/c/*.xml','languages/c/')
my_module.copy_path('../data/languages/cmake/*.xml','languages/cmake/')
my_module.copy_path('../data/languages/glsl/*.xml','languages/glsl/')
@ -114,6 +117,7 @@ def create(target, module_name):
my_module.copy_path('../data/languages/php/*.xml','languages/php/')
my_module.copy_path('../data/languages/xml/*.xml','languages/xml/')
my_module.copy_path('../data/languages/python/*.xml','languages/python/')
"""
my_module.copy_path('../data/theme/default/*.svg','theme/shape/square/')
my_module.copy_path('../data/theme/default/*.edf','theme/shape/square/')
my_module.copy_path('../data/theme/colorWhite/*.json','theme/color/white/')