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

@@ -461,12 +461,12 @@ std::ostream& operator<<(std::ostream& os, const Klammer::components& kc)
}
// Klammer_set
// Klammer_registry
std::ostream& operator<<(std::ostream& os, const Klammer_set& ks)
std::ostream& operator<<(std::ostream& os, const Klammer_registry& ks)
{
for (auto klam : ks.m_klammers) {
for (auto [k,v] : klam.second.m_defloc) {
for (const auto& klam : ks.m_klammers) {
for (const auto& [k,v] : klam.second.m_defloc) {
os << " " << k << sp_arrow << v << "\n";
}
//klam.second.m_defloc.str() << "\n";
@@ -485,30 +485,62 @@ void show_arrow_pair(std::ostream& os, std::pair<std::string,std::string> transf
std::ostream& operator<<(std::ostream& os, const Target& t)
{
os << "<\U0001D517" << broken_bar << t.m_name << broken_bar << t.m_desc << broken_bar;
for (auto i : t.m_includes) {
for (const auto& i : t.m_includes) {
os << i << right_arrow << t.m_name << broken_bar;
}
for (auto p : t.m_provides) {
for (const auto& p : t.m_provides) {
os << t.m_name << right_arrow << p << broken_bar;
}
os << ">";
return os;
}
// Target_set
// Target_registry
std::ostream& operator<<(std::ostream& os, const Target_set& ts)
std::ostream& operator<<(std::ostream& os, const Target_registry& ts)
{
size_t width = 0;
for (auto t : ts.m_targets) {
for (const auto& t : ts.m_targets) {
width = std::max(width, t.first.size());
}
for (auto [name, target] : ts.m_targets) {
for (const auto& [name, target] : ts.m_targets) {
os << std::setw(width) << name << sp_arrow << target << "\n";
}
return os;
}
// Klammerset
std::ostream& operator<<(std::ostream& os, const Klammerset& ks)
{
os << "<\U0001D516" << broken_bar << ks.m_symbol << broken_bar << ks.m_desc;
if (!ks.m_date.empty()) {
os << broken_bar << ks.m_date;
}
if (!ks.m_requires.empty()) {
os << broken_bar << "requires " << join(ks.m_requires, " / ");
}
if (!ks.m_files.empty()) {
os << broken_bar << join(ks.m_files, " / ");
}
os << ">";
return os;
}
// Klammerset_registry
std::ostream& operator<<(std::ostream& os, const Klammerset_registry& kr)
{
size_t width = 0;
for (const auto& k : kr.m_klammersets) {
width = std::max(width, k.first.size());
}
for (const auto& [symbol, klammerset] : kr.m_klammersets) {
os << std::setw(width) << symbol << sp_arrow << klammerset << "\n";
}
return os;
}
// Machine
@@ -537,6 +569,7 @@ std::ostream& operator<<(std::ostream& os, const Machine& m)
std::string argtypes_desc = m.m_argtypes.describe(false, 8);
std::string state_desc = m.m_state.describe(false, 3);
std::string targets_desc = m.m_targets.describe(4);
std::string klammersets_desc = m.m_klammersets.describe(4);
std::string klammer_desc = m.m_klammers.describe(2);
std::string source_desc = describe_sources(m);
@@ -544,12 +577,13 @@ std::ostream& operator<<(std::ostream& os, const Machine& m)
<< label("Sources", m.m_sources.size()) << source_desc << "\n"
<< label("Argtypes", m.m_argtypes.m_names.size()) << argtypes_desc << "\n"
<< label("Targets", m.m_targets.m_names.size()) << targets_desc << "\n"
<< label("Klammersets", m.m_klammersets.m_symbols.size()) << klammersets_desc << "\n"
<< label("Klammers", m.m_klammers.m_klammers.size()) << klammer_desc << "\n"
<< label("State", m.m_state.m_frames.size()) << state_desc;
<< label("State", m.m_state.m_frames.size()) << state_desc;
return os;
}
void modify_stream(std::string name)
void modify_stream(const std::string& name)
{
if (name == "all") std::cout << kall;
if (name == "type") std::cout << ktype;