9#include "json_helpers.h"
18 template <
char open = '[',
char close = ']',
typename FUNC>
21 static_assert(std::invocable<FUNC, std::string_view> && std::constructible_from<std::string, std::invoke_result_t<FUNC, std::string_view>>,
"function must take a stringable and return a string");
26 if (str.empty())
break;
42 template <
char open = '[',
char close = ']',
typename FUNC>
45 static_assert(std::invocable<FUNC, std::string_view> && std::constructible_from<std::string, std::invoke_result_t<FUNC, std::string_view>>,
"function must take a stringable and return a string");
50 if (str.empty())
break;
57 while (!str.empty() && (str[0] != close || opened))
59 if (str[0] == close && opened)
61 else if (str[0] == open)
65 key = { key.data(), str.data() };
75 template <
bool SYNTAX>
82 if (str.empty())
break;
90 value call_result = env.eval(call);
93 using nlohmann::to_string;
94 using ghassanpl::string_ops::to_string;
95 if constexpr (
requires { {
to_string(val) }; })
auto visit(nlohmann::json const &j, VISIT_FUNC &&func)
Calls func with the actual value inside j; similar to std::visit.
auto consume_list(std::string_view &sexp_str, std::array< char, 2 > braces={ '[', ']' }) -> nlohmann::json
Consumes space-delimited elements until close-brace or end-of-string.
std::string interpolate_recursive(std::string_view str, FUNC &&func)
Like interpolate_simple except [group]s can be recursive, that is, can contain other groups that will...
std::string interpolate_simple(std::string_view str, FUNC &&func)
The simplest string interpolation function; calls func for every [group] in str.
std::string interpolate_eval(std::string_view str, eval::environment< SYNTAX > &env)
Interpolation using the eval module functionality.
std::string_view consume_until(std::string_view &str, FUNC &&pred)
Consumes characters from the beginning of str until one matches pred(str[0]), exclusive.
std::string_view consume_until_delim_ex(std::string_view &str, char c)
Consumes characters from the beginning of str until one is equal to c, consuming c but not including ...
char consume(std::string_view &str)
Consumes and returns the first character in the str, or \0 if no more characters.
std::string to_string(T floating_point)
float overload
Primary namespace for everything in this library.
The primary class to store the evaluation environment, declared functions, variables,...
Represents a single evaluated value; can store an rvalue (as json), an lvalue (json*),...