[DEBUG] correct the regex error in the super size regex pattern (.|\n|\r)*? ==> bad patern

This commit is contained in:
Edouard DUPIN 2016-07-21 15:29:56 +02:00
parent 64b9f31a53
commit 8094d7c5ab
5 changed files with 138 additions and 50 deletions

View File

@ -4,25 +4,38 @@
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification --> <pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="doxygen multiline"> <rule name="doxygen multiline">
<color>commentDoxygen</color> <color>commentDoxygen</color>
<regex>/\*(\*|!)(.|\r|\n)*?\*/</regex> <regex>
<start>/\*(\*|!)</start>
<stop>\*/</stop>
</regex>
<sub>doxyparse</sub> <sub>doxyparse</sub>
</rule> </rule>
<rule name="comment multiline"> <rule name="comment multiline">
<color>comment</color> <color>comment</color>
<regex>/\*(.|\r|\n)*?(\*/|\0)</regex> <regex>
<start>/\*</start>
<stop>\*/</stop>
</regex>
<sub>TODO</sub> <sub>TODO</sub>
</rule> </rule>
<rule name="comment multiline ERROR"> <rule name="comment multiline ERROR">
<color>SYNTAX_ERROR</color> <color>SYNTAX_ERROR</color>
<regex>/\*(.|\r|\n)*</regex> <regex>
<start>/\*</start>
</regex>
</rule> </rule>
<rule name="#if 0"> <rule name="#if 0">
<color>preprocesseur</color> <color>preprocesseur</color>
<regex>#[ \t]*if 0(.|\r|\n)*?#(endif|else)</regex> <regex>
<start>#[ \t]*if 0</start>
<stop>#e(ndif|lse)</stop>
</regex>
</rule> </rule>
<rule name="#if 0 ERROR"> <rule name="#if 0 ERROR">
<color>SYNTAX_ERROR</color> <color>SYNTAX_ERROR</color>
<regex>#[ \t]*if 0(.|\r|\n)*</regex> <regex>
<start>#[ \t]*if 0</start>
</regex>
</rule> </rule>
<rule name="#preproc"> <rule name="#preproc">
<color>preprocesseur</color> <color>preprocesseur</color>

View File

