Klammerset: the @@@klammerset construct, its search path, and const correctness

The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).

(from dev 64b1abf23e56)
This commit is contained in:
2026-07-30 23:50:07 +02:00
parent c42981f7e2
commit ef77f03584
83 changed files with 1429 additions and 594 deletions

View File

@@ -7,32 +7,32 @@
//#include "text.h"
#include "util.h"
void Target::add_transform(std::string original, std::string transformed)
void Target::add_transform(const std::string& original, const std::string& transformed)
{
m_transforms.push_back({original, transformed});
}
void Target::add_transforms(std::string transforms)
void Target::add_transforms(const std::string& transforms)
{
add_transforms(parse_transforms(transforms));
}
void Target::add_transforms(string_pairs transforms)
void Target::add_transforms(const string_pairs& transforms)
{
for (auto [old_str, new_str] : transforms) {
for (const auto& [old_str, new_str] : transforms) {
add_transform(old_str, new_str);
}
}
void Target::transform(katom_list& katoms)
void Target::transform(katom_list& katoms) const
{
(void)K::log(3);
std::for_each(
katoms.begin(), katoms.end(),
[this] (Katom& k) {
katoms.begin(), katoms.end(),
[this] (Katom& k) {
// std::cout << "transform: " << k << "\n";
if (k.m_type != katom_t::literal) {
for (auto [a, b] : this->m_transforms) {
for (const auto& [a, b] : this->m_transforms) {
// std::cout << " " << a << right_arrow << b << "\n";
k.m_text = string_replace(k.m_text, a, b);
}
@@ -41,7 +41,7 @@ void Target::transform(katom_list& katoms)
}
std::vector<std::pair<std::string, std::string>>
parse_transforms(std::string transform_string)
parse_transforms(const std::string& transform_string)
{
(void)K::log(3);
if (trim(transform_string).empty()) return {};
@@ -59,7 +59,7 @@ parse_transforms(std::string transform_string)
return result;
}
void Target::add_escapes(std::string escape_spec)
void Target::add_escapes(const std::string& escape_spec)
{
auto words = word_split(escape_spec);
for (size_t i = 0; i + 1 < words.size(); i += 2) {
@@ -142,9 +142,9 @@ std::string hide_structural_characters(const std::string& s)
return result;
}
void Target::add_after_apply(std::string function_specs)
void Target::add_after_apply(const std::string& function_specs)
{
for (auto f : regex_split(function_specs, std::regex(R"(\s+;\s+)"), true)) {
for (const auto& f : regex_split(function_specs, std::regex(R"(\s+;\s+)"), true)) {
// msg() << "Add " << m_name << " after-apply: " << f << "\n";
m_after_apply.push_back(f);
}