From 4c6c9216390f7dee4552846ee17f2bcb3402b43c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 20 Oct 2015 21:55:11 -0400 Subject: .d files made, emacs org babel tangle run on .org files --- lib/sdp/ao_abstract_doc_source.d | 215 ++++++++++++++++++++++++++------------- 1 file changed, 143 insertions(+), 72 deletions(-) (limited to 'lib/sdp/ao_abstract_doc_source.d') diff --git a/lib/sdp/ao_abstract_doc_source.d b/lib/sdp/ao_abstract_doc_source.d index 2fec35d..303011b 100644 --- a/lib/sdp/ao_abstract_doc_source.d +++ b/lib/sdp/ao_abstract_doc_source.d @@ -1,10 +1,12 @@ /* -#+OPTIONS: ^:nil _:nil#+OPTIONS: ^:nil _:nil -* sisu_abstract_doc_source.d + document abstraction + ao_abstract_doc_source.d */ mixin template SiSUdocAbstraction() { class Abstraction { + /* abstract marked up document */ auto abstract_doc_source(char[][] markup_sourcefile_content) { + /* initialize */ mixin ObjectSetters; mixin AssertionsOnMarkupDocumentStructure; mixin AssertionsOnBlocks; @@ -134,6 +136,8 @@ mixin template SiSUdocAbstraction() { auto dochead_make = parseJSON(header_make_jsonstr).object; auto dochead_metadata = parseJSON(header_metadata_jsonstr).object; foreach (line; markup_sourcefile_content) { + /* loop markup document/text line by line */ + /* scope */ scope(exit) { } scope(failure) { @@ -143,8 +147,11 @@ mixin template SiSUdocAbstraction() { writeln(" node: ", node); } line = replaceAll(line, rgx.true_dollar, "$$$$"); + // dollar represented as $$ needed to stop submatching on $ + // (substitutions using ${identifiers} must take into account (e.g. happen earlier)) debug(source) { // source lines writeln(line); + // writeln(scr_txt_marker["green"], line); } debug(srclines) { if (!line.empty) { // source lines, not empty @@ -152,7 +159,9 @@ mixin template SiSUdocAbstraction() { } } if ((!line.empty) && (ft["ocn_status_multi_obj"] == 0)) { + /* not multi-line object, check whether ocn is on or turned off */ if (match(line, rgx.ocn_block_marks)) { + /* switch off ocn */ if (match(line, rgx.ocn_off_block)) { ft["ocn_status_multi_obj"] = 1; debug(ocnoff) { @@ -189,6 +198,7 @@ mixin template SiSUdocAbstraction() { } } if (ft["code"] == 1) { + /* block object: code */ if (ft["curly_code"] == 1) { if (auto m = match(line, rgx.block_curly_code_close)) { debug(code) { // code (curly) close @@ -219,10 +229,12 @@ mixin template SiSUdocAbstraction() { } } } else if (!match(line, rgx.regular_parse_skip)) { + /* object other than code block object (includes regular text paragraph) */ if (((match(line, rgx.heading_biblio) || (ft["heading_biblio"] == 1))) && (!match(line, rgx.heading)) && (!match(line, rgx.comment))) { + /* within block object: biblio */ if (match(line, rgx.heading_biblio)) { ft["heading_biblio"] = 1; } @@ -303,6 +315,7 @@ mixin template SiSUdocAbstraction() { biblio_tag_entry=""; } } else if (ft["poem"] == 1) { + /* within block object: poem */ if (ft["curly_poem"] == 1) { if (auto m = match(line, rgx.block_curly_poem_close)) { object["obj"]="verse"; // check that this is as you please @@ -498,6 +511,7 @@ mixin template SiSUdocAbstraction() { } } } + /* within block object: group */ } else if (ft["group"] == 1) { if (ft["curly_group"] == 1) { if (auto m = match(line, rgx.block_curly_group_close)) { @@ -529,6 +543,7 @@ mixin template SiSUdocAbstraction() { } } } else if (ft["block"] == 1) { + /* within block object: block */ if (ft["curly_block"] == 1) { if (auto m = match(line, rgx.block_curly_block_close)) { debug(block) { // block (curly) close @@ -559,6 +574,7 @@ mixin template SiSUdocAbstraction() { } } } else if (ft["quote"] == 1) { + /* within block object: quote */ if (ft["curly_quote"] == 1) { if (auto m = match(line, rgx.block_curly_quote_close)) { debug(quote) { // quote (curly) close @@ -589,6 +605,7 @@ mixin template SiSUdocAbstraction() { } } } else if (ft["table"] == 1) { + /* within block object: table */ if (ft["curly_table"] == 1) { if (auto m = match(line, rgx.block_curly_table_close)) { debug(table) { // table (curly) close @@ -619,6 +636,7 @@ mixin template SiSUdocAbstraction() { } } } else { + /* not within a block group */ assert( (ft["blocks"] == 0) || (ft["blocks"] == 2), @@ -626,6 +644,7 @@ mixin template SiSUdocAbstraction() { ); assertions_flag_types_block_status_none_or_closed(ft); if (auto m = match(line, rgx.block_curly_code_open)) { + /* curly code open */ debug(code) { // code (curly) open writeln( scr_txt_color["blue"], @@ -638,6 +657,7 @@ mixin template SiSUdocAbstraction() { ft["code"] = 1; ft["curly_code"] = 1; } else if (auto m = match(line, rgx.block_curly_poem_open)) { + /* curly poem open */ object.remove("obj"); object.remove("markup"); object.remove("is"); @@ -658,6 +678,7 @@ mixin template SiSUdocAbstraction() { ft["poem"] = 1; ft["curly_poem"] = 1; } else if (auto m = match(line, rgx.block_curly_group_open)) { + /* curly group open */ debug(group) { // group (curly) open writeln( scr_txt_color["blue"], @@ -670,6 +691,7 @@ mixin template SiSUdocAbstraction() { ft["group"] = 1; ft["curly_group"] = 1; } else if (auto m = match(line, rgx.block_curly_block_open)) { + /* curly block open */ debug(block) { // block (curly) open writeln( scr_txt_color["blue"], @@ -682,6 +704,7 @@ mixin template SiSUdocAbstraction() { ft["block"] = 1; ft["curly_block"] = 1; } else if (auto m = match(line, rgx.block_curly_quote_open)) { + /* curly quote open */ debug(quote) { // quote (curly) open writeln( scr_txt_color["blue"], @@ -694,6 +717,7 @@ mixin template SiSUdocAbstraction() { ft["quote"] = 1; ft["curly_quote"] = 1; } else if (auto m = match(line, rgx.block_curly_table_open)) { + /* curly table open */ debug(table) { // table (curly) open writeln( scr_txt_color["blue"], @@ -706,6 +730,7 @@ mixin template SiSUdocAbstraction() { ft["table"] = 1; ft["curly_table"] = 1; } else if (auto m = match(line, rgx.block_tic_code_open)) { + /* tic code open */ debug(code) { // code (tic) open writeln( scr_txt_color["blue"], @@ -718,6 +743,7 @@ mixin template SiSUdocAbstraction() { ft["code"] = 1; ft["tic_code"] = 1; } else if (auto m = match(line, rgx.block_tic_poem_open)) { + /* tic poem open */ object.remove("obj"); object.remove("markup"); object.remove("is"); @@ -738,6 +764,7 @@ mixin template SiSUdocAbstraction() { ft["poem"] = 1; ft["tic_poem"] = 1; } else if (auto m = match(line, rgx.block_tic_group_open)) { + /* tic group open */ debug(group) { // group (tic) open writeln( scr_txt_color["blue"], @@ -750,6 +777,7 @@ mixin template SiSUdocAbstraction() { ft["group"] = 1; ft["tic_group"] = 1; } else if (auto m = match(line, rgx.block_tic_block_open)) { + /* tic block open */ debug(block) { // block (tic) open writeln( scr_txt_color["blue"], @@ -762,6 +790,7 @@ mixin template SiSUdocAbstraction() { ft["block"] = 1; ft["tic_block"] = 1; } else if (auto m = match(line, rgx.block_tic_quote_open)) { + /* tic quote open */ debug(quote) { // quote (tic) open writeln( scr_txt_color["blue"], @@ -774,6 +803,7 @@ mixin template SiSUdocAbstraction() { ft["quote"] = 1; ft["tic_quote"] = 1; } else if (auto m = match(line, rgx.block_tic_table_open)) { + /* tic table open */ debug(table) { // table (tic) open writeln( scr_txt_color["blue"], @@ -786,6 +816,8 @@ mixin template SiSUdocAbstraction() { ft["table"] = 1; ft["tic_table"] = 1; } else if (!line.empty) { + /* line not empty */ + /* non blocks (headers, paragraphs) & closed blocks */ assert( !line.empty, "line tested, line not empty surely" @@ -796,6 +828,7 @@ mixin template SiSUdocAbstraction() { "code block status: none or closed" ); if (ft["blocks"] == 2) { + // blocks closed, unless followed by book index debug(check) { // block writeln(__LINE__); tell_l("red", line); @@ -807,14 +840,17 @@ mixin template SiSUdocAbstraction() { ); } if (auto m = match(line, rgx.book_index)) { + /* match book_index */ debug(bookindexmatch) { // book index writeln( scr_txt_color["blue"], "* [bookindex] ", scr_txt_color["off"], to!string(m.captures[1]), "\n" ); + // writeln(scr_txt_marker["blue"], to!string(m.captures[1]), "\n"); } object["bookindex"] = to!string(m.captures[1]); } else if (auto m = match(line, rgx.book_index_open)) { + /* match open book_index */ ft["book_index"] = 1; book_idx_tmp = to!string(m.captures[1]); debug(bookindexmatch) { // book index @@ -826,6 +862,7 @@ mixin template SiSUdocAbstraction() { ); } } else if (ft["book_index"] == 1 ) { + /* book_index flag set */ if (auto m = match(line, rgx.book_index_close)) { ft["book_index"] = 0; object["bookindex"] = book_idx_tmp ~ to!string(m.captures[1]); @@ -842,7 +879,9 @@ mixin template SiSUdocAbstraction() { book_idx_tmp ~= line; } } else { + /* not book_index */ if (auto m = match(line, rgx.comment)) { + /* matched comment */ debug(comment) { tell_l("blue", line); } @@ -866,6 +905,7 @@ mixin template SiSUdocAbstraction() { ft["para"] = 0; counter++; } else if (auto m = match(line, rgx.header_make)) { + /* matched header_make */ debug(header1) { // header tell_l("yellow", line); } @@ -877,6 +917,7 @@ mixin template SiSUdocAbstraction() { line_occur["header_make"]++; object["obj"] ~= line ~= "\n"; } else if (auto m = match(line, rgx.header_metadata)) { + /* matched header_metadata */ debug(header1) { // header tell_l("yellow", line); } @@ -889,8 +930,10 @@ mixin template SiSUdocAbstraction() { object["obj"] ~= line ~= "\n"; } else if (ft["header_make"] == 1 && (line_occur["header_make"] > 0)) { + /* header_make flag set */ if (auto m = match(line, rgx.header_sub)) { - debug(header1) { // header sub + /* sub-header */ + debug(header1) { tell_l("yellow", line); } line_occur["header_make"]++; @@ -898,8 +941,10 @@ mixin template SiSUdocAbstraction() { } } else if (ft["header_metadata"] == 1 && (line_occur["header_metadata"] > 0)) { + /* header_metadata flag set */ if (auto m = match(line, rgx.header_sub)) { - debug(header1) { // header sub + /* sub-header */ + debug(header1) { tell_l("yellow", line); } line_occur["header_metadata"]++; @@ -909,8 +954,10 @@ mixin template SiSUdocAbstraction() { && (line_occur["heading"] == 0)) && ((ft["para"] == 0) && (ft["heading"] == 0))) { + /* heading or para but neither flag nor line exists */ if ((to!string(dochead_make["make"]["headings"]).length > 2) && (ft["make_headings"] == 0)) { + /* headings found */ debug(headingsfound) { writeln(dochead_make["make"]["headings"]); } @@ -979,6 +1026,7 @@ mixin template SiSUdocAbstraction() { && (line_occur["heading"] == 0)) && ((ft["para"] == 0) && (ft["heading"] == 0))) { + /* heading make set */ if (match(line, rgx_h_B)) { line = "B~ " ~ line; debug(headingsfound) { @@ -1023,6 +1071,7 @@ mixin template SiSUdocAbstraction() { } } if (auto m = match(line, rgx.heading)) { + /* heading match */ ft["heading"] = 1; ft["header"] = 0; ft["header_make"] = 0; @@ -1145,6 +1194,7 @@ mixin template SiSUdocAbstraction() { tell_l("yellow", strip(line)); } } else if (line_occur["para"] == 0) { + /* para matches */ if (auto m = match(line, rgx.para_indent)) { debug(paraindent) { // para indent tell_l("blue", line); @@ -1191,25 +1241,31 @@ mixin template SiSUdocAbstraction() { line_occur["para"]++; } } else if (line_occur["header_make"] > 0) { - debug(header) { // para + /* header_make */ + // should be caught by sub-header + debug(header) { tell_l("red", line); } object["obj"] ~= line ~= "\n"; line_occur["header_make"]++; } else if (line_occur["header_metadata"] > 0) { + /* header_metadata */ + // should be caught by sub-header debug(header) { // para tell_l("red", line); } object["obj"] ~= line ~= "\n"; line_occur["header_metadata"]++; } else if (line_occur["heading"] > 0) { + /* heading */ debug(heading) { // heading tell_l("blue", line); } object["obj"] ~= line ~= "\n"; line_occur["heading"]++; } else if (line_occur["para"] > 0) { - debug(para) { // para + /* paragraph */ + debug(para) { tell_l("blue", line); } object["obj"] ~= line; @@ -1217,6 +1273,7 @@ mixin template SiSUdocAbstraction() { } } } else if (ft["blocks"] == 2) { + /* line empty, with blocks flag */ assert( line.empty, "line should be empty" @@ -1427,6 +1484,8 @@ mixin template SiSUdocAbstraction() { ft["quote"] = 0; } } else { + /* line empty */ + /* line.empty, post contents, empty variables: */ assert( line.empty, "line should be empty" @@ -1437,6 +1496,7 @@ mixin template SiSUdocAbstraction() { ); if ((ft["header_make"] == 1) && (line_occur["header_make"] > 0)) { + /* header_make instructions (current line empty) */ auto dochead_metadata_and_make = set_header.header_metadata_and_make_jsonstr(strip(object["obj"]), dochead_metadata, dochead_make); static assert(!isTypeTuple!(dochead_metadata_and_make)); @@ -1457,6 +1517,7 @@ mixin template SiSUdocAbstraction() { processing.remove("verse"); } else if ((ft["header_metadata"] == 1) && (line_occur["header_metadata"] > 0)) { + /* header_metadata (current line empty) */ auto dochead_metadata_and_make = set_header.header_metadata_and_make_jsonstr(strip(object["obj"]), dochead_metadata, dochead_make); static assert(!isTypeTuple!(dochead_metadata_and_make)); @@ -1479,6 +1540,7 @@ mixin template SiSUdocAbstraction() { processing.remove("verse"); } else if ((ft["heading"] == 1) && (line_occur["heading"] > 0)) { + /* heading object (current line empty) */ ocn = ocn_emit(ft["ocn_status"]); object["bookindex"] = ("bookindex" in object) ? object["bookindex"] : ""; @@ -1508,6 +1570,7 @@ mixin template SiSUdocAbstraction() { object["lvn"], object["lcn"] ); + // track previous heading and make assertions debug(objectrelated1) { // check tell_l("blue", line); } @@ -1530,6 +1593,7 @@ mixin template SiSUdocAbstraction() { processing.remove("verse"); counter++; } else if ((ft["para"] == 1) && (line_occur["para"] > 0)) { + /* paragraph object (current line empty) */ ocn = ocn_emit(ft["ocn_status"]); object["bookindex"] = ("bookindex" in object) ? object["bookindex"] : ""; @@ -1582,43 +1646,49 @@ mixin template SiSUdocAbstraction() { line == null, "line variable should be empty, should not occur" ); + // check what happens when paragraph separated by 2 newlines } - } - } - } + } // close else for line empty + } // close else for not the above + } // close after non code, other blocks or regular text if (((contents_arbitrary_max_length_set[counter-1]["is"] == "para") || (contents_arbitrary_max_length_set[counter-1]["is"] == "heading")) && (counter-1 > previous_count)) { if (match(contents_arbitrary_max_length_set[counter-1]["obj"], rgx.inline_notes_delimiter_al_regular_number_note)) { + // endnotes/ footnotes for + // doc objects other than paragraphs & headings + // various forms of grouped text previous_count=counter-1; notesection.gather_notes_for_endnote_section(contents_arbitrary_max_length_set, counter-1); } } - } + } // closed: loop markup document/text line by line + /* post loop markup document/text */ debug(objectrelated2) { // check tell_l("blue", line); } -/* - Backmatter: - * endnotes - * glossary - * references / bibliography - * book index -*/ + /* + Backmatter: + * endnotes + * glossary + * references / bibliography + * book index + */ obj_im.obj_inline_markup("doc_end_reset", ""); auto en_tuple = notesection.endnote_objects(ocn); static assert(!isTypeTuple!(en_tuple)); auto endnotes = en_tuple[0]; ocn = en_tuple[1]; -debug(endnotes) { - writeln(__LINE__, " ", endnotes.length); - foreach (n; endnotes) { - writeln(n); - } -} + debug(endnotes) { + writeln(__LINE__, " ", endnotes.length); + foreach (n; endnotes) { + writeln(n); + } + } auto contents = contents_arbitrary_max_length_set[0..counter].dup; auto biblio_unsorted_incomplete = biblio_arr_json[0..count_biblio_entry].dup; + // destroy(biblio_arr_json); auto biblio = new Bibliography(); auto biblio_ordered = biblio.bibliography(biblio_unsorted_incomplete); auto bi = new BookIndexReportSection(); @@ -1628,56 +1698,57 @@ debug(endnotes) { auto bookindex = bi_tuple[0]; auto document = contents ~ endnotes ~ bookindex; ocn = bi_tuple[1]; -debug(bookindex) { // bookindex - foreach (bi_entry; bookindex) { - writeln(bi_entry["obj"]); - } -} -debug(heading) { // heading - string spc; - foreach (o; document) { - if (o["is"] == "heading") { - switch (o["lvn"]) { - case "0": - spc=""; - break; - case "1": - spc=" "; - break; - case "2": - spc=" "; - break; - case "3": - spc=" "; - break; - case "4": - spc=" "; - break; - case "5": - spc=" "; - break; - case "6": - spc=" "; - break; - case "7": - spc=" "; - break; - case "8": - spc=" "; - break; - default: - spc=""; - break; + debug(bookindex) { // bookindex + foreach (bi_entry; bookindex) { + writeln(bi_entry["obj"]); + } + } + debug(heading) { // heading + string spc; + foreach (o; document) { + if (o["is"] == "heading") { + switch (o["lvn"]) { + case "0": + spc=""; + break; + case "1": + spc=" "; + break; + case "2": + spc=" "; + break; + case "3": + spc=" "; + break; + case "4": + spc=" "; + break; + case "5": + spc=" "; + break; + case "6": + spc=" "; + break; + case "7": + spc=" "; + break; + case "8": + spc=" "; + break; + default: + spc=""; + break; + } + writeln( + spc, "* ", " ", + strip(o["obj"]), + "\n ", + o["attrib"] + ); + // tell_l("yellow", spc, strip(o["obj"])); + } + } } - writeln( - spc, "* ", " ", - strip(o["obj"]), - "\n ", - o["attrib"] - ); - } - } -} destroy(contents); destroy(endnotes); destroy(bookindex); -- cgit v1.2.3