-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #458 from ArkScript-lang/refactor/repl
refactor(repl): use modern C++ instead of C, tidy up the code and make it more maintainable
- Loading branch information
Showing
10 changed files
with
487 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,25 @@ | |
* @file Repl.hpp | ||
* @author Alexandre Plateau ([email protected]) | ||
* @brief ArkScript REPL - Read Eval Print Loop | ||
* @version 0.2 | ||
* @version 1.0 | ||
* @date 2020-10-27 | ||
* | ||
* @copyright Copyright (c) 2020-2021 | ||
* @copyright Copyright (c) 2020-2024 | ||
* | ||
*/ | ||
|
||
#ifndef ARK_REPL_REPL_HPP | ||
#define ARK_REPL_REPL_HPP | ||
|
||
#include <iostream> | ||
#include <filesystem> | ||
#include <string> | ||
#include <optional> | ||
|
||
#include <Ark/Constants.hpp> | ||
#include <Ark/Compiler/Compiler.hpp> | ||
#include <Ark/VM/VM.hpp> | ||
#include <Ark/VM/State.hpp> | ||
#include <CLI/REPL/ConsoleStyle.hpp> | ||
|
||
#include <replxx.hxx> | ||
|
||
namespace Ark | ||
{ | ||
|
@@ -29,9 +30,9 @@ namespace Ark | |
/** | ||
* @brief Construct a new Repl object | ||
* | ||
* @param libenv search path for the std library | ||
* @param lib_env search path for the std library | ||
*/ | ||
explicit Repl(const std::vector<std::filesystem::path>& libenv); | ||
explicit Repl(const std::vector<std::filesystem::path>& lib_env); | ||
|
||
/** | ||
* @brief Start the REPL | ||
|
@@ -40,16 +41,29 @@ namespace Ark | |
int run(); | ||
|
||
private: | ||
Replxx m_repl; | ||
unsigned m_lines; | ||
replxx::Replxx m_repl; | ||
unsigned m_line_count; | ||
std::string m_code; | ||
bool m_running; | ||
|
||
int m_old_ip; | ||
std::vector<std::filesystem::path> m_libenv; | ||
std::vector<std::filesystem::path> m_lib_env; | ||
State m_state; | ||
VM m_vm; | ||
bool m_has_init_vm; | ||
|
||
static inline void print_repl_header(); | ||
static int count_open_parentheses(const std::string& line); | ||
static int count_open_braces(const std::string& line); | ||
static void trim_whitespace(std::string& line); | ||
void cui_setup(); | ||
/** | ||
* @brief Configure replxx | ||
*/ | ||
void cuiSetup(); | ||
|
||
/** | ||
* @brief Get a line via replxx and handle commands | ||
* @param continuation if the prompt needs to be modified because a code block isn't entirely closed, set to true | ||
* @return | ||
*/ | ||
std::optional<std::string> getLine(bool continuation); | ||
std::optional<std::string> getCodeBlock(); | ||
}; | ||
} | ||
|
||
|
Oops, something went wrong.