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

@@ -11,7 +11,7 @@
#include "log.h"
#include "file.h"
bool strbool(std::string s, Locator loc)
bool strbool(const std::string& s, const Locator& loc)
{
std::vector<std::string> values = {"false", "False", "0", "true", "True", "1"};
if (is_not_in(s, values)) {
@@ -136,7 +136,7 @@ void Document_class::save_string_input_as_file()
}
fs::path parse_input_filename(std::string s, std::string input_dir)
fs::path parse_input_filename(const std::string& s, const std::string& input_dir)
{
fs::path p(s);
if (p.extension() != ".kt") {
@@ -160,13 +160,13 @@ fs::path parse_input_filename(std::string s, std::string input_dir)
return p;
}
void Document_class::write(std::string filename, std::string contents)
void Document_class::write(const std::string& filename, const std::string& contents)
{
write_file(filename, contents, write_files);
}
void write_file(std::string filename, std::string contents, bool write_p)
void write_file(const std::string& filename, const std::string& contents, bool write_p)
{
if (write_p) {
string_to_file(filename, contents);
@@ -177,14 +177,14 @@ void write_file(std::string filename, std::string contents, bool write_p)
/*
void output_msg(std::string msg)
void output_msg(const std::string& msg)
{
std::cout << red;
(void)K::log(1, msg);
std::cout << black;
}
void Document_class::create_directory(std::string directory)
void Document_class::create_directory(const std::string& directory)
{
if (write_files) {
fs::create_directories(directory);

View File

@@ -16,7 +16,7 @@ inline std::map<std::string, int> html_tags {
using string_pairs_t = std::vector<std::pair<std::string,std::string>>;
std::string unescape_newlines(std::string s);
std::string unescape_newlines(const std::string& s);
enum class docstruct_t {
plain,
@@ -24,7 +24,7 @@ enum class docstruct_t {
book
};
inline docstruct_t docstruct(std::string name)
inline docstruct_t docstruct(const std::string& name)
{
if (name == "plain") {
return docstruct_t::plain;
@@ -43,41 +43,41 @@ public:
void save_string_input_as_file();
//void create_directory(std::string directory);
void write(std::string filename, std::string contents);
void write(const std::string& filename, const std::string& contents);
/*
strings_t get_css_files(
std::string output_dir,
std::string css_text, strings_t css_files, bool write_file);
const std::string& output_dir,
const std::string& css_text, const strings_t& css_files, bool write_file);
*/
strings_t get_js_files(
bool nav, bool include_sks_js,
std::string pages_basenames_filename); // , std::string output_dir, bool write_file);
const std::string& pages_basenames_filename); // , const std::string& output_dir, bool write_file);
argmap m_args {};
void write_basenames_js_file(std::string filename, std::vector<std::string> basenames);
void write_basenames_js_file(const std::string& filename, const std::vector<std::string>& basenames);
std::string create_html_output_directories();
std::string create_tex_output_directories();
std::pair<std::vector<std::string>, std::vector<std::string>>
html_auxiliary_files(std::string output_directory, std::string pages_basename_filename,
std::vector<std::string> custom_css_files);
html_auxiliary_files(const std::string& output_directory, const std::string& pages_basename_filename,
const std::vector<std::string>& custom_css_files);
void process_input_files();
std::vector<Heading> insert_section_numbers(std::string marker="___NUM___", bool add_to_toc=true);
std::vector<Heading> insert_section_numbers(const std::string& marker="___NUM___", bool add_to_toc=true);
void insert_html_caption_numbers();
std::vector<std::tuple<std::string, std::string, std::string>> reference_list(std::string target_marker);
std::vector<std::tuple<std::string, std::string, std::string>> reference_list(const std::string& target_marker);
std::map<std::string, std::string> id_to_caption_number();
std::map<std::string, std::vector<std::pair<std::string, std::string>>> html_references();
void resolve_html_references();
std::string single_page_toc();
elements_t page(std::string body, std::string output_dir, int max_level);
elements_t page(const std::string& body, const std::string& output_dir, int max_level);
std::string make_single_html_page(std::string output_directory);
std::string make_single_html_page(const std::string& output_directory);
std::string make_html_navigation_structure(
std::string output_directory, std::vector<Heading> headings);
const std::string& output_directory, std::vector<Heading> headings);
std::string html();
std::string tex();
std::string make_help_page();
@@ -167,13 +167,13 @@ public:
std::string m_cache_dir {};
};
fs::path parse_input_filename(std::string s, std::string input_dir);
void write_file(std::string filename, std::string contents, bool write_files);
fs::path parse_input_filename(const std::string& s, const std::string& input_dir);
void write_file(const std::string& filename, const std::string& contents, bool write_files);
/*
std::vector<std::string> combine_files(
std::vector<std::string> filenames, std::string output_filename,
std::string prolog="", std::string epilog="",
const std::vector<std::string>& filenames, const std::string& output_filename,
const std::string& prolog="", const std::string& epilog="",
bool write_file_p=true,
std::function <std::string(std::string)> processor=nullptr);
*/

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 {};

View File

@@ -40,7 +40,7 @@ int unnumbered_id = 0;
/*
std::tuple<std::string, std::vector<Heading>, std::vector<unsigned int>, unsigned int>
add_section_numbers(std::string s, std::string basename, std::vector<unsigned int> levels, unsigned int initial_id,
add_section_numbers(const std::string& s, const std::string& basename, std::vector<unsigned int> levels, unsigned int initial_id,
std::map<std::string, std::string>& section_id_map)
{
(void)K::log(3);
@@ -155,7 +155,7 @@ std::string make_html_table_of_contents(std::vector<Heading> headings)
}
std::string toc_link_attrs(
std::string section, std::string title, std::string filename, std::string target, int level)
const std::string& section, const std::string& title, const std::string& filename, const std::string& target, int level)
{
std::string basename = file_basename(filename);
std::stringstream ss {};
@@ -259,7 +259,7 @@ make_navigation_table_of_contents(std::vector<Heading> headings)
}
void show_table_of_contents(
std::string kt_root_filename, std::string title, std::vector<Heading> headings)
const std::string& kt_root_filename, const std::string& title, std::vector<Heading> headings)
{
long unsigned int width = kt_root_filename.size();
for (Heading h : headings) {
@@ -285,7 +285,7 @@ void show_table_of_contents(
}
std::string cache_table_of_contents(
std::string kt_root_filename, std::string title, std::vector<Heading> headings)
const std::string& kt_root_filename, const std::string& title, std::vector<Heading> headings)
{
long unsigned int width = kt_root_filename.size();
for (Heading h : headings) {

View File

@@ -8,8 +8,8 @@ const std::string link_delimiter { "%" };
class Heading {
public:
Heading(int level, std::string filename, std::string section, std::string id,
std::string number, std::string title)
Heading(int level, const std::string& filename, const std::string& section, const std::string& id,
const std::string& number, const std::string& title)
: m_level(level), m_filename(filename), m_section(section), m_id(id),
m_number(number), m_title(title)
{};
@@ -25,7 +25,7 @@ std::ostream& operator<<(std::ostream& os, const Heading h);
/*
std::tuple<std::string, std::vector<Heading>, std::vector<unsigned int>, unsigned int>
add_section_numbers(std::string s, std::string basename, std::vector<unsigned int> levels, unsigned int initial_id,
add_section_numbers(const std::string& s, const std::string& basename, std::vector<unsigned int> levels, unsigned int initial_id,
std::map<std::string, std::string>& section_id_map);
*/
@@ -35,7 +35,7 @@ std::pair<int, std::string>
make_navigation_table_of_contents(std::vector<Heading> headings);
void show_table_of_contents(
std::string kt_filename, std::string title, std::vector<Heading> headings);
const std::string& kt_filename, const std::string& title, std::vector<Heading> headings);
std::string cache_table_of_contents(
std::string kt_root_filename, std::string title, std::vector<Heading> headings);
const std::string& kt_root_filename, const std::string& title, std::vector<Heading> headings);

