amos 913d3c367f Add the usable task catalog and admit batch 6 tasks
All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:43:15 +08:00

75 lines
2.6 KiB
C++

#include "module_plan.h"
#include <utility>
namespace bootplan {
namespace {
bool module_byte(unsigned char byte) {
return (byte >= 'A' && byte <= 'Z') ||
(byte >= 'a' && byte <= 'z') ||
(byte >= '0' && byte <= '9') || byte == '_' || byte == '-';
}
bool space_byte(unsigned char byte) {
return byte == ' ' || byte == '\t' || byte == '\r' ||
byte == '\v' || byte == '\f';
}
bool finish_line(const std::string &line,
std::vector<std::vector<std::string>> &rows) {
std::size_t at = 0;
while (at < line.size() && space_byte(static_cast<unsigned char>(line[at]))) ++at;
if (at == line.size() || line[at] == '#') return true;
std::vector<std::string> row;
while (at < line.size()) {
std::size_t start = at;
while (at < line.size() && !space_byte(static_cast<unsigned char>(line[at]))) {
++at;
}
row.emplace_back(line.substr(start, at - start));
while (at < line.size() && space_byte(static_cast<unsigned char>(line[at]))) ++at;
}
rows.push_back(std::move(row));
return true;
}
}
bool canonical_module(const std::string &raw, std::string &output) {
// Build before publishing, including when the caller aliases input and output.
std::string next;
if (raw.empty() || raw.size() > 64) { output.clear(); return false; }
next.reserve(raw.size());
for (unsigned char byte : raw) {
if (!module_byte(byte)) { output.clear(); return false; }
next.push_back(byte == '-' ? '_' : static_cast<char>(byte));
}
output = std::move(next);
return true;
}
Error statements(const std::string &text,
std::vector<std::vector<std::string>> &output) {
output.clear();
if (text.size() > 65536) return Error::invalid;
for (unsigned char byte : text) if (byte > 127) return Error::invalid;
std::vector<std::vector<std::string>> next;
std::string logical;
std::size_t start = 0;
for (;;) {
const std::size_t lf = text.find('\n', start);
const bool has_next = lf != std::string::npos;
const std::size_t end = has_next ? lf : text.size();
const bool continued = end > start && text[end - 1] == '\\';
logical.append(text, start, end - start - (continued ? 1 : 0));
if (continued) {
if (!has_next) return Error::invalid;
logical.push_back(' ');
} else {
if (!finish_line(logical, next)) return Error::invalid;
logical.clear();
}
if (!has_next) break;
start = lf + 1;
}
output = std::move(next);
return Error::none;
}
}