Move to gitHub the edn project (remove history keep it on my nas)
This commit is contained in:
297
Sources/Highlight/Highlight.cpp
Normal file
297
Sources/Highlight/Highlight.cpp
Normal file
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file Highlight.c
|
||||
* @brief Editeur De N'ours : Hightlightning Specific
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
#include "Highlight.h"
|
||||
#include "tinyxml.h"
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Highlight"
|
||||
|
||||
|
||||
void Highlight::ParseRules(TiXmlNode *child, std::vector<HighlightPattern*> &mListPatern, int32_t level)
|
||||
{
|
||||
// Create the patern ...
|
||||
HighlightPattern *myPattern = new HighlightPattern();
|
||||
// parse under Element
|
||||
myPattern->ParseRules(child, level);
|
||||
// add element in the list
|
||||
mListPatern.push_back(myPattern);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Highlight::Highlight(Edn::String &xmlFilename)
|
||||
{
|
||||
|
||||
TiXmlDocument XmlDocument;
|
||||
// open the curent File
|
||||
bool loadError = XmlDocument.LoadFile(xmlFilename.c_str());
|
||||
if (false == loadError) {
|
||||
EDN_ERROR( "can not load Hightlight XML: PARSING error: ");
|
||||
return;
|
||||
}
|
||||
TiXmlElement* root = XmlDocument.FirstChildElement( "EdnLang" );
|
||||
if (NULL == root) {
|
||||
EDN_ERROR( "can not load Hightlight XML: main node not find: \"EdnLang\"");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t level1 = 0;
|
||||
int32_t level2 = 0;
|
||||
TiXmlNode * child = root->FirstChild();
|
||||
while(NULL != child)
|
||||
{
|
||||
if (child->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do ...
|
||||
} else if (!strcmp(child->Value(), "ext")) {
|
||||
const char *myData = child->ToElement()->GetText();
|
||||
if (NULL != myData) {
|
||||
//EDN_INFO(PFX"(l %d) node fined : %s=\"%s\"", child->Row(), child->Value() , myData);
|
||||
Edn::String myEdnData = myData;
|
||||
m_listExtentions.push_back(myEdnData);
|
||||
}
|
||||
} else if (!strcmp(child->Value(), "pass1")) {
|
||||
// Get sub Nodes ...
|
||||
TiXmlNode *passChild = child->FirstChild();
|
||||
while (NULL != passChild) {
|
||||
if (passChild->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do ...
|
||||
} else if (!strcmp(passChild->Value(), "rule")) {
|
||||
ParseRules(passChild, m_listHighlightPass1, level1++);
|
||||
} else {
|
||||
EDN_ERROR("(l "<< passChild->Row() << ") node not suported : \""<< passChild->Value() << "\" must be [rule]" );
|
||||
}
|
||||
// get the next node element :
|
||||
passChild = passChild->NextSibling();
|
||||
}
|
||||
} else if (!strcmp(child->Value(), "pass2")) {
|
||||
// Get sub Nodes ...
|
||||
TiXmlNode *passChild = child->FirstChild();
|
||||
while (NULL != passChild) {
|
||||
if (passChild->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do ...
|
||||
} else if (!strcmp(passChild->Value(), "rule")) {
|
||||
ParseRules(passChild, m_listHighlightPass2, level2++);
|
||||
} else {
|
||||
EDN_ERROR("(l "<< passChild->Row() << ") node not suported : \""<< passChild->Value() << "\" must be [rule]" );
|
||||
}
|
||||
// get the next node element :
|
||||
passChild = passChild->NextSibling();
|
||||
}
|
||||
} else {
|
||||
EDN_ERROR("(l "<< child->Row() << ") node not suported : \""<< child->Value() << "\" must be [ext,pass1,pass2]" );
|
||||
}
|
||||
// get the next node element :
|
||||
child = child->NextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
Highlight::~Highlight(void)
|
||||
{
|
||||
uint32_t i;
|
||||
// clean all Element
|
||||
for (i=0; i< m_listHighlightPass1.size(); i++) {
|
||||
delete(m_listHighlightPass1[i]);
|
||||
}
|
||||
// clear the compleate list
|
||||
m_listHighlightPass1.clear();
|
||||
}
|
||||
|
||||
|
||||
bool Highlight::HasExtention(Edn::String &ext)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i=0; i<m_listExtentions.size(); i++) {
|
||||
if (ext == m_listExtentions[i] ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Highlight::FileNameCompatible(Edn::String &fileName)
|
||||
{
|
||||
uint32_t i;
|
||||
int32_t posCopy = fileName.FindBack('/');
|
||||
Edn::String shortFilename;
|
||||
if (-1 != posCopy) {
|
||||
shortFilename = fileName.Extract(posCopy+1);
|
||||
} else {
|
||||
shortFilename = fileName;
|
||||
}
|
||||
posCopy = shortFilename.FindBack('.');
|
||||
Edn::String extention;
|
||||
if (-1 != posCopy) {
|
||||
extention = shortFilename.Extract(posCopy);
|
||||
} else {
|
||||
extention = shortFilename;
|
||||
}
|
||||
EDN_DEBUG(" try to find : in \"" << fileName.c_str() << "\" shortfilename\"" << shortFilename.c_str() << "\" extention:\"" << extention.c_str() << "\" ");
|
||||
|
||||
for (i=0; i<m_listExtentions.size(); i++) {
|
||||
if (extention == m_listExtentions[i] ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Highlight::Display(void)
|
||||
{
|
||||
uint32_t i;
|
||||
EDN_INFO("List of ALL Highlight : ");
|
||||
for (i=0; i< m_listExtentions.size(); i++) {
|
||||
EDN_INFO(" Extention : " << i << " : " << m_listExtentions[i].c_str() );
|
||||
}
|
||||
// Display all elements
|
||||
for (i=0; i< m_listHighlightPass1.size(); i++) {
|
||||
EDN_INFO(" " << i << " Pass 1 : " << m_listHighlightPass1[i]->GetName().c_str() );
|
||||
//m_listHighlightPass1[i]->Display();
|
||||
}
|
||||
// Display all elements
|
||||
for (i=0; i< m_listHighlightPass2.size(); i++) {
|
||||
EDN_INFO(" " << i << " Pass 2 : " << m_listHighlightPass2[i]->GetName().c_str() );
|
||||
//m_listHighlightPass2[i]->Display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Highlight::Parse(int32_t start, int32_t stop, std::vector<colorInformation_ts> &metaData, int32_t &addingPos, EdnVectorBuf &buffer, int32_t elementID)
|
||||
{
|
||||
if (0 > addingPos) {
|
||||
addingPos = 0;
|
||||
}
|
||||
/*int32_t emptyId = -1;
|
||||
for (i=0; i< (int32_t)metaData.size(); i++) {
|
||||
|
||||
}*/
|
||||
//EDN_DEBUG("Parse element " << elementID << " / " << m_listHighlightPass1.size() << " ==> position search: (" << start << "," << stop << ")" );
|
||||
if (elementID >= (int32_t)m_listHighlightPass1.size() ){
|
||||
//EDN_DEBUG("Return at " << elementID << " / " << m_listHighlightPass1.size() );
|
||||
return;
|
||||
}
|
||||
int32_t elementStart = start;
|
||||
int32_t elementStop = stop;
|
||||
resultFind_te ret = HLP_FIND_OK;
|
||||
colorInformation_ts resultat;
|
||||
while (HLP_FIND_ERROR != ret && elementStart<elementStop) {
|
||||
ret = m_listHighlightPass1[elementID]->Find(elementStart, elementStop, resultat, buffer);
|
||||
if (HLP_FIND_ERROR != ret) {
|
||||
//EDN_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" );
|
||||
// Add curent element in the list ...
|
||||
if (HLP_FIND_OK_NO_END == ret) {
|
||||
// find if we have a next element with th save Pointer and not higher the this one
|
||||
int32_t findNextElement = -1;
|
||||
int32_t i;
|
||||
int32_t curentLevel = ((HighlightPattern*)resultat.patern)->GetLevel();
|
||||
for (i=addingPos; i< (int32_t)metaData.size(); i++) {
|
||||
if (curentLevel > ((HighlightPattern*)metaData[i].patern)->GetLevel() ) {
|
||||
//EDN_DEBUG(" -> Find upper element at "<< i );
|
||||
break;
|
||||
} else if (curentLevel < ((HighlightPattern*)metaData[i].patern)->GetLevel() ) {
|
||||
findNextElement = i;
|
||||
//EDN_DEBUG(" -> Find under element at "<< i );
|
||||
}
|
||||
if (metaData[i].patern == resultat.patern)
|
||||
{
|
||||
findNextElement = i;
|
||||
//EDN_DEBUG(" -> Find a same element at "<< i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != findNextElement) {
|
||||
// if not find a end, we need to search the end of this one and parse all data inside...
|
||||
int32_t newEnd = buffer.Size();
|
||||
if (findNextElement >= (int32_t)metaData.size()-1) {
|
||||
// Remove old element :
|
||||
//EDN_DEBUG(" --> Remove : " << addingPos << "==>" << (int32_t)metaData.size() << " (end)" );
|
||||
metaData.erase(metaData.begin()+addingPos,metaData.end());
|
||||
} else {
|
||||
// Remove old element :
|
||||
//EDN_DEBUG(" --> Remove : " << addingPos << "==>" << findNextElement+1 );
|
||||
metaData.erase(metaData.begin()+addingPos,metaData.begin()+findNextElement+1);
|
||||
newEnd = metaData[addingPos].beginStart-1;
|
||||
}
|
||||
// Regenerate a local parsing : in a higher range of text
|
||||
Parse(elementStart, edn_max(newEnd, stop), metaData, addingPos, buffer, elementID);
|
||||
// Break the curent process, beacause we reparse the data in all range...
|
||||
return;
|
||||
} else {
|
||||
//EDN_DEBUG(" --> No element removed " );
|
||||
metaData.insert(metaData.begin() + addingPos, resultat);
|
||||
//EDN_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop );
|
||||
}
|
||||
} else {
|
||||
metaData.insert(metaData.begin() + addingPos, resultat);
|
||||
//EDN_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop );
|
||||
}
|
||||
// parse the under element :
|
||||
Parse(elementStart, resultat.beginStart-1, metaData, addingPos, buffer, elementID+1);
|
||||
addingPos++;
|
||||
elementStart = resultat.endStop;
|
||||
}
|
||||
}
|
||||
// parse the under element :
|
||||
Parse(elementStart, elementStop, metaData, addingPos, buffer, elementID+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief second pass of the hightlight
|
||||
*
|
||||
*/
|
||||
void Highlight::Parse2(int32_t start, int32_t stop, std::vector<colorInformation_ts> &metaData, EdnVectorBuf &buffer, int32_t elementID)
|
||||
{
|
||||
if (elementID >= (int32_t)m_listHighlightPass2.size() ){
|
||||
return;
|
||||
}
|
||||
int32_t elementStart = start;
|
||||
int32_t elementStop = stop;
|
||||
resultFind_te ret = HLP_FIND_OK;
|
||||
colorInformation_ts resultat;
|
||||
while (HLP_FIND_ERROR != ret && elementStart<elementStop) {
|
||||
if (m_listHighlightPass2[elementID]!=NULL) {
|
||||
ret = m_listHighlightPass2[elementID]->Find(elementStart, elementStop, resultat, buffer);
|
||||
} else {
|
||||
ret = HLP_FIND_ERROR;
|
||||
}
|
||||
if (HLP_FIND_ERROR != ret) {
|
||||
//EDN_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" );
|
||||
// parse the under element :
|
||||
Parse2(elementStart, resultat.beginStart, metaData, buffer, elementID+1);
|
||||
// Add curent element in the list ...
|
||||
metaData.push_back(resultat);
|
||||
elementStart = resultat.endStop;
|
||||
}
|
||||
}
|
||||
// parse the under element :
|
||||
Parse2(elementStart, elementStop, metaData, buffer, elementID+1);
|
||||
}
|
||||
|
||||
|
77
Sources/Highlight/Highlight.h
Normal file
77
Sources/Highlight/Highlight.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file Highlight.h
|
||||
* @brief Editeur De N'ours : Hightlightning Specific (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __HIGHLIGHT_H__
|
||||
#define __HIGHLIGHT_H__
|
||||
|
||||
|
||||
class Highlight;
|
||||
class HighlightPattern;
|
||||
|
||||
extern "C" {
|
||||
typedef struct
|
||||
{
|
||||
int32_t beginStart;
|
||||
int32_t beginStop;
|
||||
int32_t endStart;
|
||||
int32_t endStop;
|
||||
bool notEnded;
|
||||
HighlightPattern * patern; // pointer on class :
|
||||
} colorInformation_ts;
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include "HighlightPattern.h"
|
||||
#include "Colorize.h"
|
||||
#include "Edn.h"
|
||||
#include "EdnVectorBuf.h"
|
||||
#include "tinyxml.h"
|
||||
|
||||
class Highlight {
|
||||
public:
|
||||
// Constructeur
|
||||
Highlight(Edn::String &xmlFilename);
|
||||
~Highlight(void);
|
||||
bool HasExtention(Edn::String &ext);
|
||||
bool FileNameCompatible(Edn::String &fileName);
|
||||
void Display(void);
|
||||
void Parse( int32_t start, int32_t stop, std::vector<colorInformation_ts> &metaData, int32_t &addingPos, EdnVectorBuf &buffer, int32_t elementID=0);
|
||||
void Parse2(int32_t start, int32_t stop, std::vector<colorInformation_ts> &metaData, EdnVectorBuf &buffer, int32_t elementID=0);
|
||||
|
||||
private:
|
||||
void ParseRules(TiXmlNode *child, std::vector<HighlightPattern*> &mListPatern, int32_t level);
|
||||
Edn::String m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
|
||||
std::vector<Edn::String> m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h"
|
||||
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)) )
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
83
Sources/Highlight/HighlightManager.cpp
Normal file
83
Sources/Highlight/HighlightManager.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file HighlightManager.cpp
|
||||
* @brief Editeur De N'ours : Hightlining Manager
|
||||
* @author Edouard DUPIN
|
||||
* @date 16/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
#include "HighlightManager.h"
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "HighlightManager"
|
||||
|
||||
HighlightManager::HighlightManager(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HighlightManager::~HighlightManager(void)
|
||||
{
|
||||
listHighlight.clear();
|
||||
}
|
||||
|
||||
|
||||
Highlight *HighlightManager::Get(Edn::String &fileName)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i=0; i<listHighlight.size(); i++) {
|
||||
if (true == listHighlight[i]->FileNameCompatible(fileName) ) {
|
||||
return listHighlight[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool HighlightManager::Exist(Edn::String &fileName)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i=0; i<listHighlight.size(); i++) {
|
||||
if (true == listHighlight[i]->FileNameCompatible(fileName) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void HighlightManager::loadLanguages(void)
|
||||
{
|
||||
Edn::String xmlFilename = "./data/lang_c.xml";
|
||||
Highlight *myHightline = new Highlight(xmlFilename);
|
||||
listHighlight.push_back(myHightline);
|
||||
|
||||
xmlFilename = "./data/lang_boo.xml";
|
||||
myHightline = new Highlight(xmlFilename);
|
||||
listHighlight.push_back(myHightline);
|
||||
|
||||
xmlFilename = "./data/lang_Makefile.xml";
|
||||
myHightline = new Highlight(xmlFilename);
|
||||
listHighlight.push_back(myHightline);
|
||||
|
||||
myHightline->Display();
|
||||
}
|
||||
|
56
Sources/Highlight/HighlightManager.h
Normal file
56
Sources/Highlight/HighlightManager.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file HighlightManager.h
|
||||
* @brief Editeur De N'ours : Hightlining Manager (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __HIGHLIGHT_MANAGER_H__
|
||||
#define __HIGHLIGHT_MANAGER_H__
|
||||
|
||||
class HighlightManager;
|
||||
|
||||
#include "Singleton.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Highlight.h"
|
||||
|
||||
|
||||
class HighlightManager: public Singleton<HighlightManager>
|
||||
{
|
||||
friend class Singleton<HighlightManager>;
|
||||
// specific for sigleton system...
|
||||
private:
|
||||
// Constructeur
|
||||
HighlightManager(void);
|
||||
~HighlightManager(void);
|
||||
|
||||
public:
|
||||
void loadLanguages(void);
|
||||
Highlight * Get(Edn::String &fileName);
|
||||
bool Exist(Edn::String &fileName);
|
||||
|
||||
private:
|
||||
std::vector<Highlight*> listHighlight; //!< List of ALL hightlight modules
|
||||
};
|
||||
|
||||
#endif
|
||||
|
232
Sources/Highlight/HighlightPattern.cpp
Normal file
232
Sources/Highlight/HighlightPattern.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file HighlightPattern.cpp
|
||||
* @brief Editeur De N'ours : Hightlight Patern (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
#include "HighlightPattern.h"
|
||||
#include "ColorizeManager.h"
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "HighlightPattern"
|
||||
|
||||
|
||||
|
||||
HighlightPattern::HighlightPattern(void)
|
||||
{
|
||||
m_haveStopPatern = false;
|
||||
m_multiline = false;
|
||||
ColorizeManager *myColorManager = ColorizeManager::getInstance();
|
||||
m_color = myColorManager->Get("normal");
|
||||
m_regExpStart = new EdnRegExp();
|
||||
m_regExpStop = new EdnRegExp();
|
||||
m_escapeChar = 0;
|
||||
}
|
||||
|
||||
HighlightPattern::~HighlightPattern(void)
|
||||
{
|
||||
delete(m_regExpStart);
|
||||
delete(m_regExpStop);
|
||||
}
|
||||
|
||||
void HighlightPattern::SetPaternStart(Edn::String ®Exp)
|
||||
{
|
||||
m_regExpStart->SetRegExp(regExp);
|
||||
}
|
||||
|
||||
void HighlightPattern::SetPaternStop(Edn::String ®Exp)
|
||||
{
|
||||
if (regExp.Size() != 0) {
|
||||
m_regExpStop->SetRegExp(regExp);
|
||||
m_haveStopPatern = true;
|
||||
} else {
|
||||
m_haveStopPatern = false;
|
||||
}
|
||||
}
|
||||
|
||||
void HighlightPattern::SetEscapeChar(Edn::String &EscapeChar)
|
||||
{
|
||||
if (EscapeChar.Size()>0) {
|
||||
m_escapeChar = EscapeChar.c_str()[0];
|
||||
} else {
|
||||
m_escapeChar = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HighlightPattern::SetColor(Edn::String &colorName)
|
||||
{
|
||||
m_colorName = colorName;
|
||||
ColorizeManager *myColorManager = ColorizeManager::getInstance();
|
||||
m_color = myColorManager->Get(m_colorName);
|
||||
}
|
||||
|
||||
bool HighlightPattern::IsEnable(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in,out]
|
||||
*
|
||||
* @eturn
|
||||
*
|
||||
*/
|
||||
void HighlightPattern::Display(void)
|
||||
{
|
||||
/*
|
||||
EDN_INFO("patern : \"" << m_paternName.c_str() << "\" level=" << m_level );
|
||||
EDN_INFO(" ==> colorName \"" << m_colorName.c_str() << "\"");
|
||||
EDN_INFO(" ==> regExpStart \"" << m_regExpStart->GetRegExp().c_str() << "\"");
|
||||
EDN_INFO(" ==> regExpStop \"" << m_regExpStop->GetRegExp().c_str() << "\"");
|
||||
if (true == m_haveStopPatern) {
|
||||
EDN_INFO(" ==> stop pattern: YES");
|
||||
} else {
|
||||
EDN_INFO(" ==> stop pattern: NO");
|
||||
}
|
||||
if (true == m_multiline) {
|
||||
EDN_INFO(" ==> multiline pattern: YES");
|
||||
} else {
|
||||
EDN_INFO(" ==> multiline pattern: NO");
|
||||
}
|
||||
*/
|
||||
// Display all elements
|
||||
for (int32_t i=0; i< m_subPatern.Size(); i++) {
|
||||
EDN_INFO(" " << i << " SubPattern : " << m_subPatern[i]->GetName().c_str() );
|
||||
m_subPatern[i]->Display();
|
||||
}
|
||||
}
|
||||
void HighlightPattern::ParseRules(TiXmlNode *child, int32_t level)
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------
|
||||
/*
|
||||
<rule name="my preprocesseur">
|
||||
<color>preprocesseur</color>
|
||||
<start>#</start>
|
||||
<end>$</end>
|
||||
<multiline>yes</multiline>
|
||||
</rule>
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// process attribute
|
||||
const char *highLightName = child->ToElement()->Attribute("name");
|
||||
Edn::String myEdnDataTmp = "???";
|
||||
if (NULL != highLightName) {
|
||||
myEdnDataTmp = highLightName;
|
||||
}
|
||||
SetName(myEdnDataTmp);
|
||||
SetLevel(level);
|
||||
|
||||
TiXmlElement *xChild = child->FirstChildElement("color");
|
||||
if (NULL != xChild) {
|
||||
const char *myData = xChild->GetText();
|
||||
if (myData) {
|
||||
//EDN_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
|
||||
Edn::String myEdnData = myData;
|
||||
SetColor(myEdnData);
|
||||
}
|
||||
}
|
||||
xChild = child->FirstChildElement("start");
|
||||
if (NULL != xChild) {
|
||||
const char *myData = xChild->GetText();
|
||||
if (myData) {
|
||||
//EDN_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
|
||||
Edn::String myEdnData = myData;
|
||||
SetPaternStart(myEdnData);
|
||||
}
|
||||
}
|
||||
xChild = child->FirstChildElement("end");
|
||||
if (NULL != xChild) {
|
||||
const char *myData = xChild->GetText();
|
||||
if (myData) {
|
||||
//EDN_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
|
||||
Edn::String myEdnData = myData;
|
||||
SetPaternStop(myEdnData);
|
||||
}
|
||||
}
|
||||
xChild = child->FirstChildElement("EscapeChar");
|
||||
if (NULL != xChild) {
|
||||
const char *myData = xChild->GetText();
|
||||
if (myData) {
|
||||
//EDN_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
|
||||
Edn::String myEdnData = myData;
|
||||
SetEscapeChar(myEdnData);
|
||||
}
|
||||
}
|
||||
xChild = child->FirstChildElement("rule");
|
||||
if (NULL != xChild) {
|
||||
/*
|
||||
// Create the patern ...
|
||||
HighlightPattern *myPattern = new HighlightPattern();
|
||||
// parse under Element
|
||||
myPattern->ParseRules(ruleChild, level+1);
|
||||
// add element in the list
|
||||
m_subPatern.PushBack(myPattern);
|
||||
//ParseRules(passChild, m_listHighlightPass1, level1++);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer)
|
||||
{
|
||||
//EDN_DEBUG(" try to find the element");
|
||||
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->Process(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;
|
||||
}
|
||||
//EDN_DEBUG("NOT find hightlightpatern ...");
|
||||
} else {
|
||||
// try while we find the first element
|
||||
if (true == m_regExpStart->Process(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;
|
||||
}
|
||||
}
|
||||
//EDN_DEBUG("NOT find start hightlightpatern ...");
|
||||
}
|
||||
return HLP_FIND_ERROR;
|
||||
}
|
85
Sources/Highlight/HighlightPattern.h
Normal file
85
Sources/Highlight/HighlightPattern.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file HighlightPattern.h
|
||||
* @brief Editeur De N'ours : Hightlight Patern (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __HIGHLIGHT_PATTERN_H__
|
||||
#define __HIGHLIGHT_PATTERN_H__
|
||||
|
||||
class HighlightPattern;
|
||||
|
||||
#include "Edn.h"
|
||||
#include "EdnRegExp.h"
|
||||
#include "Colorize.h"
|
||||
#include "EdnVectorBin.h"
|
||||
#include "tinyxml.h"
|
||||
|
||||
typedef enum {
|
||||
HLP_FIND_ERROR,
|
||||
HLP_FIND_OK,
|
||||
HLP_FIND_OK_NO_END,
|
||||
}resultFind_te;
|
||||
|
||||
class HighlightPattern;
|
||||
|
||||
class HighlightPattern {
|
||||
public:
|
||||
// Constructeur
|
||||
HighlightPattern(void);
|
||||
~HighlightPattern(void);
|
||||
|
||||
void SetName(Edn::String &name) { m_paternName = name;};
|
||||
Edn::String GetName(void) { return m_paternName;};
|
||||
|
||||
void SetPaternStart(Edn::String ®Exp);
|
||||
void SetPaternStop(Edn::String ®Exp);
|
||||
void SetColor(Edn::String &colorName);
|
||||
void SetEscapeChar(Edn::String &EscapeChar);
|
||||
void SetMultiline(bool enable) { m_multiline = enable; };
|
||||
|
||||
void SetLevel(int32_t newLevel) { m_level = newLevel; };
|
||||
int32_t GetLevel(void) { return m_level; };
|
||||
|
||||
bool IsEnable(void);
|
||||
void Display(void);
|
||||
resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer);
|
||||
Colorize * GetColor(void) { return m_color; };
|
||||
void ParseRules(TiXmlNode *child, int32_t level);
|
||||
|
||||
private:
|
||||
int32_t m_level; //!< Level of the pattern ==> this is to overwrite next pattern when we create an higher ....
|
||||
Edn::String m_paternName; //!< Current style name (like "c++" or "c" or "script Bash")
|
||||
Edn::String m_colorName; //!< Current color name
|
||||
Colorize * m_color; //!< Link to the color manager
|
||||
EdnRegExp * m_regExpStart; //!< Start of Regular expression
|
||||
EdnRegExp * m_regExpStop; //!< Stop of Regular Expression
|
||||
bool m_haveStopPatern; //!< Stop patern presence
|
||||
bool m_multiline; //!< The patern is multiline
|
||||
char m_escapeChar; //!< Escape char to prevent exeit of patern ....
|
||||
EdnVectorBin<HighlightPattern *> m_subPatern; //!< Under patern of this one
|
||||
// EdnVectorBin<HighlightPattern *> m_subColor; //!< Under Color in the start RegExp ...
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user