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 * @version 1.0
6 * @date 2020-10-27
7 *
8 * @copyright Copyright (c) 2020-2024
9 *
10 */
11
12#ifndef ARK_REPL_REPL_HPP
13#define ARK_REPL_REPL_HPP
14
15#include <string>
16#include <optional>
17
18#include <Ark/VM/VM.hpp>
19#include <Ark/VM/State.hpp>
20
21#include <replxx.hxx>
22
23namespace Ark
24{
25 class Repl
26 {
27 public:
28 /**
29 * @brief Construct a new Repl object
30 *
31 * @param lib_env search path for the std library
32 */
33 explicit Repl(const std::vector<std::filesystem::path>& lib_env);
34
35 /**
36 * @brief Start the REPL
37 *
38 */
39 int run();
40
41 private:
42 replxx::Replxx m_repl;
43 unsigned m_line_count;
44 std::string m_code;
46
47 std::size_t m_old_ip;
48 std::vector<std::filesystem::path> m_lib_env;
52 std::vector<std::string> m_keywords;
53 std::vector<std::pair<std::string, replxx::Replxx::Color>> m_words_colors;
54
55 /**
56 * @brief Configure replxx
57 */
58 void cuiSetup();
59
60 /**
61 * @brief Get a line via replxx and handle commands
62 * @param continuation if the prompt needs to be modified because a code block isn't entirely closed, set to true
63 * @return
64 */
65 std::optional<std::string> getLine(bool continuation);
66
67 /**
68 * @brief Prompt the user to enter a complete code block and handle the prompt modifications until the code block is complete
69 * @return std::optional<std::string>
70 */
71 std::optional<std::string> getCodeBlock();
72 };
73}
74
75#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:51
std::vector< std::pair< std::string, replxx::Replxx::Color > > m_words_colors
Definition Repl.hpp:53
State m_state
Definition Repl.hpp:49
std::vector< std::string > m_keywords
Definition Repl.hpp:52
int run()
Start the REPL.
std::string m_code
Definition Repl.hpp:44
void cuiSetup()
Configure replxx.
bool m_running
Definition Repl.hpp:45
replxx::Replxx m_repl
Definition Repl.hpp:42
std::optional< std::string > getCodeBlock()
Prompt the user to enter a complete code block and handle the prompt modifications until the code blo...
std::size_t m_old_ip
Definition Repl.hpp:47
Repl(const std::vector< std::filesystem::path > &lib_env)
Construct a new Repl object.
VM m_vm
Definition Repl.hpp:50
unsigned m_line_count
Definition Repl.hpp:43
std::optional< std::string > getLine(bool continuation)
Get a line via replxx and handle commands.
std::vector< std::filesystem::path > m_lib_env
Definition Repl.hpp:48
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:44