From febbaffdf4d69c9a91a855e07f54f9e735debac3 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 3 Oct 2014 00:49:26 +0200 Subject: [PATCH 01/11] [DEV] {remove etk regexp dependency} big rework in progress to simplify code and use real std::regex templates --- sources/appl/Buffer.cpp | 125 +++++-------------- sources/appl/Buffer.h | 264 +--------------------------------------- 2 files changed, 31 insertions(+), 358 deletions(-) diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index 182593e..dd7cb0e 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -17,101 +17,33 @@ #undef __class__ #define __class__ "Buffer" -appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ () { - m_value = u32char::Null; - if (m_current < 0) { - m_current = 0; - return *this; - } - if (m_data != nullptr) { - if (m_current < m_data->m_data.size() ) { - int8_t nbChar = utf8::theoricLen(m_data->m_data[m_current]); - if (nbChar != 0) { - m_current+=nbChar; - } else { - m_current++; - } - } - if (m_current >= m_data->m_data.size()) { - m_current = m_data->m_data.size(); - } - } - return *this; -} - -appl::Buffer::Iterator& appl::Buffer::Iterator::operator-- () { - m_value = u32char::Null; - if (m_data != nullptr) { - if (m_current > 0) { - int32_t iii = -1; - while( utf8::theoricFirst(m_data->m_data[m_current+iii]) == false - && iii >= -6 - && m_current-iii>0) { - --iii; - }; - m_current += iii; - } else { - m_current = -1; - } - return *this; - } else { - m_current = -1; - } - return *this; -} - -char32_t appl::Buffer::Iterator::operator* () { - if (m_value != u32char::Null) { - return m_value; - } - if (m_data == nullptr) { - APPL_ERROR("request an element that iterator not link"); - return m_value; - } - if ( m_current < 0 - || m_current >= m_data->m_data.size()) { - APPL_ERROR("request an element out of bounding !!! 0 <= " << m_current << " < " << m_data->m_data.size()); - return m_value; - } - char tmpVal[5]; - memset(tmpVal, 0, sizeof(tmpVal)); - tmpVal[0] = m_data->m_data[m_current]; - int8_t nbChar = utf8::theoricLen(tmpVal[0]); - for (int32_t iii=1; iiim_data.size(); ++iii) { - tmpVal[iii] = m_data->m_data[m_current+iii]; - } - // transform ... - m_value = utf8::convertChar32(tmpVal); - return m_value; -} - appl::Buffer::Iterator appl::Buffer::position(int64_t _pos) { - return appl::Buffer::Iterator(this, _pos); + return m_data.begin() + _pos; } appl::Buffer::Iterator appl::Buffer::begin() { - return position(0); + return m_data.begin(); } appl::Buffer::Iterator appl::Buffer::end() { // TODO : chek the validity of the char ... - return position( m_data.size() ); + return m_data.end(); } appl::Buffer::Iterator appl::Buffer::cursor() { if (m_cursorPos<= 0) { - return begin(); + return m_data.begin(); } - return position( m_cursorPos ); + return m_data.begin() + m_cursorPos; } appl::Buffer::Iterator appl::Buffer::selectStart() { - return position( getStartSelectionPos() ); + return m_data.begin() + getStartSelectionPos(); } appl::Buffer::Iterator appl::Buffer::selectStop() { - return position( getStopSelectionPos() ); + return m_data.begin() + getStopSelectionPos(); } appl::Buffer::Buffer() : @@ -152,7 +84,9 @@ bool appl::Buffer::loadFile(const std::string& _name) { m_cursorPos = 0; setHighlightType(""); m_nbLines = 0; - if (m_data.dumpFrom(m_fileName) == true ) { + etk::FSNode filee(m_fileName); + if (filee.exist() == true) { + m_data = file.fileReadAllU32String(); countNumberofLine(); tryFindHighlightType(); m_isModify = false; @@ -175,12 +109,11 @@ void appl::Buffer::setFileName(const std::string& _name) { } bool appl::Buffer::storeFile() { - if (m_data.dumpIn(m_fileName) == true) { - APPL_INFO("saving file : " << m_fileName); - setModification(false); - return true; - } - return false; + etk::FSNode filee(m_fileName); + filee.fileWriteAll(m_data); + APPL_INFO("saving file : " << m_fileName); + setModification(false); + return true; } void appl::Buffer::setModification(bool _status) { @@ -198,10 +131,8 @@ void appl::Buffer::setModification(bool _status) { // TODO : Naming error void appl::Buffer::countNumberofLine() { m_nbLines = 1; - for (Iterator it = begin(); - (bool)it == true; - ++it) { - if (*it == u32char::Return) { + for (auto &it : m_data) { + if (it == u32char::Return) { ++m_nbLines; } } @@ -230,21 +161,21 @@ appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _p bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) { // move in the string for (Iterator it = _pos; - (bool)it == true; + it != m_data.end(); ++it) { if (*it == _search) { _result = it; return true; } } - _result = end(); + _result = m_data.end(); return false; } bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) { // move in the string for (Iterator it = _pos - 1; - (bool)it == true; + it != m_data.begin(); --it) { //APPL_DEBUG("compare : " << *it << " ?= " << _search); if (*it == _search) { @@ -267,7 +198,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, if (_caseSensitive == true) { // move in the string for (Iterator it = _pos; - (bool)it == true; + it == m_data.end(); ++it) { if (*it == _search[0]) { // find the first char ==> check next... @@ -279,7 +210,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, break; } ++tmp; - if ((bool)tmp == false) { + if (tmp == m_data.end()) { if (iii != _search.size()-1) { find = false; } @@ -296,7 +227,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, char32_t firstElement = tolower(_search[0]); // move in the string for (Iterator it = _pos; - (bool)it == true; + it == m_data.end(); ++it) { if ((char32_t)tolower(*it) == firstElement) { // find the first char ==> check next... @@ -308,7 +239,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, break; } ++tmp; - if ((bool)tmp == false) { + if (tmp != m_data.end()) { if (iii != _search.size()-1) { find = false; } @@ -337,7 +268,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, if (_caseSensitive == true) { // move in the string for (Iterator it = _pos - 1; - (bool)it == true; + it != m_data.begin(); --it) { //APPL_DEBUG("compare : " << *it << " ?= " << _search); if (*it == lastElement) { @@ -350,7 +281,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, break; } --_result; - if ((bool)_result == false) { + if (_result == m_data.begin()) { if (iii != 0) { find = false; } @@ -367,7 +298,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, lastElement = tolower(lastElement); // move in the string for (Iterator it = _pos - 1; - (bool)it == true; + it != m_data.begin(); --it) { //APPL_DEBUG("compare : " << *it << " ?= " << _search); if ((char32_t)tolower(*it) == lastElement) { @@ -380,7 +311,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, break; } --_result; - if ((bool)_result == false) { + if (_result == m_data.begin()) { if (iii != 0) { find = false; } diff --git a/sources/appl/Buffer.h b/sources/appl/Buffer.h index d413227..372b08c 100644 --- a/sources/appl/Buffer.h +++ b/sources/appl/Buffer.h @@ -29,265 +29,7 @@ namespace appl { }; class Buffer : public ewol::Object { public: - class Iterator { - // Private data : - private: - int64_t m_current; //!< curent Id in the Buffer - appl::Buffer* m_data; //!< Pointer on the curent Buffer - char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data - public: - /** - * @brief Basic itarator constructor with no link. - */ - Iterator(): - m_current(0), - m_data(nullptr), - m_value(u32char::Null) { - // nothing to do ... - }; - /** - * @brief Recopy constructor. - * @param[in] _obj The Iterator that might be copy - */ - Iterator(const Iterator & _obj): - m_current(_obj.m_current), - m_data(_obj.m_data), - m_value(u32char::Null) { - // nothing to do ... - }; - /** - * @brief Asignation operator. - * @param[in] _otherIterator The Iterator that might be copy - * @return reference on the curent Iterator - */ - Iterator& operator=(const Iterator & _obj) { - m_current = _obj.m_current; - m_data = _obj.m_data; - m_value = u32char::Null; - return *this; - }; - /** - * @brief Basic destructor - */ - virtual ~Iterator() { - m_current = 0; - m_data = nullptr; - m_value = u32char::Null; - }; - /** - * @brief basic boolean cast - * @return true if the element is present in buffer - */ - operator bool () const { - if (m_data == nullptr) { - return false; - } - if (m_current >= m_data->m_data.size()) { - return false; - } - if (m_current < 0) { - return false; - } - return true; - }; - /** - * @brief basic boolean cast - * @return true if the element is present in buffer - */ - operator int64_t () const { - if (m_data == nullptr) { - return 0; - } - if (m_current < 0) { - return 0; - } - if (m_current > m_data->m_data.size()) { - return m_data->m_data.size(); - } - return m_current; - }; - /** - * @brief Incremental operator - * @return Reference on the current iterator incremented - */ - Iterator& operator++ (); - /** - * @brief Decremental operator - * @return Reference on the current iterator decremented - */ - Iterator& operator-- (); - /** - * @brief Incremental operator - * @return Reference on a new iterator and increment the other one - */ - Iterator operator++ (int32_t) { - Iterator it(*this); - ++(*this); - return it; - }; - /** - * @brief Decremental operator - * @return Reference on a new iterator and decrement the other one - */ - Iterator operator-- (int32_t) { - Iterator it(*this); - --(*this); - return it; - }; - /** - * @brief egality iterator - * @return true if the iterator is identical pos - */ - bool operator== (const Iterator& _obj) const { - if ( m_current == _obj.m_current - && m_data == _obj.m_data) { - return true; - } - return false; - }; - /** - * @brief egality iterator - * @return true if the iterator is identical pos - */ - bool operator!= (const Iterator& _obj) const { - if ( m_current != _obj.m_current - || m_data != _obj.m_data) { - return true; - } - return false; - }; - /** - * @brief <= iterator - * @return true if the iterator is identical pos - */ - bool operator<= (const Iterator& _obj) const { - if (m_data != _obj.m_data) { - return false; - } - if (m_current <= _obj.m_current) { - return true; - } - return false; - }; - /** - * @brief >= iterator - * @return true if the iterator is identical pos - */ - bool operator>= (const Iterator& _obj) const { - if (m_data != _obj.m_data) { - return false; - } - if (m_current >= _obj.m_current) { - return true; - } - return false; - }; - /** - * @brief < iterator - * @return true if the iterator is identical pos - */ - bool operator< (const Iterator& _obj) const { - if (m_data != _obj.m_data) { - return false; - } - if (m_current < _obj.m_current) { - return true; - } - return false; - }; - /** - * @brief > iterator - * @return true if the iterator is identical pos - */ - bool operator> (const Iterator& _obj) const { - if (m_data != _obj.m_data) { - return false; - } - if (m_current > _obj.m_current) { - return true; - } - return false; - }; - /** - * @brief Get the value on the current element - * @return The request element value - */ - char32_t operator* (); - /** - * @brief Get the position in the buffer - * @return The requested position. - */ - int64_t getPos() const { - if (m_data == nullptr) { - return 0; - } - if (m_current < 0) { - return 0; - } - if (m_current >= m_data->m_data.size()) { - return m_data->m_data.size()-1; - } - return m_current; - }; - /** - * @brief move the element position - * @return a new iterator. - */ - Iterator operator+ (const int64_t _val) const { - Iterator tmpp(*this); - for (int64_t iii=0; iii<_val; ++iii) { - ++tmpp; - } - return tmpp; - }; - Iterator operator+ (const int32_t _val) const { - Iterator tmpp(*this); - for (int64_t iii=0; iii<_val; ++iii) { - ++tmpp; - } - return tmpp; - }; - Iterator operator+ (const size_t _val) const { - Iterator tmpp(*this); - for (int64_t iii=0; iii<(int64_t)_val; ++iii) { - ++tmpp; - } - return tmpp; - }; - /** - * @brief move the element position - * @return a new iterator. - */ - Iterator operator- (const int64_t _val) const { - Iterator tmpp(*this); - for (int64_t iii=0; iii<_val; ++iii) { - --tmpp; - } - return tmpp; - }; - Iterator operator- (const int32_t _val) const { - Iterator tmpp(*this); - for (int64_t iii=0; iii<_val; ++iii) { - --tmpp; - } - return tmpp; - }; - Iterator operator- (const size_t _val) const { - Iterator tmpp(*this); - for (int64_t iii=0; iii<(int64_t)_val; ++iii) { - --tmpp; - } - return tmpp; - }; - private: - Iterator(Buffer* _obj, int64_t _pos) : - m_current(_pos), - m_data(_obj), - m_value(u32char::Null) { - // nothing to do ... - }; - friend class Buffer; - }; + using Iterator = std::u32string::iterator; public: ewol::object::Signal signalIsModify; ewol::object::Signal signalIsSave; @@ -348,9 +90,9 @@ namespace appl { */ void setModification(bool _status); protected: - etk::Buffer m_data; //!< copy of the file buffer + std::u32string m_data; //!< copy of the file buffer public: - etk::Buffer& getData() { + std::u32string& getData() { return m_data; }; protected: From 154351e629cfd3de77eb34f6ebc92050fbcb4eb0 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 3 Oct 2014 21:44:13 +0200 Subject: [PATCH 02/11] [ERROR] Abandonned version in std::u32string ==> unexistant regexp --- sources/appl/Buffer.cpp | 78 ++++++++++++++----------------- sources/appl/Gui/TextViewer.cpp | 14 +++--- sources/appl/Highlight.cpp | 4 +- sources/appl/Highlight.h | 4 +- sources/appl/HighlightPattern.cpp | 55 ++++++++++++++++------ sources/appl/HighlightPattern.h | 9 ++-- 6 files changed, 94 insertions(+), 70 deletions(-) diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index dd7cb0e..08656d0 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -357,15 +357,15 @@ void appl::Buffer::moveCursor(int64_t _pos) { bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, appl::Buffer::Iterator &_beginPos, appl::Buffer::Iterator &_endPos) { - char32_t currentValue = *position(_startPos); + char32_t currentValue = *_startPos; _beginPos = begin(); _endPos = end(); if ( currentValue == u32char::Tabulation || currentValue == u32char::Space) { APPL_DEBUG("select spacer"); // Search back - for (Iterator it = --position(_startPos); - (bool)it == true; + for (Iterator it = --Iterator(_startPos); + it != m_data.begin(); --it) { currentValue = *it; if ( currentValue != u32char::Tabulation @@ -375,8 +375,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } // Search forward - for (Iterator it = position(_startPos); - (bool)it == true; + for (Iterator it = _startPos; + it != m_data.end(); ++it) { currentValue = *it; if ( currentValue != u32char::Tabulation @@ -390,8 +390,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, || currentValue == '_') { APPL_DEBUG("select normal Char"); // Search back - for (Iterator it = --position(_startPos); - (bool)it == true; + for (Iterator it = --Iterator(_startPos); + it == m_data.begin(); --it) { currentValue = *it; if ( currentValue != '_' @@ -401,8 +401,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } // Search forward - for (Iterator it = position(_startPos); - (bool)it == true; + for (Iterator it = _startPos; + it != m_data.end(); ++it) { currentValue = *it; if ( currentValue != '_' @@ -416,8 +416,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, APPL_DEBUG("select same char"); char32_t comparechar = currentValue; // Search back - for (Iterator it = --position(_startPos); - (bool)it == true; + for (Iterator it = --Iterator(_startPos); + it == m_data.begin(); --it) { currentValue = *it; if (comparechar != currentValue) { @@ -426,8 +426,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } // Search forward - for (Iterator it = position(_startPos); - (bool)it == true; + for (Iterator it = --Iterator(_startPos); + it != m_data.end(); ++it) { currentValue = *it; if (comparechar != currentValue) { @@ -437,13 +437,13 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } return true; } - _beginPos = begin(); - _endPos = begin(); + _beginPos = m_data.begin(); + _endPos = m_data.begin(); return false; } void appl::Buffer::setSelectionPos(const appl::Buffer::Iterator& _pos) { - m_cursorSelectPos = _pos; + m_cursorSelectPos = std::distance(m_data.begin(), _pos); signalSelectChange.emit(); } @@ -499,8 +499,8 @@ appl::Buffer::Iterator appl::Buffer::countForwardNLines(const appl::Buffer::Iter char32_t value; int32_t lineCount = 0; //APPL_INFO("startPos=" << startPos << " nLines=" << nLines); - for (Iterator it = position(_startPos); - (bool)it == true; + for (Iterator it = Iterator(_startPos); + it != m_data.end(); ++it) { value = *it; if (value == u32char::Return) { @@ -519,8 +519,8 @@ appl::Buffer::Iterator appl::Buffer::countBackwardNLines(const appl::Buffer::Ite //APPL_INFO("startPos=" << startPos << " nLines=" << nLines); char32_t value; int32_t lineCount = 0; - for (Iterator it = --position(_startPos); - (bool)it == true; + for (Iterator it = --Iterator(_startPos); + it != m_data.begin(); --it) { value = *it; if (value == u32char::Return) { @@ -544,7 +544,7 @@ bool appl::Buffer::copy(std::string& _data) { int32_t endPos = getStopSelectionPos(); for (Iterator it = position(startPos); it != position(endPos) && - (bool)it == true; + it != m_data.end(); ++it) { _data += *it; } @@ -557,39 +557,33 @@ void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos, _data.clear(); for (Iterator it = _pos; it != _posEnd && - (bool)it == true; + it != m_data.end(); ++it) { _data += *it; } } bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) { - int64_t position = (int64_t)_pos; - if (position < 0){ - position = 0; - } - APPL_VERBOSE("write at pos: " << (int64_t)_pos << " ==> " << position << " data : " << _data); - m_data.insert(position, (int8_t*)(_data.c_str()), _data.size()); + std::u32string data2 = utf8::convertUnicode(_data); + APPL_VERBOSE("write at pos: " << std::distance(m_data.begin(), _pos) << " data : " << data2); + m_data.insert(_pos, data2.begin(), data2.end()); if (m_cursorPos < 0) { m_cursorPos = 0; } - regenerateHighLightAt(position, 0, _data.size()); + regenerateHighLightAt(std::distance(m_data.begin(), _pos), 0, data2.size()); m_selectMode = false; - moveCursor(position+_data.size()); + moveCursor(std::distance(m_data.begin(),_pos+data2.size())); countNumberofLine(); // TODO : use more intelligent counter setModification(true); return true; } bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { - int64_t position = (int64_t)_pos; - if (position < 0){ - position = 0; - } - m_data.replace(position, (int64_t)_posEnd-(int64_t)_pos, (int8_t*)(_data.c_str()), _data.size()); - regenerateHighLightAt(position, (int64_t)_posEnd-(int64_t)_pos, _data.size()); + std::u32string data2 = utf8::convertUnicode(_data); + m_data.replace(_pos, _posEnd, data2.c_str(), data2.size()); + regenerateHighLightAt(std::distance(m_data.begin(),_pos), std::distance(m_data.begin(),_posEnd)-std::distance(m_data.begin(),_pos), data2.size()); m_selectMode = false; - moveCursor(position+_data.size()); + moveCursor(std::distance(m_data.begin(),_pos+data2.size())); countNumberofLine(); // TODO : use more intelligent counter setModification(true); return true; @@ -601,7 +595,7 @@ void appl::Buffer::removeSelection() { } int64_t startPos = getStartSelectionPos(); int64_t endPos = getStopSelectionPos(); - m_data.remove(startPos, endPos-startPos); + m_data.erase(startPos, endPos-startPos); regenerateHighLightAt(startPos, endPos-startPos, 0); m_selectMode = false; moveCursor(startPos); @@ -823,13 +817,13 @@ void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, const ap //int64_t timeStart = ewol::getTime(); appl::Buffer::Iterator HLStartLine = getStartLine(_HLStart); - int64_t HLStartPos = (int64_t)HLStartLine; + int64_t HLStartPos = std::distance(m_data.begin(),HLStartLine); _MData.HLData.clear(); - int64_t HLStop = (int64_t)countForwardNLines(HLStartLine, _nbLines); + int64_t HLStop = std::distance(m_data.begin(),countForwardNLines(HLStartLine, _nbLines)); int64_t startId = 0; int64_t stopId = 0; // find element previous - findMainHighLightPosition(_HLStart, HLStop, startId, stopId, true); + findMainHighLightPosition(std::distance(m_data.begin(),_HLStart), HLStop, startId, stopId, true); //APPL_DEBUG("List of section between : "<< startId << " & " << stopId); int64_t endSearch = stopId+1; @@ -910,7 +904,7 @@ uint32_t appl::Buffer::getCursorLinesId() { } uint32_t line = 0; for (Iterator it = begin(); - (bool)it == true && it <= cursor(); + it != m_data.end() && it <= cursor(); ++it) { if (*it == u32char::Return) { ++line; diff --git a/sources/appl/Gui/TextViewer.cpp b/sources/appl/Gui/TextViewer.cpp index 2f0f07d..1b2e978 100644 --- a/sources/appl/Gui/TextViewer.cpp +++ b/sources/appl/Gui/TextViewer.cpp @@ -222,7 +222,7 @@ void appl::TextViewer::onRegenerateDisplay() { int64_t startLineId = 0; if (m_size.y() < m_displayText.getPos().y()) { for (startingIt = m_buffer->begin(); - (bool)startingIt == true; + startingIt != m_buffer->end(); ++startingIt) { if (*startingIt == u32char::Return) { ++startLineId; @@ -275,7 +275,7 @@ void appl::TextViewer::onRegenerateDisplay() { bool DisplayCursorAndSelection = isSelectedLast(); appl::Buffer::Iterator it; for (it = startingIt; - (bool)it == true; + it != m_buffer->end(); ++it) { if (it == m_buffer->cursor()) { // need to display the cursor : @@ -307,7 +307,7 @@ void appl::TextViewer::onRegenerateDisplay() { } continue; } - HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (int64_t)it); + HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, std::distance(m_buffer->begin(),it)); bool haveBackground = false; if ( HLColor != nullptr && HLColor->patern != nullptr) { @@ -639,7 +639,7 @@ appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativeP m_displayText.forceLineReturn(); positionCurentDisplay = m_displayText.getPos(); for (appl::Buffer::Iterator it = m_buffer->begin(); - (bool)it == true; + it != m_buffer->end(); ++it) { currentValue = *it; if (currentValue == u32char::Return) { @@ -756,7 +756,7 @@ bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) { updateScrolling(); return true; } - m_buffer->moveCursor((int64_t)_pos); + m_buffer->moveCursor(std::distance(m_buffer->begin(),_pos)); updateScrolling(); return true; } @@ -937,7 +937,7 @@ appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator m_displayText.clear(); m_displayText.forceLineReturn(); for (appl::Buffer::Iterator it = _startLinePos; - (bool)it == true; + it != m_buffer->end(); ++it) { currentValue = *it; m_buffer->expand(countColomn, currentValue, stringToDisplay); @@ -965,7 +965,7 @@ float appl::TextViewer::getScreenSize(const appl::Buffer::Iterator& _startLinePo m_displayText.clear(); for (appl::Buffer::Iterator it = _startLinePos; - (bool)it == true && it <= _stopPos; + it != m_buffer->end() && it <= _stopPos; ++it) { currentValue = *it; //APPL_DEBUG("parse : " << currentValue); diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index 600dc53..9143495 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -168,7 +168,7 @@ void appl::Highlight::parse(int64_t _start, int64_t _stop, std::vector & _metaData, int64_t _addingPos, - etk::Buffer & _buffer) { + std::u32string& _buffer) { if (0 > _addingPos) { _addingPos = 0; } @@ -230,7 +230,7 @@ void appl::Highlight::parse(int64_t _start, void appl::Highlight::parse2(int64_t _start, int64_t _stop, std::vector &_metaData, - etk::Buffer &_buffer) { + std::u32string&_buffer) { HL2_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " == > position search: (" << _start << "," << _stop << ")" ); int64_t elementStart = _start; diff --git a/sources/appl/Highlight.h b/sources/appl/Highlight.h index ec49138..2359cd5 100644 --- a/sources/appl/Highlight.h +++ b/sources/appl/Highlight.h @@ -55,11 +55,11 @@ namespace appl { int64_t _stop, std::vector &_metaData, int64_t _addingPos, - etk::Buffer &_buffer); + std::u32string &_buffer); void parse2(int64_t _start, int64_t _stop, std::vector &_metaData, - etk::Buffer &_buffer); + std::u32string &_buffer); private: void parseRules(exml::Element* _child, std::vector> &_mListPatern, diff --git a/sources/appl/HighlightPattern.cpp b/sources/appl/HighlightPattern.cpp index d4c73a5..389ee52 100644 --- a/sources/appl/HighlightPattern.cpp +++ b/sources/appl/HighlightPattern.cpp @@ -16,25 +16,29 @@ appl::HighlightPattern::HighlightPattern(const std::shared_ptr& _glyphPainting) : m_glyphPainting(_glyphPainting), m_paternName(""), - m_regExp(nullptr), + m_regExp(), m_colorName(""), m_level(0) { - m_regExp = std::unique_ptr>(new etk::RegExp()); + } appl::HighlightPattern::~HighlightPattern() { } -void appl::HighlightPattern::setPatern(std::string& _regExp, bool forceMaximize) { - if (m_regExp == nullptr) { - return; - } - m_regExp->compile(_regExp); - m_regExp->setMaximize(forceMaximize); +void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) { + m_regexValue = _regExp; + const std::u32string data = utf8::convertUnicode(_regExp); + const std::u32string data2 = U"kjhkjhk"; + const std::string data3 = "kjhkjhk"; + //std::basic_regex regexp(data2); + std::basic_regex regexp((const char32_t*)data2.c_str()); + //m_regExp.assign((const std::u32string)data); + //m_regExp.assign(_regExp); + //m_regExp.setMaximize(forceMaximize); } std::string appl::HighlightPattern::getPaternString() { - return m_regExp->getRegExDecorated(); + return m_regexValue; } void appl::HighlightPattern::setColorGlyph(std::string& _colorName) { @@ -46,7 +50,8 @@ void appl::HighlightPattern::setColorGlyph(std::string& _colorName) { void appl::HighlightPattern::display() { APPL_INFO("patern : '" << m_paternName << "' level=" << m_level ); APPL_INFO(" == > colorName '" << m_colorName << "'"); - APPL_INFO(" == > regExp '" << m_regExp->getRegExp() << "'"); + //APPL_INFO(" == > regExp '" << m_regExp.getRegExp() << "'"); + APPL_INFO(" == > regExp '" << m_regexValue << "'"); } void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) { @@ -92,23 +97,47 @@ void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, b } } +typedef std::match_results s32match; enum resultFind appl::HighlightPattern::find(int32_t _start, int32_t _stop, appl::HighlightInfo& _resultat, - etk::Buffer& _buffer) { + const std::u32string& _buffer) { //APPL_DEBUG(" try to find the element"); _resultat.start = -1; _resultat.stop = -1; _resultat.notEnded = false; _resultat.patern = this; - + /* // when we have only one element: - if (true == m_regExp->processOneElement(_buffer, _start, _stop)) { + if (true == m_regExp.processOneElement(_buffer, _start, _stop)) { _resultat.start = m_regExp->start(); _resultat.stop = m_regExp->stop(); return HLP_FIND_OK; } //APPL_DEBUG("NOT find hightlightpatern ..."); return HLP_FIND_ERROR; + */ + + s32match resultMatch; + std::regex_search(_buffer, resultMatch, m_regExp); + if (resultMatch.size() > 0) { + _resultat.start = std::distance(_buffer.begin(), resultMatch[0].first);; + _resultat.stop = std::distance(_buffer.begin(), resultMatch[0].second); + /* + if (false){ + TK_DEBUG("in line : '" << etk::to_string(_buffer) << "'"); + TK_DEBUG(" Find " << resultMatch.size() << " elements"); + for (size_t iii=0; iii #include #include +#include #include #include @@ -44,9 +44,10 @@ namespace appl { return m_paternName; }; private: - std::unique_ptr> m_regExp; //!< Start of Regular expression + std::string m_regexValue; + std::basic_regex m_regExp; //!< Start of Regular expression public: - void setPatern(std::string& _regExp, bool forceMaximize=false); + void setPatern(const std::string& _regExp, bool forceMaximize=false); std::string getPaternString(); private: std::string m_colorName; //!< Current color name @@ -82,7 +83,7 @@ namespace appl { enum resultFind find(int32_t _start, int32_t _stop, appl::HighlightInfo& _resultat, - etk::Buffer& _buffer); + const std::u32string& _buffer); void parseRules(exml::Element* _child, int32_t _level, bool forceMaximize=false); }; From 243d7e7494a8c32fac760a12835c358d31c68201 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 5 Oct 2014 23:46:57 +0200 Subject: [PATCH 03/11] [DEV] change in etk::RegExp in std::regex --- data/languages/c/highlight.xml | 22 ++- sources/appl/Buffer.cpp | 216 ++++++++++++++++-------- sources/appl/Buffer.h | 264 +++++++++++++++++++++++++++++- sources/appl/Gui/TextViewer.cpp | 14 +- sources/appl/Highlight.cpp | 77 +++++---- sources/appl/Highlight.h | 4 +- sources/appl/HighlightPattern.cpp | 33 ++-- sources/appl/HighlightPattern.h | 5 +- 8 files changed, 501 insertions(+), 134 deletions(-) diff --git a/data/languages/c/highlight.xml b/data/languages/c/highlight.xml index 941f4fc..98d63ef 100644 --- a/data/languages/c/highlight.xml +++ b/data/languages/c/highlight.xml @@ -12,39 +12,39 @@ commentDoxygen - /\*\*.*(\*/|\e) + /\*\*(.|\r|\n)*?\*/ SYNTAX_ERROR - /\*[ \t]*TODO :.*(\*/|\e) + /\*[ \t]*TODO :(.|\r|\n)*?\*/ comment - /\*.*(\*/|\e) + /\*(.|\r|\n)*?\*/ preprocesseur - #[ \t]*if 0.*#(endif|else) + #[ \t]*if 0(.|\r|\n)*?#(endif|else) preprocesseur - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)* commentDoxygen - //!.*$ + //!.* SYNTAX_ERROR - //[ \t]*TODO[ \t]*:.*$ + //[ \t]*TODO[ \t]*:.* comment - //.*$ + //.* doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*" doubleQuoteText @@ -106,17 +106,15 @@ functionName \@(\w|_)+[ \t]*\( - --> boolean ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| - macro ([A-Z]|_){4,500} doxElem - --> diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index 08656d0..63ef63d 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -17,33 +17,101 @@ #undef __class__ #define __class__ "Buffer" +appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ () { + m_value = u32char::Null; + if (m_current < 0) { + m_current = 0; + return *this; + } + if (m_data != nullptr) { + if (m_current < (int64_t)m_data->m_data.size() ) { + int8_t nbChar = utf8::theoricLen(m_data->m_data[m_current]); + if (nbChar != 0) { + m_current+=nbChar; + } else { + m_current++; + } + } + if (m_current >= (int64_t)m_data->m_data.size()) { + m_current = m_data->m_data.size(); + } + } + return *this; +} + +appl::Buffer::Iterator& appl::Buffer::Iterator::operator-- () { + m_value = u32char::Null; + if (m_data != nullptr) { + if (m_current > 0) { + int32_t iii = -1; + while( utf8::theoricFirst(m_data->m_data[m_current+iii]) == false + && iii >= -6 + && m_current-iii>0) { + --iii; + }; + m_current += iii; + } else { + m_current = -1; + } + return *this; + } else { + m_current = -1; + } + return *this; +} + +char32_t appl::Buffer::Iterator::operator* () { + if (m_value != u32char::Null) { + return m_value; + } + if (m_data == nullptr) { + APPL_ERROR("request an element that iterator not link"); + return m_value; + } + if ( m_current < 0 + || m_current >= (int64_t)m_data->m_data.size()) { + APPL_ERROR("request an element out of bounding !!! 0 <= " << m_current << " < " << m_data->m_data.size()); + return m_value; + } + char tmpVal[5]; + memset(tmpVal, 0, sizeof(tmpVal)); + tmpVal[0] = m_data->m_data[m_current]; + int8_t nbChar = utf8::theoricLen(tmpVal[0]); + for (int32_t iii=1; iiim_data.size(); ++iii) { + tmpVal[iii] = m_data->m_data[m_current+iii]; + } + // transform ... + m_value = utf8::convertChar32(tmpVal); + return m_value; +} + appl::Buffer::Iterator appl::Buffer::position(int64_t _pos) { - return m_data.begin() + _pos; + return appl::Buffer::Iterator(this, _pos); } appl::Buffer::Iterator appl::Buffer::begin() { - return m_data.begin(); + return position(0); } appl::Buffer::Iterator appl::Buffer::end() { // TODO : chek the validity of the char ... - return m_data.end(); + return position( m_data.size() ); } appl::Buffer::Iterator appl::Buffer::cursor() { if (m_cursorPos<= 0) { - return m_data.begin(); + return begin(); } - return m_data.begin() + m_cursorPos; + return position( m_cursorPos ); } appl::Buffer::Iterator appl::Buffer::selectStart() { - return m_data.begin() + getStartSelectionPos(); + return position( getStartSelectionPos() ); } appl::Buffer::Iterator appl::Buffer::selectStop() { - return m_data.begin() + getStopSelectionPos(); + return position( getStopSelectionPos() ); } appl::Buffer::Buffer() : @@ -84,15 +152,20 @@ bool appl::Buffer::loadFile(const std::string& _name) { m_cursorPos = 0; setHighlightType(""); m_nbLines = 0; - etk::FSNode filee(m_fileName); - if (filee.exist() == true) { - m_data = file.fileReadAllU32String(); - countNumberofLine(); - tryFindHighlightType(); - m_isModify = false; - return true; + if (file.exist() == false) { + APPL_ERROR("File : '" << m_fileName << "' does not exist..."); + return false; } - return false; + if (file.fileOpenRead() == false) { + APPL_ERROR("File : '" << m_fileName << "' Fail to open in read mode"); + return false; + } + m_data = file.fileReadAllString(); + file.fileClose(); + countNumberofLine(); + tryFindHighlightType(); + m_isModify = false; + return true; } void appl::Buffer::setFileName(const std::string& _name) { @@ -109,8 +182,13 @@ void appl::Buffer::setFileName(const std::string& _name) { } bool appl::Buffer::storeFile() { - etk::FSNode filee(m_fileName); - filee.fileWriteAll(m_data); + etk::FSNode file(m_fileName); + if (file.fileOpenWrite() == false) { + APPL_ERROR("File : '" << m_fileName << "' Fail to open in write mode"); + return false; + } + file.fileWriteAll(m_data); + file.fileClose(); APPL_INFO("saving file : " << m_fileName); setModification(false); return true; @@ -131,8 +209,10 @@ void appl::Buffer::setModification(bool _status) { // TODO : Naming error void appl::Buffer::countNumberofLine() { m_nbLines = 1; - for (auto &it : m_data) { - if (it == u32char::Return) { + for (Iterator it = begin(); + (bool)it == true; + ++it) { + if (*it == u32char::Return) { ++m_nbLines; } } @@ -161,21 +241,21 @@ appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _p bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) { // move in the string for (Iterator it = _pos; - it != m_data.end(); + (bool)it == true; ++it) { if (*it == _search) { _result = it; return true; } } - _result = m_data.end(); + _result = end(); return false; } bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) { // move in the string for (Iterator it = _pos - 1; - it != m_data.begin(); + (bool)it == true; --it) { //APPL_DEBUG("compare : " << *it << " ?= " << _search); if (*it == _search) { @@ -198,7 +278,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, if (_caseSensitive == true) { // move in the string for (Iterator it = _pos; - it == m_data.end(); + (bool)it == true; ++it) { if (*it == _search[0]) { // find the first char ==> check next... @@ -210,7 +290,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, break; } ++tmp; - if (tmp == m_data.end()) { + if ((bool)tmp == false) { if (iii != _search.size()-1) { find = false; } @@ -227,7 +307,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, char32_t firstElement = tolower(_search[0]); // move in the string for (Iterator it = _pos; - it == m_data.end(); + (bool)it == true; ++it) { if ((char32_t)tolower(*it) == firstElement) { // find the first char ==> check next... @@ -239,7 +319,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, break; } ++tmp; - if (tmp != m_data.end()) { + if ((bool)tmp == false) { if (iii != _search.size()-1) { find = false; } @@ -268,7 +348,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, if (_caseSensitive == true) { // move in the string for (Iterator it = _pos - 1; - it != m_data.begin(); + (bool)it == true; --it) { //APPL_DEBUG("compare : " << *it << " ?= " << _search); if (*it == lastElement) { @@ -281,7 +361,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, break; } --_result; - if (_result == m_data.begin()) { + if ((bool)_result == false) { if (iii != 0) { find = false; } @@ -298,7 +378,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, lastElement = tolower(lastElement); // move in the string for (Iterator it = _pos - 1; - it != m_data.begin(); + (bool)it == true; --it) { //APPL_DEBUG("compare : " << *it << " ?= " << _search); if ((char32_t)tolower(*it) == lastElement) { @@ -311,7 +391,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, break; } --_result; - if (_result == m_data.begin()) { + if ((bool)_result == false) { if (iii != 0) { find = false; } @@ -357,15 +437,15 @@ void appl::Buffer::moveCursor(int64_t _pos) { bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, appl::Buffer::Iterator &_beginPos, appl::Buffer::Iterator &_endPos) { - char32_t currentValue = *_startPos; + char32_t currentValue = *position(_startPos); _beginPos = begin(); _endPos = end(); if ( currentValue == u32char::Tabulation || currentValue == u32char::Space) { APPL_DEBUG("select spacer"); // Search back - for (Iterator it = --Iterator(_startPos); - it != m_data.begin(); + for (Iterator it = --position(_startPos); + (bool)it == true; --it) { currentValue = *it; if ( currentValue != u32char::Tabulation @@ -375,8 +455,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } // Search forward - for (Iterator it = _startPos; - it != m_data.end(); + for (Iterator it = position(_startPos); + (bool)it == true; ++it) { currentValue = *it; if ( currentValue != u32char::Tabulation @@ -390,8 +470,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, || currentValue == '_') { APPL_DEBUG("select normal Char"); // Search back - for (Iterator it = --Iterator(_startPos); - it == m_data.begin(); + for (Iterator it = --position(_startPos); + (bool)it == true; --it) { currentValue = *it; if ( currentValue != '_' @@ -401,8 +481,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } // Search forward - for (Iterator it = _startPos; - it != m_data.end(); + for (Iterator it = position(_startPos); + (bool)it == true; ++it) { currentValue = *it; if ( currentValue != '_' @@ -416,8 +496,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, APPL_DEBUG("select same char"); char32_t comparechar = currentValue; // Search back - for (Iterator it = --Iterator(_startPos); - it == m_data.begin(); + for (Iterator it = --position(_startPos); + (bool)it == true; --it) { currentValue = *it; if (comparechar != currentValue) { @@ -426,8 +506,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } // Search forward - for (Iterator it = --Iterator(_startPos); - it != m_data.end(); + for (Iterator it = position(_startPos); + (bool)it == true; ++it) { currentValue = *it; if (comparechar != currentValue) { @@ -437,13 +517,13 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } return true; } - _beginPos = m_data.begin(); - _endPos = m_data.begin(); + _beginPos = begin(); + _endPos = begin(); return false; } void appl::Buffer::setSelectionPos(const appl::Buffer::Iterator& _pos) { - m_cursorSelectPos = std::distance(m_data.begin(), _pos); + m_cursorSelectPos = _pos; signalSelectChange.emit(); } @@ -499,8 +579,8 @@ appl::Buffer::Iterator appl::Buffer::countForwardNLines(const appl::Buffer::Iter char32_t value; int32_t lineCount = 0; //APPL_INFO("startPos=" << startPos << " nLines=" << nLines); - for (Iterator it = Iterator(_startPos); - it != m_data.end(); + for (Iterator it = position(_startPos); + (bool)it == true; ++it) { value = *it; if (value == u32char::Return) { @@ -519,8 +599,8 @@ appl::Buffer::Iterator appl::Buffer::countBackwardNLines(const appl::Buffer::Ite //APPL_INFO("startPos=" << startPos << " nLines=" << nLines); char32_t value; int32_t lineCount = 0; - for (Iterator it = --Iterator(_startPos); - it != m_data.begin(); + for (Iterator it = --position(_startPos); + (bool)it == true; --it) { value = *it; if (value == u32char::Return) { @@ -544,7 +624,7 @@ bool appl::Buffer::copy(std::string& _data) { int32_t endPos = getStopSelectionPos(); for (Iterator it = position(startPos); it != position(endPos) && - it != m_data.end(); + (bool)it == true; ++it) { _data += *it; } @@ -557,33 +637,39 @@ void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos, _data.clear(); for (Iterator it = _pos; it != _posEnd && - it != m_data.end(); + (bool)it == true; ++it) { _data += *it; } } bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) { - std::u32string data2 = utf8::convertUnicode(_data); - APPL_VERBOSE("write at pos: " << std::distance(m_data.begin(), _pos) << " data : " << data2); - m_data.insert(_pos, data2.begin(), data2.end()); + int64_t position = (int64_t)_pos; + if (position < 0){ + position = 0; + } + APPL_VERBOSE("write at pos: " << (int64_t)_pos << " ==> " << position << " data : " << _data); + m_data.insert((size_t)position, _data); if (m_cursorPos < 0) { m_cursorPos = 0; } - regenerateHighLightAt(std::distance(m_data.begin(), _pos), 0, data2.size()); + regenerateHighLightAt(position, 0, _data.size()); m_selectMode = false; - moveCursor(std::distance(m_data.begin(),_pos+data2.size())); + moveCursor(position+_data.size()); countNumberofLine(); // TODO : use more intelligent counter setModification(true); return true; } bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { - std::u32string data2 = utf8::convertUnicode(_data); - m_data.replace(_pos, _posEnd, data2.c_str(), data2.size()); - regenerateHighLightAt(std::distance(m_data.begin(),_pos), std::distance(m_data.begin(),_posEnd)-std::distance(m_data.begin(),_pos), data2.size()); + int64_t position = (int64_t)_pos; + if (position < 0){ + position = 0; + } + m_data.replace(m_data.begin() + position, m_data.begin() + (int64_t)_posEnd, _data.begin(), _data.end()); + regenerateHighLightAt(position, (int64_t)_posEnd-(int64_t)_pos, _data.size()); m_selectMode = false; - moveCursor(std::distance(m_data.begin(),_pos+data2.size())); + moveCursor(position+_data.size()); countNumberofLine(); // TODO : use more intelligent counter setModification(true); return true; @@ -817,13 +903,13 @@ void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, const ap //int64_t timeStart = ewol::getTime(); appl::Buffer::Iterator HLStartLine = getStartLine(_HLStart); - int64_t HLStartPos = std::distance(m_data.begin(),HLStartLine); + int64_t HLStartPos = (int64_t)HLStartLine; _MData.HLData.clear(); - int64_t HLStop = std::distance(m_data.begin(),countForwardNLines(HLStartLine, _nbLines)); + int64_t HLStop = (int64_t)countForwardNLines(HLStartLine, _nbLines); int64_t startId = 0; int64_t stopId = 0; // find element previous - findMainHighLightPosition(std::distance(m_data.begin(),_HLStart), HLStop, startId, stopId, true); + findMainHighLightPosition(_HLStart, HLStop, startId, stopId, true); //APPL_DEBUG("List of section between : "<< startId << " & " << stopId); int64_t endSearch = stopId+1; @@ -904,7 +990,7 @@ uint32_t appl::Buffer::getCursorLinesId() { } uint32_t line = 0; for (Iterator it = begin(); - it != m_data.end() && it <= cursor(); + (bool)it == true && it <= cursor(); ++it) { if (*it == u32char::Return) { ++line; diff --git a/sources/appl/Buffer.h b/sources/appl/Buffer.h index 372b08c..d182f1a 100644 --- a/sources/appl/Buffer.h +++ b/sources/appl/Buffer.h @@ -29,7 +29,265 @@ namespace appl { }; class Buffer : public ewol::Object { public: - using Iterator = std::u32string::iterator; + class Iterator { + // Private data : + private: + int64_t m_current; //!< curent Id in the Buffer + appl::Buffer* m_data; //!< Pointer on the curent Buffer + char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data + public: + /** + * @brief Basic itarator constructor with no link. + */ + Iterator(): + m_current(0), + m_data(nullptr), + m_value(u32char::Null) { + // nothing to do ... + }; + /** + * @brief Recopy constructor. + * @param[in] _obj The Iterator that might be copy + */ + Iterator(const Iterator & _obj): + m_current(_obj.m_current), + m_data(_obj.m_data), + m_value(u32char::Null) { + // nothing to do ... + }; + /** + * @brief Asignation operator. + * @param[in] _otherIterator The Iterator that might be copy + * @return reference on the curent Iterator + */ + Iterator& operator=(const Iterator & _obj) { + m_current = _obj.m_current; + m_data = _obj.m_data; + m_value = u32char::Null; + return *this; + }; + /** + * @brief Basic destructor + */ + virtual ~Iterator() { + m_current = 0; + m_data = nullptr; + m_value = u32char::Null; + }; + /** + * @brief basic boolean cast + * @return true if the element is present in buffer + */ + operator bool () const { + if (m_data == nullptr) { + return false; + } + if (m_current >= (int64_t)m_data->m_data.size()) { + return false; + } + if (m_current < 0) { + return false; + } + return true; + }; + /** + * @brief basic boolean cast + * @return true if the element is present in buffer + */ + operator int64_t () const { + if (m_data == nullptr) { + return 0; + } + if (m_current < 0) { + return 0; + } + if (m_current > (int64_t)m_data->m_data.size()) { + return (int64_t)m_data->m_data.size(); + } + return m_current; + }; + /** + * @brief Incremental operator + * @return Reference on the current iterator incremented + */ + Iterator& operator++ (); + /** + * @brief Decremental operator + * @return Reference on the current iterator decremented + */ + Iterator& operator-- (); + /** + * @brief Incremental operator + * @return Reference on a new iterator and increment the other one + */ + Iterator operator++ (int32_t) { + Iterator it(*this); + ++(*this); + return it; + }; + /** + * @brief Decremental operator + * @return Reference on a new iterator and decrement the other one + */ + Iterator operator-- (int32_t) { + Iterator it(*this); + --(*this); + return it; + }; + /** + * @brief egality iterator + * @return true if the iterator is identical pos + */ + bool operator== (const Iterator& _obj) const { + if ( m_current == _obj.m_current + && m_data == _obj.m_data) { + return true; + } + return false; + }; + /** + * @brief egality iterator + * @return true if the iterator is identical pos + */ + bool operator!= (const Iterator& _obj) const { + if ( m_current != _obj.m_current + || m_data != _obj.m_data) { + return true; + } + return false; + }; + /** + * @brief <= iterator + * @return true if the iterator is identical pos + */ + bool operator<= (const Iterator& _obj) const { + if (m_data != _obj.m_data) { + return false; + } + if (m_current <= _obj.m_current) { + return true; + } + return false; + }; + /** + * @brief >= iterator + * @return true if the iterator is identical pos + */ + bool operator>= (const Iterator& _obj) const { + if (m_data != _obj.m_data) { + return false; + } + if (m_current >= _obj.m_current) { + return true; + } + return false; + }; + /** + * @brief < iterator + * @return true if the iterator is identical pos + */ + bool operator< (const Iterator& _obj) const { + if (m_data != _obj.m_data) { + return false; + } + if (m_current < _obj.m_current) { + return true; + } + return false; + }; + /** + * @brief > iterator + * @return true if the iterator is identical pos + */ + bool operator> (const Iterator& _obj) const { + if (m_data != _obj.m_data) { + return false; + } + if (m_current > _obj.m_current) { + return true; + } + return false; + }; + /** + * @brief Get the value on the current element + * @return The request element value + */ + char32_t operator* (); + /** + * @brief Get the position in the buffer + * @return The requested position. + */ + int64_t getPos() const { + if (m_data == nullptr) { + return 0; + } + if (m_current < 0) { + return 0; + } + if (m_current >= (int64_t)m_data->m_data.size()) { + return m_data->m_data.size()-1; + } + return m_current; + }; + /** + * @brief move the element position + * @return a new iterator. + */ + Iterator operator+ (const int64_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<_val; ++iii) { + ++tmpp; + } + return tmpp; + }; + Iterator operator+ (const int32_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<_val; ++iii) { + ++tmpp; + } + return tmpp; + }; + Iterator operator+ (const size_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<(int64_t)_val; ++iii) { + ++tmpp; + } + return tmpp; + }; + /** + * @brief move the element position + * @return a new iterator. + */ + Iterator operator- (const int64_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<_val; ++iii) { + --tmpp; + } + return tmpp; + }; + Iterator operator- (const int32_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<_val; ++iii) { + --tmpp; + } + return tmpp; + }; + Iterator operator- (const size_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<(int64_t)_val; ++iii) { + --tmpp; + } + return tmpp; + }; + private: + Iterator(Buffer* _obj, int64_t _pos) : + m_current(_pos), + m_data(_obj), + m_value(u32char::Null) { + // nothing to do ... + }; + friend class Buffer; + }; public: ewol::object::Signal signalIsModify; ewol::object::Signal signalIsSave; @@ -90,9 +348,9 @@ namespace appl { */ void setModification(bool _status); protected: - std::u32string m_data; //!< copy of the file buffer + std::string m_data; //!< copy of the file buffer public: - std::u32string& getData() { + std::string& getData() { return m_data; }; protected: diff --git a/sources/appl/Gui/TextViewer.cpp b/sources/appl/Gui/TextViewer.cpp index 1b2e978..2f0f07d 100644 --- a/sources/appl/Gui/TextViewer.cpp +++ b/sources/appl/Gui/TextViewer.cpp @@ -222,7 +222,7 @@ void appl::TextViewer::onRegenerateDisplay() { int64_t startLineId = 0; if (m_size.y() < m_displayText.getPos().y()) { for (startingIt = m_buffer->begin(); - startingIt != m_buffer->end(); + (bool)startingIt == true; ++startingIt) { if (*startingIt == u32char::Return) { ++startLineId; @@ -275,7 +275,7 @@ void appl::TextViewer::onRegenerateDisplay() { bool DisplayCursorAndSelection = isSelectedLast(); appl::Buffer::Iterator it; for (it = startingIt; - it != m_buffer->end(); + (bool)it == true; ++it) { if (it == m_buffer->cursor()) { // need to display the cursor : @@ -307,7 +307,7 @@ void appl::TextViewer::onRegenerateDisplay() { } continue; } - HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, std::distance(m_buffer->begin(),it)); + HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (int64_t)it); bool haveBackground = false; if ( HLColor != nullptr && HLColor->patern != nullptr) { @@ -639,7 +639,7 @@ appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativeP m_displayText.forceLineReturn(); positionCurentDisplay = m_displayText.getPos(); for (appl::Buffer::Iterator it = m_buffer->begin(); - it != m_buffer->end(); + (bool)it == true; ++it) { currentValue = *it; if (currentValue == u32char::Return) { @@ -756,7 +756,7 @@ bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) { updateScrolling(); return true; } - m_buffer->moveCursor(std::distance(m_buffer->begin(),_pos)); + m_buffer->moveCursor((int64_t)_pos); updateScrolling(); return true; } @@ -937,7 +937,7 @@ appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator m_displayText.clear(); m_displayText.forceLineReturn(); for (appl::Buffer::Iterator it = _startLinePos; - it != m_buffer->end(); + (bool)it == true; ++it) { currentValue = *it; m_buffer->expand(countColomn, currentValue, stringToDisplay); @@ -965,7 +965,7 @@ float appl::TextViewer::getScreenSize(const appl::Buffer::Iterator& _startLinePo m_displayText.clear(); for (appl::Buffer::Iterator it = _startLinePos; - it != m_buffer->end() && it <= _stopPos; + (bool)it == true && it <= _stopPos; ++it) { currentValue = *it; //APPL_DEBUG("parse : " << currentValue); diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index 9143495..7583774 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -168,7 +168,7 @@ void appl::Highlight::parse(int64_t _start, int64_t _stop, std::vector & _metaData, int64_t _addingPos, - std::u32string& _buffer) { + std::string& _buffer) { if (0 > _addingPos) { _addingPos = 0; } @@ -178,6 +178,8 @@ void appl::Highlight::parse(int64_t _start, appl::HighlightInfo resultat; while (elementStart <= elementStop) { HL_DEBUG("Parse element in the buffer pos=" << elementStart); + appl::HighlightInfo resultatLast; + int64_t findAnOtherId = -1; //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; @@ -185,38 +187,53 @@ void appl::Highlight::parse(int64_t _start, // 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) { - HL_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ")" ); - // 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 <= resultat.stop) { - // remove element - HL_DEBUG("Erase element=" << kkk); - _metaData.erase(_metaData.begin()+kkk, _metaData.begin()+kkk+1); - // Increase the end of search - if (kkk < (int64_t)_metaData.size()) { - // just befor the end of the next element - elementStop = _metaData[kkk].start-1; - } else { - // end of the buffer - elementStop = _buffer.size(); - } - } else { - // Not find == > exit the 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; } } - // add curent element in the list ... - _metaData.insert(_metaData.begin()+_addingPos, resultat); - HL_DEBUG("INSERT at "<< _addingPos << " S=" << resultat.start << " E=" << resultat.stop ); - // update the current research starting element: (set position at the end of the current element - elementStart = resultat.stop-1; - // increment the position of insertion: - _addingPos++; - // We find a pattern == > Stop search for the current element - break; } } + if (findAnOtherId != -1) { + // 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); + _metaData.erase(_metaData.begin()+kkk, _metaData.begin()+kkk+1); + // Increase the end of search + if (kkk < (int64_t)_metaData.size()) { + // just befor the end of the next element + elementStop = _metaData[kkk].start-1; + } else { + // end of the buffer + elementStop = _buffer.size(); + } + } else { + // Not find == > exit the cycle : + break; + } + } + // add curent element in the list ... + _metaData.insert(_metaData.begin()+_addingPos, resultatLast); + HL_DEBUG("INSERT at "<< _addingPos << " S=" << resultatLast.start << " E=" << resultatLast.stop ); + // update the current research starting element: (set position at the end of the current element + elementStart = resultatLast.stop-1; + // increment the position of insertion: + _addingPos++; + // We find a pattern == > Stop search for the current element + } else { + break; + } // Go to the next element (and search again ...). elementStart++; } @@ -230,7 +247,7 @@ void appl::Highlight::parse(int64_t _start, void appl::Highlight::parse2(int64_t _start, int64_t _stop, std::vector &_metaData, - std::u32string&_buffer) { + std::string&_buffer) { HL2_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " == > position search: (" << _start << "," << _stop << ")" ); int64_t elementStart = _start; diff --git a/sources/appl/Highlight.h b/sources/appl/Highlight.h index 2359cd5..8dbb1ea 100644 --- a/sources/appl/Highlight.h +++ b/sources/appl/Highlight.h @@ -55,11 +55,11 @@ namespace appl { int64_t _stop, std::vector &_metaData, int64_t _addingPos, - std::u32string &_buffer); + std::string &_buffer); void parse2(int64_t _start, int64_t _stop, std::vector &_metaData, - std::u32string &_buffer); + std::string &_buffer); private: void parseRules(exml::Element* _child, std::vector> &_mListPatern, diff --git a/sources/appl/HighlightPattern.cpp b/sources/appl/HighlightPattern.cpp index 389ee52..441403d 100644 --- a/sources/appl/HighlightPattern.cpp +++ b/sources/appl/HighlightPattern.cpp @@ -16,6 +16,8 @@ appl::HighlightPattern::HighlightPattern(const std::shared_ptr& _glyphPainting) : m_glyphPainting(_glyphPainting), m_paternName(""), + m_hasParsingError(true), + m_regexValue(""), m_regExp(), m_colorName(""), m_level(0) { @@ -28,13 +30,13 @@ appl::HighlightPattern::~HighlightPattern() { void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) { m_regexValue = _regExp; - const std::u32string data = utf8::convertUnicode(_regExp); - const std::u32string data2 = U"kjhkjhk"; - const std::string data3 = "kjhkjhk"; - //std::basic_regex regexp(data2); - std::basic_regex regexp((const char32_t*)data2.c_str()); - //m_regExp.assign((const std::u32string)data); - //m_regExp.assign(_regExp); + try { + m_regExp.assign(_regExp); + m_hasParsingError = false; + } catch (std::regex_error e) { + m_hasParsingError = true; + APPL_ERROR("can not parse regExp : '" << e.what() << "' for : " << _regExp); + } //m_regExp.setMaximize(forceMaximize); } std::string appl::HighlightPattern::getPaternString() { @@ -97,17 +99,20 @@ void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, b } } -typedef std::match_results s32match; enum resultFind appl::HighlightPattern::find(int32_t _start, - int32_t _stop, - appl::HighlightInfo& _resultat, - const std::u32string& _buffer) { + int32_t _stop, + appl::HighlightInfo& _resultat, + const std::string& _buffer) { //APPL_DEBUG(" try to find the element"); _resultat.start = -1; _resultat.stop = -1; _resultat.notEnded = false; _resultat.patern = this; + if (m_hasParsingError == true) { + return HLP_FIND_ERROR; + } + /* // when we have only one element: if (true == m_regExp.processOneElement(_buffer, _start, _stop)) { @@ -119,11 +124,13 @@ enum resultFind appl::HighlightPattern::find(int32_t _start, return HLP_FIND_ERROR; */ - s32match resultMatch; - std::regex_search(_buffer, resultMatch, m_regExp); + 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); 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='" < m_regExp; //!< Start of Regular expression + std::regex m_regExp; //!< Start of Regular expression public: void setPatern(const std::string& _regExp, bool forceMaximize=false); std::string getPaternString(); @@ -83,7 +84,7 @@ namespace appl { enum resultFind find(int32_t _start, int32_t _stop, appl::HighlightInfo& _resultat, - const std::u32string& _buffer); + const std::string& _buffer); void parseRules(exml::Element* _child, int32_t _level, bool forceMaximize=false); }; From d93844d6da2dfc2e55533afbd902bf7af12c6edd Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 6 Oct 2014 23:22:14 +0200 Subject: [PATCH 04/11] [DEV] first std::regex really work in c++ --- data/languages/c/highlight.xml | 36 ++++++++--------- sources/appl/Highlight.cpp | 66 ++++++++++++++++++++++++------- sources/appl/HighlightPattern.cpp | 18 +++++++-- 3 files changed, 83 insertions(+), 37 deletions(-) diff --git a/data/languages/c/highlight.xml b/data/languages/c/highlight.xml index 98d63ef..92241c4 100644 --- a/data/languages/c/highlight.xml +++ b/data/languages/c/highlight.xml @@ -50,71 +50,69 @@ doubleQuoteText '((\\[\\'])|.){1,2}' - - SYNTAX_ERROR - ' - keyword - \@return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof\@ + \b(return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof)\b systemFunction - \@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(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 type - \@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(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 type - \@std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair)\@ + \b(std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair))\b storageKeyword - \@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(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 commonDefine - \@NULL|MAX|MIN|__LINE__|__DATA__|__FILE__|__func__|__TIME__|__STDC__\@ + \b(NULL|MAX|MIN|__LINE__|__DATA__|__FILE__|__func__|__TIME__|__STDC__)\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@true|TRUE|false|FALSE\@ + \b(true|TRUE|false|FALSE)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b memberClass - \@m_[A-Za-z_0-9]*\@ + \b(m_[A-Za-z_0-9]*)\b inputFunction - \@_[A-Za-z_0-9]*\@ + \b(_[A-Za-z_0-9]*)\b false - macro ([A-Z]|_){4,500} doxElem + + SYNTAX_ERROR + '|" + diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index 7583774..893caa9 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -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++; } diff --git a/sources/appl/HighlightPattern.cpp b/sources/appl/HighlightPattern.cpp index 441403d..a9b8c9f 100644 --- a/sources/appl/HighlightPattern.cpp +++ b/sources/appl/HighlightPattern.cpp @@ -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='" < Date: Tue, 7 Oct 2014 00:45:01 +0200 Subject: [PATCH 05/11] [DEV] correction of the regex and add some basic test example --- data/languages/asm/highlight.xml | 18 ++++---- data/languages/bash/highlight.xml | 14 +++--- data/languages/boo/highlight.xml | 12 +++--- data/languages/cmake/highlight.xml | 22 +++++----- data/languages/glsl/highlight.xml | 16 +++---- data/languages/in/highlight.xml | 16 +++---- data/languages/java/highlight.xml | 36 ++++++++-------- data/languages/json/highlight.xml | 6 +-- data/languages/lua/highlight.xml | 24 +++++------ data/languages/makefile/highlight.xml | 10 ++--- data/languages/matlab/highlight.xml | 24 +++++------ data/languages/php/highlight.xml | 28 ++++++------ data/languages/python/highlight.xml | 32 +++++++------- data/languages/xml/highlight.xml | 8 ++-- test/CMakeFile.txt | 0 test/Makefile | 0 test/asm.asm | 0 test/bash.bash | 0 test/boo.boo | 0 test/cpp.cpp | 0 test/html.html | 0 test/in.in | 0 test/java.java | 0 test/lua.lua | 0 test/matlab.m | 0 test/php.php | 62 +++++++++++++++++++++++++++ test/python.py | 0 test/vertexShader.frag | 52 ++++++++++++++++++++++ test/xml.xml | 12 ++++++ 29 files changed, 252 insertions(+), 140 deletions(-) create mode 100644 test/CMakeFile.txt create mode 100644 test/Makefile create mode 100644 test/asm.asm create mode 100644 test/bash.bash create mode 100644 test/boo.boo create mode 100644 test/cpp.cpp create mode 100644 test/html.html create mode 100644 test/in.in create mode 100644 test/java.java create mode 100644 test/lua.lua create mode 100644 test/matlab.m create mode 100644 test/php.php create mode 100644 test/python.py create mode 100644 test/vertexShader.frag create mode 100644 test/xml.xml diff --git a/data/languages/asm/highlight.xml b/data/languages/asm/highlight.xml index cb7cee7..0126cfe 100644 --- a/data/languages/asm/highlight.xml +++ b/data/languages/asm/highlight.xml @@ -6,41 +6,41 @@ commentDoxygen - /\*\*.*\*/ + /\*\*.*?\*/ comment - /\*.*\*/ + /\*.*?\*/ preprocesseur - #[ \t]*if 0.*#(regexif|else) + #[ \t]*if 0.*?#(regexif|else) preprocesseur - #.*$ + #.*?$ commentDoxygen - //!.*$ + //!.*?$ SYNTAX_ERROR - //[ \t]*TODO[ \t]*:.*$ + //[ \t]*TODO[ \t]*:.*?$ comment - (//|@).*$ + //.*?$ keyword - \@smull|ldrsh|smlal|stmdb|mul|mla|umull|ldr|add|str|mov|subs|bgt|ldmia|stmia|ldmfd|cmp|sub|strd|stmfd|bne|bhi|ldrd|mvn\@ + \b(smull|ldrsh|smlal|stmdb|mul|mla|umull|ldr|add|str|mov|subs|bgt|ldmia|stmia|ldmfd|cmp|sub|strd|stmfd|bne|bhi|ldrd|mvn)\b type - \@r(10|11|12|[0-9]?)|sp|lp|lr|pc\@ + \b(r(10|11|12|[0-9]?)|sp|lp|lr|pc)\b diff --git a/data/languages/bash/highlight.xml b/data/languages/bash/highlight.xml index cc334a6..2e8452e 100644 --- a/data/languages/bash/highlight.xml +++ b/data/languages/bash/highlight.xml @@ -4,39 +4,37 @@ commentDoxygen - #!(\\[\\\n]|.)*$ + #!(\\[\\\n]|.)*?$ comment - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - '(\\[\\']|.)*' + '(\\[\\']|.)*?' keyword - \@for|done|do|while|in|if|elif|then|else|fi\@ + \b(for|done|do|while|in|if|elif|then|else|fi)\b keyword [\$]+[a-zA-Z_][a-zA-Z0-9_]* - boolean - ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} diff --git a/data/languages/boo/highlight.xml b/data/languages/boo/highlight.xml index 704ef55..392599d 100644 --- a/data/languages/boo/highlight.xml +++ b/data/languages/boo/highlight.xml @@ -4,23 +4,23 @@ SYNTAX_ERROR - ##.*$ + ##.*?$ comment - #.*$ + #.*?$ preprocesseur - (NOTE|TODO) : .*$ + (NOTE|TODO) : .*?$ doubleQuoteText - "(\\[\\"]|.)*$ + "(\\[\\"]|.)*?$ doubleQuoteText - \@'(\\[\\']|.)*$ + \b'(\\[\\']|.)*?$ @@ -33,7 +33,7 @@ number [0-9]*% - + TestResultOK \[( )*(OK|Ok|ok)( )*\] diff --git a/data/languages/cmake/highlight.xml b/data/languages/cmake/highlight.xml index 3713d9a..4d7ea84 100644 --- a/data/languages/cmake/highlight.xml +++ b/data/languages/cmake/highlight.xml @@ -5,47 +5,45 @@ commentDoxygen - ##.*$ + ##.*?$ SYNTAX_ERROR - #[ \t]TODO[ \t]*:(\\[\\\n]|.)*$ + #[ \t]TODO[ \t]*:(\\[\\\n]|.)*?$ comment - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*$ + "(\\[\\"]|.)*?$ keyword - \@foreach|message|endforeach|if|else|endif|list|file|string\@ + \b(foreach|message|endforeach|if|else|endif|list|file|string)\b systemFunction - \@set|include_directories|add_definitions|add_library|include_directories|target_link_libraries|project|include|check_include_file|enable_testing|option|cmake_minimum_required|add_definitions|check_include_file|configure_file|include_directories|add_custom_command|add_executable|add_test\@ + \b(set|include_directories|add_definitions|add_library|include_directories|target_link_libraries|project|include|check_include_file|enable_testing|option|cmake_minimum_required|add_definitions|check_include_file|configure_file|include_directories|add_custom_command|add_executable|add_test)\b inputFunction - \${.*} + \$\{.*\} number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b - diff --git a/data/languages/glsl/highlight.xml b/data/languages/glsl/highlight.xml index 5e745e6..97d4c06 100644 --- a/data/languages/glsl/highlight.xml +++ b/data/languages/glsl/highlight.xml @@ -37,35 +37,35 @@ keyword - \@return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof\@ + \b(return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof)\b type - \@void|bool|float|int|(vec|mat|ivect|bvect)[2-4]\@ + \b(void|bool|float|int|(vec|mat|ivect|bvect)[2-4])\b storageKeyword - \@varying|uniform|attribute|precision|mediump\@ + \b(varying|uniform|attribute|precision|mediump)\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@true|false\@ + \b(true|false)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b functionName - \@(\w|_)+[ \t]*\( + \b(\w|_)+[ \t]*\( boolean - ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} diff --git a/data/languages/in/highlight.xml b/data/languages/in/highlight.xml index fc16d28..4245674 100644 --- a/data/languages/in/highlight.xml +++ b/data/languages/in/highlight.xml @@ -4,37 +4,37 @@ preprocesseur - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*$ + "(\\[\\"]|.)*?$ doubleQuoteText - '(\\[\\']|.)*$ + '(\\[\\']|.)*?$ keyword - \@menu|endmenu|comment|if|endif|help|default|choice|endchoice|prompt|depends on|config\@ + \b(menu|endmenu|comment|if|endif|help|default|choice|endchoice|prompt|depends on|config)\b type - \@int|hex|bool|string\@ + \b(int|hex|bool|string)\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b boolean - ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} diff --git a/data/languages/java/highlight.xml b/data/languages/java/highlight.xml index 73c11b7..257bcb8 100644 --- a/data/languages/java/highlight.xml +++ b/data/languages/java/highlight.xml @@ -4,75 +4,73 @@ commentDoxygen - /\*\*.*\*/ + /\*\*.*?\*/ comment - /\*.*\*/ + /\*.*?\*/ commentDoxygen - //!(\\[\\\n]|.)*$ + //!(\\[\\\n]|.)*?$ SYNTAX_ERROR - //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*$ + //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*?$ comment - //(\\[\\\n]|.)*$ + //(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - '(\\[\\']|.)*' + '(\\[\\']|.)*?' keyword - \@return|goto|if|else|case|default|switch|break|continue|while|do|for\@ + \b(return|goto|if|else|case|default|switch|break|continue|while|do|for)\b systemFunction - \@new|try|catch|print\@ + \b(new|try|catch|print)\b type - \@boolean|byte|char|double|float|int|long|short|String|Object|Thread|void|enum\@ + \b(boolean|byte|char|double|float|int|long|short|String|Object|Thread|void|enum)\b storageKeyword - \@import|package|extends|Override|implements|const|class|abstract|private|public|protected|final|const|static|transiant|volatile|interface@ + \b(import|package|extends|Override|implements|const|class|abstract|private|public|protected|final|const|static|transiant|volatile|interface)\b commonDefine - \@null\@ + \bnull\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@true|false\@ + \b(true|false)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b[A-Z_][A-Z_0-9]{3,500}\b - boolean - ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} diff --git a/data/languages/json/highlight.xml b/data/languages/json/highlight.xml index a8fe3db..4646777 100644 --- a/data/languages/json/highlight.xml +++ b/data/languages/json/highlight.xml @@ -4,7 +4,7 @@ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" @@ -22,11 +22,11 @@ number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@true|false\@ + \b(true|false)\b diff --git a/data/languages/lua/highlight.xml b/data/languages/lua/highlight.xml index baff8d4..9291441 100644 --- a/data/languages/lua/highlight.xml +++ b/data/languages/lua/highlight.xml @@ -4,51 +4,49 @@ comment - \-\-\[\[.*\-\-\]\] + \-\-\[\[.*?\-\-\]\] SYNTAX_ERROR - \-\-[ \t]*TODO[ \t]*:(\\[\\\n]|.)*$ + \-\-[ \t]*TODO[ \t]*:(\\[\\\n]|.)*?$ comment - \-\-(\\[\\\n]|.)*$ + \-\-(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - '(\\[\\']|.)*' + '(\\[\\']|.)*?' keyword - \@and|break|do|else|elseif|end|for|function|if|in|local|nil|not|or|repeat|return|then|until|while\@ + \b(and|break|do|else|elseif|end|for|function|if|in|local|nil|not|or|repeat|return|then|until|while)\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@true|false\@ + \b(true|false)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b - boolean - ==|<=|>=|~=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|~=|<{1,2}|>{1,2}|&&|\{|\} diff --git a/data/languages/makefile/highlight.xml b/data/languages/makefile/highlight.xml index caf22df..9878720 100644 --- a/data/languages/makefile/highlight.xml +++ b/data/languages/makefile/highlight.xml @@ -6,25 +6,25 @@ preprocesseur - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - '(\\[\\']|.)*' + '(\\[\\']|.)*?' type - \@if|ifeq|ifneq|else|endif|define|endef\@ + \b(if|ifeq|ifneq|else|endif|define|endef)\b keyword - \$\([a-zA-Z_][a-zA-Z0-9_]*\) + \b\([a-zA-Z_][a-zA-Z0-9_]*\) functionName diff --git a/data/languages/matlab/highlight.xml b/data/languages/matlab/highlight.xml index 511101e..b6036df 100644 --- a/data/languages/matlab/highlight.xml +++ b/data/languages/matlab/highlight.xml @@ -5,51 +5,49 @@ commentDoxygen - %%(\\[\\\n]|.)*$ + %%(\\[\\\n]|.)*?$ comment - %(\\[\\\n]|.)*$ + %(\\[\\\n]|.)*?$ doubleQuoteText - ".*($|") + ".*?($|") doubleQuoteText - '.*($|') + '.*?($|') preprocesseur - global( |\t)+(\\[\\\n]|.)*$ + global( |\t)+(\\[\\\n]|.)*?$ keyword - \@return|goto|if|else|case|default|switch|break|continue|while|do|for|otherwise|end\@ + \b(return|goto|if|else|case|default|switch|break|continue|while|do|for|otherwise|end)\b boolean - \@true|false\@ + \b(true|false)\b - boolean - ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b diff --git a/data/languages/php/highlight.xml b/data/languages/php/highlight.xml index c8661ff..0514b6e 100644 --- a/data/languages/php/highlight.xml +++ b/data/languages/php/highlight.xml @@ -7,27 +7,27 @@ comment - /\*.*\*/ + /\*.*?\*/ SYNTAX_ERROR - //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*$ + //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*?$ comment - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)*?$ comment - //(\\[\\\n]|.)*$ + //(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - '(\\[\\']|.)*' + '(\\[\\']|.)*?' @@ -37,33 +37,31 @@ type - \@array|bool|boolean|double|float|int|integer|numeric|object|resource|string|unset\@ + \b(array|bool|boolean|double|float|int|integer|numeric|object|resource|string|unset)\b storageKeyword - \@abstract|and|as|break|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|interface|isset|list|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor\@ + \b(abstract|and|as|break|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|interface|isset|list|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor)\b commonDefine - \@doubleval|floatval|gettype|intval|print_r|serialize|settype|strval|unserialize|var_dump|var_export\@ + \b(doubleval|floatval|gettype|intval|print_r|serialize|settype|strval|unserialize|var_dump|var_export)\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@true|TRUE|false|FALSE\@ + \b(true|TRUE|false|FALSE)\b - boolean - ==|<=|>=|!=|<|>|&&|\{|\}| + ==|<=|>=|!=|<|>|&&|\{|\} diff --git a/data/languages/python/highlight.xml b/data/languages/python/highlight.xml index 11d8865..d2900d3 100644 --- a/data/languages/python/highlight.xml +++ b/data/languages/python/highlight.xml @@ -4,67 +4,65 @@ comment - """.*""" + """.*?""" comment - '''.*''' + '''.*?''' commentDoxygen - ##(\\[\\\n]|.)*$ + ##(\\[\\\n]|.)*?$ comment - #(\\[\\\n]|.)*$ + #(\\[\\\n]|.)*?$ doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - '((\\[\\'])|.)*' + '((\\[\\'])|.)*?' keyword - \@if|else|elif|break|pass|continue|while|do|for|in|return\@ + \b(if|else|elif|break|pass|continue|while|do|for|in|return)\b systemFunction - \@print|len|range|del|__init__|self|os\.|sys\.|path\.\@ + \b(print|len|range|del|__init__|self|os\.|sys\.|path\.)\b type - \@bool|BOOL|char|double|float\@ + \b(bool|BOOL|char|double|float)\b storageKeyword - \@def|class|import|from|as|try|except\@ + \b(def|class|import|from|as|try|except)\b number - \@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@ + \b(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)\b boolean - \@True|False\@ + \b(True|False)\b macro - \@[A-Z_][A-Z_0-9]{3,500}\@ + \b([A-Z_][A-Z_0-9]{3,500})\b - boolean - ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\}| + ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} diff --git a/data/languages/xml/highlight.xml b/data/languages/xml/highlight.xml index 31c99a8..eb05e3d 100644 --- a/data/languages/xml/highlight.xml +++ b/data/languages/xml/highlight.xml @@ -5,16 +5,16 @@ comment - ]]> + ]]> doubleQuoteText - "(\\[\\"]|.)*" + "(\\[\\"]|.)*?" doubleQuoteText - \@'.*('|\n) + \b'.*?('|\n) @@ -31,7 +31,7 @@ functionName - + diff --git a/test/CMakeFile.txt b/test/CMakeFile.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/test/asm.asm b/test/asm.asm new file mode 100644 index 0000000..e69de29 diff --git a/test/bash.bash b/test/bash.bash new file mode 100644 index 0000000..e69de29 diff --git a/test/boo.boo b/test/boo.boo new file mode 100644 index 0000000..e69de29 diff --git a/test/cpp.cpp b/test/cpp.cpp new file mode 100644 index 0000000..e69de29 diff --git a/test/html.html b/test/html.html new file mode 100644 index 0000000..e69de29 diff --git a/test/in.in b/test/in.in new file mode 100644 index 0000000..e69de29 diff --git a/test/java.java b/test/java.java new file mode 100644 index 0000000..e69de29 diff --git a/test/lua.lua b/test/lua.lua new file mode 100644 index 0000000..e69de29 diff --git a/test/matlab.m b/test/matlab.m new file mode 100644 index 0000000..e69de29 diff --git a/test/php.php b/test/php.php new file mode 100644 index 0000000..3b8647f --- /dev/null +++ b/test/php.php @@ -0,0 +1,62 @@ + false, + 'level' => -1, + 'name' => "", + 'class' => NULL)); +// supression de cet élément inutil... +array_pop($module_list); + + +function ShowModuleList(){ + global $module_list; + $output = ""; + //On liste simplement les module ouvert: + $output .= '
'; + $output .= ''; + foreach($module_list as $element) { + $output .= ''; + } + $output .= '
'; + return $output; +} + +function addModule($module_name) { + // element global : + global $module_list; + if (file_exists($module_file)) { + //On inclu le module + include_once($module_file); + } else { + // nothing to do ... + } +} + +class ModuleSite{ + // description du plugin + protected $description; + // level d'utilisation du plugin + private $useLevel; + // version du plugin + public $version; + + /*! + * @brief Contructeur de base + * @param --- + * @return --- + */ + function ModuleSite($_nomDuModule) { + $this->description = "---"; + $this->useLevel = 1024; + $this->version = "00.00"; + return false; + } + + +?> \ No newline at end of file diff --git a/test/python.py b/test/python.py new file mode 100644 index 0000000..e69de29 diff --git a/test/vertexShader.frag b/test/vertexShader.frag new file mode 100644 index 0000000..dff8a0f --- /dev/null +++ b/test/vertexShader.frag @@ -0,0 +1,52 @@ + +/** + * Doxygen comment + */ +/* simple comment */ +#if 0 + remove value +#else + +#endif + +varying void +uniform bool +attribute float +precision int +mediump vec2 +mediump vec3 +mediump vec4 +mediump mat2 +mediump mat3 +mediump mat4 +mediump ivect2 +mediump ivect3 +mediump ivect4 +mediump bvect2 +mediump bvect3 +mediump bvect4 + +//! inline doxygen comment +void emptyFunction() { + +} +// inline comment + +void main() { + return + goto + if + else + case + default + switch + break + continue + while + do + for + sizeof + + MACRO_VALUE +} + diff --git a/test/xml.xml b/test/xml.xml new file mode 100644 index 0000000..a0bb143 --- /dev/null +++ b/test/xml.xml @@ -0,0 +1,12 @@ + + + + + + direct data + + + + \ No newline at end of file From 7952872980714e0145f267acc27c9b370912f879 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 7 Oct 2014 21:42:07 +0200 Subject: [PATCH 06/11] [DEV] better regex ==> need to update alge to recognise data --- data/languages/bash/highlight.xml | 8 +- data/languages/boo/highlight.xml | 4 +- data/languages/c/highlight.xml | 12 +- data/languages/cmake/highlight.xml | 6 +- data/languages/glsl/highlight.xml | 10 +- data/languages/in/highlight.xml | 6 +- data/languages/java/highlight.xml | 10 +- data/languages/json/highlight.xml | 2 +- data/languages/lua/highlight.xml | 8 +- data/languages/makefile/highlight.xml | 6 +- data/languages/matlab/highlight.xml | 6 +- data/languages/php/highlight.xml | 10 +- data/languages/python/highlight.xml | 6 +- data/languages/xml/highlight.xml | 22 ++-- sources/appl/HighlightPattern.cpp | 26 +++- test/cpp.cpp | 164 ++++++++++++++++++++++++++ test/xml.xml | 4 +- 17 files changed, 246 insertions(+), 64 deletions(-) diff --git a/data/languages/bash/highlight.xml b/data/languages/bash/highlight.xml index 2e8452e..59f06be 100644 --- a/data/languages/bash/highlight.xml +++ b/data/languages/bash/highlight.xml @@ -4,19 +4,19 @@ commentDoxygen - #!(\\[\\\n]|.)*?$ + #!(.|\\[\\\n])*?$ comment - #(\\[\\\n]|.)*?$ + #(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" doubleQuoteText - '(\\[\\']|.)*?' + '(.|\\[\\'])*?' diff --git a/data/languages/boo/highlight.xml b/data/languages/boo/highlight.xml index 392599d..e394fa0 100644 --- a/data/languages/boo/highlight.xml +++ b/data/languages/boo/highlight.xml @@ -16,11 +16,11 @@
doubleQuoteText - "(\\[\\"]|.)*?$ + "(.|\\[\\"])*?$ doubleQuoteText - \b'(\\[\\']|.)*?$ + \b'(.|\\[\\'])*?$ diff --git a/data/languages/c/highlight.xml b/data/languages/c/highlight.xml index 92241c4..48b8370 100644 --- a/data/languages/c/highlight.xml +++ b/data/languages/c/highlight.xml @@ -28,7 +28,7 @@ preprocesseur - #(\\[\\\n]|.)* + #(.|\\[\\\n])* commentDoxygen @@ -44,11 +44,11 @@ doubleQuoteText - "(\\[\\"]|.)*" + "(.|\\[\\"])*" doubleQuoteText - '((\\[\\'])|.){1,2}' + '\\?.' @@ -70,7 +70,7 @@ storageKeyword - \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 + \b(inline|const|class|namespace|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 commonDefine @@ -90,11 +90,11 @@ memberClass - \b(m_[A-Za-z_0-9]*)\b + \bm_\w+\b inputFunction - \b(_[A-Za-z_0-9]*)\b + \b_\w+\b false diff --git a/data/languages/cmake/highlight.xml b/data/languages/cmake/highlight.xml index 4d7ea84..e9989a8 100644 --- a/data/languages/cmake/highlight.xml +++ b/data/languages/cmake/highlight.xml @@ -9,15 +9,15 @@ SYNTAX_ERROR - #[ \t]TODO[ \t]*:(\\[\\\n]|.)*?$ + #[ \t]TODO[ \t]*:(.|\\[\\\n])*?$ comment - #(\\[\\\n]|.)*?$ + #(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?$ + "(.|\\[\\"])*?$ diff --git a/data/languages/glsl/highlight.xml b/data/languages/glsl/highlight.xml index 97d4c06..0f7bbb7 100644 --- a/data/languages/glsl/highlight.xml +++ b/data/languages/glsl/highlight.xml @@ -15,23 +15,23 @@ preprocesseur - #[ \t]*if 0(\\[\\\n]|.)*#(endif|else) + #[ \t]*if 0(.|\\[\\\n])*#(endif|else) preprocesseur - #(\\[\\\n]|.)*$ + #(.|\\[\\\n])*$ commentDoxygen - //!(\\[\\\n]|.)*$ + //!(.|\\[\\\n])*$ SYNTAX_ERROR - //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*$ + //[ \t]*TODO[ \t]*:(.|\\[\\\n])*$ comment - //(\\[\\\n]|.)*$ + //(.|\\[\\\n])*$ diff --git a/data/languages/in/highlight.xml b/data/languages/in/highlight.xml index 4245674..1dc5000 100644 --- a/data/languages/in/highlight.xml +++ b/data/languages/in/highlight.xml @@ -4,15 +4,15 @@ preprocesseur - #(\\[\\\n]|.)*?$ + #(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?$ + "(.|\\[\\"])*?$ doubleQuoteText - '(\\[\\']|.)*?$ + '(.|\\[\\'])*?$ diff --git a/data/languages/java/highlight.xml b/data/languages/java/highlight.xml index 257bcb8..500a002 100644 --- a/data/languages/java/highlight.xml +++ b/data/languages/java/highlight.xml @@ -12,23 +12,23 @@ commentDoxygen - //!(\\[\\\n]|.)*?$ + //!(.|\\[\\\n])*?$ SYNTAX_ERROR - //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*?$ + //[ \t]*TODO[ \t]*:(.|\\[\\\n])*?$ comment - //(\\[\\\n]|.)*?$ + //(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" doubleQuoteText - '(\\[\\']|.)*?' + '(.|\\[\\'])*?' diff --git a/data/languages/json/highlight.xml b/data/languages/json/highlight.xml index 4646777..fd54150 100644 --- a/data/languages/json/highlight.xml +++ b/data/languages/json/highlight.xml @@ -4,7 +4,7 @@ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" diff --git a/data/languages/lua/highlight.xml b/data/languages/lua/highlight.xml index 9291441..45753de 100644 --- a/data/languages/lua/highlight.xml +++ b/data/languages/lua/highlight.xml @@ -8,19 +8,19 @@ SYNTAX_ERROR - \-\-[ \t]*TODO[ \t]*:(\\[\\\n]|.)*?$ + \-\-[ \t]*TODO[ \t]*:(.|\\[\\\n])*?$ comment - \-\-(\\[\\\n]|.)*?$ + \-\-(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" doubleQuoteText - '(\\[\\']|.)*?' + '(.|\\[\\'])*?' diff --git a/data/languages/makefile/highlight.xml b/data/languages/makefile/highlight.xml index 9878720..995beb6 100644 --- a/data/languages/makefile/highlight.xml +++ b/data/languages/makefile/highlight.xml @@ -6,15 +6,15 @@ preprocesseur - #(\\[\\\n]|.)*?$ + #(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" doubleQuoteText - '(\\[\\']|.)*?' + '(.|\\[\\'])*?' diff --git a/data/languages/matlab/highlight.xml b/data/languages/matlab/highlight.xml index b6036df..1ef733c 100644 --- a/data/languages/matlab/highlight.xml +++ b/data/languages/matlab/highlight.xml @@ -5,11 +5,11 @@ commentDoxygen - %%(\\[\\\n]|.)*?$ + %%(.|\\[\\\n])*?$ comment - %(\\[\\\n]|.)*?$ + %(.|\\[\\\n])*?$ doubleQuoteText @@ -21,7 +21,7 @@ preprocesseur - global( |\t)+(\\[\\\n]|.)*?$ + global( |\t)+(.|\\[\\\n])*?$ diff --git a/data/languages/php/highlight.xml b/data/languages/php/highlight.xml index 0514b6e..a7a8b7b 100644 --- a/data/languages/php/highlight.xml +++ b/data/languages/php/highlight.xml @@ -11,23 +11,23 @@ SYNTAX_ERROR - //[ \t]*TODO[ \t]*:(\\[\\\n]|.)*?$ + //[ \t]*TODO[ \t]*:(.|\\[\\\n])*?$ comment - #(\\[\\\n]|.)*?$ + #(.|\\[\\\n])*?$ comment - //(\\[\\\n]|.)*?$ + //(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" doubleQuoteText - '(\\[\\']|.)*?' + '(.|\\[\\'])*?' diff --git a/data/languages/python/highlight.xml b/data/languages/python/highlight.xml index d2900d3..8e2b67e 100644 --- a/data/languages/python/highlight.xml +++ b/data/languages/python/highlight.xml @@ -12,15 +12,15 @@ commentDoxygen - ##(\\[\\\n]|.)*?$ + ##(.|\\[\\\n])*?$ comment - #(\\[\\\n]|.)*?$ + #(.|\\[\\\n])*?$ doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\\[\\"])*?" doubleQuoteText diff --git a/data/languages/xml/highlight.xml b/data/languages/xml/highlight.xml index eb05e3d..039d80c 100644 --- a/data/languages/xml/highlight.xml +++ b/data/languages/xml/highlight.xml @@ -5,33 +5,31 @@ comment - ]]> + ]]> doubleQuoteText - "(\\[\\"]|.)*?" + "(.|\r|\n|\\\\|\\")*?" doubleQuoteText - \b'.*?('|\n) + \b'(.|\r|\n)*?('|\n) + + + macro + ]]> error - <\?\w*|\?> + ]]> + - - - functionName - - + |>)?]]> diff --git a/sources/appl/HighlightPattern.cpp b/sources/appl/HighlightPattern.cpp index a9b8c9f..f40dc47 100644 --- a/sources/appl/HighlightPattern.cpp +++ b/sources/appl/HighlightPattern.cpp @@ -30,13 +30,14 @@ appl::HighlightPattern::~HighlightPattern() { void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) { m_regexValue = _regExp; + APPL_DEBUG("parse regex='" << _regExp << "'"); try { 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; - APPL_ERROR("can not parse regExp : '" << e.what() << "' for : " << _regExp); + APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << _regExp); } //m_regExp.setMaximize(forceMaximize); } @@ -54,7 +55,7 @@ void appl::HighlightPattern::display() { APPL_INFO("patern : '" << m_paternName << "' level=" << m_level ); APPL_INFO(" == > colorName '" << m_colorName << "'"); //APPL_INFO(" == > regExp '" << m_regExp.getRegExp() << "'"); - APPL_INFO(" == > regExp '" << m_regexValue << "'"); + APPL_INFO(" == > regex '" << m_regexValue << "'"); } void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) { @@ -126,8 +127,27 @@ enum resultFind appl::HighlightPattern::find(int32_t _start, */ std::smatch resultMatch; + std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous; + //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_constants::match_continuous); + if ((int64_t)_stop <= (int64_t)_buffer.size()) { + char val = _buffer[_stop]; + if ( val != '\n' + && val != '\r') { + //after last char ==> not end of line ($ would not work)) + flags |= std::regex_constants::match_not_eol; + } + if (!( ('a' <= val && val <= 'z') + || ('A' <= val && val <= 'Z') + || ('0' <= val && val <= '9') + || val == '_')) { + flags |= std::regex_constants::match_not_eow; + } + } + if (_start>0) { + flags |= std::regex_constants::match_prev_avail; + } + 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); diff --git a/test/cpp.cpp b/test/cpp.cpp index e69de29..6ab7374 100644 --- a/test/cpp.cpp +++ b/test/cpp.cpp @@ -0,0 +1,164 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EWOL_WIDGET_H__ +#define __EWOL_WIDGET_H__ + +#include +#include +'dfgd\'fg' +'e' sdfsdf '\e' + +"dqf\"gsdfg" // \\ \n " +// TODO : sqdkfjsdldkqfj + + +example_param + +=_param + +_ +_s +_3RTDRsdfqsd + +m_ + +m_d6 + + +namespace ewol { + class Widget; + namespace widget { + class Manager; + class Windows; + }; +}; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ULTIMATE_MAX_SIZE (99999999) + +namespace ewol { +#if 0 + /** + * @not-in-doc + */ +#endif + class DrawProperty{ + /* + /--> m_windowsSize + *--------------------------------------------------* + | g | + | | + | m_size | + | / | + | o-------------------o | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | o-------------------o | + | / | + | m_origin | + | | + *--------------------------------------------------* + / + (0,0) + */ + public : + ivec2 m_windowsSize; //!< Windows compleate size + ivec2 m_origin; //!< Windows clipping upper widget (can not be <0) + ivec2 m_size; //!< Windows clipping upper widget (can not be <0 and >m_windowsSize) + void limit(const vec2& _origin, const vec2& _size); + }; + std::ostream& operator <<(std::ostream& _os, const ewol::DrawProperty& _obj); + /** + * @brief Gravity of the widget property + * @not-in-doc + */ + enum gravity { + gravityCenter=0x00, //!< gravity is in certer + gravityTopLeft=0x05, + gravityTop=0x01, + gravityTopRight=0x03, + gravityRight=0x02, + gravityButtomRight=0x06, + gravityButtom=0x04, + gravityButtomLeft=0x0C, + gravityLeft=0x08, + }; + std::ostream& operator <<(std::ostream& _os, const enum ewol::gravity _obj); + std::string gravityToString(const enum ewol::gravity _obj); + enum ewol::gravity stringToGravity(const std::string& _obj); + /** + * @not-in-doc + */ + class EventShortCut { + public: + bool broadcastEvent; //!< if it is true, then the message is sent to all the system + const char* generateEventId; //!< Local generated event + std::string eventData; //!< data link with the event + ewol::key::Special specialKey; //!< special board key + char32_t unicodeValue; //!< 0 if not used + enum ewol::key::keyboard keyboardMoveValue; //!< ewol::EVENT_KB_MOVE_TYPE_NONE if not used + EventShortCut(void) { + broadcastEvent = false; + generateEventId = NULL; + eventData = ""; + unicodeValue = 0; + keyboardMoveValue = ewol::key::keyboardUnknow; + }; + ~EventShortCut(void) { }; + }; + /** + * @brief Widget class is the main widget interface, it hase some generic properties: + * :** known his parent + * :** Can be display at a special position with a special scale + * :** Can get focus + * :** Receive Event (keyboard / mouse / ...) + * + */ + class Widget : public ewol::Object { + public: + // Config list of properties + static const char* const configFill; + static const char* const configExpand; + static const char* const configHide; + static const char* const configFocus; + static const char* const configMinSize; + static const char* const configMaxSize; + static const char* const configGravity; + public: + /** + * @brief Constructor of the widget classes + * @return (no execption generated (not managed in embended platform)) + */ + Widget(void); + /** + * @brief Destructor of the widget classes + */ + virtual ~Widget(void) { + vec2 plop = vec2(15.2, 56.6f); + } + }; +}; + + +#endif diff --git a/test/xml.xml b/test/xml.xml index a0bb143..cbcf34f 100644 --- a/test/xml.xml +++ b/test/xml.xml @@ -1,6 +1,6 @@ - + - + direct data From 67a08dd77562dd08a982f4e15d40e446fe923060 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 8 Oct 2014 21:32:41 +0200 Subject: [PATCH 07/11] [DEBUG] correction of end of file regexp change --- data/languages/c/highlight.xml | 38 ++++++---- sources/appl/Buffer.cpp | 53 ++++++++------ sources/appl/Highlight.cpp | 112 ++++++++++-------------------- sources/appl/HighlightPattern.cpp | 30 +------- 4 files changed, 95 insertions(+), 138 deletions(-) diff --git a/data/languages/c/highlight.xml b/data/languages/c/highlight.xml index 48b8370..9740fbc 100644 --- a/data/languages/c/highlight.xml +++ b/data/languages/c/highlight.xml @@ -10,43 +10,51 @@ *.m *.mm - + commentDoxygen - /\*\*(.|\r|\n)*?\*/ + /\*(\*|!)(.|\r|\n)*?\*/ - + SYNTAX_ERROR - /\*[ \t]*TODO :(.|\r|\n)*?\*/ + /\*[ \t]*TODO :(.|\r|\n)*?(\*/|\0) - + comment - /\*(.|\r|\n)*?\*/ + /\*(.|\r|\n)*?(\*/|\0) - + + SYNTAX_ERROR + /\*(.|\r|\n)* + + preprocesseur - #[ \t]*if 0(.|\r|\n)*?#(endif|else) + #[ \t]*if 0(.|\r|\n)*?(#endif|else) - + + SYNTAX_ERROR + #[ \t]*if 0(.|\r|\n)* + + preprocesseur #(.|\\[\\\n])* - + commentDoxygen //!.* - + SYNTAX_ERROR //[ \t]*TODO[ \t]*:.* - + comment //.* - + doubleQuoteText - "(.|\\[\\"])*" + "(.|\\[\\"])*?" - + doubleQuoteText '\\?.' diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index 63ef63d..6d56e1e 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -723,7 +723,7 @@ void appl::Buffer::regenerateHighLightAt(int64_t _pos, int64_t _nbDeleted, int64 return; } // normal case - //APPL_INFO("(pos="<" << elem.stop); + } + // Remove previous element to prevent many errors like parsing of // for example + startId--; + APPL_VERBOSE("Find startId=" << startId << " stopId=" << stopId << " list size=" << m_HLDataPass1.size()); + // remove deprecated element - if ( startId == -1 - && stopId == -1) { + if ( startId <= -1 + && stopId <= -1) { m_HLDataPass1.clear(); - } else if (startId == -1) { + APPL_VERBOSE("1 * clear"); + } else if (startId <= -1) { if (stopId == 0){ m_HLDataPass1.erase(m_HLDataPass1.begin()); - //APPL_DEBUG("1 * Erase 0"); + APPL_VERBOSE("1 * Erase 0"); } else { m_HLDataPass1.erase(m_HLDataPass1.begin(), m_HLDataPass1.begin()+stopId); - //APPL_DEBUG("2 * Erase 0->" << stopId); + APPL_VERBOSE("2 * Erase 0->" << stopId); } - } else if (stopId == -1) { - //APPL_DEBUG("3 * Erase " << startId+1 << "-> end"); + } else if (stopId <= -1) { + APPL_VERBOSE("3 * Erase " << startId+1 << "-> end"); m_HLDataPass1.erase(m_HLDataPass1.begin()+startId+1, m_HLDataPass1.end()); stopId = -1; } else { int32_t currentSize = m_HLDataPass1.size(); - //APPL_DEBUG("4 * Erase " << startId+1 << "->" << stopId << " in " << currentSize << " elements" ); - m_HLDataPass1.erase(m_HLDataPass1.begin()+startId+1, m_HLDataPass1.begin()+stopId); + APPL_VERBOSE("4 * Erase " << startId+1 << "->" << stopId << " in " << currentSize << " elements" ); + m_HLDataPass1.erase(m_HLDataPass1.begin()+startId+1, m_HLDataPass1.begin()+stopId+1); if (stopId == currentSize-1) { stopId = -1; } } - //APPL_DEBUG("new size=" << (int32_t)m_HLDataPass1.size()-1); + APPL_VERBOSE(" list afterRemove:"); + for (auto &elem : m_HLDataPass1) { + APPL_VERBOSE(" " << elem.start << "=>" << elem.stop); + } + // update position after the range position : int64_t elemStart; if (startId == -1) { @@ -775,18 +788,18 @@ void appl::Buffer::regenerateHighLightAt(int64_t _pos, int64_t _nbDeleted, int64 it->stop += _nbAdded - _nbDeleted; } //Regenerate Element inside range - if ( startId == -1 - && stopId == -1) { - //APPL_DEBUG("******* Regenerate ALL"); + if ( startId <= -1 + && stopId <= -1) { + APPL_VERBOSE("******* Regenerate ALL"); generateHighLightAt(0, m_data.size()); - } else if(-1 == startId) { - //APPL_DEBUG("******* Regenerate START"); + } else if(startId <= -1) { + APPL_VERBOSE("******* Regenerate START"); generateHighLightAt(0, m_HLDataPass1[0].start, 0); - } else if(-1 == stopId) { - //APPL_DEBUG("******* Regenerate STOP"); + } else if(stopId <= -1) { + APPL_VERBOSE("******* Regenerate STOP"); generateHighLightAt(m_HLDataPass1[m_HLDataPass1.size() -1].stop, m_data.size(), m_HLDataPass1.size()); } else { - //APPL_DEBUG("******* Regenerate RANGE"); + APPL_VERBOSE("******* Regenerate RANGE"); generateHighLightAt(m_HLDataPass1[startId].stop, m_HLDataPass1[startId+1].start, startId+1); } } diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index 893caa9..ae6cada 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -179,73 +179,54 @@ void appl::Highlight::parse(int64_t _start, appl::HighlightInfo resultat; int64_t startTime = ewol::getTime(); while (elementStart <= elementStop) { - //APPL_DEBUG("Parse element in the buffer pos=" << elementStart); - appl::HighlightInfo resultatLast; - int64_t findAnOtherId = -1; + //HL_DEBUG("Parse element in the buffer pos=" << elementStart); 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; /* if (_buffer[elementStart] == '\n') { - APPL_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 { - APPL_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); if (HLP_FIND_ERROR != ret) { - if (elementStart == resultat.start) { - //APPL_DEBUG(" native Find"); - 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; - } - } - } - } - 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 - 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()) { - // just befor the end of the next element - elementStop = _metaData[kkk].start-1; + 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()); + // 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 <= resultat.stop) { + // remove element + HL_DEBUG("Erase element=" << kkk); + _metaData.erase(_metaData.begin()+kkk, _metaData.begin()+kkk+1); + // Increase the end of search + if (kkk < (int64_t)_metaData.size()) { + // just before the end of the next element + elementStop = _metaData[kkk].start-1; + } else { + // end of the buffer + elementStop = _buffer.size(); + } } else { - // end of the buffer - elementStop = _buffer.size(); + // Not find == > exit the cycle : + break; } - } else { - // Not find == > exit the cycle : - break; } + // add curent element in the list ... + _metaData.insert(_metaData.begin()+_addingPos, resultat); + HL_DEBUG("INSERT at "<< _addingPos << " S=" << resultat.start << " E=" << resultat.stop ); + // update the current research starting element: (set position at the end of the current element + elementStart = resultat.stop-1; + // increment the position of insertion: + _addingPos++; + // We find a pattern == > Stop search for the current element + break; } - // add curent element in the list ... - _metaData.insert(_metaData.begin()+_addingPos, resultatLast); - HL_DEBUG("INSERT at "<< _addingPos << " S=" << resultatLast.start << " E=" << resultatLast.stop ); - // update the current research starting element: (set position at the end of the current element - elementStart = resultatLast.stop-1; - // increment the position of insertion: - _addingPos++; - // We find a pattern == > Stop search for the current element - } else { - //APPL_DEBUG("loose time : time=" << deltaTime << " us"); - //break; } // Go to the next element (and search again ...). elementStart++; @@ -276,42 +257,21 @@ 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; - HL_DEBUG("Parse HL id=" << jjj << " position search: (" << + HL2_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) { - 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; - } - } + _metaData.push_back(resultat); + elementStart = resultat.stop-1; + break; } } - - 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++; } diff --git a/sources/appl/HighlightPattern.cpp b/sources/appl/HighlightPattern.cpp index f40dc47..679b231 100644 --- a/sources/appl/HighlightPattern.cpp +++ b/sources/appl/HighlightPattern.cpp @@ -115,19 +115,8 @@ enum resultFind appl::HighlightPattern::find(int32_t _start, return HLP_FIND_ERROR; } - /* - // when we have only one element: - if (true == m_regExp.processOneElement(_buffer, _start, _stop)) { - _resultat.start = m_regExp->start(); - _resultat.stop = m_regExp->stop(); - return HLP_FIND_OK; - } - //APPL_DEBUG("NOT find hightlightpatern ..."); - return HLP_FIND_ERROR; - */ - std::smatch resultMatch; - std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous; + std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous; // check only the match at the first character. //APPL_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'"); if ((int64_t)_stop <= (int64_t)_buffer.size()) { @@ -147,9 +136,9 @@ 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.begin() + _stop, resultMatch, m_regExp, flags); + std::regex_search(_buffer.begin() + _start, _buffer.end(), resultMatch, m_regExp, flags); if (resultMatch.size() > 0) { - _resultat.start = std::distance(_buffer.begin(), resultMatch[0].first);; + _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='" < Date: Thu, 9 Oct 2014 21:23:19 +0200 Subject: [PATCH 08/11] [DEV] Update the parsing of many languages (pyton, cmake) is now good --- data/languages/asm/highlight.xml | 4 +-- data/languages/bash/highlight.xml | 2 +- data/languages/boo/highlight.xml | 3 +- data/languages/c/highlight.xml | 12 ++----- data/languages/cmake/highlight.xml | 16 +++++---- data/languages/glsl/highlight.xml | 5 +-- data/languages/in/highlight.xml | 2 +- data/languages/java/highlight.xml | 2 +- data/languages/json/highlight.xml | 2 +- data/languages/lua/highlight.xml | 2 +- data/languages/makefile/highlight.xml | 5 ++- data/languages/matlab/highlight.xml | 5 ++- data/languages/php/highlight.xml | 7 ++-- data/languages/python/highlight.xml | 22 ++++++------ data/languages/xml/highlight.xml | 3 +- sources/appl/Buffer.cpp | 2 +- sources/appl/Gui/MainWindows.cpp | 30 ++++------------ sources/appl/Highlight.cpp | 25 ++++++++++--- sources/appl/Highlight.h | 2 +- sources/appl/HighlightManager.cpp | 10 +++--- sources/appl/HighlightManager.h | 4 +-- test/CMakeFile.txt | 0 test/CMakeLists.txt | 52 +++++++++++++++++++++++++++ test/python.py | 44 +++++++++++++++++++++++ 24 files changed, 170 insertions(+), 91 deletions(-) delete mode 100644 test/CMakeFile.txt create mode 100644 test/CMakeLists.txt diff --git a/data/languages/asm/highlight.xml b/data/languages/asm/highlight.xml index 0126cfe..50de0d6 100644 --- a/data/languages/asm/highlight.xml +++ b/data/languages/asm/highlight.xml @@ -1,8 +1,6 @@ - *.s - *.S - *.asm + .*\.(s|S|asm) commentDoxygen diff --git a/data/languages/bash/highlight.xml b/data/languages/bash/highlight.xml index 59f06be..dd5b0ea 100644 --- a/data/languages/bash/highlight.xml +++ b/data/languages/bash/highlight.xml @@ -1,6 +1,6 @@ - *.sh + .*\.sh commentDoxygen diff --git a/data/languages/boo/highlight.xml b/data/languages/boo/highlight.xml index e394fa0..a9c72a1 100644 --- a/data/languages/boo/highlight.xml +++ b/data/languages/boo/highlight.xml @@ -1,6 +1,6 @@ - *.boo + .*\.boo SYNTAX_ERROR @@ -24,7 +24,6 @@ - TestResultOK 100% diff --git a/data/languages/c/highlight.xml b/data/languages/c/highlight.xml index 9740fbc..9292d5c 100644 --- a/data/languages/c/highlight.xml +++ b/data/languages/c/highlight.xml @@ -1,14 +1,6 @@ - *.c - *.cpp - *.cxx - *.cc - *.h - *.hpp - *.hxx - *.m - *.mm + .*\.(c|cpp|cxx|cc|h|hpp|hxx|m|mm) commentDoxygen @@ -28,7 +20,7 @@ preprocesseur - #[ \t]*if 0(.|\r|\n)*?(#endif|else) + #[ \t]*if 0(.|\r|\n)*?#(endif|else) SYNTAX_ERROR diff --git a/data/languages/cmake/highlight.xml b/data/languages/cmake/highlight.xml index e9989a8..2c1d492 100644 --- a/data/languages/cmake/highlight.xml +++ b/data/languages/cmake/highlight.xml @@ -1,23 +1,23 @@ - + CMakeLists.txt CMakeCache.txt commentDoxygen - ##.*?$ + ##.* SYNTAX_ERROR - #[ \t]TODO[ \t]*:(.|\\[\\\n])*?$ + #[ \t]TODO[ \t]*:(.|\\[\\\n])* comment - #(.|\\[\\\n])*?$ + #(.|\\[\\\n])* doubleQuoteText - "(.|\\[\\"])*?$ + "(.|\\[\\"])*?" @@ -27,7 +27,7 @@ systemFunction - \b(set|include_directories|add_definitions|add_library|include_directories|target_link_libraries|project|include|check_include_file|enable_testing|option|cmake_minimum_required|add_definitions|check_include_file|configure_file|include_directories|add_custom_command|add_executable|add_test)\b + \b(set|include_directories|add_definitions|add_library|include_directories|target_link_libraries|project|include|check_include_file|enable_testing|option|cmake_minimum_required|add_definitions|check_include_file|configure_file|include_directories|add_custom_command|add_executable|add_test|find_package|pkg_check_modules|set_target_properties|source_group)\b inputFunction @@ -45,5 +45,9 @@ functionName \b(\w|_)+[ \t]*\( + + memberClass + [\w-]*(\.|/)\w* + diff --git a/data/languages/glsl/highlight.xml b/data/languages/glsl/highlight.xml index 0f7bbb7..0a97c96 100644 --- a/data/languages/glsl/highlight.xml +++ b/data/languages/glsl/highlight.xml @@ -1,9 +1,6 @@ - *.glsl - *.vert - *.frag - *.prog + .*\.(glsl|vert|frag|prog) commentDoxygen diff --git a/data/languages/in/highlight.xml b/data/languages/in/highlight.xml index 1dc5000..33925ff 100644 --- a/data/languages/in/highlight.xml +++ b/data/languages/in/highlight.xml @@ -1,6 +1,6 @@ - *.in + .*\.in preprocesseur diff --git a/data/languages/java/highlight.xml b/data/languages/java/highlight.xml index 500a002..c19f128 100644 --- a/data/languages/java/highlight.xml +++ b/data/languages/java/highlight.xml @@ -1,6 +1,6 @@ - *.java + .*\.java commentDoxygen diff --git a/data/languages/json/highlight.xml b/data/languages/json/highlight.xml index fd54150..a0a9601 100644 --- a/data/languages/json/highlight.xml +++ b/data/languages/json/highlight.xml @@ -1,6 +1,6 @@ - *.json + .*\.json doubleQuoteText diff --git a/data/languages/lua/highlight.xml b/data/languages/lua/highlight.xml index 45753de..ea42b8c 100644 --- a/data/languages/lua/highlight.xml +++ b/data/languages/lua/highlight.xml @@ -1,6 +1,6 @@ - *.lua + .*\.lua comment diff --git a/data/languages/makefile/highlight.xml b/data/languages/makefile/highlight.xml index 995beb6..8e19015 100644 --- a/data/languages/makefile/highlight.xml +++ b/data/languages/makefile/highlight.xml @@ -1,8 +1,7 @@ Makefile - *.mk - *.global + .*\.(mk|global) preprocesseur @@ -32,7 +31,7 @@ boolean - :=|?=|!=|= + :=|\?=|!=|= diff --git a/data/languages/matlab/highlight.xml b/data/languages/matlab/highlight.xml index 1ef733c..50bf419 100644 --- a/data/languages/matlab/highlight.xml +++ b/data/languages/matlab/highlight.xml @@ -1,7 +1,6 @@ - *.m - *.M + .*\.(m|M) commentDoxygen @@ -35,7 +34,7 @@ functionName - \b((\w|_)+[ \t]*\( + \b(\w|_)+[ \t]*\( boolean diff --git a/data/languages/php/highlight.xml b/data/languages/php/highlight.xml index a7a8b7b..26b2c73 100644 --- a/data/languages/php/highlight.xml +++ b/data/languages/php/highlight.xml @@ -1,9 +1,6 @@ - *.php - *.php3 - *.php4 - *.phtml + .*\.(php|php3|php4|phtml) comment @@ -57,7 +54,7 @@ functionName - \b((\w|_)+[ \t]*\( + \b\w+[ \t]*\( boolean diff --git a/data/languages/python/highlight.xml b/data/languages/python/highlight.xml index 8e2b67e..c2d7301 100644 --- a/data/languages/python/highlight.xml +++ b/data/languages/python/highlight.xml @@ -1,22 +1,26 @@ - *.py + .*\.py comment - """.*?""" + """(.|\r|\n)*?""" comment - '''.*?''' + '''(.|\r|\n)*?''' + + + SYNTAX_ERROR + ("""|''')(.|\n|\r)* commentDoxygen - ##(.|\\[\\\n])*?$ + ##.* comment - #(.|\\[\\\n])*?$ + #.* doubleQuoteText @@ -64,11 +68,9 @@ boolean ==|<=|>=|!=|<{1,2}|>{1,2}|&&|\{|\} - - - macro - ([A-Z]|_){4,500} - doxElem + + SYNTAX_ERROR + '|" diff --git a/data/languages/xml/highlight.xml b/data/languages/xml/highlight.xml index 039d80c..a46ea63 100644 --- a/data/languages/xml/highlight.xml +++ b/data/languages/xml/highlight.xml @@ -1,7 +1,6 @@ - *.xml - *.svg + .*\.(xml|svg) comment diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index 6d56e1e..f80b8fd 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -691,7 +691,7 @@ void appl::Buffer::removeSelection() { void appl::Buffer::tryFindHighlightType() { etk::FSNode file(m_fileName); - std::string type = appl::highlightManager::getTypeExtention(file.fileGetExtention()); + std::string type = appl::highlightManager::getTypeFile(file.getNameFile()); if (type.size() == 0) { return; } diff --git a/sources/appl/Gui/MainWindows.cpp b/sources/appl/Gui/MainWindows.cpp index f3560a2..ad5b293 100644 --- a/sources/appl/Gui/MainWindows.cpp +++ b/sources/appl/Gui/MainWindows.cpp @@ -390,31 +390,13 @@ void MainWindows::displayProperty() { } else { #ifdef SDGSDFGSDFGSDFGSDFGSTERGDHFGHFDS std::string menuDescription = "Properties\n"; - menuDescription += "\n"; - menuDescription += " Editor\n"; - menuDescription += " \n"; - menuDescription += " Editor Interface\n"; - menuDescription += " Editor\n"; - menuDescription += " appl-text-viewer\n"; - menuDescription += " \n"; + menuDescription += "\n"; + menuDescription += " \n"; menuDescription += "\n"; - menuDescription += "\n"; - menuDescription += " Gui\n"; - menuDescription += " \n"; - menuDescription += " Font selection\n"; - menuDescription += " Font\n"; - menuDescription += " \n"; - menuDescription += " \n"; - menuDescription += " \n"; - menuDescription += " Color selection\n"; - menuDescription += " Color\n"; - menuDescription += " \n"; - menuDescription += " \n"; - menuDescription += " \n"; - menuDescription += " Theme selection\n"; - menuDescription += " Theme\n"; - menuDescription += " \n"; - menuDescription += " \n"; + menuDescription += "\n"; + menuDescription += " \n"; + menuDescription += " \n"; + menuDescription += " \n"; menuDescription += "\n"; tmpWidget->setMenu(menuDescription); diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index ae6cada..3afa75f 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -114,13 +114,28 @@ appl::Highlight::~Highlight() { m_listExtentions.clear(); } -bool appl::Highlight::hasExtention(const std::string& _ext) { +bool appl::Highlight::isCompatible(const std::string& _name) { for (auto &it : m_listExtentions) { - APPL_VERBOSE(" check : " << it << "=?=" << _ext); - if ( it == "*." + _ext - || it == _ext) { - return true; + APPL_VERBOSE(" check : " << it << "=?=" << _name); + std::regex expression; + try { + expression.assign(it, std::regex_constants::optimize | std::regex_constants::ECMAScript); + } catch (std::regex_error e) { + APPL_ERROR("can not parse regex : '" << e.what() << "' for : " << it); + continue; } + std::smatch resultMatch; + std::regex_search(_name.begin(), _name.end(), resultMatch, expression, std::regex_constants::match_continuous); + if (resultMatch.size() <= 0) { + continue; + } + if (resultMatch[0].first != _name.begin()) { + continue; + } + if (resultMatch[0].second != _name.end()) { + continue; + } + return true; } return false; } diff --git a/sources/appl/Highlight.h b/sources/appl/Highlight.h index 8dbb1ea..b4975d0 100644 --- a/sources/appl/Highlight.h +++ b/sources/appl/Highlight.h @@ -48,7 +48,7 @@ namespace appl { return m_typeName; } public: - bool hasExtention(const std::string& _ext); + bool isCompatible(const std::string& _name); bool fileNameCompatible(const std::string& _fileName); void display(); void parse(int64_t _start, diff --git a/sources/appl/HighlightManager.cpp b/sources/appl/HighlightManager.cpp index 447108b..7a3d95e 100644 --- a/sources/appl/HighlightManager.cpp +++ b/sources/appl/HighlightManager.cpp @@ -70,19 +70,19 @@ void appl::highlightManager::unInit() { hlList.clear(); } -std::string appl::highlightManager::getTypeExtention(const std::string& _extention) { - if (_extention.size() == 0) { +std::string appl::highlightManager::getTypeFile(const std::string& _fileName) { + if (_fileName.size() == 0) { return ""; } - APPL_DEBUG("Try to find type for extention : '" << _extention << "' in " << s_list().size() << " types"); + APPL_DEBUG("Try to find type for extention : '" << _fileName << "' in " << s_list().size() << " types"); std::vector>& hlList = s_list(); for (auto &it : hlList) { if (it == nullptr) { continue; } APPL_DEBUG(" check : " << it->getTypeName()); - if (it->hasExtention(_extention) == true) { - APPL_DEBUG("Find type for extention : " << _extention + if (it->isCompatible(_fileName) == true) { + APPL_DEBUG("Find type for extention : " << _fileName << " type : " << it->getTypeName()); return it->getTypeName(); } diff --git a/sources/appl/HighlightManager.h b/sources/appl/HighlightManager.h index d77de66..ec38a1f 100644 --- a/sources/appl/HighlightManager.h +++ b/sources/appl/HighlightManager.h @@ -27,10 +27,10 @@ namespace appl { void unInit(); /** * @brief Un-Init the Highlight manager - * @param[in] extention of the file + * @param[in] _fileName name of the file * @return type of highlight */ - std::string getTypeExtention(const std::string& _extention); + std::string getTypeFile(const std::string& _fileName); /** * @brief Get filename with type. * @param[in] _type Type name of the highlight. diff --git a/test/CMakeFile.txt b/test/CMakeFile.txt deleted file mode 100644 index e69de29..0000000 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..9d6a38e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,52 @@ + +set(GAMEPLAY_SRC + src/AbsoluteLayout.cpp + src/AbsoluteLayout.h + src/BoundingBox.h + src/Transform.h + src/Vector2.cpp + src/Vector2.h + src/lua/lua_ThemeUVs.h + src/lua/lua_Touch.cpp + src/lua/lua_Touch.h + src/lua/lua_TouchTouchEvent.cpp + src/lua/lua_TouchTouchEvent +) +include_directories( + src + ../external-deps/lua/include + ../external-deps/bullet/include + ../external-deps/png/include + ../external-deps/zlib/include + ../external-deps/oggvorbis/include + ../external-deps/openal/include + ../external-deps/glew/include +) + +if(CMAKE_SYSTEM_NAME MATCHES "Linux") +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK2 REQUIRED gtk+-2.0) +include_directories(${GTK2_INCLUDE_DIRS}) +add_definitions(${GTK2_CFLAGS_OTHER}) +add_definitions(-D__linux__) +endif(CMAKE_SYSTEM_NAME MATCHES "Linux") + +add_definitions(-lstdc++) + +add_library(gameplay STATIC + ${GAMEPLAY_SRC} + ${GAMEPLAY_LUA} +) + +set_target_properties(gameplay PROPERTIES + OUTPUT_NAME "gameplay" + CLEAN_DIRECT_OUTPUT 1 + VERSION ${GAMEPLAY_VERSION} +) + +source_group(lua FILES ${GAMEPLAY_LUA}) +source_group(res FILES ${GAMEPLAY_RES} ${GAMEPLAY_RES} ${GAMEPLAY_RES_SHADERS} ${GAMEPLAY_RES_UI}) +source_group(src FILES ${GAMEPLAY_SRC}) + + + diff --git a/test/python.py b/test/python.py index e69de29..330e904 100644 --- a/test/python.py +++ b/test/python.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +import lutinModule as module +import lutinTools as tools + +def get_desc(): + return "gameplay : video game engine (based on bullet lib)" + +""" + multline comment +""" +''' + multline comment +''' + +def create(target): + myModule = module.Module(__file__, 'gameplay', 'LIBRARY') + + # add the file to compile: + myModule.add_src_file([ + 'ege/debug.cpp', + 'ege/AudioElement.cpp', + 'ege/AudioEngine.cpp', + 'ege/Camera.cpp' + ]) + + # myModule.copy_folder('data/ParticuleMesh.*','') + + # name of the dependency + myModule.add_module_depend(['etk', 'ewol', 'bullet']) + + myModule.compile_flags_CC([ + '-Wno-write-strings', + '-Wall']) + + myModule.add_export_path(tools.get_current_path(__file__)) + + + # add the currrent module at the + return myModule + + + +""" +multline comment error ... From 7c37d8e5492e46279f204e07f2da3cac4c216fd6 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 13 Oct 2014 22:39:49 +0200 Subject: [PATCH 09/11] [DEV] add sub parsing of pass1 --- data/languages/bash/highlight.xml | 4 +- data/languages/boo/highlight.xml | 4 +- data/languages/c/highlight.xml | 38 ++++++--- data/languages/cmake/highlight.xml | 2 +- data/languages/in/highlight.xml | 4 +- data/languages/java/highlight.xml | 4 +- data/languages/json/highlight.xml | 4 +- data/languages/lua/highlight.xml | 4 +- data/languages/makefile/highlight.xml | 4 +- data/languages/matlab/highlight.xml | 4 +- data/languages/php/highlight.xml | 4 +- data/languages/python/highlight.xml | 10 +-- data/languages/xml/highlight.xml | 80 +++++++++++++----- data/theme/colorBlack/textViewer.json | 3 + data/theme/colorWhite/textViewer.json | 4 + sources/appl/Buffer.cpp | 30 ++++--- sources/appl/Highlight.cpp | 117 ++++++++++++++++++++------ sources/appl/Highlight.h | 26 +++--- sources/appl/HighlightPattern.cpp | 44 ++++++---- sources/appl/HighlightPattern.h | 22 +++-- 20 files changed, 284 insertions(+), 128 deletions(-) diff --git a/data/languages/bash/highlight.xml b/data/languages/bash/highlight.xml index dd5b0ea..5da44b7 100644 --- a/data/languages/bash/highlight.xml +++ b/data/languages/bash/highlight.xml @@ -12,11 +12,11 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" doubleQuoteText - '(.|\\[\\'])*?' + '(.|\\[\\'])*?' diff --git a/data/languages/boo/highlight.xml b/data/languages/boo/highlight.xml index a9c72a1..d7fbc8c 100644 --- a/data/languages/boo/highlight.xml +++ b/data/languages/boo/highlight.xml @@ -16,11 +16,11 @@ doubleQuoteText - "(.|\\[\\"])*?$ + "(.|\\[\\"])*?$ doubleQuoteText - \b'(.|\\[\\'])*?$ + \b'(.|\\[\\'])*?$ diff --git a/data/languages/c/highlight.xml b/data/languages/c/highlight.xml index 9292d5c..e033d48 100644 --- a/data/languages/c/highlight.xml +++ b/data/languages/c/highlight.xml @@ -5,14 +5,12 @@ commentDoxygen /\*(\*|!)(.|\r|\n)*?\*/ - - - SYNTAX_ERROR - /\*[ \t]*TODO :(.|\r|\n)*?(\*/|\0) + doxyparse comment /\*(.|\r|\n)*?(\*/|\0) + TODO SYNTAX_ERROR @@ -33,14 +31,12 @@ commentDoxygen //!.* - - - SYNTAX_ERROR - //[ \t]*TODO[ \t]*:.* + doxyparse comment //.* + TODO doubleQuoteText @@ -66,7 +62,7 @@ type - \b(std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair))\b + \bstd::[\w:]*\b storageKeyword @@ -95,7 +91,6 @@ inputFunction \b_\w+\b - false functionName @@ -108,11 +103,30 @@ macro ([A-Z]|_){4,500} - doxElem SYNTAX_ERROR - '|" + '|" + + + doxygen-key + (@|\\)[\t ]*\w+ + + + doxygen-in-out + \[(in|in,out|out)\] + + + inputFunction + \b_\w+\b + + + + + SYNTAX_ERROR + TODO[ \t]*:.* + + diff --git a/data/languages/cmake/highlight.xml b/data/languages/cmake/highlight.xml index 2c1d492..082bb91 100644 --- a/data/languages/cmake/highlight.xml +++ b/data/languages/cmake/highlight.xml @@ -17,7 +17,7 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" diff --git a/data/languages/in/highlight.xml b/data/languages/in/highlight.xml index 33925ff..5ce5728 100644 --- a/data/languages/in/highlight.xml +++ b/data/languages/in/highlight.xml @@ -8,11 +8,11 @@ doubleQuoteText - "(.|\\[\\"])*?$ + "(.|\\[\\"])*?$ doubleQuoteText - '(.|\\[\\'])*?$ + '(.|\\[\\'])*?$ diff --git a/data/languages/java/highlight.xml b/data/languages/java/highlight.xml index c19f128..3e27502 100644 --- a/data/languages/java/highlight.xml +++ b/data/languages/java/highlight.xml @@ -24,11 +24,11 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" doubleQuoteText - '(.|\\[\\'])*?' + '(.|\\[\\'])*?' diff --git a/data/languages/json/highlight.xml b/data/languages/json/highlight.xml index a0a9601..d48b7fa 100644 --- a/data/languages/json/highlight.xml +++ b/data/languages/json/highlight.xml @@ -4,7 +4,7 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" @@ -18,7 +18,7 @@ functionName - ([a-zA-Z0-9]|-|_)* + ([a-zA-Z0-9]|-|_)+ number diff --git a/data/languages/lua/highlight.xml b/data/languages/lua/highlight.xml index ea42b8c..606e7df 100644 --- a/data/languages/lua/highlight.xml +++ b/data/languages/lua/highlight.xml @@ -16,11 +16,11 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" doubleQuoteText - '(.|\\[\\'])*?' + '(.|\\[\\'])*?' diff --git a/data/languages/makefile/highlight.xml b/data/languages/makefile/highlight.xml index 8e19015..2416009 100644 --- a/data/languages/makefile/highlight.xml +++ b/data/languages/makefile/highlight.xml @@ -9,11 +9,11 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" doubleQuoteText - '(.|\\[\\'])*?' + '(.|\\[\\'])*?' diff --git a/data/languages/matlab/highlight.xml b/data/languages/matlab/highlight.xml index 50bf419..410ba87 100644 --- a/data/languages/matlab/highlight.xml +++ b/data/languages/matlab/highlight.xml @@ -12,11 +12,11 @@ doubleQuoteText - ".*?($|") + ".*?($|") doubleQuoteText - '.*?($|') + '.*?($|') preprocesseur diff --git a/data/languages/php/highlight.xml b/data/languages/php/highlight.xml index 26b2c73..592d664 100644 --- a/data/languages/php/highlight.xml +++ b/data/languages/php/highlight.xml @@ -20,11 +20,11 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" doubleQuoteText - '(.|\\[\\'])*?' + '(.|\\[\\'])*?' diff --git a/data/languages/python/highlight.xml b/data/languages/python/highlight.xml index c2d7301..d406528 100644 --- a/data/languages/python/highlight.xml +++ b/data/languages/python/highlight.xml @@ -4,7 +4,7 @@ comment - """(.|\r|\n)*?""" + """(.|\r|\n)*?""" comment @@ -12,7 +12,7 @@ SYNTAX_ERROR - ("""|''')(.|\n|\r)* + ("""|''')(.|\n|\r)* commentDoxygen @@ -24,11 +24,11 @@ doubleQuoteText - "(.|\\[\\"])*?" + "(.|\\[\\"])*?" doubleQuoteText - '((\\[\\'])|.)*?' + '((\\[\\'])|.)*?' @@ -70,7 +70,7 @@ SYNTAX_ERROR - '|" + '|" diff --git a/data/languages/xml/highlight.xml b/data/languages/xml/highlight.xml index a46ea63..654799e 100644 --- a/data/languages/xml/highlight.xml +++ b/data/languages/xml/highlight.xml @@ -4,32 +4,74 @@ comment - ]]> - + + -<!\-\-(.|\r|\n)*?\-\-> - - doubleQuoteText - "(.|\r|\n|\\\\|\\")*?" - - - doubleQuoteText - \b'(.|\r|\n)*?('|\n) - - + macro - ]]> + + <!\[CDATA\[(.|\r|\n)*?\]\]> + + + functionName + + </[ \t]*\w+?[ \t]*> + + + SYNTAX_ERROR + + </(.|\n|\r)*?> + + + normal + + <(.|\n|\r)*?> + parseInsideBalise - - error - ]]> - + + commonDefine + + &(gt|lt|amp|apos|quot); - - functionName - |>)?]]> + + error + >|<|&|'|" + + + error + + <\?\w*|\?> + + + functionName + + <[ \t]*[0-9a-zA-Z_]+ + + + functionName + + /?> + + + doubleQuoteText + "(.|\r|\n|\\\\|\\")*?" + + + doubleQuoteText + \b'(.|\r|\n)*?('|\n) + + + boolean + = + + + keyword + \w+ + + diff --git a/data/theme/colorBlack/textViewer.json b/data/theme/colorBlack/textViewer.json index f08a525..65bdc66 100644 --- a/data/theme/colorBlack/textViewer.json +++ b/data/theme/colorBlack/textViewer.json @@ -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}, ] } diff --git a/data/theme/colorWhite/textViewer.json b/data/theme/colorWhite/textViewer.json index dd0b0eb..a67cfc1 100644 --- a/data/theme/colorWhite/textViewer.json +++ b/data/theme/colorWhite/textViewer.json @@ -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}, ] } diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index f80b8fd..225c5b6 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -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="< (under section ) kkk="< (empty section 4 ) kkk=" << kkk << " start=0 stop=" << HLStop ); m_highlight->parse2(0, - HLStop, - _MData.HLData, - m_data); + HLStop, + _MData.HLData, + m_data); } } /* diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index 3afa75f..7121a50 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -25,18 +25,6 @@ //#define HL2_DEBUG APPL_INFO #define HL2_DEBUG APPL_VERBOSE -void appl::Highlight::parseRules(exml::Element* _child, - std::vector>& _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(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>(attributeName, std::vector())); + 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 &_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++; + } +} \ No newline at end of file diff --git a/sources/appl/Highlight.h b/sources/appl/Highlight.h index b4975d0..3f9966d 100644 --- a/sources/appl/Highlight.h +++ b/sources/appl/Highlight.h @@ -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 &_metaData, + std::vector& _metaData, int64_t _addingPos, - std::string &_buffer); + std::string& _buffer); void parse2(int64_t _start, int64_t _stop, - std::vector &_metaData, - std::string &_buffer); + std::vector& _metaData, + std::string& _buffer); + void parseSubElement(const appl::HighlightInfo& _upper, + std::vector& _metaData, + std::string &_buffer); private: - void parseRules(exml::Element* _child, - std::vector> &_mListPatern, - int32_t _level, - bool forceMaximize=false); std::string m_styleName; //!< curent style name (like "c++" or "c" or "script Bash") std::vector m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h" - std::vector> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 == > when we load and wride data on the buffer) - std::vector> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 == > When we display the buffer( only the display area (100 lines)) ) + std::vector m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 == > when we load and wride data on the buffer) + std::vector m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 == > When we display the buffer( only the display area (100 lines)) ) + std::map> m_listHighlightNamed; //!< list of all sub partern to parse... public: // herited function : virtual void updateContext() { // no upfate to do ... diff --git a/sources/appl/HighlightPattern.cpp b/sources/appl/HighlightPattern.cpp index 679b231..e465916 100644 --- a/sources/appl/HighlightPattern.cpp +++ b/sources/appl/HighlightPattern.cpp @@ -13,13 +13,24 @@ #undef __class__ #define __class__ "HighlightPattern" -appl::HighlightPattern::HighlightPattern(const std::shared_ptr& _glyphPainting) : +appl::HighlightPattern::HighlightPattern(const std::shared_ptr& _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) { //-------------------------------------------------------------------------------------------- /* preprocesseur # - false + namexxx */ //-------------------------------------------------------------------------------------------- - // 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); diff --git a/sources/appl/HighlightPattern.h b/sources/appl/HighlightPattern.h index 59db43e..369c254 100644 --- a/sources/appl/HighlightPattern.h +++ b/sources/appl/HighlightPattern.h @@ -32,29 +32,39 @@ namespace appl { std::shared_ptr m_glyphPainting; public: // Constructeur - HighlightPattern(const std::shared_ptr& _glyphPainting); + HighlightPattern(); + HighlightPattern(const std::shared_ptr& _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); }; }; From 7f7b3283e3c366d04ba9a218923fbd679632f7f7 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 17 Oct 2014 08:38:41 +0200 Subject: [PATCH 10/11] [DEV] add update of clang to set it work with timer --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fa6ae6f..5433d81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,9 @@ install: - if [ "$CXX" == "g++" ]; then sudo rm /usr/bin/gcc /usr/bin/g++; fi - if [ "$CXX" == "g++" ]; then sudo ln -s /usr/bin/gcc-4.8 /usr/bin/gcc; fi - if [ "$CXX" == "g++" ]; then sudo ln -s /usr/bin/g++-4.8 /usr/bin/g++; fi - + - if [ "$CXX" == "clang++" ]; then wget http://llvm.org/releases/3.4.1/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04.tar.xz; fi + - if [ "$CXX" == "clang++" ]; then tar xJf clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04.tar.xz; fi + - if [ "$CXX" == "clang++" ]; then export PATH=$PWD/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin:$PATH; fi # build sequence with Lutin : script: From 3c79dec2c8bc120d4ca01bcfb5b7b974487cb7c6 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 17 Oct 2014 09:02:57 +0200 Subject: [PATCH 11/11] [INTEGRATION] add color in travis build --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5433d81..dd12a11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,8 +32,8 @@ install: # build sequence with Lutin : script: - - if [ "$CXX" == "clang++" ]; then ./ewol/build/lutin.py -cclang -mdebug -p edn; fi - - if [ "$CXX" == "g++" ]; then ./ewol/build/lutin.py -cgcc -mdebug -p edn; fi + - if [ "$CXX" == "clang++" ]; then ./ewol/build/lutin.py -C -cclang -mdebug -p edn; fi + - if [ "$CXX" == "g++" ]; then ./ewol/build/lutin.py -C -cgcc -mdebug -p edn; fi #send e-mail on compilation result: notifications: