lib/utils: build s-expression programmatically building

Allow for programmatically buildings sexps, rather that using raw
strings.
This commit is contained in:
Dirk-Jan C. Binnema
2020-06-01 19:01:03 +03:00
parent b672f6bc1d
commit 3afdc08d50
11 changed files with 507 additions and 270 deletions

View File

@ -1131,9 +1131,11 @@ make_command_map (Context& context)
{
CommandMap cmap;
using Type = Node::Type;
cmap.emplace("add",
CommandInfo{
ArgMap{ {"path", ArgInfo{Type::String, true, "file system path to the message" }}},
ArgMap{ {"path", ArgInfo{Type::String, true, "file system path to the message" }}},
"add a message to the store",
[&](const auto& params){add_handler(context, params);}});
@ -1277,7 +1279,7 @@ mu_cmd_server (MuConfig *opts, GError **err) try
if (opts->commands) {
Context ctx{};
auto cmap = make_command_map(ctx);
invoke(cmap, Sexp::parse("(help :full t)"));
invoke(cmap, Sexp::Node::make("(help :full t)"));
return MU_OK;
}
@ -1285,7 +1287,7 @@ mu_cmd_server (MuConfig *opts, GError **err) try
context.command_map = make_command_map (context);
if (opts->eval) { // evaluate command-line command & exit
auto call{Sexp::parse(opts->eval)};
auto call{Sexp::Node::make(opts->eval)};
invoke(context.command_map, call);
return MU_OK;
}
@ -1306,8 +1308,7 @@ mu_cmd_server (MuConfig *opts, GError **err) try
if (line.find_first_not_of(" \t") == std::string::npos)
continue; // skip whitespace-only lines
auto call{Sexp::parse(line)};
auto call{Sexp::Node::make(line)};
invoke(context.command_map, call);
} catch (const Error& er) {