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:
1 parent
e4f1307aa9
commit
760fda5470
17 files changed
+1241
-78
No files matched your search
+17
-8
@@ -1,3 +1,5 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "error.h"
|
||||
#include "show.h"
|
||||
#include "util.h"
|
||||
@@ -13,26 +15,33 @@ bool display_source(const std::string& filename_arg)
|
||||
}
|
||||
}
|
||||
|
||||
void Error::print_message(const std::string& epilog)
|
||||
std::string Error::message(const std::string& epilog) const
|
||||
{
|
||||
// The separator is not cosmetic: the description ends with a sentence, and
|
||||
// appending the advice straight onto it ran the two together into one word
|
||||
// ("...for an unspecified targetkdiag loads no klammerset..."). m_desc is
|
||||
// then justified to 80 columns, so the break has to be a blank line rather
|
||||
// than a single newline, which justify() would fold back into the flow.
|
||||
std::string desc = m_desc;
|
||||
if (epilog != "") {
|
||||
m_desc += "\n\n" + epilog + "\n";
|
||||
desc += "\n\n" + epilog + "\n";
|
||||
}
|
||||
m_desc = justify(m_desc, 80, 0);
|
||||
std::cerr << "\n" << red << command_name << " (" << m_type << " error)";
|
||||
std::stringstream ss {};
|
||||
ss << command_name << " (" << m_type << " error)";
|
||||
if (display_source(m_loc.m_filename)) {
|
||||
std::cerr << ":\n " << m_loc.m_filename;
|
||||
ss << ":\n " << m_loc.m_filename;
|
||||
}
|
||||
if (m_loc.m_line > -1) {
|
||||
std::cerr << ", line " << m_loc.m_line;
|
||||
ss << ", line " << m_loc.m_line;
|
||||
}
|
||||
if (m_loc.m_chr > -1) {
|
||||
std::cerr << ", character " << m_loc.m_chr + 1;
|
||||
ss << ", character " << m_loc.m_chr + 1;
|
||||
}
|
||||
std::cerr << ":\n\n" << m_desc << reset << "\n";
|
||||
ss << ":\n\n" << justify(desc, 80, 0);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Error::print_message(const std::string& epilog)
|
||||
{
|
||||
std::cerr << "\n" << red << message(epilog) << reset << "\n";
|
||||
}
|
||||
Reference in new issue
Block a user