sheet_model.h
impl/nordshrift/sheet_model.h · 348 line(s) · c
// ===========================================================================
// sheet_model.h -- The Nordshrift sheet model (NS-SST-0001 §II–§XIII).
// ===========================================================================
#ifndef NORDSHRIFT_SHEET_MODEL_H
#define NORDSHRIFT_SHEET_MODEL_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "subject_model.h" // nordshrift::semantic::Subject and friends
#include "input_object.h"
namespace nordshrift {
enum class Layout { MirrorSource, Flat, PackageMapped, Custom };
enum class Verbosity{ Silent, Quiet, Normal, Verbose, Debug };
enum class Severity { Error, Warning, Notice };
enum class EffectPolicy { Strict, Lenient, Audit, Off };
enum class GuardMode { CompileOnly, RuntimeOnly, CompileAndRuntime, Off };
enum class FailureAction { Throw, Assert, LogAndContinue, Halt };
enum class NullWrap { Maybe, NullableAnnotation, Trust };
enum class CheckedEx { Wrap, Propagate, RethrowUnchecked };
enum class DeriveStyle { Record, ImmutableClass, Builder, Lombok };
enum class TargetLang { Java, Sleela, C };
// ---------------------------------------------------------------------------
// First-class scalar typing (NS-SST String support, 1.4).
// ---------------------------------------------------------------------------
// The SST lexer already distinguishes a quoted "..." literal (Tok::String)
// from an integer, a dotted version, a boolean, and a bare identifier. Until
// now the parser collapsed all of them to raw text via readScalarText(), so a
// String scalar had no first-class standing. ScalarKind + TypedScalar preserve
// that distinction so a sheet value can be a genuine String type -- parallel to
// how SLeeLa source has a String literal (SLEELA.syntax 1.4).
enum class ScalarKind { String, Integer, Version, Boolean, Identifier, None };
inline const char* scalarKindName(ScalarKind k) {
switch (k) {
case ScalarKind::String: return "string";
case ScalarKind::Integer: return "integer";
case ScalarKind::Version: return "version";
case ScalarKind::Boolean: return "boolean";
case ScalarKind::Identifier: return "identifier";
default: return "none";
}
}
struct TypedScalar {
std::string text; // the decoded value text
ScalarKind kind = ScalarKind::None; // how the lexer classified it
int line = 0;
bool isString() const { return kind == ScalarKind::String; }
bool present() const { return kind != ScalarKind::None; }
};
// A named String value declared in a sheet's `strings:` block. First-class and
// closed to the String type: a non-String literal in this block is a typed
// error (NSS-E-STR-001), mirroring the "never silently coerce" discipline the
// network/finance blocks use.
struct StringVar {
std::string name; // identifier key
std::string value; // the String literal's decoded text
int line = 0;
};
struct StringSpec {
std::vector<StringVar> vars;
bool present = false;
int line = 0;
};
// Network objects are first-class SST declarations. These names correspond
// to the Nordshrift network model and are deliberately closed so an SST sheet
// cannot silently request an unsupported runtime object.
enum class NetworkObject {
Endpoint,
NIC,
Link,
Packet,
Queue,
Switch,
Router,
Fabric,
Listener,
Connector,
Gateway,
LoadBalancer,
Service,
TLS,
DNS
};
enum class NetworkTransport { TCP, UDP, TLS, QUIC };
enum class NetworkAddressFamily { IPv4, IPv6, Dual };
struct NetworkSpec {
std::vector<NetworkObject> objects;
std::vector<NetworkTransport> transports;
NetworkAddressFamily addressFamily = NetworkAddressFamily::Dual;
bool tls = false;
bool present = false;
int line = 0;
};
// Finance objects are first-class SST declarations, parallel to the network
// object set. These names correspond to the Nordshrift financial integration
// model (SST.FINANCIAL.md) and are deliberately closed so an SST sheet cannot
// silently request an unsupported financial component.
enum class FinanceObject {
FutureValue,
PresentValue,
AnnuityPresent,
AnnuityFuture,
NetPresentValue,
BondPrice,
CAPM,
WACC,
Determinant2x2,
LinearSolve2x2,
QuadraticEquation,
Ratio
};
// Timing/period convention required before a financial quantity can be
// interpreted (see the domain contract in SST.FINANCIAL.md).
enum class FinancePeriodConvention { Annual, SemiAnnual, Quarterly, Monthly, Continuous };
// How discounting is applied for time-value-of-money components.
enum class FinanceDiscounting { Discrete, Continuous };
struct FinanceSpec {
std::vector<FinanceObject> objects;
std::string currency; // currency identity, e.g. "USD"; empty = unset
FinancePeriodConvention period = FinancePeriodConvention::Annual;
FinanceDiscounting discounting = FinanceDiscounting::Discrete;
bool present = false;
bool hasCurrency = false;
bool hasPeriod = false;
int line = 0;
};
// Munction reach-composition objects are first-class SST declarations, parallel
// to the network object set. These names correspond to the Munction reach model
// (MUNCTION.md / core/sleela_munction.*) and are deliberately closed so an SST
// sheet cannot silently request an unsupported reach verb.
enum class ReachVerb {
Start, Connect, Open, Enable, Send, Thatch, Consume, Observe,
Propagate, Latch, Contain, Close, CloseWithReceipt, Abort
};
// The system-method channels a reach may connect over (MUNCTION.md §4).
enum class ReachChannel { Pipe, File, Tcp, Http, Sdps, Crypto };
struct ReachSpec {
std::vector<ReachVerb> verbs; // declared reach verb ladder
std::vector<ReachChannel> channels; // declared system-method channels
int minVerbs = 4; // sanity bound floor (MUNCTION.md §1.2)
int maxVerbs = 16; // sanity bound ceiling
bool receivable = true; // every reach yields a receipt
bool coherent = true; // every send is coherent
bool present = false;
int line = 0;
};
// Synchro measurement objects are first-class SST declarations. These names
// correspond to the honest packet-dispatch/measurement model (SYNCHRO.md /
// synchro/ / core/sleela_synchro.*) and are deliberately closed.
enum class MeasureMetric {
Sent, Received, Loss, Mean, Min, Max, P95, Report
};
struct MeasureSpec {
std::vector<MeasureMetric> metrics; // declared measured metrics
bool honest = true; // no delivery-time guarantee; measured only
int timeoutMs = 1000; // default per-dispatch timeout budget
bool present = false;
bool hasTimeout = false;
int line = 0;
};
struct Pragmas {
std::string nordshrift;
std::string sleela;
std::string encoding;
bool hasNordshrift = false;
int nordshriftLine = 0;
};
struct SheetMeta {
std::string name;
std::string version;
std::string author;
std::string description;
std::string extends;
std::vector<std::string> tags;
int line = 0;
bool present = false;
};
struct Import {
std::string path;
std::string alias;
std::vector<std::string> only;
std::vector<std::string> except;
bool hasOnly = false;
bool hasExcept = false;
int line = 0;
};
struct Source {
std::string root;
std::vector<std::string> globs;
std::vector<std::string> exclude;
std::string encoding = "utf-8";
bool watch = false;
bool present = false;
bool hasRoot = false;
int line = 0;
int rootLine = 0;
};
struct Target {
std::string root;
Layout layout = Layout::MirrorSource;
int javaVersion = 0;
std::string packageRoot;
bool overwrite = true;
bool sourceMap = true;
bool optimize = false;
bool clean = false;
std::map<std::string, std::string> layoutMap;
TargetLang language = TargetLang::Java;
bool present = false;
bool hasRoot = false;
bool hasLayout = false;
bool hasJavaVersion = false;
int line = 0;
int javaVersionLine = 0;
};
struct Pipeline {
std::vector<std::string> phases;
std::vector<std::string> skip;
int parallelThreshold = 1;
bool cache = true;
std::string cacheDir = ".nordshrift-cache";
Verbosity verbosity = Verbosity::Normal;
bool failFast = false;
bool present = false;
int line = 0;
int phasesLine = 0;
};
struct RuleConfig {
std::string name;
Severity severity = Severity::Error;
bool hasSeverity = false;
std::map<std::string, std::string> config;
int line = 0;
};
struct Rules {
std::vector<std::string> activate;
std::vector<std::string> deactivate;
std::map<std::string, Severity> severity;
std::map<std::string, std::map<std::string, std::string>> config;
bool present = false;
int line = 0;
};
struct Effects {
EffectPolicy policy = EffectPolicy::Strict;
std::vector<std::string> declare;
std::map<std::string, std::vector<std::string>> aliases;
std::string defaultEffect = "Pure";
bool present = false;
int line = 0;
};
struct Derive {
bool lens = false, projection = false, equality = false, hashcode = false;
bool toStringD = false, builder = false, copy = false;
bool hasBuilder = false;
DeriveStyle targetStyle = DeriveStyle::Record;
bool hasTargetStyle = false;
bool present = false;
int line = 0;
};
struct Guards {
GuardMode mode = GuardMode::CompileAndRuntime;
FailureAction onFailure = FailureAction::Throw;
std::string messageFormat;
bool present = false;
int line = 0;
};
struct Interop {
bool assumeImpure = false;
NullWrap nullWrapping = NullWrap::Maybe;
bool hasNullWrapping = false;
CheckedEx checkedExceptions = CheckedEx::Wrap;
std::map<std::string, std::string> typeMapping;
std::vector<std::string> packageAllow;
std::vector<std::string> packageDeny;
bool present = false;
int line = 0;
};
struct Sheet;
struct Profile {
std::string name;
std::string inherits;
bool hasInherits = false;
std::shared_ptr<Sheet> overlay;
int line = 0;
};
struct Sheet {
Pragmas pragmas;
SheetMeta meta;
std::vector<Import> imports;
Source source;
Target target;
Pipeline pipeline;
Rules rules;
Effects effects;
Derive derive;
Guards guards;
Interop interop;
NetworkSpec network;
FinanceSpec finance;
StringSpec strings; // first-class String values block (1.4)
ReachSpec reach; // Munction reach-composition block (1.3)
MeasureSpec measure; // Synchro measurement block (1.3)
std::vector<semantic::Subject> subjects; // 2.0 semantic subject blocks
std::vector<InputObject> inputObjects; // SLeeLa architecture input objects
std::vector<RuleConfig> ruleBlocks;
std::vector<Profile> profiles;
std::string file;
};
} // namespace nordshrift
#endif // NORDSHRIFT_SHEET_MODEL_H