Go to the documentation of this file.
4 #ifndef LEXY_EXT_SHELL_HPP_INCLUDED
5 #define LEXY_EXT_SHELL_HPP_INCLUDED
24 void primary_prompt();
27 void continuation_prompt();
35 struct read_line_callback
50 return read_line_callback{...};
53 struct write_message_callback
64 auto write_message(Args&&... config_args)
66 return write_message_callback{...};
72 template <
typename Encoding = lexy::default_encoding>
77 static_assert(
sizeof(
char_type) ==
sizeof(
char),
"only support single-byte encodings");
81 std::fputs(
"> ", stdout);
86 std::fputs(
". ", stdout);
92 std::fputs(
"\n", stdout);
97 return std::feof(stdin) == 0 && std::ferror(stdin) == 0;
106 auto memory =
reinterpret_cast<char*
>(
buffer);
107 if (
auto str = std::fgets(memory,
int(
size), stdin))
108 return std::strlen(str);
117 return read_line_callback{};
126 std::fprintf(stdout,
"%.*s",
int(
size),
reinterpret_cast<const char*
>(
buffer));
139 return write_message_callback{};
147 template <
typename Prompt = default_prompt<>>
210 _idx = m._it.index();
271 typename Prompt::write_message_callback*
_writer;
273 iterator& operator*() noexcept
277 iterator& operator++(
int) noexcept
301 auto length = std::size_t(0);
302 for (
auto ptr = str; *ptr; ++ptr)
313 template <
typename CharT,
314 typename = std::enable_if_t<encoding::template is_secondary_char_type<CharT>()>>
319 template <
typename CharT,
320 typename = std::enable_if_t<encoding::template is_secondary_char_type<CharT>()>>
325 template <
typename CharT,
326 typename = std::enable_if_t<encoding::template is_secondary_char_type<CharT>()>>
335 auto data = &*
lexeme.begin();
352 template <
typename... Args>
372 constexpr
auto min_capacity = 128;
376 for (
auto reader =
_prompt.read_line();
true;)
391 else if (read < buffer_size)
411 template <
typename Prompt = default_prompt<>>
414 template <
typename Tag,
typename Prompt = default_prompt<>>
417 template <
typename Prompt = default_prompt<>>
421 #endif // LEXY_EXT_SHELL_HPP_INCLUDED
constexpr auto size(const C &c) -> decltype(c.size())
void operator()(const char_type *buffer, std::size_t size)
string_view::value_type char_type
Reads input from an interactive shell.
const T * read_data() const noexcept
Prompt using stdin and stdout.
std::size_t operator()(char_type *buffer, std::size_t size)
typename encoding::char_type char_type
typename lexy::default_encoding ::char_type char_type
T * write_data() noexcept
LEXY_EMPTY_MEMBER Prompt::write_message_callback _writer
Contains information about the context of an error, production is type-erased.
writer & operator()(const char_type *str)
#define LEXY_PRECONDITION(Expr)
void primary_prompt() noexcept
auto write_message(Args &&... args)
void eof_prompt() noexcept
writer(const writer &)=delete
typename Prompt::encoding encoding
writer & operator()(lexy::lexeme_for< input > lexeme)
writer & operator()(CharT c)
buffer(const CharT *, const CharT *) -> buffer< deduce_encoding< CharT >>
writer & operator()(const CharT *str, std::size_t length)
bool is_open() const noexcept
Whether or not the shell is still open.
An encoding where the input is some 8bit encoding (ASCII, UTF-8, extended ASCII etc....
std::size_t read_size() const noexcept
writer(typename Prompt::write_message_callback &&writer)
writer & operator()(char_type c)
lexy::_detail::buffer_builder< char_type > _buffer
LEXY_EMPTY_MEMBER Prompt _prompt
void commit(std::size_t n) noexcept
bool is_open() const noexcept
lexeme(const Reader &, typename Reader::iterator) -> lexeme< typename Reader::canonical_reader >
const Prompt & get_prompt() const noexcept
writer & operator()(const char_type *str, std::size_t length)
#define LEXY_EMPTY_MEMBER
writer & operator()(const CharT *str)
std::size_t write_size() const noexcept
void continuation_prompt() noexcept
constexpr auto eof
Matches EOF.
#define LEXY_ASSERT(Expr, Msg)
Prompt & get_prompt() noexcept
writer & operator=(const writer &)=delete