#pragma once #include "definitions.h" #include "internal/generic.h" #include "pch.h" namespace bed::internal::address { struct address_error : ed_error { address_error(const char *msg) : ed_error(msg) {} }; struct Address { // % refers to range of whatever was resulted from the previous modification. // it expands in theory to a Num,Num and so can be followed by chaining more adresses the ed way. // this is handled and resolved by the handle function, // the constuctor and resolve etc. are also only called in the handle function, // i.e. handle is the only public facing API from this namespace & class for now. // // in case of any issue an instance of address_error(const char *) is thrown. struct Result { std::array data{}; uint8_t size{0}; std::span span(uint8_t max = UINT8_MAX) const { return {data.data(), std::min(size, max)}; } }; struct None {}; // Posix ed types of addressing. struct Current {}; // . struct Last {}; // $ struct Number { // n uint64_t i; }; struct Mark { // 'm char m; }; struct RegexLine { // /re/ or ?re? internal::Direction dir; std::string re; }; // BEd Extended types of addressing. struct Regex { // &/re/ or &?re? internal::Direction dir; // returns next/previous line containing the regex std::string re; // (not only if it matches full line) }; struct Diagnostic { // #n# for diagnostic number n. (From lsp.) uint16_t n; }; struct DiagnosticNext { // ^ or % for previous/next diagnostic internal::Direction dir; }; struct SymbolDefinition { // goto symbol definition. (From lsp or using internal language parsers) std::string sym; }; struct SymbolReference { // goto nth symbol reference uint16_t n; std::string sym; }; struct SymbolReferenceNext { // >sym> or base{}; // they can then be followed by any number of +n or -n etc accumulating in. int64_t offset = 0; Address(std::string &cmd, uint64_t &i); Address() = default; uint64_t resolve(BEd &ctx); static Result handle(BEd &ctx, std::string &cmd, uint64_t &i); }; } // namespace bed::internal::address