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

@@ -132,7 +132,7 @@ std::string to_string(elements_t e)
bool HTML::void_element(std::string tag) const
bool HTML::void_element(const std::string& tag) const
{
if (tag == "!DOCTYPE")
return true;
@@ -141,7 +141,7 @@ bool HTML::void_element(std::string tag) const
(m_void_tags.begin(), m_void_tags.end(), tag) != m_void_tags.end();
}
bool HTML::empty_element(std::string tag) const
bool HTML::empty_element(const std::string& tag) const
{
if (tag == preamble_tag)
return true;
@@ -151,13 +151,13 @@ bool HTML::empty_element(std::string tag) const
}
//HTML& HTML::attr(std::string name, std::variant<int, float, std::string> value)
HTML& HTML::attr(std::string name, attr_t value)
HTML& HTML::attr(const std::string& name, attr_t value)
{
m_attrs.push_back({name, value});
return *this;
}
HTML& HTML::attrs(std::string s)
HTML& HTML::attrs(const std::string& s)
{
static const std::regex attr_rgx(R"((\w+)\s*=\s*\"(.*?)\")");
auto attrs_begin = std::sregex_iterator(s.begin(), s.end(), attr_rgx);
@@ -177,25 +177,25 @@ HTML& HTML::attrs(std::string s)
namespace html {
HTML elt(std::string tag)
HTML elt(const std::string& tag)
{
HTML h(tag);
return h;
}
HTML elt(std::string tag, std::string text)
HTML elt(const std::string& tag, const std::string& text)
{
HTML h(tag, trim(text));
return h;
}
HTML elt(std::string tag, elements_t elements)
HTML elt(const std::string& tag, elements_t elements)
{
HTML h(tag, elements);
return h;
}
HTML elt(std::string tag, HTML e, elements_t elts)
HTML elt(const std::string& tag, HTML e, elements_t elts)
{
elements_t elements = {e};
elements.insert(elements.end(), elts.begin(), elts.end());
@@ -242,7 +242,7 @@ namespace html {
return result;
}
elements_t local_font_elements(strings_t fontnames)
elements_t local_font_elements(const strings_t& fontnames)
{
elements_t result {};
for (auto name : fontnames) {
@@ -254,7 +254,7 @@ namespace html {
return result;
}
elements_t javascript(std::string output_dir, strings_t js_filenames)
elements_t javascript(const std::string& output_dir, const strings_t& js_filenames)
{
//elements_t result { jquery_elements() };
elements_t result {};
@@ -276,10 +276,10 @@ namespace html {
return result;
}
HTML head(std::string title,
std::string css,
strings_t css_filenames,
strings_t local_fonts)
HTML head(const std::string& title,
const std::string& css,
const strings_t& css_filenames,
const strings_t& local_fonts)
{
elements_t elts = meta_elements();
// msg() << "ELTS sks: " << elts << "\n";
@@ -317,8 +317,8 @@ namespace html {
}
HTML button(std::string id, std::string name,
std::string attrib="", std::string value="")
HTML button(const std::string& id, const std::string& name,
const std::string& attrib="", const std::string& value="")
{
std::vector<std::string> hidden = {"Clear", "Back"};
HTML result = elt("span", string_replace(name, " ", "&#160;")).id(id).cls("navb");
@@ -449,7 +449,7 @@ namespace html {
return result;
}
elements_t status(std::string date, std::string version, std::string copyright)
elements_t status(const std::string& date, const std::string& version, const std::string& copyright)
{
elements_t result {};
if (!date.empty()) {
@@ -465,21 +465,21 @@ namespace html {
}
elements_t page(
std::string title,
const std::string& title,
std::string page_title,
std::string output_dir,
std::string nav,
const std::string& output_dir,
const std::string& nav,
int max_level,
std::string toc,
std::string text,
std::string date,
std::string version,
std::string copyright,
std::string css,
strings_t css_filenames,
strings_t js_filenames,
strings_t local_fonts,
std::string logo)
const std::string& toc,
const std::string& text,
const std::string& date,
const std::string& version,
const std::string& copyright,
const std::string& css,
const strings_t& css_filenames,
const strings_t& js_filenames,
const strings_t& local_fonts,
const std::string& logo)
{
if (page_title.empty())
page_title = title;
@@ -540,7 +540,7 @@ namespace html {
}
void add_title(elements_t& body, std::string title, std::string logo)
void add_title(elements_t& body, const std::string& title, const std::string& logo)
{
// No title bar at all when there is nothing to put in it (an
// untitled document); a logo alone still gets the bar.
@@ -561,7 +561,7 @@ namespace html {
body.push_back(navigation(max_level));
}
void add_text(elements_t& body, std::string text, std::string toc, bool text_only)
void add_text(elements_t& body, const std::string& text, const std::string& toc, bool text_only)
{
if (text_only) {
elements_t content {};
@@ -580,7 +580,7 @@ namespace html {
}
void add_status_bar(
elements_t& body, std::string date, std::string version, std::string copyright)
elements_t& body, const std::string& date, const std::string& version, const std::string& copyright)
{
elements_t status_elements = status(date, version, copyright);
if (!empty(status_elements)) {
@@ -593,7 +593,7 @@ namespace html {
body.push_back(elt("div", "").attr("id", "pagecache"));
}
void add_js_links(elements_t& body, strings_t js_filenames, std::string output_dir)
void add_js_links(elements_t& body, const strings_t& js_filenames, const std::string& output_dir)
{
if (!js_filenames.empty()) {
auto js_elements { javascript(output_dir, js_filenames) };
@@ -603,8 +603,8 @@ namespace html {
elements_t make_page(
elements_t body,
std::string page_title, std::string css,
strings_t css_filenames, strings_t local_fonts)
std::string page_title, const std::string& css,
const strings_t& css_filenames, const strings_t& local_fonts)
{
elements_t page { preamble() };
page.push_back(
@@ -615,7 +615,7 @@ namespace html {
return page;
}
bool tag_is_block_element(std::string tag)
bool tag_is_block_element(const std::string& tag)
{
auto location = std::find(block_elements.begin(), block_elements.end(), tag);
return location != block_elements.end();
@@ -635,7 +635,7 @@ namespace html {
return result;
}
std::string make_paragraphs(std::string html_text)
std::string make_paragraphs(const std::string& html_text)
{
(void)K::log(3);
std::string result {};
@@ -654,7 +654,7 @@ namespace html {
return result;
}
std::string minimize_css(std::string src)
std::string minimize_css(const std::string& src)
{
(void)K::log(3);
std::string result = src;
@@ -668,7 +668,7 @@ namespace html {
return result;
}
std::string minimize_js(std::string src)
std::string minimize_js(const std::string& src)
{
(void)K::log(3);
return src;