View File

@@ -29,7 +29,7 @@ std::ostream& operator<<(std::ostream& os, const numbered_elements& line_states)
return os;
}
std::string add_latex_caption_numbers(std::string latex_text)
std::string add_latex_caption_numbers(const std::string& latex_text)
{
std::string caption_delimiter { "__CAPTION__" }; // But also in kutil.py
std::regex caption_delimiter_rgx(caption_delimiter);
@@ -74,7 +74,7 @@ std::string add_latex_caption_numbers(std::string latex_text)
return result;
}
numbered_elements latex_line_states(std::vector<std::string> lines)
numbered_elements latex_line_states(const std::vector<std::string>& lines)
{
// \hypertarget{Reference-Figure-0}{}\label{Label-Reference-Figure-0}
std::regex element_container_rgx(BS + R"(hypertarget\{(Reference-(\w+)-\d+)\}.*)");
@@ -96,9 +96,9 @@ numbered_elements latex_line_states(std::vector<std::string> lines)
return states;
}
std::string find_target(std::string target,
std::vector<std::string>& lines, int start, numbered_elements states,
std::string target_type, int target_count, std::string direction)
std::string find_target(const std::string& target,
const std::vector<std::string>& lines, int start, const numbered_elements& states,
const std::string& target_type, int target_count, const std::string& direction)
{
// msg() << "find_target: " << target_type << " target_count: " << target_count
// << " direction: " << direction << "\n";
@@ -137,7 +137,7 @@ std::string find_target(std::string target,
}
std::string resolve_caption_references(
std::string target, std::vector<std::string> lines, numbered_elements states)
const std::string& target, const std::vector<std::string>& lines, numbered_elements states)
{
//auto lines = regex_split(text, std::regex(R"(\n)"), false);
// numbered_elements states = line_states(lines);

View File

@@ -11,12 +11,12 @@ using numbered_element_spec = std::tuple<std::string, std::string, std::string>;
//using numbered_elements = std::vector<std::vector<numbered_element_spec>>;
using numbered_elements = std::vector<numbered_element_spec>;
numbered_elements html_line_states(std::vector<std::string> lines);
numbered_elements latex_line_states(std::vector<std::string> lines);
numbered_elements html_line_states(const std::vector<std::string>& lines);
numbered_elements latex_line_states(const std::vector<std::string>& lines);
std::pair<std::string, int> add_html_caption_numbers(std::string html_text, int& chapter_number);
std::string add_latex_caption_numbers(std::string text);
std::pair<std::string, int> add_html_caption_numbers(const std::string& html_text, int& chapter_number);
std::string add_latex_caption_numbers(const std::string& text);
std::string resolve_caption_references(
std::string target, std::vector<std::string> lines, numbered_elements states);
const std::string& target, const std::vector<std::string>& lines, numbered_elements states);