2026-07-18 18:48:23 +02:00
|
|
|
#include <regex>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include "show.h"
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "error.h"
|
|
|
|
|
#include "state.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
int State::class_id = 0;
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
bool Var::defined() const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
return !m_name.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> Frame::names() const
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> result;
|
|
|
|
|
result.reserve(m_vars.size());
|
|
|
|
|
std::transform(m_vars.begin(), m_vars.end(), std::back_inserter(result),
|
|
|
|
|
[](const auto& pair) { return pair.first; });
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
void Frame::set(const std::string& name, const std::string& value,
|
|
|
|
|
const std::string& delim, const std::string& desc, const Locator& loc,
|
|
|
|
|
const Argtype& argtype)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
Var v(name, value, delim, desc, loc, argtype);
|
2026-07-18 18:48:23 +02:00
|
|
|
m_vars[name] = v;
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
std::pair<Var, bool> Frame::get(const std::string& name) const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
std::pair<Var, bool> result {Var(), false};
|
|
|
|
|
if (m_vars.contains(name)) {
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
result = {m_vars.at(name), true};
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
void State::open_frame(const std::string& name)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
Frame f(name);
|
|
|
|
|
// m_frames.push_back(f);
|
|
|
|
|
m_frames.emplace(m_frames.begin(), f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void State::close_frame()
|
|
|
|
|
{
|
|
|
|
|
if (m_frames.empty()) {
|
|
|
|
|
throw Internal_error("No frame to close", Locator());
|
|
|
|
|
}
|
|
|
|
|
// Preserve altered machine state:
|
|
|
|
|
string_map machine_state {};
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& [name, var] : m_frames[0].m_vars) {
|
2026-07-18 18:48:23 +02:00
|
|
|
if (contains(name, "K_")) {
|
|
|
|
|
machine_state[name] = var.m_value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_frames.erase(m_frames.begin());
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& [name, value] : machine_state) {
|
2026-07-18 18:48:23 +02:00
|
|
|
set(name, value, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
void State::set(const std::string& name, const std::string& value, bool update,
|
|
|
|
|
const std::string& delim, const std::string& desc, const Locator& loc,
|
|
|
|
|
const Argtype& argtype)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
if (m_frames.empty()) {
|
|
|
|
|
std::stringstream ss {};
|
|
|
|
|
ss << "No open frame to set " << q_(name) << " to " << q_(value);
|
|
|
|
|
throw Internal_error(ss.str(), Locator());
|
|
|
|
|
}
|
|
|
|
|
auto [current, exists] = m_frames[0].get(name);
|
|
|
|
|
|
|
|
|
|
if (exists && current.m_value != klammerstate::no_value && !update) {
|
|
|
|
|
std::stringstream ss {};
|
|
|
|
|
ss << "Variable " << q_(name) << " is already defined at " << current.m_loc.desc()
|
|
|
|
|
<< ". Use ':replace <new-value>' to replace the current value of "
|
|
|
|
|
<< q_(current.m_value) << ".";
|
|
|
|
|
throw Argument_error(ss.str(), current.m_loc);
|
|
|
|
|
}
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
m_frames[0].set(name, value, delim, desc, loc, argtype);
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
void State::set(const std::map<std::string, std::string>& varmap)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& [k, v] : varmap) {
|
2026-07-18 18:48:23 +02:00
|
|
|
set(k, v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
void State::set(const std::map<std::string, std::string>& varmap,
|
|
|
|
|
const Parameter_set& parameters)
|
|
|
|
|
{
|
|
|
|
|
for (const auto& [name, value] : varmap) {
|
|
|
|
|
const Parameter* parameter = parameters.find(name);
|
|
|
|
|
set(name, value, false, " ", "", Locator(),
|
|
|
|
|
parameter ? parameter->m_argtype : Argtype());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 18:48:23 +02:00
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
void State::replace(const std::string& name, const std::string& value, bool error_if_not_defined)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
if (error_if_not_defined && !get(name).defined()) {
|
|
|
|
|
std::stringstream ss {};
|
|
|
|
|
ss << "Cannot replace value of nonexistent variable " << q_(name) << " with " << q_(value);
|
|
|
|
|
throw Argument_error(ss.str(), Locator());
|
|
|
|
|
}
|
|
|
|
|
set(name, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void State::add_environment_frame()
|
|
|
|
|
{
|
|
|
|
|
open_frame(klammerstate::shell_environment_name);
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& [name, value] : environment_variables()) {
|
2026-07-18 18:48:23 +02:00
|
|
|
set(name, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
Var State::get(const std::string& name, bool error_if_not_defined, const Locator& loc) const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& f : m_frames) {
|
2026-07-18 18:48:23 +02:00
|
|
|
auto [result, found] = f.get(name);
|
|
|
|
|
if (found) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (error_if_not_defined) {
|
An output policy for the three commands, and @cond as a true special form
A snapshot of the development tree. The substantial changes since the last one:
COMMAND OUTPUT POLICY. The three commands display text in exactly three cases,
and each owns a stream: LOGGING under "-v" greater than 0 and an ERROR before
termination go to STDERR; OUTPUT THE USER ASKED FOR goes to STDOUT. For ktext
that output is a document, so "ktext doc.kt -d | ..." is now safe -- logging
used to share the stream and land inside the document. A bare command prints
its usage and succeeds rather than failing. Colour is emitted only to a
terminal, per stream, and NO_COLOR is honoured.
"-v 1" reports every decision whose outcome you could not have read off your own
input: the klammerset that was loaded and from which file, a font's directory, a
":files" name's file, how "-o" was expanded. Higher levels are the trace.
The commands no longer warn and continue: an anomaly is an error, described with
its location. Two exceptions remain, each for a stated reason -- a condition
that is expected and temporary by design, and a judgment that is a heuristic
rather than exact.
@cond IS NOW A TRUE SPECIAL FORM, resolved at APPLICATION time rather than when
the file is read. Two consequences for a writer:
* a state variable reaches the predicate. "@@@state Flag :value true @@@
@cond *Flag* | T | F @" renders "T"; it used to see the literal "*Flag*" and
silently take the false branch. The document now behaves like a klammer
body, whose arguments are bound before its conditionals are decided.
* nothing in a discarded branch happens -- it is not read, not evaluated, not
expanded. An @eval in the branch not taken used to run anyway.
Its predicate relation is total and strict: true, True, 1; false, False, 0, and
empty; anything else is an error at the @cond rather than silently false.
@eval REACHING OUTSIDE. ":shell" and ":haskell" now keep the command's standard
error out of the document (it appears under "-v 1") and treat a nonzero exit as
an error naming what the command reported. A command that exits nonzero on
purpose -- "grep" finding no match -- says so with "|| true".
KLAMMER SETS. Several combine: "--klammersets a b c" loads all three in the
order given, sharing one namespace, with the definition modes deciding
collisions. "none" means none and may not be combined with other symbols. A
klammerset with symbol X is declared in a file X/X.k, which is what lets two
sets require the same third set without loading it twice.
TESTS. Four new suites: the kdiag command's interface, the @eval primitive's
contract with the outside world, and verbosity at both tiers. Three suites
that could not run on macOS at all now do.
Assembled from dev commit 6c8ee6c22fca.
2026-08-16 01:37:59 +02:00
|
|
|
// Which frames were searched belongs IN the error, not printed beside
|
|
|
|
|
// it. This was a msg() dumping the whole state to stdout before the
|
|
|
|
|
// throw -- scaffolding, on the wrong stream, and separated from the
|
|
|
|
|
// message it was explaining. The frame NAMES are the useful part: a
|
|
|
|
|
// variable missing because the expected frame was never opened looks
|
|
|
|
|
// exactly like one that was never set.
|
|
|
|
|
strings_t frame_names {};
|
|
|
|
|
for (const auto& f : m_frames) {
|
|
|
|
|
frame_names.push_back(f.m_name);
|
|
|
|
|
}
|
|
|
|
|
throw Argument_error(
|
|
|
|
|
"Variable " + q_(name) + " not defined (searched: "
|
|
|
|
|
+ join(frame_names, ", ") + ")", loc);
|
2026-07-18 18:48:23 +02:00
|
|
|
} else {
|
|
|
|
|
return Var();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
std::string State::value(const std::string& name, bool error_if_not_defined, const Locator& loc) const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
return get(name, error_if_not_defined, loc).m_value;
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
std::string State::subst(const std::string& text, bool quote_values) const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
(void)K::log(3);
|
|
|
|
|
std::string result = text;
|
|
|
|
|
std::regex varpat(R"(\*(\w+)\*)");
|
|
|
|
|
for (std::sregex_iterator iter(text.begin(), text.end(), varpat), end; iter != end; ++iter) {
|
|
|
|
|
std::string match = iter->str();
|
|
|
|
|
std::string var = (*iter)[1].str();
|
|
|
|
|
//std::cout << "Found: " << iter->str() << sp_arrow << (*iter)[1].str() << "\n";
|
|
|
|
|
// std::cout << "Found: " << match << sp_arrow << var << "\n";
|
|
|
|
|
|
|
|
|
|
//std::string value = get(var).m_value;
|
|
|
|
|
|
|
|
|
|
auto var_value = value(var, false);
|
|
|
|
|
auto printable = q_(var_value);
|
|
|
|
|
if (var_value != klammerstate::no_value) {
|
|
|
|
|
if (quote_values) {
|
|
|
|
|
var_value = q_(var_value);
|
|
|
|
|
}
|
|
|
|
|
result = string_replace(result, match, var_value);
|
|
|
|
|
} else {
|
|
|
|
|
// throw Argument_error("Variable " + printable + " is not defined");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void State::subst(katom_iter begin, katom_iter end)
|
|
|
|
|
{
|
|
|
|
|
(void)K::log(3);
|
|
|
|
|
std::regex varpat(R"((.*?)\*(\w+)\*(.*))");
|
|
|
|
|
for (auto ki = begin; ki < end ; ki++) {
|
|
|
|
|
// msg() << kall << ktype << *ki << "\n";
|
|
|
|
|
std::smatch match;
|
|
|
|
|
if (std::regex_match(ki->m_text, match, varpat)
|
|
|
|
|
&& ki->m_type == katom_t::karg) {
|
|
|
|
|
//auto [var, found] = get(match[1]);
|
|
|
|
|
auto var_value = value(match[2], true, begin->m_loc);
|
|
|
|
|
if (var_value != klammerstate::no_value) {
|
An output policy for the three commands, and @cond as a true special form
A snapshot of the development tree. The substantial changes since the last one:
COMMAND OUTPUT POLICY. The three commands display text in exactly three cases,
and each owns a stream: LOGGING under "-v" greater than 0 and an ERROR before
termination go to STDERR; OUTPUT THE USER ASKED FOR goes to STDOUT. For ktext
that output is a document, so "ktext doc.kt -d | ..." is now safe -- logging
used to share the stream and land inside the document. A bare command prints
its usage and succeeds rather than failing. Colour is emitted only to a
terminal, per stream, and NO_COLOR is honoured.
"-v 1" reports every decision whose outcome you could not have read off your own
input: the klammerset that was loaded and from which file, a font's directory, a
":files" name's file, how "-o" was expanded. Higher levels are the trace.
The commands no longer warn and continue: an anomaly is an error, described with
its location. Two exceptions remain, each for a stated reason -- a condition
that is expected and temporary by design, and a judgment that is a heuristic
rather than exact.
@cond IS NOW A TRUE SPECIAL FORM, resolved at APPLICATION time rather than when
the file is read. Two consequences for a writer:
* a state variable reaches the predicate. "@@@state Flag :value true @@@
@cond *Flag* | T | F @" renders "T"; it used to see the literal "*Flag*" and
silently take the false branch. The document now behaves like a klammer
body, whose arguments are bound before its conditionals are decided.
* nothing in a discarded branch happens -- it is not read, not evaluated, not
expanded. An @eval in the branch not taken used to run anyway.
Its predicate relation is total and strict: true, True, 1; false, False, 0, and
empty; anything else is an error at the @cond rather than silently false.
@eval REACHING OUTSIDE. ":shell" and ":haskell" now keep the command's standard
error out of the document (it appears under "-v 1") and treat a nonzero exit as
an error naming what the command reported. A command that exits nonzero on
purpose -- "grep" finding no match -- says so with "|| true".
KLAMMER SETS. Several combine: "--klammersets a b c" loads all three in the
order given, sharing one namespace, with the definition modes deciding
collisions. "none" means none and may not be combined with other symbols. A
klammerset with symbol X is declared in a file X/X.k, which is what lets two
sets require the same third set without loading it twice.
TESTS. Four new suites: the kdiag command's interface, the @eval primitive's
contract with the outside world, and verbosity at both tiers. Three suites
that could not run on macOS at all now do.
Assembled from dev commit 6c8ee6c22fca.
2026-08-16 01:37:59 +02:00
|
|
|
(void)K::log(3, "Found subst:", match[1].str(), var_value);
|
2026-07-18 18:48:23 +02:00
|
|
|
std::stringstream ss {};
|
|
|
|
|
ss << match[1] << var_value << match[3];
|
|
|
|
|
ki->m_text = ss.str(); // match[1] + var_value + match[3];
|
|
|
|
|
} else {
|
|
|
|
|
throw Argument_error("Variable " + q_(match[1]) + " is not defined", begin->m_loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prohibit_change_of_description(
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
const std::string& name, bool defined, const std::string& old_desc,
|
|
|
|
|
const std::string& new_desc, const Locator& old_loc, const Locator& loc)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
if (defined && !old_desc.empty() && !new_desc.empty()) {
|
|
|
|
|
std::stringstream ss {};
|
|
|
|
|
ss << "The " << q_(name) << " variable's description is already defined";
|
|
|
|
|
if (new_desc != old_desc) {
|
|
|
|
|
ss << "; the description cannot be changed to " << q_(new_desc)
|
|
|
|
|
<< " from " << q_(old_desc);
|
|
|
|
|
}
|
|
|
|
|
ss << " at " << old_loc.desc() << ".";
|
|
|
|
|
|
|
|
|
|
throw Argument_error(ss.str(), loc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Parameter_set m_parameters = Parameter_set("name :value :append :replace :delim :desc");
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
void State::parse_state_katoms(katom_iter begin, katom_iter end, katom_list& katoms)
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
(void)K::log(3, *begin, *(end-1));
|
|
|
|
|
// std::cout << "parse_katoms: " << std::pair(begin + 1, end - 1) << "\n";
|
|
|
|
|
auto [positional, optional, rest] = argument_split(begin + 1, end - 1);
|
|
|
|
|
auto args = m_parameters.value_map(positional, optional, rest, begin->m_loc);
|
|
|
|
|
|
|
|
|
|
// std::cout << std::setfill(' ') << "\nArgument values:\n" << args;
|
|
|
|
|
|
|
|
|
|
Var current = get(args["name"]);
|
|
|
|
|
bool defined = current.defined();
|
|
|
|
|
std::string delim = args["delim"];
|
|
|
|
|
delim = delim.empty() ? " " : delim;
|
|
|
|
|
|
|
|
|
|
prohibit_change_of_description(
|
|
|
|
|
args["name"], defined, current.m_desc, args["desc"], current.m_loc, begin->m_loc);
|
|
|
|
|
|
|
|
|
|
if (defined && !args["replace"].empty()) {
|
|
|
|
|
replace(args["name"], args["replace"]);
|
|
|
|
|
} else if (defined && !args["append"].empty()) {
|
|
|
|
|
replace(args["name"], current.m_value + delim + args["append"]);
|
|
|
|
|
} else if (!args["value"].empty()) {
|
|
|
|
|
set(args["name"], args["value"], false, delim, args["desc"], begin->m_loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modify_type(katom_t::replaced, begin, end);
|
|
|
|
|
auto next_iter = end;
|
|
|
|
|
ignore_whitespace(next_iter, katoms);
|
|
|
|
|
}
|
|
|
|
|
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
std::vector<std::string> State::all_names() const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
|
|
|
|
std::vector<std::string> result {};
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const Frame& f : m_frames) {
|
|
|
|
|
for (const auto& [name, var] : f.m_vars) {
|
2026-07-18 18:48:23 +02:00
|
|
|
// std::cout << "Name: " << name << "\n";
|
|
|
|
|
result.push_back(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-07-27 20:25:49 +02:00
|
|
|
void State::add_search_dir(const std::string& dir)
|
|
|
|
|
{
|
|
|
|
|
if (!dir.empty()
|
|
|
|
|
&& std::find(m_search_dirs.begin(), m_search_dirs.end(), dir)
|
|
|
|
|
== m_search_dirs.end()) {
|
|
|
|
|
m_search_dirs.push_back(dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-07-18 18:48:23 +02:00
|
|
|
std::string State::python_code()
|
|
|
|
|
{
|
|
|
|
|
(void)K::log(3);
|
|
|
|
|
std::vector<std::string> names = all_names();
|
|
|
|
|
std::string margin = " ";
|
|
|
|
|
std::stringstream ss {};
|
|
|
|
|
|
|
|
|
|
ss << "import sys\n";
|
2026-07-27 20:25:49 +02:00
|
|
|
strings_t python_dirs = sks_dirs();
|
|
|
|
|
// The directories of the files this Machine has read: a module next to
|
|
|
|
|
// the file whose @eval names it is found regardless of the cwd.
|
|
|
|
|
python_dirs.insert(python_dirs.end(),
|
|
|
|
|
m_search_dirs.begin(), m_search_dirs.end());
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& d : python_dirs) {
|
2026-07-18 18:48:23 +02:00
|
|
|
auto python_files = pathnames_with_extension(d, "py");
|
|
|
|
|
if (!python_files.empty()) {
|
|
|
|
|
ss << "sys.path.append('" << d << "')\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!m_frames.empty()) {
|
|
|
|
|
int name_length = max_length(names);
|
|
|
|
|
ss << "class K:\n"
|
|
|
|
|
<< margin << std::left << std::setw(name_length) << "K_eval_id" << " = "
|
|
|
|
|
<< State::class_id++ << "\n";
|
|
|
|
|
for (const auto& name : names) {
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
Var var = get(name);
|
|
|
|
|
ss << var.m_argtype.python_value(name, {var.m_value}, name_length) << "\n";
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// msg() << ss.str() << "\n";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string State::describe(bool show_environment, int margin_size) const
|
|
|
|
|
{
|
|
|
|
|
std::string margin(margin_size, ' ');
|
|
|
|
|
int i = m_frames.size() - 1;
|
|
|
|
|
std::stringstream ss {};
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& f : m_frames) {
|
2026-07-18 18:48:23 +02:00
|
|
|
int width = max_key_length(f.m_vars);
|
|
|
|
|
ss << margin << "Frame " << i-- << ": " << f.m_name << "\n";
|
|
|
|
|
if ((f.m_name != klammerstate::shell_environment_name) ||
|
|
|
|
|
(show_environment && f.m_name == klammerstate::shell_environment_name)) {
|
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)
2026-07-30 23:50:07 +02:00
|
|
|
for (const auto& [key, value] : f.m_vars) {
|
2026-07-18 18:48:23 +02:00
|
|
|
std::string print_value = value.m_value;
|
|
|
|
|
if (print_value == klammerstate::no_value) {
|
|
|
|
|
print_value = "<no-value>";
|
|
|
|
|
}
|
|
|
|
|
ss << margin << " " << std::setw(width) << std::left << key << " "
|
|
|
|
|
<< abbrev(print_value) << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ss << "\n";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|