ArkScript
A small, fast, functional and scripting language for video games
Repl.hpp
Go to the documentation of this file.
1/**
2 * @file Repl.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief ArkScript REPL - Read Eval Print Loop
5 * @date 2020-10-27
6 *
7 * @copyright Copyright (c) 2020-2025
8 *
9 */
10
11#ifndef ARK_REPL_REPL_HPP
12#define ARK_REPL_REPL_HPP
13
14#include <string>
15#include <optional>
16
17#include <Ark/VM/VM.hpp>
18#include <Ark/VM/State.hpp>
19
20#include <replxx.hxx>
21
22namespace Ark
23{
24 class Repl
25 {
26 public:
27 /**
28 * @brief Construct a new Repl object
29 *
30 * @param lib_env search path for the std library
31 */
32 explicit Repl(const std::vector<std::filesystem::path>& lib_env);
33
34 /**
35 * @brief Start the REPL
36 *
37 */
38 int run();
39
40 private:
41 replxx::Replxx m_repl;
42 unsigned m_line_count;
43 std::string m_code;
45
46 std::size_t m_old_ip;
47 std::vector<std::filesystem::path> m_lib_env;
51 std::vector<std::string> m_keywords;
52 std::vector<std::pair<std::string, replxx::Replxx::Color>> m_words_colors;
53
54 /**
55 * @brief Configure replxx
56 */
57 void cuiSetup();
58
59 /**
60 * @brief Get a line via replxx and handle commands
61 * @param continuation if the prompt needs to be modified because a code block isn't entirely closed, set to true
62 * @return
63 */
64 std::optional<std::string> getLine(bool continuation);
65
66 /**
67 * @brief Prompt the user to enter a complete code block and handle the prompt modifications until the code block is complete
68 * @return std::optional<std::string>
69 */
70 std::optional<std::string> getCodeBlock();
71 };
72}
73
74#endif
State used by the virtual machine: it loads the bytecode, can compile it if needed,...
The ArkScript virtual machine.
bool m_has_init_vm
Definition Repl.hpp:50
std::vector< std::pair< std::string, replxx::Replxx::Color > > m_words_colors
Definition Repl.hpp:52
State m_state
Definition Repl.hpp:48
std::vector< std::string > m_keywords
Definition Repl.hpp:51
int run()
Start the REPL.
Definition Repl.cpp:24
std::string m_code
Definition Repl.hpp:43
void cuiSetup()
Configure replxx.
Definition Repl.cpp:72
bool m_running
Definition Repl.hpp:44
replxx::Replxx m_repl
Definition Repl.hpp:41
std::optional< std::string > getCodeBlock()
Prompt the user to enter a complete code block and handle the prompt modifications until the code blo...
Definition Repl.cpp:169
std::size_t m_old_ip
Definition Repl.hpp:46
Repl(const std::vector< std::filesystem::path > &lib_env)
Construct a new Repl object.
Definition Repl.cpp:16
VM m_vm
Definition Repl.hpp:49
unsigned m_line_count
Definition Repl.hpp:42
std::optional< std::string > getLine(bool continuation)
Get a line via replxx and handle commands.
Definition Repl.cpp:110
std::vector< std::filesystem::path > m_lib_env
Definition Repl.hpp:47
Ark state to handle the dirty job of loading and compiling ArkScript code.
Definition State.hpp:32
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:45