Characters that killed a render, what may sit next to a klammer, and ref/

A character written in the ^...^ mnemonic form -- ^oe^, ^zz^, ^hello^ --
used to kill ktext outright: no message, no output, and an exit status
that looked like a crash because it was one.  Only the forms that happen
to spell hexadecimal digits escaped, and they were right by luck rather
than by reading.  Any caret form that names no character is now a located
error that quotes what was written.

A klammer may now sit inside square brackets and braces as it already
could inside parentheses, and may be followed by the punctuation that
ends a sentence: [@i word@], {@b word@}, @i word@'s.  The rule is a fixed
list of characters, because none of them can occur inside a klammer name
and so none of them is ambiguous next to a delimiter.  A letter still
cannot: "x@" is the named closing delimiter, so a letter before "@" has
two readings and no rule can separate them.

The abbreviations an author writes -- the hyphen form @i-word, a klammer
glued to its neighbouring punctuation -- are now recognised as author
conveniences only.  They are not applied to @@ definitions or @@@ system
commands, which are written by someone who needs no such shorthand and
whose forms are already whole.

Also fixed, each of them silent: an exported shell function in the
environment broke every @eval in the document; a line break written with
@nl was destroyed when it passed through a klammer that generates a
table, printing as \textbackslash{}newline in the finished PDF; and
"kdesc --coverage" shortened its file column by comparing the spelling of
a path rather than the path, so a klammer set reached by a symbolic link
showed a full path where its neighbours showed a short one.

New in the distribution: ref/, a small klammerset that describes the
Klammermachine's own tables in Klammertext.  It currently provides the
character tables -- the diacritics and the extended Latin letters -- as
klammers that render to any target, so the documentation of what can be
written cannot drift from what the machine accepts.  It is early, and
will grow.

The Klammertext taxonomy now has a section on targets, describes the
@@@klammerset system command alongside the other three, and states the
precedence of "^" -- what a caret means before a letter, a digit, a
punctuation character, and a quote, in one ordered list.

(from dev 6594c7ff8c1f)
This commit is contained in:
ack committed 2026-09-07 22:37:05 +02:00
1 parent b80e823ab3
commit e4f1307aa9
53 files changed
+2014 -350

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Build products: the dependency files the pattern rule generates.
*.d
+56
View File
@@ -0,0 +1,56 @@
# ref/ -- the reflection library.
#
# reflect.cpp holds C++ functions that read the engine's OWN registries and
# character tables and return Klammertext (a "@table" call and such), which
# the .kt fragments in this directory then render for whichever target is
# in force. They are reached through "@eval :cpp", so this builds a DSO
# loaded at run time, not part of libklammertext.so.
#
# Adapted from sks/document/Makefile. Two things differ and both matter:
# ref/ has no sks dependencies (a generator returns Klammertext, so it
# needs none of kutil/target's markup helpers), and it sits ONE level below
# $(KLAMMERTEXT_HOME) rather than two, which changes the rpath.
K := $(KLAMMERTEXT_HOME)
include $(K)/env/makefile.env
# CPPFLAGS already carries -I$(KLAMMERTEXT_HOME)/mac, which is every header
# reflect.cpp includes (machine, character, error, show). No local -I.
LIBDIR := $(K)/lib
LIBRARY := $(LIBDIR)/libklammertext.so
# "../lib", not "../../lib": reflect.so sits in $(K)/ref, so one level up
# reaches $(K)/lib. (sks/document.so needs two, which is what this was
# copied from -- a wrong rpath here shows up only at dlopen time, and only
# where the loading process does not already have the library.)
REF_LDFLAGS := $(SHARED) $(EXPORT_DYNAMIC) -Wl,-rpath,'$(ORIGIN)/../lib' -L$(LIBDIR)
OBJECTS := reflect.o
DEPFILES := $(OBJECTS:.o=.d)
DEPFLAGS = -MMD -MP -MF $(@:.o=.d)
.PHONY: all clean
all : reflect.so
%.o : %.cpp
@echo Compiling $<
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $< -o $@
# The objects are LINKED here, never recompiled. sks/document/Makefile
# names document.cpp on its link line as well, which is correct THERE only
# because document.o is the one object not in its LOCAL_OBJECTS; doing both
# for the same file -- compiling reflect.cpp inline AND linking reflect.o --
# defines every symbol in it twice. Building through the pattern rule also
# gets reflect.d, so a header change rebuilds it.
reflect.so : $(OBJECTS) $(LIBRARY)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(REF_LDFLAGS) $(LDFLAGS) \
-o $@ $(OBJECTS) -lklammertext $(LDLIBS)
clean :
rm -f $(OBJECTS) $(DEPFILES) *.so *~
-include $(DEPFILES)
+16
View File
@@ -0,0 +1,16 @@
# Reflection Klammer set
@@@klammerset ref | Descriptions of Klammermachine data structures in Klammertext syntax
:name Reflection Klammer Set
:author Andy Kopra
:date 2026-08-27
:requires sks
@@@
@@diacritics_examples.k : Show the diacritics codes and their result in the text @@
@@diacritics_examples.* :: @eval :cpp *KLAMMERTEXT_HOME*/ref/reflect diacritics_examples @ @@
@@extended_latin_examples.k : Show the codes and the resulting extended Latin characters @@
@@extended_latin_examples.* :: @eval :cpp *KLAMMERTEXT_HOME*/ref/reflect extended_latin_examples @ @@
+55
View File
@@ -0,0 +1,55 @@
#include "machine.h"
#include "character.h"
#include "error.h"
#include "show.h"
// extern "C" is needed for dlsym name lookup. Returning std::string from
// C-linkage functions is technically non-standard but works correctly on
// Linux (Itanium ABI) where C and C++ calling conventions are identical.
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
#endif
extern "C"
std::string diacritics_examples([[maybe_unused]] Machine& machine)
{
if (diacritics.size() != diacritic_symbols_order.size()) {
throw Internal_error("Mismatch between diacritics order list and their definitions");
}
//std::cout << machine;
std::stringstream kt {};
kt << "@table :caption Diacritics (with typical base characters) :cell_hpos c c l |\n"
<< "@i-Displayed | @i-Written | @i-Name ||\n";
for (char symbol : diacritic_symbols_order) {
std::string sym { symbol };
auto [code, name] = diacritics[sym];
std::string letter = diacritic_example_letter[sym];
std::string written = "^" + letter + sym;
if (sym == "~") {
written = "^" + letter + "^~";
}
std::string display = "^" + letter + sym;
kt << display << " | @t ^" << written << " @ | " << name << " ||\n";
}
kt << "table@";
return kt.str();
}
extern "C"
std::string extended_latin_examples([[maybe_unused]] Machine& machine)
{
std::stringstream kt {};
kt << "@table :caption Extended Latin characters and ligatures :cell_hpos c c l |\n"
<< "@i-Displayed | @i-Written | @i-Name ||\n";
for (const std::string& symbol : extended_latin_symbols) {
auto [code, name] = extended_latin[symbol];
std::string coded = "^" + symbol + "^";
std::string file_literal = "^^ #- " + symbol + " #- ^^";
kt << coded << " | @t " << file_literal << " @ | " << name << " ||\n";
}
kt << "table@";
return kt.str();
}