Add define parameters and support aliases and definitions in action files

This commit is contained in:
cantyonion committed 2026-11-24 13:45:18 +08:00
1 parent fb8ef636bd
commit 0a6193f68e
12 files changed
+291 -63

No files matched your search

+18 -1
View File
@@ -277,6 +277,8 @@ ActionCommand ParseCommand(std::string_view verb, std::string_view line, const s
struct Loader
{
CommandBindings bindings;
std::size_t expandedBytes = 0;
ActionProgram program;
std::vector<std::filesystem::path> active;
std::size_t loads = 0;
@@ -363,6 +365,20 @@ struct Loader
continue;
if (!header_seen)
Fail(source, line_number, "missing action header before first instruction");
std::string expanded;
try
{
expanded = bindings.Expand(line, kMaxFileBytes);
}
catch (const std::runtime_error &error)
{
Fail(source, line_number, error.what());
}
if (expanded.empty()) continue;
expandedBytes += expanded.size();
if (expandedBytes > kMaxTotalBytes)
Fail(source, line_number, "total expanded action text exceeds 16 MiB");
line = expanded;
const auto verb = TakeToken(line);
if (verb == "import")
{
@@ -396,11 +412,12 @@ struct Loader
};
} // namespace
ActionProgram LoadActionFile(const std::filesystem::path &path)
ActionProgram LoadActionFile(const std::filesystem::path &path, CommandBindings bindings)
{
if (path.extension() != ".act")
Fail(path, 1, "action file must have the .act extension");
Loader loader;
loader.bindings = std::move(bindings);
loader.Load(path);
return std::move(loader.program);
}