The Python binding (kpy/): klammertext.Machine from a script

Assembled from klammertext-dev ed13dfaa5b7a.  kpy/klammertext.cpp is a
CPython extension module giving a Python script an instance of the
Machine class -- ktext in-process, set up through the same functions the
command uses.  Errors map one-to-one to Python exceptions under the C++
names; an @eval's Python exception is chained as __cause__.  Built by
make -C mac, found through PYTHONPATH (env/runtime.env sets it), tested
by tst/kpy_test.sh.  Three engine changes came with it: Error::message(),
set_command_state(), and the @eval error report carrying its traceback.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uv7KWxafinDPraswEf4GsC
This commit is contained in:
ackandClaude Fable 5.1 committed 2026-09-08 16:54:21 +02:00
1 parent e4f1307aa9
commit 760fda5470
17 files changed
+1241 -78

No files matched your search

+6 -1
View File
@@ -935,7 +935,12 @@ void Machine::escape_target_characters(const Target& target, katom_list& katoms)
std::string Machine::apply(const std::string& target_name, bool final_processing, bool escape_characters)
{
(void)K::log(3, "top level");
m_state.set("K_target", target_name);
// update=true: K_target is THIS apply's target. A command applies once,
// but the Python binding (kpy/) applies the same Machine under several
// targets -- apply("html") then apply("tex") -- and the second call
// found the first's value in the same frame and died with "Variable
// K_target is already defined" (found by tst/kpy_test.sh, 2026-09-08).
m_state.set("K_target", target_name, true);
m_state.subst(m_katoms.begin(), m_katoms.end());
// Escape target-specific characters in writer text before klammer application.