@ -84,11 +84,14 @@ def create(target, module_name):
]) ])
my_module.add_module_depend(['ewol']) my_module.add_module_depend(['ewol'])
my_module.copy_path('data/icon.*','') my_module.copy_path('data/icon.*','')
"""
my_module.copy_path('data/languages/gcov/*.xml','languages/gcov/') 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/asm/*.xml','languages/asm/')
my_module.copy_path('data/languages/bash/*.xml','languages/bash/') 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/boo/*.xml','languages/boo/')
"""
my_module.copy_path('data/languages/cpp/*.xml','languages/cpp/') 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/c/*.xml','languages/c/')
my_module.copy_path('data/languages/cmake/*.xml','languages/cmake/') my_module.copy_path('data/languages/cmake/*.xml','languages/cmake/')
my_module.copy_path('data/languages/glsl/*.xml','languages/glsl/') my_module.copy_path('data/languages/glsl/*.xml','languages/glsl/')
@ -101,6 +104,7 @@ def create(target, module_name):
my_module.copy_path('data/languages/php/*.xml','languages/php/') 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/xml/*.xml','languages/xml/')
my_module.copy_path('data/languages/python/*.xml','languages/python/') 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/*.svg','theme/shape/square/')
my_module.copy_path('data/theme/default/*.edf','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/') my_module.copy_path('data/theme/colorWhite/*.json','theme/color/white/')

View File

@ -223,7 +223,7 @@ void appl::Highlight::parse(int64_t _start,
if (ret == true) { if (ret == true) {
int64_t currentTimeEnd = ewol::getTime(); int64_t currentTimeEnd = ewol::getTime();
int64_t deltaTime = currentTimeEnd - currentTime; 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()); HL_DEBUG("Find Pattern in the Buffer : time=" << (float)deltaTime/1000.0f << " ms (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart << " for=" << m_listHighlightPass1[jjj].getPaternString().first << " " << m_listHighlightPass1[jjj].getPaternString().second);
// remove element in the current List where the current Element have a end inside the next... // remove element in the current List where the current Element have a end inside the next...
int64_t kkk=_addingPos; int64_t kkk=_addingPos;
while(kkk < (int64_t)_metaData.size() ) { while(kkk < (int64_t)_metaData.size() ) {
@ -292,7 +292,7 @@ void appl::Highlight::parse2(int64_t _start,
for (int64_t jjj=0; jjj<int64_t(m_listHighlightPass2.size()); jjj++){ for (int64_t jjj=0; jjj<int64_t(m_listHighlightPass2.size()); jjj++){
HL2_DEBUG("Parse HL id=" << jjj << " position search: (" << HL2_DEBUG("Parse HL id=" << jjj << " position search: (" <<
elementStart << "," << elementStop << ") in='" elementStart << "," << elementStop << ") in='"
<< /*_buffer[elementStart]*/ std::string(_buffer.begin()+elementStart,_buffer.begin()+elementStop) << "' " << m_listHighlightPass2[jjj].getPaternString()); << /*_buffer[elementStart]*/ std::string(_buffer.begin()+elementStart,_buffer.begin()+elementStop) << "' " << m_listHighlightPass2[jjj].getPaternString().first << " " << m_listHighlightPass1[jjj].getPaternString().second);
// Stop the search to the end (to get the end of the pattern) // Stop the search to the end (to get the end of the pattern)
bool ret = m_listHighlightPass2[jjj].find(elementStart, elementStop, resultat, _buffer); bool ret = m_listHighlightPass2[jjj].find(elementStart, elementStop, resultat, _buffer);
if (ret == true) { if (ret == true) {
@ -336,7 +336,7 @@ void appl::Highlight::parseSubElement(const appl::HighlightInfo& _upper,
while (elementStart < elementStop) { while (elementStart < elementStop) {
//try to fond the HL in ALL of we have //try to fond the HL in ALL of we have
for (auto &it : itHL->second){ for (auto &it : itHL->second){
HL2_DEBUG("Parse HL position search: (" << elementStart << "," << elementStop << ") in='" << _buffer[elementStart] << "' " << it.getPaternString()); HL2_DEBUG("Parse HL position search: (" << elementStart << "," << elementStop << ") in='" << _buffer[elementStart] << "' " << it.getPaternString().first << " " << it.getPaternString().second);
// Stop the search to the end (to get the end of the pattern) // Stop the search to the end (to get the end of the pattern)
bool ret = it.find(elementStart, elementStop, resultat, _buffer); bool ret = it.find(elementStart, elementStop, resultat, _buffer);
if (ret == true) { if (ret == true) {

View File

@ -11,7 +11,8 @@ appl::HighlightPattern::HighlightPattern(const ememory::SharedPtr<appl::GlyphPai
m_glyphPainting(_glyphPainting), m_glyphPainting(_glyphPainting),
m_paternName(""), m_paternName(""),
m_hasParsingError(true), m_hasParsingError(true),
m_regexValue(""), m_regexValue(),
m_hasEndRegEx(false),
m_regExp(), m_regExp(),
m_colorName(""), m_colorName(""),
m_level(0) { m_level(0) {
@ -22,7 +23,8 @@ appl::HighlightPattern::HighlightPattern() :
m_glyphPainting(), m_glyphPainting(),
m_paternName(""), m_paternName(""),
m_hasParsingError(true), m_hasParsingError(true),
m_regexValue(""), m_regexValue(),
m_hasEndRegEx(false),
m_regExp(), m_regExp(),
m_colorName(""), m_colorName(""),
m_level(0) { m_level(0) {
@ -33,20 +35,32 @@ appl::HighlightPattern::~HighlightPattern() {
} }
void appl::HighlightPattern::setPatern(const std::string& _regExp) { void appl::HighlightPattern::setPatern(const std::string& _regExp, const std::string& _regExpStop, bool _hasEndRegEx) {
m_regexValue = _regExp; m_regexValue[0] = _regExp;
APPL_DEBUG("parse regex='" << _regExp << "'"); m_regexValue[1] = _regExpStop;
try { m_hasEndRegEx = _hasEndRegEx;
m_regExp.assign(_regExp, std::regex_constants::optimize | std::regex_constants::ECMAScript); APPL_INFO("parse regex='" << _regExp << "' -> '" << _regExpStop << "'");
//m_regExp.assign(_regExp, std::regex_constants::optimize | std::regex_constants::extended); m_hasParsingError = false;
m_hasParsingError = false; if (_regExp != "") {
} catch (std::regex_error e) { try {
m_hasParsingError = true; m_regExp[0].assign(_regExp, std::regex_constants::optimize | std::regex_constants::ECMAScript);
APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << _regExp); } catch (std::regex_error e) {
m_hasParsingError = true;
APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << _regExp);
}
}
if (_regExpStop != "") {
try {
m_regExp[1].assign(_regExpStop, std::regex_constants::optimize | std::regex_constants::ECMAScript);
} catch (std::regex_error e) {
m_hasParsingError = true;
APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << _regExpStop);
}
} }
} }
std::string appl::HighlightPattern::getPaternString() {
return m_regexValue; std::pair<std::string,std::string> appl::HighlightPattern::getPaternString() {
return std::make_pair(m_regexValue[0], m_regexValue[1]);
} }
void appl::HighlightPattern::setColorGlyph(const std::string& _colorName) { void appl::HighlightPattern::setColorGlyph(const std::string& _colorName) {
@ -85,41 +99,51 @@ void appl::HighlightPattern::parseRules(const exml::Element& _child, int32_t _le
if (xChild.exist() == true) { if (xChild.exist() == true) {
std::string myData = xChild.getText(); std::string myData = xChild.getText();
if (myData.size() != 0) { if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
setColorGlyph(myData); setColorGlyph(myData);
} }
} }
std::string paterStart;
std::string paterStop;
xChild = _child.nodes["regex"]; xChild = _child.nodes["regex"];
if (xChild.exist() == true) { if (xChild.exist() == true) {
std::string myData = xChild.getText(); if (xChild.nodes.size() == 1 && xChild.nodes[0].getType() == exml::nodeType::text) {
if (myData.size() != 0) { std::string myData = xChild.getText();
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData); if (myData.size() != 0) {
setPatern(myData); paterStart = myData;
}
setPatern(paterStart);
} else {
exml::Element xxChild = xChild.nodes["start"];
if (xxChild.exist() == true) {
std::string myData = xxChild.getText();
if (myData.size() != 0) {
paterStart = myData;
}
}
xxChild = xChild.nodes["stop"];
if (xxChild.exist() == true) {
std::string myData = xxChild.getText();
if (myData.size() != 0) {
paterStop = myData;
}
}
setPatern(paterStart, paterStop, true);
} }
} }
xChild = _child.nodes["sub"]; xChild = _child.nodes["sub"];
if (xChild.exist() == true) { if (xChild.exist() == true) {
std::string myData = xChild.getText(); std::string myData = xChild.getText();
if (myData.size() != 0) { if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
setSubPatternName(myData); setSubPatternName(myData);
} }
} }
} }
bool appl::HighlightPattern::find(int32_t _start, static std::pair<int64_t,int64_t> findRegex(int32_t _start,
int32_t _stop, int32_t _stop,
appl::HighlightInfo& _resultat, std::regex& _regex,
const std::string& _buffer) { 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 false;
}
std::smatch resultMatch; std::smatch resultMatch;
std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous; // check only the match at the first character. 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 << "'"); //APPL_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'");
@ -145,21 +169,21 @@ bool appl::HighlightPattern::find(int32_t _start,
if ( _stop < 0 if ( _stop < 0
|| size_t(_stop) > _buffer.size()) { || size_t(_stop) > _buffer.size()) {
APPL_ERROR(" error in indexing for regex ... _stop=" << _stop << " >= _buffer.size()=" << _buffer.size()); APPL_ERROR(" error in indexing for regex ... _stop=" << _stop << " >= _buffer.size()=" << _buffer.size());
return false; return std::pair<int64_t,int64_t>(-1,0);
} }
if ( _start < 0 if ( _start < 0
|| size_t(_start) > _buffer.size()) { || size_t(_start) > _buffer.size()) {
APPL_ERROR(" error in indexing for regex ... _start=" << _start << " >= _buffer.size()=" << _buffer.size()); APPL_ERROR(" error in indexing for regex ... _start=" << _start << " >= _buffer.size()=" << _buffer.size());
return false; return std::pair<int64_t,int64_t>(-1,0);
} }
if (_start > _stop) { if (_start > _stop) {
APPL_ERROR(" error in indexing for regex ... _start=" << _start << " > _stop=" << _stop); APPL_ERROR(" error in indexing for regex ... _start=" << _start << " > _stop=" << _stop);
return false; return std::pair<int64_t,int64_t>(-1,0);
} }
std::regex_search(_buffer.begin() + _start, _buffer.begin() + _stop, resultMatch, m_regExp, flags); std::regex_search(_buffer.begin() + _start, _buffer.begin() + _stop, resultMatch, _regex, flags);
if (resultMatch.size() > 0) { if (resultMatch.size() > 0) {
_resultat.start = std::distance(_buffer.begin(), resultMatch[0].first); int64_t start = std::distance(_buffer.begin(), resultMatch[0].first);
_resultat.stop = std::distance(_buffer.begin(), resultMatch[0].second); int64_t stop = std::distance(_buffer.begin(), resultMatch[0].second);
//APPL_DEBUG("find data at : start=" << _resultat.start << " stop=" << _resultat.stop << " data='" <<std::string(_buffer, _resultat.start, _resultat.stop-_resultat.start) << "'" ); //APPL_DEBUG("find data at : start=" << _resultat.start << " stop=" << _resultat.stop << " data='" <<std::string(_buffer, _resultat.start, _resultat.stop-_resultat.start) << "'" );
/* /*
if (true){ if (true){
@ -172,6 +196,52 @@ bool appl::HighlightPattern::find(int32_t _start,
} }
} }
*/ */
return std::pair<int64_t,int64_t>(start,stop);
}
return std::pair<int64_t,int64_t>(-1,0);
}
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 false;
}
// phase 1 start regEx or global regex:
if (m_regexValue[0].size() == 0) {
return false;
}
std::pair<int64_t,int64_t> ret0 = findRegex(_start, _stop, m_regExp[0], _buffer);
if (ret0.first >= 0) {
_resultat.start = ret0.first;
_resultat.stop = ret0.second;
//APPL_DEBUG("find data at : start=" << _resultat.start << " stop=" << _resultat.stop << " data='" <<std::string(_buffer, _resultat.start, _resultat.stop-_resultat.start) << "'" );
// second step : Complex searching ...
if (m_hasEndRegEx == true) {
// when no regex specify ==> get all the buffer ...
if (m_regexValue[1].size() == 0) {
_resultat.stop = _stop;
return true;
}
_start = _resultat.stop;
while (_start < _stop) {
std::pair<int64_t,int64_t> ret1 = findRegex(_start, _stop, m_regExp[1], _buffer);
if (ret1.first >= 0) {
_resultat.stop = ret1.second;
return true;
}
_start++;
}
_resultat.stop = _stop;
_resultat.notEnded = true; // TODO : Manege back the not ended ...
return false;
}
return true; return true;
} }
return false; return false;

View File

@ -42,11 +42,12 @@ namespace appl {
}; };
private: private:
bool m_hasParsingError; bool m_hasParsingError;
std::string m_regexValue; std::string m_regexValue[2];
std::regex m_regExp; //!< Start of Regular expression bool m_hasEndRegEx;
std::regex m_regExp[2]; //!< Start of Regular expression
public: public:
void setPatern(const std::string& _regExp); void setPatern(const std::string& _regExp, const std::string& _regExpStop="", bool _hasEndRegEx=false);
std::string getPaternString(); std::pair<std::string,std::string> getPaternString();
private: private:
std::string m_colorName; //!< Current color name std::string m_colorName; //!< Current color name
int32_t m_colorId; //!< Id of the the glyph painting int32_t m_colorId; //!< Id of the the glyph painting