[DEV] work on highlight

This commit is contained in:
2013-10-25 22:12:34 +02:00
parent 6f4a67b47b
commit 8eb4aff266
14 changed files with 249 additions and 512 deletions

View File

@@ -10,28 +10,35 @@
#include <appl/global.h>
#include <Highlight.h>
#include <exml/exml.h>
#include <ewol/resources/ResourceManager.h>
#undef __class__
#define __class__ "Highlight"
#define __class__ "Highlight"
void Highlight::parseRules(exml::Element* _child, etk::Vector<HighlightPattern*>& _mListPatern, int32_t _level) {
void appl::Highlight::parseRules(exml::Element* _child,
etk::Vector<HighlightPattern*>& _mListPatern,
int32_t _level) {
// Create the patern ...
HighlightPattern *myPattern = new HighlightPattern();
HighlightPattern *myPattern = new HighlightPattern(m_paintingProperties);
// parse under Element
myPattern->parseRules(_child, _level);
// add element in the list
_mListPatern.pushBack(myPattern);
}
Highlight::Highlight(const etk::UString& _xmlFilename) {
appl::Highlight::Highlight(const etk::UString& _xmlFilename, const etk::UString& _colorFile) :
ewol::Resource(_xmlFilename) {
// keep color propertiy file :
m_paintingProperties = appl::GlyphPainting::keep(_colorFile);
exml::Document doc;
if (doc.load(_xmlFilename) == false) {
APPL_ERROR(" can not load file XML : " << _xmlFilename);
return;
}
exml::Element* root = (exml::Element*)doc.getNamed("EdnLang");
exml::Element* root = doc.getNamed("EdnLang");
if (NULL == root ) {
APPL_ERROR("(l ?) main node not find: \"EdnLang\" ...");
return;
@@ -39,7 +46,7 @@ Highlight::Highlight(const etk::UString& _xmlFilename) {
int32_t level1 = 0;
int32_t level2 = 0;
// parse all the elements :
for(int32_t iii=0; iii< root->size(); iii++) {
for(int32_t iii = 0; iii < root->size(); ++iii) {
exml::Element* child = root->getElement(iii);
if (child == NULL) {
// trash here all that is not element ...
@@ -83,13 +90,13 @@ Highlight::Highlight(const etk::UString& _xmlFilename) {
}
}
Highlight::~Highlight(void) {
appl::Highlight::~Highlight(void) {
int32_t i;
// clean all Element
for (i=0; i< m_listHighlightPass1.size(); i++) {
if (NULL != m_listHighlightPass1[i]) {
delete(m_listHighlightPass1[i]);
m_listHighlightPass1[i] = NULL;
for (esize_t iii = 0; iii < m_listHighlightPass1.size(); ++iii) {
if (m_listHighlightPass1[iii] != NULL) {
delete(m_listHighlightPass1[iii]);
m_listHighlightPass1[iii] = NULL;
}
}
// clear the compleate list
@@ -98,38 +105,25 @@ Highlight::~Highlight(void) {
m_listExtentions.clear();
}
void Highlight::reloadColor(void) {
int32_t i;
for (i=0; i< m_listHighlightPass1.size(); i++) {
if (NULL != m_listHighlightPass1[i]) {
m_listHighlightPass1[i]->reloadColor();
}
}
for (i=0; i< m_listHighlightPass2.size(); i++) {
if (NULL != m_listHighlightPass2[i]) {
m_listHighlightPass2[i]->reloadColor();
}
}
}
bool Highlight::hasExtention(const etk::UString& _ext) {
bool appl::Highlight::hasExtention(const etk::UString& _ext) {
for (int32_t iii=0; iii<m_listExtentions.size(); iii++) {
if (_ext == m_listExtentions[iii] ) {
if (m_listExtentions[iii] == _ext) {
return true;
}
}
return false;
}
bool Highlight::fileNameCompatible(etk::FSNode &_fileName) {
bool appl::Highlight::fileNameCompatible(const etk::UString& _fileName) {
etk::UString extention;
if (true == _fileName.fileHasExtention() ) {
etk::FSNode file(_fileName);
if (true == file.fileHasExtention() ) {
extention = "*.";
extention += _fileName.fileGetExtention();
extention += file.fileGetExtention();
} else {
extention = _fileName.getNameFile();
extention = file.getNameFile();
}
APPL_DEBUG(" try to find : in \"" << _fileName << "\" extention:\"" << extention << "\" ");
APPL_DEBUG(" try to find : in \"" << file << "\" extention:\"" << extention << "\" ");
for (int32_t iii=0; iii<m_listExtentions.size(); iii++) {
if (extention == m_listExtentions[iii] ) {
@@ -140,7 +134,7 @@ bool Highlight::fileNameCompatible(etk::FSNode &_fileName) {
}
void Highlight::display(void) {
void appl::Highlight::display(void) {
APPL_INFO("List of ALL Highlight : ");
for (int32_t iii=0; iii< m_listExtentions.size(); iii++) {
APPL_INFO(" Extention : " << iii << " : " << m_listExtentions[iii] );
@@ -148,19 +142,19 @@ void Highlight::display(void) {
// display all elements
for (int32_t iii=0; iii< m_listHighlightPass1.size(); iii++) {
APPL_INFO(" " << iii << " Pass 1 : " << m_listHighlightPass1[iii]->getName() );
//m_listHighlightPass1[i]->display();
//m_listHighlightPass1[iii]->display();
}
// display all elements
for (int32_t iii=0; iii< m_listHighlightPass2.size(); iii++) {
APPL_INFO(" " << iii << " Pass 2 : " << m_listHighlightPass2[iii]->getName() );
//m_listHighlightPass2[i]->display();
//m_listHighlightPass2[iii]->display();
}
}
// 13h 46min 22s | (l= 214) Highlight::Parse | [II] find Pattern in the Buffer : (2457,2479)
// TODO : Celui qui appelle suprime des element pour rien ... Enfin c'est pas tr<74>grave... Il suffirait juste de suprimer celuis d'avant si il n'est pas terminer...
void Highlight::parse(int32_t start,
/* TODO : Celui qui appelle suprime des element pour rien ... Enfin c'est pas tr<74>grave...
* Il suffirait juste de suprimer celuis d'avant si il n'est pas terminer...
*/
void appl::Highlight::parse(int32_t start,
int32_t stop,
etk::Vector<appl::ColorInfo> &metaData,
int32_t addingPos,
@@ -223,7 +217,7 @@ void Highlight::parse(int32_t start,
* @brief second pass of the hightlight
*
*/
void Highlight::parse2(int32_t start,
void appl::Highlight::parse2(int32_t start,
int32_t stop,
etk::Vector<appl::ColorInfo> &metaData,
etk::Buffer &buffer) {
@@ -254,3 +248,29 @@ void Highlight::parse2(int32_t start,
}
}
appl::Highlight* appl::Highlight::keep(const etk::UString& _filename) {
//EWOL_INFO("KEEP : appl::Highlight : file : \"" << _filename << "\"");
appl::Highlight* object = static_cast<appl::Highlight*>(getManager().localKeep(_filename));
if (NULL != object) {
return object;
}
EWOL_INFO("CREATE : appl::Highlight : file : \"" << _filename << "\"");
// this element create a new one every time ....
object = new appl::Highlight(_filename, "THEME:COLOR:textViewer.json");
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??Highlight??");
return NULL;
}
getManager().localAdd(object);
return object;
}
void appl::Highlight::release(appl::Highlight*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@@ -10,11 +10,11 @@
#define __HIGHLIGHT_H__
class appl {
namespace appl {
class Highlight;
class HighlightPattern;
class ColorInfo{
class ColorInfo {
public:
int32_t beginStart;
int32_t beginStop;
@@ -27,20 +27,22 @@ class appl {
#include <etk/os/FSNode.h>
#include <HighlightPattern.h>
#include <Colorize.h>
#include <appl/glyphDecoration/GlyphPainting.h>
#include <etk/Buffer.h>
#include <exml/exml.h>
class appl {
class Highlight : public ewol::EObject {
public:
namespace appl {
class Highlight : public ewol::Resource {
private:
appl::GlyphPainting* m_paintingProperties;
protected:
// Constructeur
Highlight(const etk::UString& _xmlFilename);
Highlight(const etk::UString& _xmlFilename, const etk::UString& _colorFile);
~Highlight(void);
public:
bool hasExtention(const etk::UString& _ext);
bool fileNameCompatible(etk::FSNode &_fileName);
bool fileNameCompatible(const etk::UString& _fileName);
void display(void);
void reloadColor(void);
void parse(int32_t _start,
int32_t _stop,
etk::Vector<appl::ColorInfo> &_metaData,
@@ -58,6 +60,23 @@ class appl {
etk::Vector<etk::UString> m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h"
etk::Vector<HighlightPattern*> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 == > when we load and wride data on the buffer)
etk::Vector<HighlightPattern*> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 == > When we display the buffer( only the display area (100 lines)) )
public:
/**
* @brief keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static appl::Highlight* keep(const etk::UString& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(appl::Highlight*& _object);
public: // herited function :
virtual void updateContext(void) {
// no upfate to do ...
};
};
};

View File

@@ -15,14 +15,14 @@
#undef __class__
#define __class__ "highlightManager"
static etk::Vector<Highlight*>& s_list(void) {
static etk::Vector<Highlight*> list;
static etk::Vector<appl::Highlight*>& s_list(void) {
static etk::Vector<appl::Highlight*> list;
return list;
}
void appl::highlightManager::init(void) {
etk::Vector<Highlight*>& hlList = s_list();
etk::Vector<appl::Highlight*>& hlList = s_list();
if (hlList.size() != 0) {
APPL_ERROR("HighlightManager == > already exist, just unlink the previous ...");
hlList.clear();
@@ -30,9 +30,7 @@ void appl::highlightManager::init(void) {
etk::FSNode myFile("DATA:languages/");
// get the subfolder list :
etk::Vector<etk::FSNode *> list = myFile.folderGetSubList(false, true, false,false);
for (esize_t iii=0;
iii<list.size();
++iii ) {
for (esize_t iii = 0; iii < list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
@@ -41,8 +39,19 @@ void appl::highlightManager::init(void) {
}
etk::UString filename = list[iii]->getName() + "/highlight.xml";
APPL_DEBUG("Load xml name : " << filename);
appl::Highlight *myHightline = appl::Highlight::keep(filename);
hlList.pushBack(myHightline);
appl::Highlight *myHightLine = appl::Highlight::keep(filename);
if (myHightLine != NULL) {
hlList.pushBack(myHightLine);
} else {
APPL_ERROR("Can not allocate HighLight");
}
}
// display :
for (esize_t iii = 0; iii < hlList.size(); ++iii) {
if (hlList[iii] == NULL) {
continue;
}
hlList[iii]->display();
}
}
@@ -53,9 +62,7 @@ void appl::highlightManager::unInit(void) {
hlList.clear();
return;
}
for (esize_t iii = 0;
iii < hlList.size();
++iii ) {
for (esize_t iii = 0; iii < hlList.size(); ++iii) {
if (hlList[iii] == NULL) {
continue;
}

View File

@@ -9,79 +9,79 @@
#include <appl/Debug.h>
#include <appl/global.h>
#include <HighlightPattern.h>
#include <ColorizeManager.h>
#undef __class__
#define __class__ "HighlightPattern"
HighlightPattern::HighlightPattern(void) {
m_haveStopPatern = false;
m_multiline = false;
m_color = ColorizeManager::get("normal");
appl::HighlightPattern::HighlightPattern(appl::GlyphPainting*& _glyphPainting) :
m_glyphPainting(_glyphPainting),
m_paternName(""),
m_regExpStart(NULL),
m_regExpStop(NULL),
m_colorName(""),
m_escapeChar(etk::UChar::Null),
m_multiline(false),
m_level(0) {
m_regExpStart = new etk::RegExp<etk::Buffer>();
m_regExpStop = new etk::RegExp<etk::Buffer>();
m_escapeChar = 0;
}
HighlightPattern::~HighlightPattern(void) {
delete(m_regExpStart);
delete(m_regExpStop);
appl::HighlightPattern::~HighlightPattern(void) {
if (m_regExpStart != NULL) {
delete(m_regExpStart);
m_regExpStart = NULL;
}
if (m_regExpStop != NULL) {
delete(m_regExpStop);
m_regExpStop = NULL;
}
}
void HighlightPattern::setPaternStart(etk::UString& _regExp) {
void appl::HighlightPattern::setPaternStart(etk::UString& _regExp) {
if (m_regExpStart == NULL) {
return;
}
m_regExpStart->setRegExp(_regExp);
}
void HighlightPattern::setPaternStop(etk::UString& _regExp) {
void appl::HighlightPattern::setPaternStop(etk::UString& _regExp) {
if (m_regExpStop != NULL) {
delete(m_regExpStop);
m_regExpStop = NULL;
}
if (_regExp.size() != 0) {
m_regExpStop->setRegExp(_regExp);
m_haveStopPatern = true;
} else {
m_haveStopPatern = false;
m_regExpStop = new etk::RegExp<etk::Buffer>();
if (m_regExpStop != NULL) {
m_regExpStop->setRegExp(_regExp);
} else {
APPL_ERROR("Allocation error");
}
}
}
void HighlightPattern::setEscapeChar(etk::UString& _EscapeChar) {
if (_EscapeChar.size()>0) {
m_escapeChar = _EscapeChar[0];
} else {
m_escapeChar = 0;
}
void appl::HighlightPattern::setEscapeChar(const etk::UChar& _EscapeChar) {
m_escapeChar = _EscapeChar;
}
void HighlightPattern::setColorGlyph(etk::UString& _colorName) {
void appl::HighlightPattern::setColorGlyph(etk::UString& _colorName) {
m_colorName = _colorName;
m_color = ColorizeManager::get(m_colorName);
m_colorId = m_glyphPainting->request(m_colorName);
}
bool HighlightPattern::isEnable(void) {
return true;
}
void HighlightPattern::reloadColor(void) {
m_color = ColorizeManager::get(m_colorName);
}
void HighlightPattern::display(void) {
/*
void appl::HighlightPattern::display(void) {
APPL_INFO("patern : \"" << m_paternName << "\" level=" << m_level );
APPL_INFO(" == > colorName \"" << m_colorName << "\"");
APPL_INFO(" == > regExpStart \"" << m_regExpStart->getRegExp() << "\"");
APPL_INFO(" == > regExpStop \"" << m_regExpStop->getRegExp() << "\"");
if (true == m_haveStopPatern) {
APPL_INFO(" == > stop pattern: YES");
} else {
APPL_INFO(" == > stop pattern: NO");
if (m_regExpStop != NULL) {
APPL_INFO(" == > regExpStop \"" << m_regExpStop->getRegExp() << "\"");
}
if (true == m_multiline) {
if (m_multiline == true) {
APPL_INFO(" == > multiline pattern: YES");
} else {
APPL_INFO(" == > multiline pattern: NO");
}
*/
}
void HighlightPattern::parseRules(exml::Element *child, int32_t level) {
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level) {
//--------------------------------------------------------------------------------------------
/*
<rule name="my preprocesseur">
@@ -93,101 +93,92 @@ void HighlightPattern::parseRules(exml::Element *child, int32_t level) {
*/
//--------------------------------------------------------------------------------------------
// process attribute
etk::UString highLightName = child->getAttribute("name");
etk::UString highLightName = _child->getAttribute("name");
etk::UString myEdnDataTmp = "???";
if (highLightName.size()!=0) {
myEdnDataTmp = highLightName;
}
setName(myEdnDataTmp);
setLevel(level);
setLevel(_level);
exml::Element* xChild = (exml::Element*)child->getNamed("color");
exml::Element* xChild = _child->getNamed("color");
if (NULL != xChild) {
etk::UString 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);
etk::UString myEdnData = myData;
setColor(myEdnData);
setColorGlyph(myEdnData);
}
}
xChild = (exml::Element*)child->getNamed("start");
xChild = _child->getNamed("start");
if (NULL != xChild) {
etk::UString 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);
etk::UString myEdnData = myData;
setPaternStart(myEdnData);
}
}
xChild = (exml::Element*)child->getNamed("end");
xChild = _child->getNamed("end");
if (NULL != xChild) {
etk::UString 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);
etk::UString myEdnData = myData;
setPaternStop(myEdnData);
}
}
xChild = (exml::Element*)child->getNamed("EscapeChar");
xChild = _child->getNamed("EscapeChar");
if (NULL != xChild) {
etk::UString 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);
etk::UString myEdnData = myData;
setEscapeChar(myEdnData);
setEscapeChar(myData[0]);
}
}
}
/**
* @brief find Element only in the specify start characters and find the end with the range done
*
* @param[in] start First character to search data (if recognise it start here)
* @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
*/
resultFind_te HighlightPattern::find(int32_t start, int32_t stop, colorInformation_ts &resultat, etk::Buffer &buffer) {
resultFind_te appl::HighlightPattern::find(int32_t _start,
int32_t _stop,
appl::ColorInfo& _resultat,
etk::Buffer& _buffer) {
//APPL_DEBUG(" try to find the element");
resultat.beginStart = -1;
resultat.beginStop = -1;
resultat.endStart = -1;
resultat.endStop = -1;
resultat.notEnded = false;
resultat.patern = this;
_resultat.beginStart = -1;
_resultat.beginStop = -1;
_resultat.endStart = -1;
_resultat.endStop = -1;
_resultat.notEnded = false;
_resultat.patern = this;
// when we have only one element :
if (false == m_haveStopPatern) {
if (true == m_regExpStart->processOneElement(buffer, start, stop)) {
resultat.beginStart = m_regExpStart->start();
resultat.beginStop = m_regExpStart->stop();
resultat.endStart = m_regExpStart->start();
resultat.endStop = m_regExpStart->stop();
// when we have only one element:
if (m_regExpStop == NULL) {
if (true == m_regExpStart->processOneElement(_buffer, _start, _stop)) {
_resultat.beginStart = m_regExpStart->start();
_resultat.beginStop = m_regExpStart->stop();
_resultat.endStart = m_regExpStart->start();
_resultat.endStop = m_regExpStart->stop();
return HLP_FIND_OK;
}
//APPL_DEBUG("NOT find hightlightpatern ...");
} else {
// try while we find the first element
if (true == m_regExpStart->processOneElement(buffer, start, stop, m_escapeChar)) {
resultat.beginStart = m_regExpStart->start();
resultat.beginStop = m_regExpStart->stop();
if (true == m_regExpStop->process(buffer, resultat.beginStop, stop, m_escapeChar)) {
resultat.endStart = m_regExpStop->start();
resultat.endStop = m_regExpStop->stop();
return HLP_FIND_OK;
} else {
resultat.endStart = stop+1;
resultat.endStop = stop+1;
resultat.notEnded = true;
return HLP_FIND_OK_NO_END;
}
}
//APPL_DEBUG("NOT find start hightlightpatern ...");
return HLP_FIND_ERROR;
}
// try while we find the first element
if (m_regExpStart->processOneElement(_buffer, _start, _stop, m_escapeChar) == false) {
return HLP_FIND_ERROR;
}
_resultat.beginStart = m_regExpStart->start();
_resultat.beginStop = m_regExpStart->stop();
if (m_regExpStop->process(_buffer, _resultat.beginStop, _stop, m_escapeChar) == true) {
_resultat.endStart = m_regExpStop->start();
_resultat.endStop = m_regExpStop->stop();
return HLP_FIND_OK;
} else {
_resultat.endStart = _stop+1;
_resultat.endStop = _stop+1;
_resultat.notEnded = true;
return HLP_FIND_OK_NO_END;
}
//APPL_DEBUG("NOT find start hightlightpatern ...");
return HLP_FIND_ERROR;
}

View File

@@ -15,7 +15,7 @@ class HighlightPattern;
#include <etk/RegExp.h>
#include <Colorize.h>
#include <glyphDecoration/GlyphPainting.h>
#include <etk/Vector.h>
#include <exml/exml.h>
#include <etk/Buffer.h>
@@ -28,9 +28,11 @@ typedef enum {
namespace appl {
class HighlightPattern {
private:
appl::GlyphPainting*& m_glyphPainting;
public:
// Constructeur
HighlightPattern(void);
HighlightPattern(appl::GlyphPainting*& _glyphPainting);
~HighlightPattern(void);
private:
etk::UString m_paternName; //!< Current style name (like "c++" or "c" or "script Bash")
@@ -46,22 +48,21 @@ namespace appl {
public:
void setPaternStart(etk::UString& _regExp);
private:
bool m_haveStopPatern; //!< Stop patern presence
etk::RegExp<etk::Buffer>* m_regExpStop; //!< Stop of Regular Expression
public:
void setPaternStop(etk::UString& _regExp);
private:
etk::UString m_colorName; //!< Current color name
appl::ColorGlyph* m_color; //!< Link to the color manager
esize_t m_colorId; //!< Id of the the glyph painting
public:
void setColorGlyph(etk::UString& _colorName);
appl::ColorGlyph* getColorGlyph(void) {
return m_color;
const appl::GlyphDecoration& getColorGlyph(void) {
return (*m_glyphPainting)[m_colorId];
};
private:
etk::UChar m_escapeChar; //!< Escape char to prevent exeit of patern ....
public:
void setEscapeChar(etk::UString& _EscapeChar);
void setEscapeChar(const etk::UChar& _EscapeChar);
private:
bool m_multiline; //!< The patern is multiline
public:
@@ -80,16 +81,23 @@ namespace appl {
private:
public:
bool isEnable(void);
void display(void);
/**
* @brief find Element only in the specify start characters and find the end with the range done
* @param[in] _start First character to search data (if recognise it start here)
* @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
*/
resultFind_te find(int32_t _start,
int32_t _stop,
colorInformation_ts& _resultat,
appl::ColorInfo& _resultat,
etk::Buffer& _buffer);
void parseRules(exml::Element* _child, int32_t _level);
void reloadColor(void);
};
};