diff --git a/eci/File.cpp b/eci/File.cpp index 6e3b829..72af0fd 100644 --- a/eci/File.cpp +++ b/eci/File.cpp @@ -10,6 +10,7 @@ #include #include #include +#include static std::string getValue(const std::string& _file, const std::shared_ptr& _it) { @@ -60,64 +61,77 @@ eci::Variable getVariableWithType(const std::string& _value) { eci::File::File(const std::string& _filename) { m_fileName = _filename; - m_fileData = etk::FSNodeReadAllData(_filename); - eci::ParserCpp tmpParser; - tmpParser.parse(m_fileData); - - // all we need all the time: - std::vector returnList; - std::vector argumentList; - std::string name; - std::string value; - std::shared_ptr lastClass; - std::shared_ptr lastFunction; - std::shared_ptr lastVariable; - enum eci::visibility lastVisibility = eci::visibilityPublic; - - for (auto &it : tmpParser.m_result.m_list) { - value = getValue(m_fileData, it); - switch (it->getTockenId()) { - case tokenCppVisibility: - ECI_INFO("get visibility : " << value << "'" ); - if (value == "private") { - lastVisibility = eci::visibilityPrivate; - } else if (value == "public") { - lastVisibility = eci::visibilityPublic; - } else if (value == "protected") { - lastVisibility = eci::visibilityProtected; - //} else if (value == "inline") { - - //} else if (value == "const") { - - //} else if (value == "virtual") { - - //} else if (value == "friend") { - - //} else if (value == "extern") { - - //} else if (value == "register") { - - //} else if (value == "static") { - - //} else if (value == "volatile") { - - } else { - ECI_ERROR("get visibility : " << value << "' << NOT parsed !!!!" ); - } - break; - case tokenCppType: - ECI_INFO("get type : " << value << "'" ); - if (name == "") { - returnList.push_back(getVariableWithType(value)); - } else { - ECI_ERROR(" get type : " << value << "' after name !!!" ); - } - break; - case tokenCppString: - ECI_INFO("get string : " << value << "'" ); - name = value; - break; + m_fileData = etk::FSNodeReadAllData(m_fileName); + if ( etk::end_with(m_fileName, "cpp", false) == true + || etk::end_with(m_fileName, "cxx", false) == true + || etk::end_with(m_fileName, "c", false) == true + || etk::end_with(m_fileName, "hpp", false) == true + || etk::end_with(m_fileName, "hxx", false) == true + || etk::end_with(m_fileName, "h", false) == true) { + eci::ParserCpp tmpParser; + tmpParser.parse(m_fileData); + + // all we need all the time: + std::vector returnList; + std::vector argumentList; + std::string name; + std::string value; + std::shared_ptr lastClass; + std::shared_ptr lastFunction; + std::shared_ptr lastVariable; + enum eci::visibility lastVisibility = eci::visibilityPublic; + + for (auto &it : tmpParser.m_result.m_list) { + value = getValue(m_fileData, it); + switch (it->getTockenId()) { + case tokenCppVisibility: + ECI_INFO("get visibility : " << value << "'" ); + if (value == "private") { + lastVisibility = eci::visibilityPrivate; + } else if (value == "public") { + lastVisibility = eci::visibilityPublic; + } else if (value == "protected") { + lastVisibility = eci::visibilityProtected; + //} else if (value == "inline") { + + //} else if (value == "const") { + + //} else if (value == "virtual") { + + //} else if (value == "friend") { + + //} else if (value == "extern") { + + //} else if (value == "register") { + + //} else if (value == "static") { + + //} else if (value == "volatile") { + + } else { + ECI_ERROR("get visibility : " << value << "' << NOT parsed !!!!" ); + } + break; + case tokenCppType: + ECI_INFO("get type : " << value << "'" ); + if (name == "") { + returnList.push_back(getVariableWithType(value)); + } else { + ECI_ERROR(" get type : " << value << "' after name !!!" ); + } + break; + case tokenCppString: + ECI_INFO("get string : " << value << "'" ); + name = value; + break; + } } + } else if (etk::end_with(m_fileName, "js", false) == true) { + eci::ParserJS tmpParser; + tmpParser.parse(m_fileData); + + } else { + ECI_CRITICAL("Unknow file type ... '" << m_fileName << "'"); } } diff --git a/eci/eci.cpp b/eci/eci.cpp index ef1c5d7..14b910f 100644 --- a/eci/eci.cpp +++ b/eci/eci.cpp @@ -12,25 +12,95 @@ #include #include -int main(int argc, char** argv) { - etk::log::setLevel(etk::log::logLevelDebug); - //etk::log::setLevel(etk::log::logLevelInfo); - ECI_INFO("Start Application interpeter languages"); - if (argc<=1) { - ECI_CRITICAL("need the file to parse"); - return -1; - } - //eci::ParserCpp tmpParser; - //std::string data = "/* plop */ \n int eee = 22; // error value \nint main(void) {\n return 0;\n}\n";//etk::FSNodeReadAllData(argv[1]); - //std::string data = "alpha /* plop */ test"; - //std::string data = "pp \n // qdfqdfsdf \nde"; - //tmpParser.parse(data); - //tmpParser.parse(etk::FSNodeReadAllData(argv[1])); - +void run_interactive() { + ECI_CRITICAL("TODO ... create interactive interface"); +} + +bool run_test(const std::string& _filename) { eci::Interpreter::Interpreter virtualMachine; - virtualMachine.addFile(argv[1]); + virtualMachine.addFile(_filename); virtualMachine.main(); + return false; +} + +void run_test(const std::vector& _listFileToTest) { + + int32_t test_num = 1; + int32_t count = 0; + int32_t passed = 0; + for (auto &it : _listFileToTest) { + enum etk::typeNode type = etk::FSNode(it).getNodeType(); + if (type == etk::FSN_FOLDER) { + etk::FSNode node(it); + std::vector list; + node.folderGetRecursiveFiles(list, false); + for (auto &it2 : list) { + if (run_test(it2)) { + passed++; + } + count++; + test_num++; + } + } else if (type == etk::FSN_FILE) { + if (run_test(it)) { + passed++; + } + count++; + test_num++; + } + } + ECI_INFO("Done. " << count << " tests, " << passed << " pass, " << count-passed << " fail"); +} + + +int main(int argc, char** argv) { + // the only one init for etk: + std::vector listFileToTest; + for (int32_t iii=1; iii +#include + + +eci::ParserJS::ParserJS() { + m_lexer.append(tokenJSCommentMultiline, "/\\*(.|\\r|\\n)*?(\\*/|\\0)"); + m_lexer.append(tokenJSCommentSingleLine, "//.*"); + m_lexer.append(tokenJSStringDoubleQuote, "\"(.|\\\\[\\\\\"])*?\""); + m_lexer.append(tokenJSStringSimpleQuote, "'\\?.'"); + m_lexer.append(tokenJSBraceIn, "\\{"); + m_lexer.append(tokenJSBraceOut, "\\}"); + m_lexer.append(tokenJSPtheseIn, "\\("); + m_lexer.append(tokenJSPtheseOut, "\\)"); + m_lexer.append(tokenJSHookIn, "\\["); + m_lexer.append(tokenJSHookOut, "\\]"); + m_lexer.append(tokenJSBranch, "\\b(return|if|else|while|do|for)\\b"); + m_lexer.append(tokenJSType, "\\b(bool|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void)\\b"); + m_lexer.append(tokenJSContener, "\\b(var|function)\\b"); + m_lexer.append(tokenJSNumericValue, "\\b(((0(x|X)[0-9a-fA-F]*)|(\\d+\\.?\\d*|\\.\\d+)((e|E)(\\+|\\-)?\\d+)?)(L|l|UL|ul|u|U|F|f)?)\\b"); + m_lexer.append(tokenJSBoolean, "\\b(true|false)\\b"); + m_lexer.append(tokenJSCondition, "===|!==|==|>=|<=|!=|<|>|&&|\\|\\|"); + m_lexer.append(tokenJSAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)"); + m_lexer.append(tokenJSString, "\\w+"); + m_lexer.append(tokenJSSeparator, "(;|,)"); + m_lexer.appendSection(tokenJSSectionBrace, tokenJSBraceIn, tokenJSBraceOut); + m_lexer.appendSection(tokenJSSectionPthese, tokenJSPtheseIn, tokenJSPtheseOut); + m_lexer.appendSection(tokenJSSectionHook, tokenJSHookIn, tokenJSHookOut); +} + +eci::ParserJS::~ParserJS() { + +} + +static void printNode(const std::string& _data, const std::vector>& _nodes, int32_t _level=0) { + std::string offset; + for (int32_t iii=0; iii<_level; ++iii) { + offset += " "; + } + for (auto &it : _nodes) { + if (it->isNodeContainer() == true) { + std::shared_ptr sec = std::dynamic_pointer_cast(it); + if (sec != nullptr) { + ECI_INFO(offset << " " << it->getStartPos() << "->" << it->getStopPos() << " (container)"); + printNode(_data, sec->m_list, _level+1); + } + } else { + ECI_INFO(offset << it->getStartPos() << "->" << it->getStopPos() << " data='" <getStartPos(), it->getStopPos()-it->getStartPos()) << "'" ); + } + } +} + +bool eci::ParserJS::parse(const std::string& _data) { + m_result = m_lexer.interprete(_data); + + // TODO: Agregate type + // TODO: Agregate Action + // TODO: Agregate Function + + ECI_INFO("find :"); + printNode(_data, m_result.m_list); + /* + for (auto &it : m_result.m_list) { + ECI_INFO(" start=" << it->getStartPos() << " stop=" << it->getStopPos() << " data='" <getStartPos(), it->getStopPos()-it->getStartPos()) << "'" ); + } + */ + return false; +} + diff --git a/eci/lang/ParserJS.h b/eci/lang/ParserJS.h new file mode 100644 index 0000000..cf04abe --- /dev/null +++ b/eci/lang/ParserJS.h @@ -0,0 +1,53 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_PARSER_JS_H__ +#define __ECI_PARSER_JS_H__ + +#include + +namespace eci { + + enum jsTokenList { + tokenJSCommentMultiline, + tokenJSCommentSingleLine, + + tokenJSStringDoubleQuote, + tokenJSStringSimpleQuote, + tokenJSBraceIn, + tokenJSBraceOut, + tokenJSPtheseIn, + tokenJSPtheseOut, + tokenJSHookIn, + tokenJSHookOut, + tokenJSSectionBrace, + tokenJSSectionPthese, + tokenJSSectionHook, + tokenJSBranch, + tokenJSSystem, + tokenJSType, + tokenJSContener, + tokenJSNumericValue, + tokenJSBoolean, + tokenJSCondition, + tokenJSAssignation, + tokenJSString, + tokenJSSeparator, + }; + class ParserJS { + public: + eci::Lexer m_lexer; + eci::LexerResult m_result; + public: + ParserJS(); + ~ParserJS(); + bool parse(const std::string& _data); + }; +} + +#endif diff --git a/lutin_eci2.py b/lutin_eci2.py index af1ee3b..327ba44 100644 --- a/lutin_eci2.py +++ b/lutin_eci2.py @@ -26,7 +26,8 @@ def create(target): 'eci/Type.cpp', 'eci/Variable.cpp', 'eci/Value.cpp', - 'eci/lang/ParserCpp.cpp' + 'eci/lang/ParserCpp.cpp', + 'eci/lang/ParserJS.cpp' ]) myModule.add_export_path(tools.get_current_path(__file__)) myModule.add_module_depend('etk')