Target coverage: a klammer states the targets it serves
kdesc gains --coverage, which reports for every klammer the set of targets it can render to, and — the point of it — which klammers' coverage cannot be derived and must therefore be declared. Three rules: coverage is DERIVED where the definitions determine it (a general body of klammer calls covers the intersection of what those klammers cover, by a greatest fixpoint after loading), DECLARED where the engine cannot interpret what decides it (an @eval body, whose targets are undecidable), and UNKNOWN where nothing is written — which never means "deliberately unavailable". Two new spellings in a definition's name. A comma-separated target list, "@@table.html,tex :: ...", gives one body several targets; it is surface syntax, expanded at registration, and each member goes through the redefinition rules on its own. And "@@date.* :: ..." writes the general target out, asserting that the klammer works for EVERY target including ones not yet defined — a stronger claim than a list of the targets defined today, and the one target declaration that could be mechanically falsified. The Standard Klammer Set was swept accordingly: it now has no general definitions at all, every klammer names the targets it serves, six use ".*", and tex and pdf are at zero undecided. kdesc's flags are reorganised on two rules: a flag reached for often gets a single letter (-k klammers, -t targets, -c characters, -i input), a more specialised topic a multi-letter name (--argtypes, --katoms, --rewrite, --optionsets, --coverage, --klammerset, --font); and -v says how much to show about PROCESSING, never what the RESULT contains — so the katom regex column is "--katoms full" and the coverage detail "--coverage all". NOTE: "-k" now lists klammers (optionally filtered by a name/description search); the katom table moved to "--katoms". Fixes carried along: an option written with no value crashed the command with SIGSEGV instead of reporting the mistake; two required positional arguments never parsed; kdesc and kdiag printed an error and exited 0; and definition diagnostics counted registrations rather than what was written, so one line could be reported as two definitions and then printed twice. Four new test suites: target_list, coverage, command_option, kdesc. (from dev 46f54080bd9a)
This commit is contained in:
@@ -18,13 +18,11 @@ void Klammer_registry::add(
|
||||
{
|
||||
(void)K::log(3, *begin, *(end - 1));
|
||||
restore_initial_type(begin, end);
|
||||
auto [klammer_name, target_name] = parse_name(targets, *begin);
|
||||
if (!targets.has(target_name)) {
|
||||
throw Argument_error("The target \"" + target_name + "\" is not defined", begin->m_loc);
|
||||
}
|
||||
if (target_name == Target_registry::optionset_name) {
|
||||
auto [klammer_name, target_names, general_declared] = parse_name(targets, *begin);
|
||||
if (is_in(Target_registry::optionset_name, target_names)) {
|
||||
// The Machine routes an ".o" definition to the option set registry;
|
||||
// reaching here means it did not.
|
||||
// reaching here means it did not. parse_name has already rejected
|
||||
// ".o" as a member of a list, so this is the bare ".o" form.
|
||||
throw Internal_error(
|
||||
"The option set declaration \"" + klammer_name + ".o\" reached the klammer registry",
|
||||
begin->m_loc);
|
||||
@@ -41,37 +39,47 @@ void Klammer_registry::add(
|
||||
|
||||
if (m_klammers.count(klammer_name) == 0) {
|
||||
m_klammers[klammer_name] = Klammer(klammer_name);
|
||||
} else if (m_klammers[klammer_name].m_defloc.count(target_name) > 0) {
|
||||
defmode_t existing_mode = m_klammers[klammer_name].m_defmode[target_name];
|
||||
const auto& result = defmode_transition(existing_mode, incoming_mode);
|
||||
std::string name_target = klammer_name + "." + target_name;
|
||||
std::string at_desc = m_klammers[klammer_name].m_defloc[target_name].desc();
|
||||
if (!result.replace) {
|
||||
if (result.message.empty()) {
|
||||
// Silent ignore (e.g., create + default)
|
||||
modify_type(katom_t::replaced, begin, end);
|
||||
ignore_whitespace(end, katoms);
|
||||
return;
|
||||
}
|
||||
std::string msg = result.message;
|
||||
msg = string_replace(msg, "NAME", q_(name_target));
|
||||
msg = string_replace(msg, "AT", at_desc);
|
||||
throw Definition_error(msg, begin->m_loc);
|
||||
}
|
||||
if (result.warn) {
|
||||
std::string msg = result.message;
|
||||
msg = string_replace(msg, "NAME", q_(name_target));
|
||||
msg = string_replace(msg, "AT", at_desc);
|
||||
warning(msg, begin->m_loc);
|
||||
}
|
||||
m_klammers[klammer_name].remove_target_definition(target_name);
|
||||
}
|
||||
m_klammers[klammer_name].add_target_definition(
|
||||
target_name, argtypes, option_sets, begin + 1, end - 1);
|
||||
// Sticky: once a definition has written ".*", the klammer carries the
|
||||
// claim. A klammer with both a ".*" body and a target-specific one still
|
||||
// asserts that the general body serves everything else.
|
||||
if (general_declared) {
|
||||
m_klammers[klammer_name].m_general_declared = true;
|
||||
}
|
||||
// One definition per target named. A comma-separated list is surface
|
||||
// syntax: each target goes through the same registration, including the
|
||||
// redefinition transition table, so a list that collides with an existing
|
||||
// definition is decided per target -- one member may be silently ignored
|
||||
// or rejected while the others are created.
|
||||
for (const auto& target_name : target_names) {
|
||||
if (m_klammers[klammer_name].m_defloc.count(target_name) > 0) {
|
||||
defmode_t existing_mode = m_klammers[klammer_name].m_defmode[target_name];
|
||||
const auto& result = defmode_transition(existing_mode, incoming_mode);
|
||||
std::string name_target = klammer_name + "." + target_name;
|
||||
std::string at_desc = m_klammers[klammer_name].m_defloc[target_name].desc();
|
||||
if (!result.replace) {
|
||||
if (result.message.empty()) {
|
||||
// Silent ignore (e.g., create + default)
|
||||
continue;
|
||||
}
|
||||
std::string msg = result.message;
|
||||
msg = string_replace(msg, "NAME", q_(name_target));
|
||||
msg = string_replace(msg, "AT", at_desc);
|
||||
throw Definition_error(msg, begin->m_loc);
|
||||
}
|
||||
if (result.warn) {
|
||||
std::string msg = result.message;
|
||||
msg = string_replace(msg, "NAME", q_(name_target));
|
||||
msg = string_replace(msg, "AT", at_desc);
|
||||
warning(msg, begin->m_loc);
|
||||
}
|
||||
m_klammers[klammer_name].remove_target_definition(target_name);
|
||||
}
|
||||
m_klammers[klammer_name].add_target_definition(
|
||||
target_name, argtypes, option_sets, begin + 1, end - 1);
|
||||
|
||||
// This add's target:
|
||||
Target target = targets.get(target_name, begin->m_loc);
|
||||
if (!target.m_provides.empty()) {
|
||||
// This add's target:
|
||||
Target target = targets.get(target_name, begin->m_loc);
|
||||
for (const auto& provide_name : target.m_provides) {
|
||||
if (m_klammers[klammer_name].m_defloc.count(provide_name) > 0) {
|
||||
m_klammers[klammer_name].remove_target_definition(provide_name);
|
||||
@@ -164,7 +172,7 @@ std::string Klammer_registry::instance_list(int margin) const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Klammer_registry::describe(int margin) const
|
||||
std::string Klammer_registry::describe(int margin, const std::string& search) const
|
||||
{
|
||||
/*
|
||||
strings_t names {};
|
||||
@@ -172,7 +180,13 @@ std::string Klammer_registry::describe(int margin) const
|
||||
strings_t locations {};
|
||||
*/
|
||||
std::string result;
|
||||
std::string query = collapse_whitespace(search);
|
||||
for (const auto& [name, k] : m_klammers) {
|
||||
if (!query.empty() &&
|
||||
!contains_fold(name, query) &&
|
||||
!contains_fold(collapse_whitespace(k.description_text()), query)) {
|
||||
continue;
|
||||
}
|
||||
result += k.describe(margin) + "\n";
|
||||
/*
|
||||
names.push_back(name);
|
||||
|
||||
Reference in New Issue
Block a user