aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/out_src_abstraction_ocda_peg_ssp.org
diff options
context:
space:
mode:
Diffstat (limited to 'org/out_src_abstraction_ocda_peg_ssp.org')
-rw-r--r--org/out_src_abstraction_ocda_peg_ssp.org49
1 files changed, 48 insertions, 1 deletions
diff --git a/org/out_src_abstraction_ocda_peg_ssp.org b/org/out_src_abstraction_ocda_peg_ssp.org
index 88fd8c8..3be6ce2 100644
--- a/org/out_src_abstraction_ocda_peg_ssp.org
+++ b/org/out_src_abstraction_ocda_peg_ssp.org
@@ -32,6 +32,48 @@ rename source_abstraction_peg_txt.d
module sisudoc.ocda.abstraction.ssp;
@safe:
/+ ↓ write document abstraction as human-readable .ssp text file +/
+/+ ↓ escaping for values that are folded onto one line
+
+ a .ssp property value runs to the end of its line, and
+ .heading_ancestors_text joins its eight slots with "|", so a slot that
+ itself contains "|", a backslash or a line break has to be escaped or
+ the value cannot be read back. the pair here is the whole of the rule,
+ used by the writer and by the reader.
++/
+template sspEscape() {
+ import std.array : replace;
+ string sspEscapeValue(string _s) {
+ return _s
+ .replace("\\", "\\\\")
+ .replace("|", "\\|")
+ .replace("\n", "\\n")
+ .replace("\r", "\\r");
+ }
+ string[] sspUnescapeSplit(string _s) {
+ string[] _out;
+ string _cur;
+ bool _esc;
+ foreach (c; _s) {
+ if (_esc) {
+ switch (c) {
+ case 'n': _cur ~= '\n'; break;
+ case 'r': _cur ~= '\r'; break;
+ default: _cur ~= c; break; // covers \\ and \|
+ }
+ _esc = false;
+ } else if (c == '\\') {
+ _esc = true;
+ } else if (c == '|') {
+ _out ~= _cur;
+ _cur = "";
+ } else {
+ _cur ~= c;
+ }
+ }
+ _out ~= _cur;
+ return _out;
+ }
+}
/+ ↓ one object record: the single definition of what an object looks
like in a .ssp file. the writer emits with it, and the reader is
checked against it by round trip, so the two cannot drift
@@ -42,6 +84,7 @@ template sspObjectRecord() {
import std.stdio;
import std.string;
import std.array;
+ mixin sspEscape;
string[] sspObjectRecord(O)(O obj, string section, bool _vox = false) {
string[] output;
/+ ↓ object declaration line. a heading carries its identifier here,
@@ -310,7 +353,11 @@ template sspObjectRecord() {
if (h.length > 0) { has_hat = true; break; }
}
if (has_hat) {
- output ~= ".heading_ancestors_text: " ~ obj.tags.heading_ancestors_text.join("|");
+ string[] _hat;
+ foreach (h; obj.tags.heading_ancestors_text) {
+ _hat ~= sspEscapeValue(h.to!string);
+ }
+ output ~= ".heading_ancestors_text: " ~ _hat.join("|");
}
}
/+ ↓ lev4 subtoc +/