From 35cf6b13e537db2dbb3b8e55c746003239639e3d Mon Sep 17 00:00:00 2001 From: VaclavT Date: Mon, 15 Mar 2021 23:24:58 +0100 Subject: [PATCH] move list of builtins to ml_util.cpp this is not final solution, just for now --- ml.cpp | 9 --------- ml_util.cpp | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ml.cpp b/ml.cpp index e2ccf0d..b7982c0 100644 --- a/ml.cpp +++ b/ml.cpp @@ -1830,16 +1830,7 @@ std::vector MlEnvironment::get_lambdas_list() const { lambdas.push_back(it->first); } } - std::vector commands { - "eval", "type", "parse", "do", "if", "for", "while", "scope", "quote", "defun", - "define", "lambda", "benchmark", "=", "!=", ">", "<", ">=", "<=", "+", "-", "*", "/", "%", - "list", "insert", "index", "remove", "len", "push", "pop", "head", "tail", "first", "last", - "range", "map", "filter", "reduce", "exit", "quit", "print", "input", "random", "include", - "read-file", "write-file", "read-url", "system-cmd", "ls-dir", "is-file?", "is-dir?", - "parse-csv", "parse-json", "get-universal-time", "date-to-str", "str-to-date", "date-add", "debug", - "sprintf", "display", "string-replace", "string-regex?", "string-pad", "int", "float", "string" }; - lambdas.insert(end(lambdas), begin(commands), end(commands)); return lambdas; } diff --git a/ml_util.cpp b/ml_util.cpp index 8ed8d03..d6264bb 100644 --- a/ml_util.cpp +++ b/ml_util.cpp @@ -4,6 +4,14 @@ #include #include + const std::vector commands { + "eval", "type", "parse", "do", "if", "for", "while", "scope", "quote", "defun", + "define", "lambda", "benchmark", "=", "!=", ">", "<", ">=", "<=", "+", "-", "*", "/", "%", + "list", "insert", "index", "remove", "len", "push", "pop", "head", "tail", "first", "last", + "range", "map", "filter", "reduce", "exit", "quit", "print", "input", "random", "include", + "read-file", "write-file", "read-url", "system-cmd", "ls-dir", "is-file?", "is-dir?", + "parse-csv", "parse-json", "get-universal-time", "date-to-str", "str-to-date", "date-add", "debug", + "sprintf", "display", "string-replace", "string-regex?", "string-pad", "int", "float", "string" }; std::string get_history_file_dir() { // TODO not portable and in function @@ -58,7 +66,10 @@ void completion(const char *buf, linenoiseCompletions *lc) { std::string token = str.substr(pos+1); std::string begining = str.substr(0, pos+1); + // TODO optimize not to get all lambdas, but those begining with token std::vector lambdas = repl_env->get_lambdas_list(); + lambdas.insert(end(lambdas), begin(commands), end(commands)); + for (std::vector::iterator t = lambdas.begin(); t != lambdas.end(); ++t) { if(t->find(token) == 0) { std::string completion_string = begining + *t;