Files
klammertext/mac/locator.h
Andy Kopra ef77f03584 Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).

(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00

53 lines
1.4 KiB
C++

#pragma once
#include <iostream>
#include <string>
// #include <filesystem>
#include <source_location>
#include <map>
#include "file.h"
inline std::string klammertext_home_var = "KLAMMERTEXT_HOME";
class Locator
{
public:
explicit Locator(const std::source_location location =
std::source_location::current())
// std::source_location::file_name() can return nullptr on some
// toolchains (e.g. Homebrew GCC on macOS); guard against
// fs::path(nullptr) -> strlen(NULL).
: m_filename(location.file_name()
? fs::absolute(location.file_name()) : fs::path{})
, m_line(int(location.line()))
, m_chr(int(location.column()))
{};
Locator(const fs::path& filename, int line, int chr);
std::string str(bool relative = false) const;
std::string desc(bool relative = false) const;
std::string abbrev(bool include_chr=true) const;
std::string m_filename {};
int m_line;
int m_chr;
//std::string m_desc {};
};
std::ostream &nformat(std::ostream &os);
std::string locator_range(
const Locator& start_loc, const Locator& end_loc,
std::map<std::string, std::string>& relpath);
Locator current_locator(
const std::source_location location = std::source_location::current());
std::string locator_summary(std::vector<Locator> locators);
inline
std::string showloc(Locator loc=Locator()) {
return loc.abbrev(false) + " ";
}