From daba9810984b2924c28f5bedf838535f8711e669 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 25 Sep 2026 16:34:44 -0400 Subject: the abstraction as a library & a discovered defect The readers each read one serialisation and print. A writer needs neither: it needs the document. So the model and both loaders live here, and a writer cannot tell which serialisation it was handed, exactly as spine own writers cannot. ocda.model imports nothing, which is the property that makes writers possible: they depend on the model and on neither loader. The model and the .ssp loader are the ssp-reader code, moved and renamed to the level they belong to: the model is neither the .ssp nor the .ocda.db. ocda.load_db is new, and returns the same value from sqlite that load_ssp returns from text. ocda.load is the one place that decides what a path is. The claim is only true if the two loaders agree, so test/agree.d asks: load a document both ways and compare the models object by object. It found a real defect on its first run. Eight of thirty-six disagreed, and the cause was the .ssp loader, not the formats: an object whose first text line is blank lost it, the loader having decided whether to start a new line by asking whether the accumulated text was empty, which is a different question from whether a line has been seen. Seven documents of the sample set have verse opening on a blank line and every one of them was wrong. Nothing else had caught it: the two .ssp readers were compared on section counts, which the bug does not disturb. It took loading one document two ways and comparing the objects. Fixed here, and in ssp-reader/dlang which carried the same code. All documents in the markup sample set now agree. (assisted by Claude-Code) --- dlang/src/ocda/load.d | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 dlang/src/ocda/load.d (limited to 'dlang/src/ocda/load.d') diff --git a/dlang/src/ocda/load.d b/dlang/src/ocda/load.d new file mode 100644 index 0000000..0f630bc --- /dev/null +++ b/dlang/src/ocda/load.d @@ -0,0 +1,58 @@ +module ocda.load; + +/+ ↓ what a path is, and loading it. + . + One place that decides, so that every reader and every writer accepts + the same inputs and a new input type is added once. This mirrors + spine's own ocda/abstraction/load.d, which names the sources it can + enter the pipeline from and tells them apart by suffix. + . + Deliberately *not* here: .sst and .ssm markup. Reading markup means + implementing the parser, which is spine's work and a far larger thing + than a reader or a sample writer needs. This library reads + abstractions. ++/ + +import std.algorithm : endsWith; +import ocda.model; +import ocda.load_ssp; +import ocda.load_db; + +enum Source { + ssp, // .ssp, the abstraction as text + ocda_db, // .ocda.db, the abstraction as sqlite + unknown, +} + +Source sourceOf(string path) { + if (path.endsWith(".ocda.db")) { return Source.ocda_db; } + if (path.endsWith(".ssp")) { return Source.ssp; } + if (path.endsWith(".db")) { return Source.ocda_db; } + return Source.unknown; +} + +string sourceName(Source s) { + final switch (s) { + case Source.ssp: return ".ssp (the abstraction as text)"; + case Source.ocda_db: return ".ocda.db (the abstraction as sqlite)"; + case Source.unknown: return "not an abstraction this library reads"; + } +} + +class OcdaLoadError : Exception { + this(string msg) { super(msg); } +} + +/+ ↓ load whatever the path is into the model. + lang applies only to a .ocda.db, which holds every language of its + document; a .ssp is one language and the argument is ignored. ++/ +OcdaDocument load(string path, string lang = "", bool any_version = false) { + final switch (sourceOf(path)) { + case Source.ssp: return parseSspFile(path); + case Source.ocda_db: return loadDbFile(path, lang, any_version); + case Source.unknown: + throw new OcdaLoadError(path ~ ": " ~ sourceName(Source.unknown) + ~ " (expected .ssp or .ocda.db)"); + } +} -- cgit v1.2.3