Extend the tester to compile sources
This commit is contained in:
@ -5,10 +5,11 @@
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
#include "elna/lexer.hpp"
|
||||
#include "elna/state.hpp"
|
||||
#include "elna/history.hpp"
|
||||
|
||||
#define BOOST_PROCESS_USE_STD_FS
|
||||
|
||||
namespace elna
|
||||
{
|
||||
/**
|
||||
@ -42,15 +43,14 @@ namespace elna
|
||||
* \param line The command and arguments.
|
||||
* \return Whether the input shoud continued (no exit requested).
|
||||
*/
|
||||
bool execute(const std::vector<token>& line);
|
||||
bool execute(const std::string& line);
|
||||
|
||||
/**
|
||||
* Runs the binary specified in its argument.
|
||||
*
|
||||
* \param program Program name in PATH.
|
||||
* \param arguments Command arguments.
|
||||
*/
|
||||
void launch(const std::string& program, const std::vector<std::string>& arguments);
|
||||
void launch(const std::string& program);
|
||||
|
||||
/**
|
||||
* Enables the raw mode.
|
||||
@ -74,7 +74,16 @@ namespace elna
|
||||
/**
|
||||
* Calls autocompletion.
|
||||
*
|
||||
* \param User input.
|
||||
* \param Cursor position in the user input.
|
||||
* \return Selected item.
|
||||
*/
|
||||
std::string complete();
|
||||
std::string complete(const std::string& input, const std::size_t position);
|
||||
|
||||
/**
|
||||
* Prints the message from the exception.
|
||||
*
|
||||
* \param exception The exception to print.
|
||||
*/
|
||||
void print_exception(const std::exception& exception);
|
||||
}
|
||||
|
@ -14,9 +14,10 @@ namespace elna
|
||||
class const_iterator
|
||||
{
|
||||
std::string::const_iterator m_buffer;
|
||||
Position m_position;
|
||||
source_position m_position;
|
||||
|
||||
const_iterator(std::string::const_iterator buffer, const Position& position);
|
||||
const_iterator(std::string::const_iterator buffer,
|
||||
const source_position position = source_position());
|
||||
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
@ -25,7 +26,7 @@ namespace elna
|
||||
using pointer = const value_type *;
|
||||
using reference = const value_type&;
|
||||
|
||||
const Position& position() const noexcept;
|
||||
const source_position& position() const noexcept;
|
||||
|
||||
reference operator*() const noexcept;
|
||||
pointer operator->() const noexcept;
|
||||
@ -68,11 +69,11 @@ namespace elna
|
||||
|
||||
type of() const noexcept;
|
||||
const value& identifier() const noexcept;
|
||||
const Position& position() const noexcept;
|
||||
const source_position& position() const noexcept;
|
||||
|
||||
private:
|
||||
std::string m_value;
|
||||
Position m_position;
|
||||
source_position m_position;
|
||||
type m_type;
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace elna
|
||||
/**
|
||||
* Position in the source text.
|
||||
*/
|
||||
struct Position
|
||||
struct source_position
|
||||
{
|
||||
/// Line.
|
||||
std::size_t line = 1;
|
||||
@ -20,21 +20,21 @@ namespace elna
|
||||
/**
|
||||
* A compilation error consists of an error message and position.
|
||||
*/
|
||||
struct CompileError
|
||||
struct compile_error
|
||||
{
|
||||
private:
|
||||
char const *message_;
|
||||
Position position_;
|
||||
char const *message;
|
||||
source_position position;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @param message Error text.
|
||||
* @param position Error position in the source text.
|
||||
*/
|
||||
CompileError(char const *message, Position position) noexcept;
|
||||
compile_error(char const *message, const source_position position) noexcept;
|
||||
|
||||
/// Error text.
|
||||
char const *message() const noexcept;
|
||||
const char *what() const noexcept;
|
||||
|
||||
/// Error line in the source text.
|
||||
std::size_t line() const noexcept;
|
||||
@ -44,5 +44,5 @@ namespace elna
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using result = boost::outcome_v2::result<T, CompileError>;
|
||||
using result = boost::outcome_v2::result<T, compile_error>;
|
||||
}
|
||||
|
@ -38,30 +38,28 @@ namespace elna
|
||||
num_lock = 0b10000000, ///< 128
|
||||
};
|
||||
|
||||
class key
|
||||
struct key
|
||||
{
|
||||
std::variant<special_key, unsigned char> store;
|
||||
std::uint8_t modifiers;
|
||||
using char_t = std::uint32_t;
|
||||
|
||||
public:
|
||||
key();
|
||||
explicit key(const unsigned char c, const std::uint8_t modifiers = 0);
|
||||
explicit key(const unsigned char c, const modifier modifiers);
|
||||
explicit key(const char_t c, const std::uint8_t modifiers = 0);
|
||||
explicit key(const char_t c, const modifier modifiers);
|
||||
explicit key(const special_key control, const std::uint8_t modifiers = 0);
|
||||
explicit key(const special_key control, const modifier modifiers);
|
||||
|
||||
bool operator==(const unsigned char c) const;
|
||||
friend bool operator==(const unsigned char c, const key& that);
|
||||
bool operator==(const char_t c) const;
|
||||
friend bool operator==(const char_t c, const key& that);
|
||||
bool operator==(const special_key control) const;
|
||||
friend bool operator==(const special_key control, const key& that);
|
||||
bool operator==(const key& that) const;
|
||||
bool operator!=(const unsigned char c) const;
|
||||
friend bool operator!=(const unsigned char c, const key& that);
|
||||
bool operator!=(const char_t c) const;
|
||||
friend bool operator!=(const char_t c, const key& that);
|
||||
bool operator!=(const special_key control) const;
|
||||
friend bool operator!=(const special_key control, const key& that);
|
||||
bool operator!=(const key& that) const;
|
||||
|
||||
unsigned char character() const;
|
||||
char_t character() const;
|
||||
special_key control() const;
|
||||
bool modified(const std::uint8_t modifiers) const noexcept;
|
||||
bool modified(const modifier modifiers) const noexcept;
|
||||
@ -69,6 +67,10 @@ namespace elna
|
||||
bool is_character() const noexcept;
|
||||
bool is_control() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
private:
|
||||
std::variant<special_key, char_t> store;
|
||||
std::uint8_t modifiers;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -143,12 +145,20 @@ namespace elna
|
||||
*/
|
||||
std::size_t absolute_position() const noexcept;
|
||||
|
||||
/**
|
||||
* Cursor position relative to the start of the user input.
|
||||
*
|
||||
* \returns Cursor position.
|
||||
*/
|
||||
std::size_t relative_position() const noexcept;
|
||||
|
||||
/**
|
||||
* Inserts text at cursor position.
|
||||
*
|
||||
* \param text Text to insert.
|
||||
*/
|
||||
void insert(const std::string& text);
|
||||
void insert(const key::char_t text);
|
||||
|
||||
/**
|
||||
* Replaces the user input with the given string.
|
||||
|
Reference in New Issue
Block a user