[DEV] add sub parsing of pass1

This commit is contained in:
Edouard DUPIN 2014-10-13 22:39:49 +02:00
parent a201439665
commit 7c37d8e549
20 changed files with 284 additions and 128 deletions

View File

@ -12,11 +12,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'(.|\\[\\'])*?'</regex>
<regex>&apos;(.|\\[\\&apos;])*?&apos;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -16,11 +16,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?$</regex>
<regex>&quot;(.|\\[\\&quot;])*?$</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>\b'(.|\\[\\'])*?$</regex>
<regex>\b&apos;(.|\\[\\&apos;])*?$</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -5,14 +5,12 @@
<rule name="doxygen multiline">
<color>commentDoxygen</color>
<regex>/\*(\*|!)(.|\r|\n)*?\*/</regex>
</rule>
<rule name="comment multiline TODO">
<color>SYNTAX_ERROR</color>
<regex>/\*[ \t]*TODO :(.|\r|\n)*?(\*/|\0)</regex>
<sub>doxyparse</sub>
</rule>
<rule name="comment multiline">
<color>comment</color>
<regex>/\*(.|\r|\n)*?(\*/|\0)</regex>
<sub>TODO</sub>
</rule>
<rule name="comment miltiline ERROR">
<color>SYNTAX_ERROR</color>
@ -33,14 +31,12 @@
<rule name="inline doxygen">
<color>commentDoxygen</color>
<regex>//!.*</regex>
</rule>
<rule name="inline comment TODO">
<color>SYNTAX_ERROR</color>
<regex>//[ \t]*TODO[ \t]*:.*</regex>
<sub>doxyparse</sub>
</rule>
<rule name="inline comment">
<color>comment</color>
<regex>//.*</regex>
<sub>TODO</sub>
</rule>
<rule name="double quote text">
<color>doubleQuoteText</color>
@ -66,7 +62,7 @@
</rule>
<rule name="std type">
<color>type</color>
<regex>\b(std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair))\b</regex>
<regex>\bstd::[\w:]*\b</regex>
</rule>
<rule name="my storage keyword">
<color>storageKeyword</color>
@ -95,7 +91,6 @@
<rule name="function input">
<color>inputFunction</color>
<regex>\b_\w+\b</regex>
<max>false</max>
</rule>
<rule name="Function name">
<color>functionName</color>
@ -108,11 +103,30 @@
<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>
<regex>&apos;|&quot;</regex>
</rule>
</pass2>
<pass name="doxyparse">
<rule name="key">
<color>doxygen-key</color>
<regex>(@|\\)[\t ]*\w+</regex>
</rule>
<rule name="in-out">
<color>doxygen-in-out</color>
<regex>\[(in|in,out|out)\]</regex>
</rule>
<rule name="function input">
<color>inputFunction</color>
<regex>\b_\w+\b</regex>
</rule>
</pass>
<pass name="TODO">
<rule name="function input">
<color>SYNTAX_ERROR</color>
<regex>TODO[ \t]*:.*</regex>
</rule>
</pass>
</EdnLang>

View File

@ -17,7 +17,7 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -8,11 +8,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?$</regex>
<regex>&quot;(.|\\[\\&quot;])*?$</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'(.|\\[\\'])*?$</regex>
<regex>&apos;(.|\\[\\&apos;])*?$</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -24,11 +24,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'(.|\\[\\'])*?'</regex>
<regex>&apos;(.|\\[\\&apos;])*?&apos;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -4,7 +4,7 @@
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->
@ -18,7 +18,7 @@
</rule>
<rule name="names">
<color>functionName</color>
<regex>([a-zA-Z0-9]|-|_)*</regex>
<regex>([a-zA-Z0-9]|-|_)+</regex>
</rule>
<rule name="numeric constant">
<color>number</color>

View File

@ -16,11 +16,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'(.|\\[\\'])*?'</regex>
<regex>&apos;(.|\\[\\&apos;])*?&apos;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -9,11 +9,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'(.|\\[\\'])*?'</regex>
<regex>&apos;(.|\\[\\&apos;])*?&apos;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -12,11 +12,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex> ".*?($|")</regex>
<regex> &quot;.*?($|&quot;)</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex> '.*?($|')</regex>
<regex> &apos;.*?($|&apos;)</regex>
</rule>
<rule name="global inclusion">
<color>preprocesseur</color>

View File

@ -20,11 +20,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'(.|\\[\\'])*?'</regex>
<regex>&apos;(.|\\[\\&apos;])*?&apos;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->

