[DEV] std:regex does not work ==> I use my own regexp

This commit is contained in:
Edouard DUPIN 2014-07-18 07:32:06 +02:00
parent 7eba645b45
commit d5365428ea
4 changed files with 14 additions and 12 deletions

View File

@ -18,25 +18,27 @@ eci::Lexer::~Lexer() {
}
void eci::Lexer::append(int32_t _tokenId, const std::string& _regularExpression) {
try {
m_searchList.insert(std::make_pair(_tokenId, std::regex(_regularExpression, std::regex_constants::basic)));
} catch (std::regex_error e) {
ECI_ERROR("plop : " << e.what() << " from '" << _regularExpression << "'");
}
m_searchList.insert(std::make_pair(_tokenId, etk::RegExp<std::string>(_regularExpression)));
etk::RegExp<std::string>(_regularExpression).display();
}
eci::LexerResult eci::Lexer::interprete(const std::string& _data) {
eci::LexerResult result;
ECI_INFO("Parse : \n" << _data);
ECI_INFO("Parse : \n" << _data);
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::regex_search (_data, m, it.second);
for (unsigned i=0; i<m.size(); ++i) {
ECI_INFO(" match " << i << " (" << m[i] << ") ");
ECI_INFO(" @ " << m.position(i) );
}
*/
//std::regex_iterator it_search(_data.begin(), _data.end(), it.second);
//std::sregex_iterator it_end;

View File

@ -11,7 +11,7 @@
#include <etk/types.h>
#include <etk/stdTools.h>
#include <regex>
#include <etk/RegExp.h>
#include <map>
#include <vector>
@ -21,7 +21,7 @@ namespace eci {
class Lexer {
private:
std::map<int32_t, std::regex> m_searchList;
std::map<int32_t, etk::RegExp<std::string>> m_searchList;
public:
Lexer();
~Lexer();

View File

@ -18,7 +18,7 @@ int main(int argc, char** argv) {
return -1;
}
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);
return 0;

View File

@ -17,7 +17,7 @@ enum cppTokenList {
eci::ParserCpp::ParserCpp() {
m_lexer.append(tokenCppMultilineComment, "/\\*.*\\*/");
m_lexer.append(tokenCppSingleLineComment, "//$");
m_lexer.append(tokenCppSingleLineComment, "//.*$");
m_lexer.append(tokenCppString, "[a-z]");
}