ArkScript
A small, lisp-inspired, functional scripting language
Repl.hpp
Go to the documentation of this file.
1/**
2 * @file Repl.hpp
3 * @author Lex Plateau (lexplt.dev@gmail.com)
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;
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 void registerBuiltins();
61
62 /**
63 * @brief Get a line via replxx and handle commands
64 * @param continuation if the prompt needs to be modified because a code block isn't entirely closed, set to true
65 * @return
66 */
67 std::optional<std::string> getLine(bool continuation);
68
69 /**
70 * @brief Prompt the user to enter a complete code block and handle the prompt modifications until the code block is complete
71 * @return std::optional<std::string>
72 */
73 std::optional<std::string> getCodeBlock();
74 };
75}
76
77#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.
Definition Repl.cpp:28
std::string m_code
Definition Repl.hpp:43
void cuiSetup()
Configure replxx.
Definition Repl.cpp:85
bool m_running
Definition Repl.hpp:45
void registerBuiltins()
Definition Repl.cpp:121
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:219
std::size_t m_old_ip
Definition Repl.hpp:47
std::string m_temp_additional_code
Definition Repl.hpp:44
Repl(const std::vector< std::filesystem::path > &lib_env)
Construct a new Repl object.
Definition Repl.cpp:20
VM m_vm
Definition Repl.hpp:50
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:156
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:33
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:47