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

@@ -10,7 +10,7 @@
#include "show.h"
#include "file.h"
std::string unescape_newlines(std::string s)
std::string unescape_newlines(const std::string& s)
{
return string_replace(s, " ___NL___ ", "\n");
@@ -44,7 +44,7 @@ std::string insert_missing_ids(std::smatch match)
return result;
}
std::string insert_ids(std::string html_text)
std::string insert_ids(const std::string& html_text)
{
(void)K::log(3);
std::string result = html_text;
@@ -154,7 +154,7 @@ std::string Document_class::font_definitions()
return ss.str();
}
void Document_class::write_basenames_js_file(std::string filename, std::vector<std::string> basenames)
void Document_class::write_basenames_js_file(const std::string& filename, const std::vector<std::string>& basenames)
{
(void)K::log(3);
std::string tab(" ");
@@ -202,7 +202,7 @@ std::string Document_class::create_html_output_directories()
return output_directory;
}
strings_t get_css_files(strings_t custom_css_files)
strings_t get_css_files(const strings_t& custom_css_files)
{
(void)K::log(3);
strings_t result = sks_files_of_type("css");
@@ -223,7 +223,7 @@ std::vector<std::string> js_basenames(bool nav)
strings_t Document_class::get_js_files(
bool nav, bool include_sks_js,
std::string pages_basenames_filename)
const std::string& pages_basenames_filename)
{
(void)K::log(3);
strings_t result {};
@@ -244,13 +244,13 @@ strings_t Document_class::get_js_files(
}
strings_t link_filenames(strings_t& full_filenames, std::string page_dir)
strings_t link_filenames(strings_t& full_filenames, const std::string& page_dir)
{
strings_t result {};
fs::path page_dir_path(page_dir);
// int i = 0;
std::transform(full_filenames.begin(), full_filenames.end(), std::back_inserter(result),
[&](std::string f) {
[&](const std::string& f) {
fs::path full(f);
//msg() << i << full << " " << full.filename() << "\n";
fs::path path(page_dir_path / full.filename());
@@ -260,8 +260,8 @@ strings_t link_filenames(strings_t& full_filenames, std::string page_dir)
}
std::pair<std::vector<std::string>, std::vector<std::string>>
Document_class::html_auxiliary_files(std::string output_directory, std::string pages_basenames_filename,
std::vector<std::string> custom_css_files)
Document_class::html_auxiliary_files(const std::string& output_directory, const std::string& pages_basenames_filename,
const std::vector<std::string>& custom_css_files)
{
(void)K::log(3);
strings_t all_css_files = custom_css_files;
@@ -352,7 +352,7 @@ std::string increment_level(int level, std::vector<int> &levels)
}
std::string extract_id(std::string attr)
std::string extract_id(const std::string& attr)
{
std::smatch match {};
if (!std::regex_match(attr, match, id_attr_rgx)) {
@@ -362,7 +362,7 @@ std::string extract_id(std::string attr)
}
std::vector<Heading>
Document_class::insert_section_numbers(std::string marker, bool add_to_toc)
Document_class::insert_section_numbers(const std::string& marker, bool add_to_toc)
{
std::vector<int> levels(9, 0);
std::smatch match {};
@@ -407,7 +407,7 @@ Document_class::insert_section_numbers(std::string marker, bool add_to_toc)
return headings;
}
int get_caption_number(std::map<std::string, int>& numbers, std::string label)
int get_caption_number(std::map<std::string, int>& numbers, const std::string& label)
{
int result;
if (numbers.count(label) == 0) {
@@ -470,7 +470,7 @@ void Document_class::insert_html_caption_numbers()
std::vector<std::tuple<std::string, std::string, std::string>>
Document_class::reference_list(std::string target_marker)
Document_class::reference_list(const std::string& target_marker)
{
std::regex reference_rgx("__REF__");
std::regex target_rgx("<div id=\"(.*?)\" data-label=\"(.*?)\" class=\"caption_");
@@ -519,7 +519,7 @@ std::map<std::string, std::string> Document_class::id_to_caption_number()
}
std::pair<int, int> offset_spec_to_count(std::string spec)
std::pair<int, int> offset_spec_to_count(const std::string& spec)
{
std::regex rgx(R"((\w+)\s*(\d*))");
std::smatch match {};
@@ -637,7 +637,7 @@ std::string Document_class::single_page_toc()
}
elements_t Document_class::page(std::string body_text, std::string output_dir, int max_level)
elements_t Document_class::page(const std::string& body_text, const std::string& output_dir, int max_level)
{
(void)K::log(3);
std::string toc {}; // Calculate
@@ -674,7 +674,7 @@ elements_t Document_class::page(std::string body_text, std::string output_dir, i
return page;
}
std::string Document_class::make_single_html_page(std::string output_directory)
std::string Document_class::make_single_html_page(const std::string& output_directory)
{
(void)K::log(3);
std::stringstream ss {};;
@@ -694,7 +694,7 @@ std::string Document_class::make_single_html_page(std::string output_directory)
}
std::string Document_class::make_html_navigation_structure(
std::string output_directory, std::vector<Heading> headings)
const std::string& output_directory, std::vector<Heading> headings)
{
msg() << "Navigation format\n";
std::vector<std::string> pages_basenames {};