[DEV] std:regex does not work ==> I use my own regexp
This commit is contained in:
parent
7eba645b45
commit
d5365428ea
@ -18,25 +18,27 @@ eci::Lexer::~Lexer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void eci::Lexer::append(int32_t _tokenId, const std::string& _regularExpression) {
|
void eci::Lexer::append(int32_t _tokenId, const std::string& _regularExpression) {
|
||||||
try {
|
m_searchList.insert(std::make_pair(_tokenId, etk::RegExp<std::string>(_regularExpression)));
|
||||||
m_searchList.insert(std::make_pair(_tokenId, std::regex(_regularExpression, std::regex_constants::basic)));
|
etk::RegExp<std::string>(_regularExpression).display();
|
||||||
} catch (std::regex_error e) {
|
|
||||||
ECI_ERROR("plop : " << e.what() << " from '" << _regularExpression << "'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eci::LexerResult eci::Lexer::interprete(const std::string& _data) {
|
eci::LexerResult eci::Lexer::interprete(const std::string& _data) {
|
||||||
eci::LexerResult result;
|
eci::LexerResult result;
|
||||||
ECI_INFO("Parse : \n" << _data);
|
ECI_INFO("Parse : \n" << _data);
|
||||||
for (auto &it : m_searchList) {
|
for (auto &it : m_searchList) {
|
||||||
ECI_INFO("Parse RegEx : " << it.first);// << " : '" << it.second.str() << "'");
|
ECI_INFO("Parse RegEx : " << it.first << " : " << it.second.getRegExDecorated());
|
||||||
|
if (it.second.parse(_data, 0, _data.size()) == true) {
|
||||||
|
ECI_INFO(" match [" << it.second.start() << ".." << it.second.stop() << "] ");
|
||||||
|
ECI_INFO(" ==> '" << std::string(_data, it.second.start(), it.second.stop()) << "'");
|
||||||
|
}
|
||||||
|
/*
|
||||||
std::smatch m;
|
std::smatch m;
|
||||||
std::regex_search (_data, m, it.second);
|
std::regex_search (_data, m, it.second);
|
||||||
for (unsigned i=0; i<m.size(); ++i) {
|
for (unsigned i=0; i<m.size(); ++i) {
|
||||||
ECI_INFO(" match " << i << " (" << m[i] << ") ");
|
ECI_INFO(" match " << i << " (" << m[i] << ") ");
|
||||||
ECI_INFO(" @ " << m.position(i) );
|
ECI_INFO(" @ " << m.position(i) );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//std::regex_iterator it_search(_data.begin(), _data.end(), it.second);
|
//std::regex_iterator it_search(_data.begin(), _data.end(), it.second);
|
||||||
//std::sregex_iterator it_end;
|
//std::sregex_iterator it_end;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include <etk/types.h>
|
#include <etk/types.h>
|
||||||
#include <etk/stdTools.h>
|
#include <etk/stdTools.h>
|
||||||
#include <regex>
|
#include <etk/RegExp.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ namespace eci {
|
|||||||
|
|
||||||
class Lexer {
|
class Lexer {
|
||||||
private:
|
private:
|
||||||
std::map<int32_t, std::regex> m_searchList;
|
std::map<int32_t, etk::RegExp<std::string>> m_searchList;
|
||||||
public:
|
public:
|
||||||
Lexer();
|
Lexer();
|
||||||
~Lexer();
|
~Lexer();
|
||||||
|
@ -18,7 +18,7 @@ int main(int argc, char** argv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
eci::ParserCpp tmpParser;
|
eci::ParserCpp tmpParser;
|
||||||
std::string data = "/* plop */ \n int main(void) {\n return 0;\n}\n";//etk::FSNodeReadAllData(argv[1]);
|
std::string data = "/* plop */ \n int eee = 22; // error value \nint main(void) {\n return 0;\n}\n";//etk::FSNodeReadAllData(argv[1]);
|
||||||
tmpParser.parse(data);
|
tmpParser.parse(data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -17,7 +17,7 @@ enum cppTokenList {
|
|||||||
|
|
||||||
eci::ParserCpp::ParserCpp() {
|
eci::ParserCpp::ParserCpp() {
|
||||||
m_lexer.append(tokenCppMultilineComment, "/\\*.*\\*/");
|
m_lexer.append(tokenCppMultilineComment, "/\\*.*\\*/");
|
||||||
m_lexer.append(tokenCppSingleLineComment, "//$");
|
m_lexer.append(tokenCppSingleLineComment, "//.*$");
|
||||||
m_lexer.append(tokenCppString, "[a-z]");
|
m_lexer.append(tokenCppString, "[a-z]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user