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;

View File

@@ -32,24 +32,24 @@ public:
operator std::string() {
std::stringstream ss {}; ss << *this; return ss.str(); };
HTML(std::string tag) :
HTML(const std::string& tag) :
m_tag(tag) {};
HTML(std::string tag, std::string text) :
HTML(const std::string& tag, const std::string& text) :
m_tag(tag), m_text({text}) {};
HTML(std::string tag, elements_t elements) :
HTML(const std::string& tag, elements_t elements) :
m_tag(tag), m_elements(elements) {};
HTML& attr(std::string name, attr_t value);
HTML& attrs(std::string s);
HTML& attr(const std::string& name, attr_t value);
HTML& attrs(const std::string& s);
HTML& cls(std::string name) { return attr("class", name); };
HTML& sty(std::string css) { return attr("style", css); };
HTML& id(std::string id) { return attr("id", id); };
HTML& cls(const std::string& name) { return attr("class", name); };
HTML& sty(const std::string& css) { return attr("style", css); };
HTML& id(const std::string& id) { return attr("id", id); };
bool void_element(std::string tag) const;
bool empty_element(std::string tag) const;
bool void_element(const std::string& tag) const;
bool empty_element(const std::string& tag) const;
friend std::ostream& operator<<(std::ostream& os, const HTML& h);
friend std::ostream& operator<<(std::ostream& os, const std::vector<HTML>& hv);
@@ -68,48 +68,48 @@ private:
};
namespace html {
HTML elt(std::string tag);
HTML elt(std::string tag, std::string text);
HTML elt(std::string tag, elements_t elements);
HTML elt(std::string tag, HTML e, elements_t elts);
HTML elt(const std::string& tag);
HTML elt(const std::string& tag, const std::string& text);
HTML elt(const std::string& tag, elements_t elements);
HTML elt(const std::string& tag, HTML e, elements_t elts);
//HTML preamble();
//HTML head(strings_t css_filenames, strings_t js_filenames);
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,
const std::string& toc,
const std::string& text,
const std::string& date,
const std::string& version,
const std::string& copyright,
const std::string& css,
strings_t css_filenames = {},
strings_t js_filenames = {},
strings_t local_fonts = {},
std::string logo = {});
void add_title(elements_t& body, std::string title, std::string logo="");
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="");
void add_title(elements_t& body, const std::string& title, const std::string& logo);
void add_nav(elements_t& body, int max_level);
void add_text(elements_t& body, std::string text, std::string toc_text, bool text_only);
void add_text(elements_t& body, const std::string& text, const std::string& toc_text, bool text_only);
void add_bottom_spacer(elements_t& body);
void add_status_bar(elements_t& body, std::string date, std::string version, std::string copyright);
void add_status_bar(elements_t& body, const std::string& date, const std::string& version, const std::string& copyright);
void add_page_cache(elements_t& body);
void add_js_links(elements_t& body, std::vector<std::string> js_filenames, std::string output_dir);
void add_js_links(elements_t& body, const std::vector<std::string>& js_filenames, const std::string& output_dir);
elements_t make_page(
elements_t body,
std::string page_title, std::string css,
std::vector<std::string> css_filenames,
std::vector<std::string> local_fonts);
std::string page_title, const std::string& css,
const std::vector<std::string>& css_filenames,
const std::vector<std::string>& local_fonts);
bool tag_is_block_element(std::string tag);
std::string make_paragraphs(std::string html_text);
std::string minimize_css(std::string src);
std::string minimize_js(std::string src);
bool tag_is_block_element(const std::string& tag);
std::string make_paragraphs(const std::string& html_text);
std::string minimize_css(const std::string& src);
std::string minimize_js(const std::string& src);
}

View File

@@ -33,7 +33,7 @@ namespace latex {
std::string title_line(
std::string text, std::string font="1.3", std::string vskip="4pt",
const std::string& text, const std::string& font="1.3", const std::string& vskip="4pt",
bool vskip_if_missing=false)
{
std::stringstream ss {};
@@ -48,8 +48,8 @@ namespace latex {
}
std::string default_cover(
std::string title, std::string subtitle,
std::string author, std::string date, std::string version)
const std::string& title, const std::string& subtitle,
const std::string& author, const std::string& date, const std::string& version)
{
std::string test = trim(title + subtitle + author + date + version);
std::stringstream ss {};
@@ -65,8 +65,8 @@ namespace latex {
}
std::string nonbook_title(
std::string title, std::string subtitle,
std::string author, std::string date, std::string version)
const std::string& title, const std::string& subtitle,
const std::string& author, const std::string& date, const std::string& version)
{
std::string test = trim(title + subtitle + author + date + version);
std::stringstream ss {};
@@ -86,7 +86,7 @@ namespace latex {
return ss.str();
}
std::string pagenumber(int n, std::string style="arabic")
std::string pagenumber(int n, const std::string& style="arabic")
{
(void)K::log(3);
std::stringstream ss {};
@@ -94,7 +94,7 @@ namespace latex {
return ss.str();
}
std::string book_verso_page(std::string copyright)
std::string book_verso_page(const std::string& copyright)
{
(void)K::log(3);
std::stringstream ss {};
@@ -111,7 +111,7 @@ namespace latex {
return ss.str();
}
std::string font_command(std::string command, const Resolved_font& font, float scale)
std::string font_command(const std::string& command, const Resolved_font& font, float scale)
{
std::stringstream ss {};
if (font.family_name.empty())
@@ -150,23 +150,23 @@ namespace latex {
return ss.str();
}
std::string page(std::string structure,
std::string title,
std::string subtitle,
std::string authors,
std::string date,
std::string version,
std::string copyright,
std::string bottom,
std::string prolog,
std::string paper_size,
std::string page(const std::string& structure,
const std::string& title,
const std::string& subtitle,
const std::string& authors,
const std::string& date,
const std::string& version,
const std::string& copyright,
const std::string& bottom,
const std::string& prolog,
const std::string& paper_size,
bool two_column,
float leading,
int pointsize,
bool ragged_right,
std::string cover,
const std::string& cover,
bool landscape,
std::string body,
const std::string& body,
Resolved_font serif_font,
Resolved_font sans_font,
Resolved_font mono_font,

View File

@@ -6,23 +6,23 @@
namespace latex {
std::string page(std::string structure,
std::string title,
std::string subtitle,
std::string authors,
std::string date,
std::string version,
std::string copyright,
std::string bottom,
std::string prolog,
std::string paper_size,
std::string page(const std::string& structure,
const std::string& title,
const std::string& subtitle,
const std::string& authors,
const std::string& date,
const std::string& version,
const std::string& copyright,
const std::string& bottom,
const std::string& prolog,
const std::string& paper_size,
bool two_column,
float leading,
int pointsize,
bool ragged_right,
std::string cover,
const std::string& cover,
bool landscape,
std::string body,
const std::string& body,
Resolved_font serif_font = {},
Resolved_font sans_font = {},
Resolved_font mono_font = {},

View File

@@ -3,7 +3,7 @@ The targets in the SKS use the LaTeX convention for converting ASCII
characters into standard typographical characters. This is done
by LaTeX by default; other targets must use the transforms parameter
of Parameter_set, as defined for the m_parameters variable of the
Target_set class. (See file target_set.cpp.)
Target_registry class. (See file target_registry.cpp.)
The LaTeX transformations supported by the SKS are: