From af80415a3a3e4b1717d0dbeefb1f9b97fb84b5e4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 9 Jul 2023 17:57:26 -0400 Subject: ocda, improve doc markup structure error messages - ocda, metadoc_from_src workon doc markup structure error message, check --- src/doc_reform/meta/metadoc_from_src.d | 608 +++++++++++++++++++++++++++------ 1 file changed, 499 insertions(+), 109 deletions(-) (limited to 'src') diff --git a/src/doc_reform/meta/metadoc_from_src.d b/src/doc_reform/meta/metadoc_from_src.d index 3962beb..59cbc0b 100644 --- a/src/doc_reform/meta/metadoc_from_src.d +++ b/src/doc_reform/meta/metadoc_from_src.d @@ -610,14 +610,13 @@ template docAbstraction() { foreach (line; markup_sourcefile_content) { /+ ↓ markup document/text line by line +/ // "line" variable can be empty but should never be null /+ scope +/ - scope(exit) { - } + scope(exit) { } scope(failure) { stderr.writefln( - "%s\n%s\n%s:%s failed here:\n line: %s", + "\n%s\n%s\n\n%s:%s\nFAILED while processing the file: ❮❮ %s ❯❯ on line with text:\n%s\n", __MODULE__, __FUNCTION__, __FILE__, __LINE__, - line, + manifested.src.filename, line, ); } debug(source) { @@ -625,10 +624,7 @@ template docAbstraction() { } debug(srclines) { if (!line.empty) { - writefln( - "* %s", - line - ); + writefln("* %s", line); } } if (!line.empty) { @@ -1310,8 +1306,7 @@ template docAbstraction() { } } } /+ ← srcDocLoop closed: loop markup document/text line by line +/ - /+ ↓ post loop markup document/text +/ - /+ ↓ post loop markup document/text +/ + /+ ↓ post loop markup document/text +/ { // EOF comp_obj_heading_ = comp_obj_heading_.init; comp_obj_heading_.metainfo.is_of_part = "backmatter"; @@ -4049,7 +4044,7 @@ template docAbstraction() { } an_object[an_object_key] ~= line ~= "\n"; an_object["lev"] ~= m.captures[1]; - assertions_doc_structure(an_object, lv); // includes most of the logic for collapsed levels + assertions_doc_structure(an_object, an_object_key, lv); // includes most of the logic for collapsed levels switch (an_object["lev"]) { case "A": // Title set if ((an_object[an_object_key].match(rgx.variable_doc_title_author_date)) @@ -6165,173 +6160,568 @@ template docAbstraction() { /+ ↓ abstraction functions assertions +/ @safe pure void assertions_doc_structure()( string[string] an_object, + string an_object_key, int[string] lv ) { + string msg_error_doc_struct = "\nERROR in document structure, check markup (heading level relationships):\n"; if (lv["h3"] > eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); - assert(lv["h2"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h2"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else if (lv["h2"] > eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else if (lv["h1"] > eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else if (lv["h0"] > eN.bi.off) { - assert(lv["h1"] == eN.bi.off); - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h1"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else { - assert(lv["h0"] == eN.bi.off); - assert(lv["h1"] == eN.bi.off); - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h0"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h1"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h7"] > eN.bi.off) { - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); - assert(lv["h6"] > eN.bi.off); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h6"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else if (lv["h6"] > eN.bi.off) { - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else if (lv["h5"] > eN.bi.off) { - assert(lv["h4"] > eN.bi.off); - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else if (lv["h4"] > eN.bi.off) { - assert(lv["h5"] == eN.bi.off); - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h5"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } else { - assert(lv["h4"] == eN.bi.off); - assert(lv["h5"] == eN.bi.off); - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h4"] == eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h0"] == eN.bi.off) { - assert(lv["h1"] == eN.bi.off); - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); - assert(lv["h4"] == eN.bi.off); - assert(lv["h5"] == eN.bi.off); - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h1"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h4"] == eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h1"] == eN.bi.off) { - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h2"] == eN.bi.off) { - assert(lv["h3"] == eN.bi.off); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h3"] == eN.bi.off) { } if (lv["h4"] == eN.bi.off) { - assert(lv["h5"] == eN.bi.off); - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h5"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h5"] == eN.bi.off) { - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h6"] == eN.bi.off) { - assert(lv["h7"] == eN.bi.off); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ an_object[an_object_key] + ); } if (lv["h7"] == eN.bi.off) { } switch ((an_object["lev"]).to!string) { case "A": if (lv["h0"] == eN.bi.off) { - assert(lv["h1"] == eN.bi.off); - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); - assert(lv["h4"] == eN.bi.off); - assert(lv["h5"] == eN.bi.off); - assert(lv["h6"] == eN.bi.off); - assert(lv["h7"] == eN.bi.off); + assert(lv["h1"] == eN.bi.off, + msg_error_doc_struct + ~ "at level A~\n" + ~ an_object[an_object_key] + ); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ "at level A~\n" + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ "at level A~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] == eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~\n" + ~ "at level A~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] == eN.bi.off, + msg_error_doc_struct + ~ "at level A~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ "at level A~\n" + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ "at level A~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h0"] > eN.bi.off) - assert(lv["h0"] == eN.bi.off,"error should not enter level A a second time"); + assert(lv["h0"] == eN.bi.off, + msg_error_doc_struct + ~ "should not enter level A a second time\n" + ~ "at level A~\n" + ~ an_object[an_object_key] + ); } break; case "B": if (lv["h1"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h2"] == eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level B~\n" + ~ an_object[an_object_key] + ); + assert(lv["h2"] == eN.bi.off, + msg_error_doc_struct + ~ "at level B~\n" + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ "at level B~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h1"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level B~\n" + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ "at level B~\n" + ~ an_object[an_object_key] + ); } break; case "C": if (lv["h2"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); - assert(lv["h3"] == eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level C~\n" + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ "level C should not follow level A\n" + ~ "at level C~\n" + ~ an_object[an_object_key] + ); + assert(lv["h3"] == eN.bi.off, + msg_error_doc_struct + ~ "at level C~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h2"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); - assert(lv["h2"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level C~\n" + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ "at level C~\n" + ~ an_object[an_object_key] + ); + assert(lv["h2"] > eN.bi.off, + msg_error_doc_struct + ~ "at level C~\n" + ~ an_object[an_object_key] + ); } break; case "D": if (lv["h3"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); - assert(lv["h2"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level D~\n" + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ "level D should not follow level A\n" + ~ "at level D~\n" + ~ an_object[an_object_key] + ); + assert(lv["h2"] > eN.bi.off, + msg_error_doc_struct + ~ "at level D~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h3"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h1"] > eN.bi.off); - assert(lv["h2"] > eN.bi.off); - assert(lv["h3"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level D~\n" + ~ an_object[an_object_key] + ); + assert(lv["h1"] > eN.bi.off, + msg_error_doc_struct + ~ "at level D~\n" + ~ an_object[an_object_key] + ); + assert(lv["h2"] > eN.bi.off, + msg_error_doc_struct + ~ "at level D~\n" + ~ an_object[an_object_key] + ); + assert(lv["h3"] > eN.bi.off, + msg_error_doc_struct + ~ "at level D~\n" + ~ an_object[an_object_key] + ); } break; case "1": if (lv["h4"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] == eN.bi.off, + msg_error_doc_struct + ~ "at level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ "at level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ "at level 1~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h4"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 1~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 1~\n" + ~ an_object[an_object_key] + ); } break; case "2": if (lv["h5"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] == eN.bi.off, + msg_error_doc_struct + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h5"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 2~\n" + ~ an_object[an_object_key] + ); } break; case "3": if (lv["h6"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 2~ ?\n" + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); + assert(lv["h7"] == eN.bi.off, + msg_error_doc_struct + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h6"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); - assert(lv["h6"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 3~\n" + ~ an_object[an_object_key] + ); } break; case "4": if (lv["h7"] == eN.bi.off) { - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); - assert(lv["h6"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 2~ ?\n" + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 3~ ?\n" + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); } else { // (lv["h7"] > eN.bi.off) - assert(lv["h0"] > eN.bi.off); - assert(lv["h4"] > eN.bi.off); - assert(lv["h5"] > eN.bi.off); - assert(lv["h6"] > eN.bi.off); - assert(lv["h7"] > eN.bi.off); + assert(lv["h0"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h4"] > eN.bi.off, + msg_error_doc_struct + ~ "missing segment level 1~ ?\n" + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h5"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h6"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); + assert(lv["h7"] > eN.bi.off, + msg_error_doc_struct + ~ "at level 4~\n" + ~ an_object[an_object_key] + ); } break; default: -- cgit v1.2.3