diff --git a/aql2/src/REPL.cpp b/aql2/src/REPL.cpp index 30e52fe06f3dbded1b94d29fe1919e220684d2b2..b875d010b13d2f7b5c42a4303b2b1083470a8c62 100644 --- a/aql2/src/REPL.cpp +++ b/aql2/src/REPL.cpp @@ -15,7 +15,6 @@ cli::CommandResult REPL::run(cli::Environment& env) // numbers {"[\\-|+]{0,1}[0-9]+", cl::BLUE}, // integers {"[\\-|+]{0,1}[0-9]*\\.[0-9]+", cl::BLUE}, // decimals - {"[\\-|+]{0,1}[0-9]+e[\\-|+]{0,1}[0-9]+", cl::BLUE}, // scientific notation // strings {"\"(.|\n)*?\"", cl::YELLOW}, // double quotes @@ -76,8 +75,24 @@ cli::CommandResult REPL::run(cli::Environment& env) const auto& suggestions = complete.getSuggestions(context, prefix); - for (const auto& suggestion : suggestions) { - completions.emplace_back(suggestion.second); + for (const auto& [kind, suggestion] : suggestions) { + replxx::Replxx::Color color; + switch (kind) { + case cli::Autocomplete::SuggestionKind::Keyword: + color = Replxx::Color::BRIGHTBLUE; + break; + case cli::Autocomplete::SuggestionKind::Variable: + color = Replxx::Color::BRIGHTGREEN; + break; + case cli::Autocomplete::SuggestionKind::Identifier: + color = Replxx::Color::GREEN; + break; + default: + color = Replxx::Color::BRIGHTCYAN; + break; + } + + completions.emplace_back(suggestion, color); } return completions; @@ -88,7 +103,7 @@ cli::CommandResult REPL::run(cli::Environment& env) cli::CommandResult state = cli::CommandResult::OK; // display the prompt and retrieve input from the user char const* cInput; - while (state != cli::CommandResult::QUIT) { + while (state == cli::CommandResult::OK || state == cli::CommandResult::ERROR) { do { cInput = rx.input(prompt); } while ((cInput == nullptr) && (errno == EAGAIN)); @@ -103,12 +118,13 @@ cli::CommandResult REPL::run(cli::Environment& env) if (input.empty()) { continue; } - - const std::unique_ptr<cli::Command> ast = cli::Parser2::parseString(input); - state = env.execute(ast); - - if (state == cli::CommandResult::OK) - rx.history_add(input); + try { + state = env.execute(input); + if (state == cli::CommandResult::OK) + rx.history_add(input); + } catch (const std::exception& e) { + std::cerr << e.what() << '\n'; + } } if (REPL::historyFile.has_value())