View File

@ -4,7 +4,7 @@
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="my comment multiline">
<color>comment</color>
<regex>"""(.|\r|\n)*?"""</regex>
<regex>&quot;&quot;&quot;(.|\r|\n)*?&quot;&quot;&quot;</regex>
</rule>
<rule name="my comment multiline">
<color>comment</color>
@ -12,7 +12,7 @@
</rule>
<rule name="comment multiline Error">
<color>SYNTAX_ERROR</color>
<regex>("""|''')(.|\n|\r)*</regex>
<regex>(&quot;&quot;&quot;|''')(.|\n|\r)*</regex>
</rule>
<rule name="my comment doxygen">
<color>commentDoxygen</color>
@ -24,11 +24,11 @@
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\\[\\"])*?"</regex>
<regex>&quot;(.|\\[\\&quot;])*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>'((\\[\\'])|.)*?'</regex>
<regex>&apos;((\\[\\&apos;])|.)*?&apos;</regex>
</rule>
</pass1>
<pass2> <!-- Parse on display data ==> nor regenerate every display but every time modification apear -->
@ -70,7 +70,7 @@
</rule>
<rule name="simpleQuteTextError">
<color>SYNTAX_ERROR</color>
<regex>'|"</regex>
<regex>&apos;|&quot;</regex>
</rule>
</pass2>
</EdnLang>

View File

@ -4,32 +4,74 @@
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="Comment">
<color>comment</color>
<regex><![CDATA[<!\-\-(.|\r|\n)*?\-\->]]></regex>
<!--<regex>&lt;!\-\-.*\-\-&gt;</regex>-->
<!--<regex><![CDATA[<!\-\-(.|\r|\n)*?\-\->]]></regex>-->
-<regex>&lt;!\-\-(.|\r|\n)*?\-\-&gt;</regex>
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(.|\r|\n|\\\\|\\")*?"</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>\b'(.|\r|\n)*?('|\n)</regex>
</rule>
<rule name="NormalData">
<rule name="CDATA">
<color>macro</color>
<regex><![CDATA[<!\[CDATA\[(.|\r|\n)*?\]\]>]]></regex>
<!--<regex><![CDATA[<!\[CDATA\[(.|\r|\n)*?\]\]>]]></regex>-->
<regex>&lt;!\[CDATA\[(.|\r|\n)*?\]\]&gt;</regex>
</rule>
<rule name="stop balise">
<color>functionName</color>
<!--<regex><![CDATA[</[ \t]*\w+?[ \t]*>]]></regex>-->
<regex>&lt;/[ \t]*\w+?[ \t]*&gt;</regex>
</rule>
<rule name="stop balise">
<color>SYNTAX_ERROR</color>
<!--<regex><![CDATA[</(.|\n|\r)*?>]]></regex>-->
<regex>&lt;/(.|\n|\r)*?&gt;</regex>
</rule>
<rule name="start balise">
<color>normal</color>
<!--<regex><![CDATA[<(.|\n|\r)*?>]]></regex>-->
<regex>&lt;(.|\n|\r)*?&gt;</regex>
<sub>parseInsideBalise</sub>
</rule>
</pass1>
<pass2>
<rule name="special Balise">
<color>error</color>
<regex><![CDATA[<\?\w*|\?>]]></regex>
<!--<regex>&lt;\?\w*|\?&gt;</regex>-->
<rule name="start balise">
<color>commonDefine</color>
<!--<regex><![CDATA[&(gt|lt|amp|apos|quot);]]></regex>-->
<regex>&amp;(gt|lt|amp|apos|quot);</regex>
</rule>
<rule name="normale Balise2">
<color>functionName</color>
<regex><![CDATA[(</[0-9a-zA-Z_]+|<[0-9a-zA-Z_]+)(/>|>)?]]></regex>
<rule name="start balise">
<color>error</color>
<regex>&gt;|&lt;|&amp;|&apos;|&quot;</regex>
</rule>
</pass2>
<pass name="parseInsideBalise">
<rule name="special Balise">
<color>error</color>
<!--<regex><![CDATA[<\?\w*|\?>]]></regex>-->
<regex>&lt;\?\w*|\?&gt;</regex>
</rule>
<rule name="open balise">
<color>functionName</color>
<!--<regex><![CDATA[<[ \t]*[0-9a-zA-Z_]+]]></regex>-->
<regex>&lt;[ \t]*[0-9a-zA-Z_]+</regex>
</rule>
<rule name="close balise">
<color>functionName</color>
<!--<regex><![CDATA[/?>]]></regex>-->
<regex>/?&gt;</regex>
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>&quot;(.|\r|\n|\\\\|\\&quot;)*?&quot;</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
<regex>\b&apos;(.|\r|\n)*?(&apos;|\n)</regex>
</rule>
<rule name="condition">
<color>boolean</color>
<regex>=</regex>
</rule>
<rule name="condition">
<color>keyword</color>
<regex>\w+</regex>
</rule>
</pass>
</EdnLang>

View File

@ -27,5 +27,8 @@
{ name:"functionName", foreground:"#24d1e0", bold:true},
{ name:"TestResultOK", foreground:"#000000", background:"#00FF00", bold:true},
{ name:"TestResultERROR", FG:"#000000", background:"#FF0000", bold:true}
{ name:"doxygen-key", foreground:"#dc3700", bold:true, italic:false},
{ name:"doxygen-in-out", foreground:"#dc7000", bold:true, italic:false},
]
}

View File

@ -9,6 +9,7 @@
{ name:"SelectedText", foreground:"#292929", background:"#009ce7"},
{ name:"error", foreground:"#FF0000"},
{ name:"doubleQuoteText", foreground:"#008e00"},
{ name:"type", foreground:"#376d0a", bold:true},
{ name:"memberClass", foreground:"#7c5406", bold:true},
{ name:"inputFunction", foreground:"#B80000", bold:true, italic:true},
@ -26,6 +27,9 @@
{ name:"functionName", foreground:"#09857e", bold:true},
{ name:"TestResultOK", foreground:"#000000", background:"#009c00", bold:true},
{ name:"TestResultERROR", foreground:"#000000", background:"#c20000", bold:true}
{ name:"doxygen-key", foreground:"#dc3700", bold:true, italic:false},
{ name:"doxygen-in-out", foreground:"#dc7000", bold:true, italic:false},
]
}

View File

@ -938,22 +938,24 @@ void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, const ap
" start=" << HLStartPos <<
" stop=" << m_HLDataPass1[kkk].start );
m_highlight->parse2(HLStartPos,
m_HLDataPass1[kkk].start,
_MData.HLData,
m_data);
m_HLDataPass1[kkk].start,
_MData.HLData,
m_data);
} // else : nothing to do ...
} else {
APPL_VERBOSE(" == > (empty section 2 ) kkk=" << kkk <<
" start=" << m_HLDataPass1[kkk-1].stop <<
" stop=" << m_HLDataPass1[kkk].start );
m_highlight->parse2(m_HLDataPass1[kkk-1].stop,
m_HLDataPass1[kkk].start,
_MData.HLData,
m_data);
m_HLDataPass1[kkk].start,
_MData.HLData,
m_data);
}
// under section :
//APPL_DEBUG(" == > (under section ) k="<<k<<" start="<<m_HLDataPass1[k].beginStart<<" stop="<<m_HLDataPass1[k].endStop << " subSectionOfID=" << 99999999);
// TODO : ...
APPL_VERBOSE(" == > (under section ) kkk="<<kkk<<" start="<<m_HLDataPass1[kkk].start<<" stop="<<m_HLDataPass1[kkk].stop << " subSectionOfID=" << 99999999);
m_highlight->parseSubElement(m_HLDataPass1[kkk],
_MData.HLData,
m_data);
}
if (endSearch == (int32_t)m_HLDataPass1.size() ){
//if( k < (int32_t)m_HLDataPass1.size()) {
@ -962,16 +964,16 @@ void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, const ap
" start=" << m_HLDataPass1[kkk-1].stop <<
" stop=" << HLStop );
m_highlight->parse2(m_HLDataPass1[kkk-1].stop,
HLStop,
_MData.HLData,
m_data);
HLStop,
_MData.HLData,
m_data);
} else {
APPL_VERBOSE(" == > (empty section 4 ) kkk=" << kkk <<
" start=0 stop=" << HLStop );
m_highlight->parse2(0,
HLStop,
_MData.HLData,
m_data);
HLStop,
_MData.HLData,
m_data);
}
}
/*

View File

@ -25,18 +25,6 @@
//#define HL2_DEBUG APPL_INFO
#define HL2_DEBUG APPL_VERBOSE
void appl::Highlight::parseRules(exml::Element* _child,
std::vector<std::unique_ptr<HighlightPattern>>& _mListPatern,
int32_t _level,
bool forceMaximize) {
// Create the patern ...
HighlightPattern *myPattern = new HighlightPattern(m_paintingProperties);
// parse under Element
myPattern->parseRules(_child, _level, forceMaximize);
// add element in the list
_mListPatern.push_back(std::unique_ptr<HighlightPattern>(myPattern));
}
appl::Highlight::Highlight() {
addObjectType("appl::Highlight");
}
@ -84,7 +72,8 @@ void appl::Highlight::init(const std::string& _xmlFilename, const std::string& _
APPL_ERROR("(l "<< passChild->getPos() << ") node not suported : \""<< passChild->getValue() << "\" must be [rule]" );
continue;
}
parseRules(passChild, m_listHighlightPass1, level1++);
// Create the patern in list
m_listHighlightPass1.push_back(HighlightPattern(m_paintingProperties, passChild, level1++));
}
} else if (child->getValue() == "pass2") {
// get sub Nodes ...
@ -97,7 +86,30 @@ void appl::Highlight::init(const std::string& _xmlFilename, const std::string& _
APPL_ERROR("(l "<< passChild->getPos() << ") node not suported : \""<< passChild->getValue() << "\" must be [rule]" );
continue;
}
parseRules(passChild, m_listHighlightPass2, level2++, true);
// Create the patern in list
m_listHighlightPass2.push_back(HighlightPattern(m_paintingProperties, passChild, level2++));
}
} else if (child->getValue() == "pass") {
std::string attributeName = child->getAttribute("name");
if (attributeName == "") {
APPL_ERROR("Can not parse an element pass with no attribute name ... ligne=" << child->getPos());
continue;
}
m_listHighlightNamed.insert(std::pair<std::string, std::vector<HighlightPattern>>(attributeName, std::vector<HighlightPattern>()));
auto it = m_listHighlightNamed.find(attributeName);
int32_t level3=0;
// get sub Nodes ...
for(size_t jjj=0; jjj< child->size(); jjj++) {
exml::Element* passChild = child->getElement(jjj);
if (passChild == nullptr) {
continue;
}
if (passChild->getValue() != "rule") {
APPL_ERROR("(l "<< passChild->getPos() << ") node not suported : \""<< passChild->getValue() << "\" must be [rule]" );
continue;
}
// add element in the list
it->second.push_back(HighlightPattern(m_paintingProperties, passChild, level3++));
}
} else {
APPL_ERROR("(l "<< child->getPos() << ") node not suported : \""<< child->getValue() << "\" must be [ext,pass1,pass2]" );
@ -167,13 +179,20 @@ void appl::Highlight::display() {
}
// display all elements
for (auto &it : m_listHighlightPass1) {
APPL_INFO(" Pass 1 : " << it->getName() );
//m_listHighlightPass1[iii]->display();
APPL_INFO(" Pass 1 : " << it.getName() );
//it.display();
}
// display all elements
for (auto &it : m_listHighlightPass2) {
APPL_INFO(" pass 2 : " << it->getName() );
//m_listHighlightPass2[iii]->display();
APPL_INFO(" pass 2 : " << it.getName() );
//it.display();
}
for (auto &it : m_listHighlightNamed) {
APPL_INFO(" pass * : " << it.first << " : ");
for (auto &it2 : it.second) {
APPL_INFO(" " << it2.getName() );
//it.display();
}
//it.display();
}
}
@ -201,17 +220,17 @@ void appl::Highlight::parse(int64_t _start,
enum resultFind ret = HLP_FIND_OK;
/*
if (_buffer[elementStart] == '\n') {
HL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='\\n' " << m_listHighlightPass1[jjj]->getPaternString());
HL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='\\n' " << m_listHighlightPass1[jjj].getPaternString());
} else {
HL_DEBUG("Parse HL id=" << jjj << " position search: (" << elementStart << "," << _stop << ") input start='" << _buffer[elementStart] << "' " << m_listHighlightPass1[jjj]->getPaternString());
HL_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);
ret = m_listHighlightPass1[jjj].find(elementStart, _buffer.size(), resultat, _buffer);
if (HLP_FIND_ERROR != ret) {
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());
HL_DEBUG("Find Pattern in the Buffer : time=" << (float)deltaTime/1000.0f << " ms (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart << " for=" << m_listHighlightPass1[jjj].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() ) {
@ -256,7 +275,10 @@ void appl::Highlight::parse(int64_t _start,
/**
* @brief second pass of the hightlight
*
* @param[in] _start Start searching data
* @param[in] _stop End searching data
* @param[out] _metaData Output list of all find patern
* @param[in] _buffer buffer where we need to search data
*/
void appl::Highlight::parse2(int64_t _start,
int64_t _stop,
@ -278,9 +300,9 @@ void appl::Highlight::parse2(int64_t _start,
enum resultFind ret;
HL2_DEBUG("Parse HL id=" << jjj << " position search: (" <<
elementStart << "," << elementStop << ") in='"
<< _buffer[elementStart] << "' " << m_listHighlightPass2[jjj]->getPaternString());
<< _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);
ret = m_listHighlightPass2[jjj].find(elementStart, elementStop, resultat, _buffer);
if (ret != HLP_FIND_ERROR) {
_metaData.push_back(resultat);
elementStart = resultat.stop-1;
@ -291,3 +313,46 @@ void appl::Highlight::parse2(int64_t _start,
elementStart++;
}
}
/**
* @brief second pass of the hightlight pattern (have found something before)
* @param[in] _upper upper pattern to find the data
* @param[out] _metaData Output list of all find patern
* @param[in] _buffer buffer where we need to search data
*/
void appl::Highlight::parseSubElement(const appl::HighlightInfo& _upper,
std::vector<appl::HighlightInfo> &_metaData,
std::string &_buffer) {
if (_upper.patern->getSubPatternName().size() == 0) {
return;
}
HL2_DEBUG("Parse element 0 => " << m_listHighlightNamed.size() <<
" == > position search: (" << _upper.start << "," << _upper.stop << ")" );
int64_t elementStart = _upper.start;
int64_t elementStop = _upper.stop;
appl::HighlightInfo resultat;
// Find element in the list:
auto itHL = m_listHighlightNamed.find(_upper.patern->getSubPatternName());
if (itHL == m_listHighlightNamed.end()) {
APPL_ERROR("Patern does not exist : " << _upper.patern->getSubPatternName() << " note : Removing it ...");
_upper.patern->setSubPatternName("");
return;
}
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) {
_metaData.push_back(resultat);
elementStart = resultat.stop-1;
break;
}
}
// Go to the next element (and search again ...).
elementStart++;
}
}

View File

@ -19,7 +19,7 @@ namespace appl {
int32_t start;
int32_t stop;
bool notEnded;
appl::HighlightPattern* patern; // pointer on class :
appl::HighlightPattern* patern;
};
};
@ -44,6 +44,10 @@ namespace appl {
private:
std::string m_typeName; //!< descriptive string type like "C/C++"
public:
/**
* @brief Get the Type of the Hightlight like c++/Bash/...
* @return descriptive string
*/
const std::string& getTypeName() {
return m_typeName;
}
@ -53,22 +57,22 @@ namespace appl {
void display();
void parse(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
std::vector<appl::HighlightInfo>& _metaData,
int64_t _addingPos,
std::string &_buffer);
std::string& _buffer);
void parse2(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
std::string &_buffer);
std::vector<appl::HighlightInfo>& _metaData,
std::string& _buffer);
void parseSubElement(const appl::HighlightInfo& _upper,
std::vector<appl::HighlightInfo>& _metaData,
std::string &_buffer);
private:
void parseRules(exml::Element* _child,
std::vector<std::unique_ptr<HighlightPattern>> &_mListPatern,
int32_t _level,
bool forceMaximize=false);
std::string m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
std::vector<std::string> m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h"
std::vector<std::unique_ptr<HighlightPattern>> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 == > when we load and wride data on the buffer)
std::vector<std::unique_ptr<HighlightPattern>> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 == > When we display the buffer( only the display area (100 lines)) )
std::vector<HighlightPattern> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 == > when we load and wride data on the buffer)
std::vector<HighlightPattern> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 == > When we display the buffer( only the display area (100 lines)) )
std::map<std::string, std::vector<HighlightPattern>> m_listHighlightNamed; //!< list of all sub partern to parse...
public: // herited function :
virtual void updateContext() {
// no upfate to do ...

View File

@ -13,13 +13,24 @@
#undef __class__
#define __class__ "HighlightPattern"
appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting) :
appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting, exml::Element* _child, int32_t _level) :
m_glyphPainting(_glyphPainting),
m_paternName(""),
m_hasParsingError(true),
m_regexValue(""),
m_regExp(),
m_colorName(""),
m_level(0) {
parseRules(_child, _level);
}
appl::HighlightPattern::HighlightPattern() :
m_glyphPainting(),
m_paternName(""),
m_hasParsingError(true),
m_regexValue(""),
m_regExp(),
m_colorName(""),
m_level(0) {
}
@ -28,7 +39,7 @@ appl::HighlightPattern::~HighlightPattern() {
}
void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) {
void appl::HighlightPattern::setPatern(const std::string& _regExp) {
m_regexValue = _regExp;
APPL_DEBUG("parse regex='" << _regExp << "'");
try {
@ -39,13 +50,12 @@ void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMax
m_hasParsingError = true;
APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << _regExp);
}
//m_regExp.setMaximize(forceMaximize);
}
std::string appl::HighlightPattern::getPaternString() {
return m_regexValue;
}
void appl::HighlightPattern::setColorGlyph(std::string& _colorName) {
void appl::HighlightPattern::setColorGlyph(const std::string& _colorName) {
m_colorName = _colorName;
m_colorId = m_glyphPainting->request(m_colorName);
APPL_VERBOSE("Resuest color name '" << m_colorName << "' => id=" << m_colorId);
@ -58,17 +68,17 @@ void appl::HighlightPattern::display() {
APPL_INFO(" == > regex '" << m_regexValue << "'");
}
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) {
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level) {
//--------------------------------------------------------------------------------------------
/*
<rule name="my preprocesseur">
<color>preprocesseur</color>
<regex>#</regex>
<max>false</max>
<sub>namexxx</sub>
</rule>
*/
//--------------------------------------------------------------------------------------------
// process attribute
// process attribute
std::string highLightName = _child->getAttribute("name");
std::string myEdnDataTmp = "???";
if (highLightName.size()!=0) {
@ -82,21 +92,23 @@ void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, b
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
std::string myEdnData = myData;
setColorGlyph(myEdnData);
setColorGlyph(myData);
}
}
xChild = _child->getNamed("max");
if (nullptr != xChild) {
forceMaximize = etk::string_to_bool(xChild->getText());
}
xChild = _child->getNamed("regex");
if (nullptr != xChild) {
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
std::string myEdnData = myData;
setPatern(myEdnData, forceMaximize);
setPatern(myData);
}
}
xChild = _child->getNamed("sub");
if (nullptr != xChild) {
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
setSubPatternName(myData);
}
}
}
@ -136,7 +148,7 @@ enum resultFind appl::HighlightPattern::find(int32_t _start,
if (_start>0) {
flags |= std::regex_constants::match_prev_avail;
}
std::regex_search(_buffer.begin() + _start, _buffer.end(), resultMatch, m_regExp, flags);
std::regex_search(_buffer.begin() + _start, _buffer.begin() + _stop, resultMatch, m_regExp, flags);
if (resultMatch.size() > 0) {
_resultat.start = std::distance(_buffer.begin(), resultMatch[0].first);
_resultat.stop = std::distance(_buffer.begin(), resultMatch[0].second);

View File

@ -32,29 +32,39 @@ namespace appl {
std::shared_ptr<appl::GlyphPainting> m_glyphPainting;
public:
// Constructeur
HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting);
HighlightPattern();
HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting, exml::Element* _child, int32_t _level);
virtual ~HighlightPattern();
private:
std::string m_paternName; //!< Current style name (like "c++" or "c" or "script Bash")
public:
void setName(std::string& _name) {
void setName(const std::string& _name) {
m_paternName = _name;
};
std::string getName() {
const std::string& getName() {
return m_paternName;
};
private:
std::string m_paternSubName; //!< Sub patern name if needed
public:
void setSubPatternName(const std::string& _name) {
m_paternSubName = _name;
};
const std::string& getSubPatternName() {
return m_paternSubName;
};
private:
bool m_hasParsingError;
std::string m_regexValue;
std::regex m_regExp; //!< Start of Regular expression
public:
void setPatern(const std::string& _regExp, bool forceMaximize=false);
void setPatern(const std::string& _regExp);
std::string getPaternString();
private:
std::string m_colorName; //!< Current color name
int32_t m_colorId; //!< Id of the the glyph painting
public:
void setColorGlyph(std::string& _colorName);
void setColorGlyph(const std::string& _colorName);
const appl::GlyphDecoration& getColorGlyph() {
return (*m_glyphPainting)[m_colorId];
};
@ -86,7 +96,7 @@ namespace appl {
appl::HighlightInfo& _resultat,
const std::string& _buffer);
void parseRules(exml::Element* _child, int32_t _level, bool forceMaximize=false);
void parseRules(exml::Element* _child, int32_t _level);
};
};