[DEV] first std::regex really work in c++
This commit is contained in:
parent
243d7e7494
commit
d93844d6da
@ -50,71 +50,69 @@
|
||||
<color>doubleQuoteText</color>
|
||||
<regex>'((\\[\\'])|.){1,2}'</regex>
|
||||
</rule>
|
||||
<rule name="simpleQuteTextError">
|
||||
<color>SYNTAX_ERROR</color>
|
||||
<regex>'</regex>
|
||||
</rule>
|
||||
</pass1>
|
||||
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->
|
||||
<rule name="my keyword">
|
||||
<color>keyword</color>
|
||||
<regex>\@return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof\@</regex>
|
||||
<regex>\b(return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof)\b</regex>
|
||||
</rule>
|
||||
<rule name="my function keyword">
|
||||
<color>systemFunction</color>
|
||||
<regex>\@new|delete|try|catch|memset|fopen|fread|fwrite|fgets|fclose|printf|(f|s|diag_)printf|calloc|malloc|realloc|(cyg|sup)_([a-z]|[A-Z]|[0-9]|_)+\@</regex>
|
||||
<regex>\b(new|delete|try|catch|memset|fopen|fread|fwrite|fgets|fclose|printf|(f|s|diag_)printf|calloc|malloc|realloc|(cyg|sup)_([a-z]|[A-Z]|[0-9]|_)+)\b</regex>
|
||||
</rule>
|
||||
<rule name="my type">
|
||||
<color>type</color>
|
||||
<regex>\@bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128)\@</regex>
|
||||
<regex>\b(bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128))\b</regex>
|
||||
</rule>
|
||||
<rule name="std type">
|
||||
<color>type</color>
|
||||
<regex>\@std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair)\@</regex>
|
||||
<regex>\b(std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair))\b</regex>
|
||||
</rule>
|
||||
<rule name="my storage keyword">
|
||||
<color>storageKeyword</color>
|
||||
<regex>\@inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|unsigned|signed|volatile|char|double|float|int|long|short|void|typedef|struct|union|enum\@</regex>
|
||||
<regex>\b(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|unsigned|signed|volatile|char|double|float|int|long|short|void|typedef|struct|union|enum)\b</regex>
|
||||
</rule>
|
||||
<rule name="my common Define">
|
||||
<color>commonDefine</color>
|
||||
<regex>\@NULL|MAX|MIN|__LINE__|__DATA__|__FILE__|__func__|__TIME__|__STDC__\@</regex>
|
||||
<regex>\b(NULL|MAX|MIN|__LINE__|__DATA__|__FILE__|__func__|__TIME__|__STDC__)\b</regex>
|
||||
</rule>
|
||||
<rule name="numeric constant">
|
||||
<color>number</color>
|
||||
<regex>\@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@</regex>
|
||||
<regex>\b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b</regex>
|
||||
</rule>
|
||||
<rule name="my boolean">
|
||||
<color>boolean</color>
|
||||
<regex>\@true|TRUE|false|FALSE\@</regex>
|
||||
<regex>\b(true|TRUE|false|FALSE)\b</regex>
|
||||
</rule>
|
||||
<rule name="BIG LETTER">
|
||||
<color>macro</color>
|
||||
<regex>\@[A-Z_][A-Z_0-9]{3,500}\@</regex>
|
||||
<regex>\b([A-Z_][A-Z_0-9]{3,500})\b</regex>
|
||||
</rule>
|
||||
<rule name="CPP member">
|
||||
<color>memberClass</color>
|
||||
<regex>\@m_[A-Za-z_0-9]*\@</regex>
|
||||
<regex>\b(m_[A-Za-z_0-9]*)\b</regex>
|
||||
</rule>
|
||||
<rule name="function input">
|
||||
<color>inputFunction</color>
|
||||
<regex>\@_[A-Za-z_0-9]*\@</regex>
|
||||
<regex>\b(_[A-Za-z_0-9]*)\b</regex>
|
||||
<max>false</max>
|
||||
</rule>
|
||||
<!--
|
||||
<rule name="Function name">
|
||||
<color>functionName</color>
|
||||
<regex>\@(\w|_)+[ \t]*\(</regex>
|
||||
<regex>\b((\w|_)+[ \t]*\()</regex>
|
||||
</rule>
|
||||
<rule name="condition">
|
||||
<color>boolean</color>
|
||||
<regex>==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}|</regex>
|
||||
<regex>==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}</regex>
|
||||
</rule>
|
||||
-->
|
||||
<rule name="BIG LETTER">
|
||||
<color>macro</color>
|
||||
<regex>([A-Z]|_){4,500}</regex>
|
||||
<elemSubColor id="1">doxElem</elemSubColor>
|
||||
</rule>
|
||||
<rule name="simpleQuteTextError">
|
||||
<color>SYNTAX_ERROR</color>
|
||||
<regex>'|"</regex>
|
||||
</rule>
|
||||
</pass2>
|
||||
</EdnLang>
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <appl/global.h>
|
||||
#include <appl/Highlight.h>
|
||||
#include <exml/exml.h>
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/resource/Manager.h>
|
||||
|
||||
|
||||
@ -176,19 +177,27 @@ void appl::Highlight::parse(int64_t _start,
|
||||
int64_t elementStart = _start;
|
||||
int64_t elementStop = _stop;
|
||||
appl::HighlightInfo resultat;
|
||||
int64_t startTime = ewol::getTime();
|
||||
while (elementStart <= elementStop) {
|
||||
HL_DEBUG("Parse element in the buffer pos=" << elementStart);
|
||||
//APPL_DEBUG("Parse element in the buffer pos=" << elementStart);
|
||||
appl::HighlightInfo resultatLast;
|
||||
int64_t findAnOtherId = -1;
|
||||
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;
|
||||
HL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='" << _buffer[elementStart] << "' " << m_listHighlightPass1[jjj]->getPaternString());
|
||||
/*
|
||||
if (_buffer[elementStart] == '\n') {
|
||||
APPL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='\\n' " << m_listHighlightPass1[jjj]->getPaternString());
|
||||
} else {
|
||||
APPL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='" << _buffer[elementStart] << "' " << m_listHighlightPass1[jjj]->getPaternString());
|
||||
}
|
||||
*/
|
||||
// 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 (elementStart == resultat.start) {
|
||||
APPL_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart );
|
||||
//APPL_DEBUG(" native Find");
|
||||
findAnOtherId = jjj;
|
||||
resultatLast = resultat;
|
||||
break;
|
||||
@ -202,13 +211,16 @@ void appl::Highlight::parse(int64_t _start,
|
||||
}
|
||||
}
|
||||
}
|
||||
int64_t currentTimeEnd = ewol::getTime();
|
||||
int64_t deltaTime = currentTimeEnd - currentTime;
|
||||
if (findAnOtherId != -1) {
|
||||
//APPL_DEBUG("Find Pattern in the Buffer : time=" << (float)deltaTime/1000.0f << " ms (" << resultatLast.start << "," << resultatLast.stop << ") startPos=" << elementStart << " for=" << m_listHighlightPass1[findAnOtherId]->getPaternString());
|
||||
// remove element in the current List where the current Element have a end inside the next...
|
||||
int64_t kkk=_addingPos;
|
||||
while(kkk < (int64_t)_metaData.size() ) {
|
||||
if (_metaData[kkk].start <= resultatLast.stop) {
|
||||
// remove element
|
||||
HL_DEBUG("Erase element=" << kkk);
|
||||
APPL_DEBUG("Erase element=" << kkk);
|
||||
_metaData.erase(_metaData.begin()+kkk, _metaData.begin()+kkk+1);
|
||||
// Increase the end of search
|
||||
if (kkk < (int64_t)_metaData.size()) {
|
||||
@ -232,11 +244,17 @@ void appl::Highlight::parse(int64_t _start,
|
||||
_addingPos++;
|
||||
// We find a pattern == > Stop search for the current element
|
||||
} else {
|
||||
break;
|
||||
//APPL_DEBUG("loose time : time=" << deltaTime << " us");
|
||||
//break;
|
||||
}
|
||||
// Go to the next element (and search again ...).
|
||||
elementStart++;
|
||||
}
|
||||
int64_t stopTime = ewol::getTime();
|
||||
int64_t deltaTimeGlobal = stopTime - startTime;
|
||||
APPL_DEBUG("parse in time=" << (float)deltaTimeGlobal/1000.0f << " ms ");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -258,24 +276,42 @@ void appl::Highlight::parse2(int64_t _start,
|
||||
if (elementStart == 306) {
|
||||
//etk::log::setLevel(etk::log::logLevelVerbose);
|
||||
}
|
||||
appl::HighlightInfo resultatLast;
|
||||
int64_t findAnOtherId = -1;
|
||||
//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 = HLP_FIND_OK;
|
||||
HL2_DEBUG("Parse HL id=" << jjj << " position search: (" <<
|
||||
elementStart << "," << elementStop << ") in='"
|
||||
<< _buffer[elementStart] << "' " << m_listHighlightPass2[jjj]->getPaternString());
|
||||
enum resultFind ret;
|
||||
HL_DEBUG("Parse HL id=" << jjj << " position search: (" <<
|
||||
elementStart << "," << elementStop << ") in='"
|
||||
<< _buffer[elementStart] << "' " << 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) {
|
||||
HL2_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ")" );
|
||||
// add curent element in the list ...
|
||||
_metaData.push_back(resultat);
|
||||
elementStart = resultat.stop-1;
|
||||
// Exit current cycle
|
||||
break;
|
||||
if (elementStart == resultat.start) {
|
||||
//APPL_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart );
|
||||
findAnOtherId = jjj;
|
||||
resultatLast = resultat;
|
||||
break;
|
||||
} else {
|
||||
// stack last find to prevent a unneded seach:
|
||||
if ( findAnOtherId == -1
|
||||
|| resultat.start < resultatLast.start) {
|
||||
findAnOtherId = jjj;
|
||||
resultatLast = resultat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (findAnOtherId != -1) {
|
||||
//APPL_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart );
|
||||
// add curent element in the list ...
|
||||
_metaData.push_back(resultat);
|
||||
elementStart = resultat.stop-1;
|
||||
} else {
|
||||
//break;
|
||||
}
|
||||
// Go to the next element (and search again ...).
|
||||
elementStart++;
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ appl::HighlightPattern::~HighlightPattern() {
|
||||
void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) {
|
||||
m_regexValue = _regExp;
|
||||
try {
|
||||
m_regExp.assign(_regExp);
|
||||
m_regExp.assign(_regExp, std::regex_constants::optimize | std::regex_constants::ECMAScript);
|
||||
//m_regExp.assign(_regExp, std::regex_constants::optimize | std::regex_constants::extended);
|
||||
m_hasParsingError = false;
|
||||
} catch (std::regex_error e) {
|
||||
m_hasParsingError = true;
|
||||
@ -126,12 +127,23 @@ enum resultFind appl::HighlightPattern::find(int32_t _start,
|
||||
|
||||
std::smatch resultMatch;
|
||||
//APPL_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'");
|
||||
std::regex_search(_buffer.begin() + _start, _buffer.begin() + _stop, resultMatch, m_regExp);
|
||||
std::regex_search(_buffer.begin() + _start, _buffer.begin() + _stop, resultMatch, m_regExp, std::regex_constants::match_continuous);
|
||||
if (resultMatch.size() > 0) {
|
||||
_resultat.start = std::distance(_buffer.begin(), resultMatch[0].first);;
|
||||
_resultat.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) << "'" );
|
||||
/*
|
||||
if (true){
|
||||
//TK_DEBUG("in line : '" << etk::to_string(_buffer) << "'");
|
||||
TK_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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (false){
|
||||
TK_DEBUG("in line : '" << etk::to_string(_buffer) << "'");
|
||||
TK_DEBUG(" Find " << resultMatch.size() << " elements");
|
||||
@ -140,7 +152,7 @@ enum resultFind appl::HighlightPattern::find(int32_t _start,
|
||||
int32_t posStop = std::distance(_buffer.begin(), resultMatch[iii].second);
|
||||
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].first);
|
||||
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].second);
|
||||
TK_DEBUG(" [" << iii << "] " << etk::to_string(std::u32string(_buffer, posStart, posStop-posStart)));
|
||||
TK_DEBUG(" [" << iii << "] " << std::string(_buffer, posStart, posStop-posStart));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user