diff --git a/Consts.h b/Consts.h index 3495694..4385838 100644 --- a/Consts.h +++ b/Consts.h @@ -4,7 +4,7 @@ #include #include -const std::string NSM_VERSION = "2.4.6"; +const std::string NSM_VERSION = "2.4.7"; const int HASH_RS = -2011; const int HASH_JS = -2012; diff --git a/Parser.cpp b/Parser.cpp index 59c6136..8694867 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -508,25 +508,25 @@ int Parser::refresh_completions() return 0; } -int Parser::shell(std::string& lang, std::ostream& eos) +int Parser::shell(std::string& langStr, char& langCh, std::ostream& eos) { mode = MODE_SHELL; - return interactive(lang, eos); + return interactive(langStr, langCh, eos); } -int Parser::interpreter(std::string& lang, std::ostream& eos) +int Parser::interpreter(std::string& langStr, char& langCh, std::ostream& eos) { mode = MODE_INTERP; - return interactive(lang, eos); + return interactive(langStr, langCh, eos); } -int Parser::interactive(std::string& lang, std::ostream& eos) +int Parser::interactive(std::string& langStr, char& langCh, std::ostream& eos) { bool addPath; vars.precision = 6; vars.fixedPrecision = vars.scientificPrecision = 0; - if(lang.find_first_of("eEfFlLnN")) + /*if(langStr.find_first_of("eEfFlLnN")) { if(!consoleLocked) os_mtx->lock(); @@ -536,7 +536,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos) start_err(eos) << "sh: unknown language " << c_light_blue << lang << c_white << std::endl; os_mtx->unlock(); return 1; - } + }*/ depFiles.clear(); includedFiles.clear(); @@ -553,7 +553,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos) symbol_table.add_package(vectorops_package); exprtk_nsm_lang exprtk_nsm_lang_fn; - exprtk_nsm_lang_fn.setLangPtr(&lang); + exprtk_nsm_lang_fn.setLangPtr(&langStr); symbol_table.add_function("nsm_lang", exprtk_nsm_lang_fn); exprtk_nsm_mode exprtk_nsm_mode_fn; exprtk_nsm_mode_fn.setModePtr(&mode); @@ -564,7 +564,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos) lua.init(); lua_addnsmfns(); - lua_pushlightuserdata(lua.L, &lang); + lua_pushlightuserdata(lua.L, &langStr); lua_setglobal(lua.L, "nsm_lang__"); lua_register(lua.L, "nsm_lang", lua_nsm_lang); lua_register(lua.L, "nsm_mode", lua_nsm_mode); @@ -591,7 +591,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos) int netBrackets = 0; try { - result = getline(lang, addPath, promptChar, lolcatActive, inLine, 1, tabCompletionStrs); + result = getline(langStr, addPath, promptChar, lolcatActive, inLine, 1, tabCompletionStrs); } catch(...) { @@ -628,7 +628,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos) toProcess += inLine + "\n"; inLine = ""; - result = getline(lang, addPath, ">", lolcatActive, inLine, 1, tabCompletionStrs); + result = getline(langStr, addPath, ">", lolcatActive, inLine, 1, tabCompletionStrs); for(size_t i=0; iunlock(); } } - else if(lang == 'x') + else if(lang == 'e') { std::string strippedScriptStr = scriptStr; strip_surrounding_whitespace_multiline(strippedScriptStr); @@ -1544,13 +1556,28 @@ int Parser::n_read_and_process_fast(const bool& indent, } else if(inStr[linePos] == '@') //checks for function calls { - linePos++; - int ret_val = read_and_process_fn(indent, baseIndentAmount, 'n', addOutput, inStr, lineNo, linePos, readPath, antiDepsOfReadPath, outStr, eos); + try + { + linePos++; + int ret_val = read_and_process_fn(indent, baseIndentAmount, 'n', addOutput, inStr, lineNo, linePos, readPath, antiDepsOfReadPath, outStr, eos); - if(ret_val == NSM_CONT) - return 0; - else if(ret_val) - return ret_val; + //skips over 'end of statement' semicolons + while(linePos < inStr.size() && inStr[linePos] == ';') + ++linePos; + + if(ret_val == NSM_CONT) + return 0; + else if(ret_val) + return ret_val; + } + catch(...) + { + if(!consoleLocked) + os_mtx->lock(); + start_err(eos, readPath, lineNo) << "caught an unknown error" << std::endl; + os_mtx->unlock(); + return 1; + } } else if(inStr[linePos] == '$' && (inStr[linePos+1] == '{' || inStr[linePos+1] == '[' || inStr[linePos+1] == '`')) { @@ -1706,9 +1733,12 @@ int Parser::f_read_and_process_fast(const bool& addOutput, continue; } - else if(inStr[linePos] == '@') //ignores @ for function calls + else if(inStr[linePos] == '@') { - outStr += "@"; + /*if(linePos && (inStr[linePos] == ' ' || + inStr[linePos] == '\t' || + inStr[linePos] == '\n'))*/ + //outStr += "@"; ++linePos; } else if(inStr[linePos] == '<') @@ -1745,7 +1775,7 @@ int Parser::f_read_and_process_fast(const bool& addOutput, return 1; } } - /*else if(isdigit(inStr[linePos])) + /*]else if(isdigit(inStr[linePos])) { do { @@ -1765,6 +1795,10 @@ int Parser::f_read_and_process_fast(const bool& addOutput, { int ret_val = read_and_process_fn(0, "", 'f', addOutput, inStr, lineNo, linePos, readPath, antiDepsOfReadPath, outStr, eos); + //skips over 'end of statement' semicolons + while(linePos < inStr.size() && inStr[linePos] == ';') + ++linePos; + if(ret_val == NSM_CONT) return 0; else if(ret_val) @@ -1774,7 +1808,7 @@ int Parser::f_read_and_process_fast(const bool& addOutput, { if(!consoleLocked) os_mtx->lock(); - start_err(eos, readPath, lineNo) << "an unknown error occurred" << std::endl; + start_err(eos, readPath, lineNo) << "caught an unknown error" << std::endl; os_mtx->unlock(); return 1; } @@ -14297,14 +14331,14 @@ int Parser::read_and_process_fn(const bool& indent, } else { - std::string trash, toParse = "sys(" + funcName; + //std::string trash, toParse = "sys(" + funcName; - if(options.size()) + /*if(options.size()) { for(size_t o=0; o& estNoPagesFinished, diff --git a/ProjectInfo.cpp b/ProjectInfo.cpp index c82bfd2..55b66e7 100644 --- a/ProjectInfo.cpp +++ b/ProjectInfo.cpp @@ -548,6 +548,11 @@ Path ProjectInfo::execrc_path(const std::string& exec, const std::string& execrc return Path(app_dir() + "/.nift/", exec + "rc." + execrc_ext); } +Path ProjectInfo::execrc_path(const std::string& exec, const char& execrc_ext) +{ + return Path(app_dir() + "/.nift/", exec + "rc." + execrc_ext); +} + int ProjectInfo::save_config(const std::string& configPathStr, const bool& global) { std::ofstream ofs(configPathStr); diff --git a/ProjectInfo.h b/ProjectInfo.h index 489aa39..d6f87b0 100644 --- a/ProjectInfo.h +++ b/ProjectInfo.h @@ -62,6 +62,7 @@ struct ProjectInfo int open_tracking(const bool& addMsg); Path execrc_path(const std::string& exec, const std::string& execrc_ext); + Path execrc_path(const std::string& exec, const char& execrc_ext); int save_config(const std::string& configPathStr, const bool& global); int save_global_config(); diff --git a/ReleaseNotes.md b/ReleaseNotes.md index c57c77b..5920f66 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -2,6 +2,15 @@ Nift Release Notes ------------------ +Version 2.4.7 of Nift +* Reverted to handling @fns with f++, too ingrained in the codebase +* Reverted to calling sys call on whole line for zero param functions +* Reverted to breaking at non-escaped @'s when reading function names +* Fixed up allowing for ';' at end of statements (hopefully no bugs/undesirable + features), though any potential system call will be called on whole line for + possibly multiple statements, use a new line if needed +* cleaned up (hopefully) language choce with interactive REPL's (both interp and sh) and run + Version 2.4.6 of Nift * Initialised all bLineNo's to zero (started getting warnings on OSX) * Fixed up "run commands" in-built scripts from last version to handle language names as well as chars for script extensions diff --git a/nsm.cpp b/nsm.cpp index 7278427..edbe990 100644 --- a/nsm.cpp +++ b/nsm.cpp @@ -771,45 +771,6 @@ int main(int argc, const char* argv[]) std::string param; Path path; - std::string lang = "?"; - if(noParams == 1) - lang = "f++"; - else - { - param = argv[2]; - - size_t i = param.find_first_of("eEfFlLnN"); - - if(!i) - { - if(lang[0] == 't' || lang[0] == 'T') - lang = "n++"; - else if(lang[0] == 'x' || lang[0] == 'X') - lang = "exprtk"; - else - lang = param; - } - else if(i != std::string::npos) - { - char c = param[i]; - - if(c == 'f' || c == 'F') - lang = "f++"; - else if(c == 'n' || c == 'N' || c == 't' || c == 'T') - lang = "n++"; - else if(c == 'l' || c == 'L') - lang = "lua"; - else if(c == 'e' || c == 'E' || c == 'x' || c == 'X') - lang = "exprtk"; - } - else - { - start_err(std::cout) << cmd << ": cannot determine chosen language from " << quote(param) << ", "; - std::cout << "valid options include '-f++', '-n++', '-lua', '-exprtk'" << std::endl; - return 1; - } - } - std::set trackedAll; std::mutex os_mtx; @@ -842,6 +803,22 @@ int main(int argc, const char* argv[]) project.unixTextEditor, project.winTextEditor); + std::string langStr = "f++"; + if(noParams == 2) + langStr = argv[2]; + char langCh = 'f'; + + /*if(langStr.find_first_of("fF") != std::string::npos) + langCh = 'f'; + else */if(langStr.find_first_of("nNtT") != std::string::npos) + langCh = 'n'; + else if(langStr.find_first_of("lL") != std::string::npos) + langCh = 'l'; + else if(langStr.find_first_of("eExX") != std::string::npos) + langCh = 'x'; + /*else + langCh = 'f';*/ + /*if(project.lolcatDefault) if(!parser.lolcat_init(project.lolcatCmd)) return NSM_ERR;*/ @@ -852,37 +829,38 @@ int main(int argc, const char* argv[]) parser.lolcatCmd = project.lolcatCmd; } - if(file_exists(project.execrc_path(argv[0], lang.substr(0, 1)).str())) + std::cout << project.execrc_path(argv[0], langStr).str() << std::endl; + if(file_exists(project.execrc_path(argv[0], langCh).str())) { - std::cout << "running " << argv[0] << "rc." << lang[0] << " file: "; - std::cout << project.execrc_path(argv[0], lang.substr(0, 1)) << std::endl; - parser.run(project.execrc_path(argv[0], lang.substr(0, 1)).str(), lang[0], std::cout); + std::cout << "running " << argv[0] << "rc." << langCh << " file: "; + std::cout << project.execrc_path(argv[0], langCh) << std::endl; + parser.run(project.execrc_path(argv[0], langCh).str(), langCh, std::cout); } - else if(file_exists(project.execrc_path(argv[0], lang).str())) + else if(file_exists(project.execrc_path(argv[0], langStr).str())) { - std::cout << "running " << argv[0] << "rc." << lang[0] << " file: "; - std::cout << project.execrc_path(argv[0], lang) << std::endl; - parser.run(project.execrc_path(argv[0], lang).str(), lang[0], std::cout); + std::cout << "running " << argv[0] << "rc." << langCh << " file: "; + std::cout << project.execrc_path(argv[0], langStr) << std::endl; + parser.run(project.execrc_path(argv[0], langStr).str(), langCh, std::cout); } - if(file_exists(Path(".nsm/", cmd + "." + lang.substr(0, 1)).str())) + if(file_exists(Path(".nsm/", cmd + "." + langCh).str())) { - std::cout << "runnning project " << cmd << "." << lang[0] << " file: "; - std::cout << Path(".nsm/", cmd + "." + lang.substr(0, 1)) << std::endl; - parser.run(Path(".nsm/", cmd + "." + lang.substr(0, 1)).str(), lang[0], std::cout); + std::cout << "runnning project " << cmd << "." << langCh << " file: "; + std::cout << Path(".nsm/", cmd + "." + langCh) << std::endl; + parser.run(Path(".nsm/", cmd + "." + langCh).str(), langCh, std::cout); } - else if(file_exists(Path(".nsm/", cmd + "." + lang).str())) + else if(file_exists(Path(".nsm/", cmd + "." + langStr).str())) { - std::cout << "runnning project " << cmd << "." << lang << " file: "; - std::cout << Path(".nsm/", cmd + "." + lang) << std::endl; - parser.run(Path(".nsm/", cmd + "." + lang).str(), lang[0], std::cout); + std::cout << "runnning project " << cmd << "." << langStr << " file: "; + std::cout << Path(".nsm/", cmd + "." + langStr) << std::endl; + parser.run(Path(".nsm/", cmd + "." + langStr).str(), langCh, std::cout); } if(cmd == "interp") - return parser.interpreter(lang, std::cout); + return parser.interpreter(langStr, langCh, std::cout); else - return parser.shell(lang, std::cout); + return parser.shell(langStr, langCh, std::cout); } else if(cmd == "medit" || cmd == "mopen") { @@ -1024,13 +1002,13 @@ int main(int argc, const char* argv[]) langOpt = cmd.substr(3, cmd.size()-3); strip_surrounding_whitespace(langOpt); - if(langOpt.find_first_of('n') != std::string::npos) + if(langOpt.find_first_of("nNtT") != std::string::npos) lang = 'n'; - else if(langOpt.find_first_of('f') != std::string::npos) + else if(langOpt.find_first_of("fF") != std::string::npos) lang = 'f'; - else if(langOpt.find_first_of('x') != std::string::npos) + else if(langOpt.find_first_of("eExX") != std::string::npos) lang = 'x'; - else if(langOpt.find_first_of('l') != std::string::npos) + else if(langOpt.find_first_of("lL") != std::string::npos) lang = 'l'; else { @@ -1045,13 +1023,13 @@ int main(int argc, const char* argv[]) path.set_file_path_from(argv[3]); langOpt = argv[2]; - if(langOpt.find_first_of('n') != std::string::npos) + if(langOpt.find_first_of("nNtT") != std::string::npos) lang = 'n'; - else if(langOpt.find_first_of('f') != std::string::npos) + else if(langOpt.find_first_of("fF") != std::string::npos) lang = 'f'; - else if(langOpt.find_first_of('x') != std::string::npos) + else if(langOpt.find_first_of("eExX") != std::string::npos) lang = 'x'; - else if(langOpt.find_first_of('l') != std::string::npos) + else if(langOpt.find_first_of("lL") != std::string::npos) lang = 'l'; else {