11 Repl::Repl(uint16_t options,
const std::vector<std::string>& libenv) :
12 m_options(options), m_lines(1), m_old_ip(0), m_libenv(libenv)
28 std::stringstream tmp_code;
29 unsigned open_parentheses = 0;
30 unsigned open_braces = 0;
35 std::string str_lines =
"000";
36 if (std::to_string(
m_lines).size() < 3)
38 std::size_t size = std::to_string(
m_lines).size();
39 str_lines.replace((str_lines.size() - size), size, std::to_string(
m_lines));
42 str_lines = std::to_string(
m_lines);
44 std::string prompt =
"main:" + str_lines +
"> ";
45 char const* buf {
nullptr };
48 buf =
m_repl.input(prompt);
49 }
while ((buf ==
nullptr) && (errno == EAGAIN));
50 std::string line = (buf !=
nullptr) ? std::string(buf) :
"";
57 if (line ==
"(quit)" || buf ==
nullptr)
59 std::cout <<
"\nExiting REPL\n";
64 tmp_code << line <<
"\n";
70 if (open_parentheses == 0 && open_braces == 0)
76 if (!tmp_code.str().empty())
89 code = tmp_code.str();
102 std::cout <<
"Ark::State::doString failed\n";
112 "ArkScript REPL -- Version %i.%i.%i [LICENSE: Mozilla Public License 2.0]\n"
113 "Type \"(quit)\" to quit.\n",
121 int open_parentheses = 0;
123 for (
const char& c : line)
127 case '(': ++open_parentheses;
break;
128 case ')': --open_parentheses;
break;
132 return open_parentheses;
139 for (
const char& c : line)
143 case '{': ++open_braces;
break;
144 case '}': --open_braces;
break;
153 size_t string_begin = line.find_first_not_of(
" \t");
154 if (std::string::npos != string_begin)
156 size_t string_end = line.find_last_not_of(
" \t");
157 line = line.substr(string_begin, string_end - string_begin + 1);
163 using namespace std::placeholders;
169 m_repl.set_word_break_characters(
" \t.,-%!;:=*~^'\"/?<>|[](){}");
170 m_repl.set_completion_count_cutoff(128);
171 m_repl.set_double_tab_completion(
false);
172 m_repl.set_complete_on_empty(
true);
173 m_repl.set_beep_on_ambiguous_completion(
false);
174 m_repl.set_no_color(
false);
constexpr int ARK_VERSION_MAJOR
constexpr int ARK_VERSION_PATCH
constexpr int ARK_VERSION_MINOR
ArkScript REPL - Read Eval Print Loop.
Replxx::completions_t hook_completion(std::string const &context, int &contextLen, std::vector< std::string > const &user_data)
void hook_color(std::string const &str, Replxx::colors_t &colors, std::vector< std::pair< std::string, Replxx::Color > > const &user_data)
Replxx::hints_t hook_hint(std::string const &context, int &contextLen, Replxx::Color &color, std::vector< std::string > const &examples)
Repl(uint16_t options, const std::vector< std::string > &libenv)
Construct a new Repl object.
std::vector< std::string > m_libenv
int count_open_braces(const std::string &line)
void trim_whitespace(std::string &line)
int count_open_parentheses(const std::string &line)
Ark state to handle the dirty job of loading and compiling ArkScript code.
void reset() noexcept
Reset State (all member variables related to execution)
void setDebug(unsigned level) noexcept
Set the debug level.
bool doString(const std::string &code)
Compile a string (representing ArkScript code) and store resulting bytecode in m_bytecode.
The ArkScript virtual machine, executing ArkScript bytecode.
std::vector< std::unique_ptr< internal::ExecutionContext > > m_execution_contexts
int safeRun(internal::ExecutionContext &context, std::size_t untilFrameCount=0)
Run ArkScript bytecode inside a try catch to retrieve all the exceptions and display a stack trace if...
void init() noexcept
Initialize the VM according to the parameters.
const std::vector< std::pair< std::string, Replxx::Color > > ColorsRegexDict
const std::vector< std::string > KeywordsDict