From ed302d1be74d2b4e69ee4b6e3834637ed531eaea Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 24 Apr 2016 22:08:24 -0400 Subject: step1 --- org/ao_abstract_doc_source.org | 369 +++++---- org/ao_assertions.org | 6 +- org/ao_defaults.org | 76 +- org/ao_emitter.org | 1568 +++++++++++++++++++++++++++++++++++ org/ao_emitters_and_interfaces.org | 1601 ------------------------------------ org/ao_object_setter.org | 121 ++- org/ao_output_debugs.org | 177 ++-- org/ao_read_markup_source.org | 8 +- org/ao_rgx.org | 42 +- org/ao_scan_inserts.org | 128 ++- org/ao_structs.org | 71 ++ org/ao_utils.org | 4 +- org/compile_time_info.org | 101 +++ org/sdp.org | 211 +++-- 14 files changed, 2486 insertions(+), 1997 deletions(-) create mode 100644 org/ao_emitter.org delete mode 100644 org/ao_emitters_and_interfaces.org create mode 100644 org/ao_structs.org create mode 100644 org/compile_time_info.org (limited to 'org') diff --git a/org/ao_abstract_doc_source.org b/org/ao_abstract_doc_source.org index 5356a15..a89b14c 100644 --- a/org/ao_abstract_doc_source.org +++ b/org/ao_abstract_doc_source.org @@ -15,7 +15,7 @@ * document abstraction :abstract: [[./sdp.org][sdp]] [[./][org/]] Process markup document, create document abstraction. -** initialize +** initialize :initialize: #+name: abs_init #+BEGIN_SRC d /+ initialize +/ @@ -23,19 +23,20 @@ mixin ObjectSetters; mixin AssertionsOnMarkupDocumentStructure; mixin AssertionsOnBlocks; mixin ScreenTxtColors; -auto rgx = new Rgx(); -auto set_oa = new ObjectAbstractSet(); -auto set_header = new HeaderDocMetadataMakeJson(); -auto notesection = new NotesSection(); -string[string][131072] contents_arbitrary_max_length_set; // 2000 pg * 50 lines == 100000 -string[1024] notes; +auto rgx = Rgx(); +auto set_oa = ObjectAbstractSet(); +auto set_header = HeaderDocMetadataMakeJson(); +auto notesection = NotesSection(); +string[string][] contents; +mixin Structs; string notes_str; string[string] object, processing, head; string biblio_tag_name, biblio_tag_entry, book_idx_tmp, st; -string[1024] biblio_arr_json = biblio_entry_tags_jsonstr; -JSONValue[1024] bib_arr_json; +string[] biblio_arr_json; +JSONValue[] bib_arr_json; uint[string] line_occur; -uint counter, previous_count, count_biblio_entry, ocn, ocn_, verse_line, bib_entry, heading_pointer, notepoint; +uint counter, ocn, ocn_, verse_line, bib_entry, heading_pointer, notepoint, count_biblio_entry; +ulong previous_count; string indent_first, indent_second; string[][string][string] bookindex_unordered_hashes; bool bullet = true; @@ -79,18 +80,18 @@ auto str_h_3 = "^(none)"; auto str_h_4 = "^(none)"; string content_non_header = "8"; string node; -auto obj_im = new ObjInlineMarkup(); -auto obj_att = new ObjAttrib(); -auto object_citation_number = new OCNemitter(); +auto obj_im = ObjInlineMarkup(); +auto obj_att = ObjAttrib(); +auto object_citation_number = OCNemitter(); auto ft = flag_type.dup; int ocn_emit(int ocn_status_flag) { return object_citation_number.ocn_emitter(ocn_status_flag); } -auto bookindex_extract_hash = new BookIndexNuggetHash(); +auto bookindex_extract_hash = BookIndexNuggetHash(); string[][string][string] bkidx_hash(string bookindex, int ocn) { return bookindex_extract_hash.bookindex_nugget_hash(bookindex, ocn); } -auto node_construct = new NodeStructureMetadata(); +auto node_construct = NodeStructureMetadata(); string node_jstr( string lvn, int ocn_, @@ -128,11 +129,20 @@ string[string] ocn_poem = [ "end" : "" ]; int tell_lo(string color, int ocn, in char[] line) { - writeln(scr_txt_marker[color], to!string(ocn), " ", to!string(line)); + writefln( + "%s%s %s", + scr_txt_marker[color], + to!string(ocn), + to!string(line) + ); return 0; } int tell_l(string color, in char[] line) { - writeln(scr_txt_marker[color], line); + writefln( + "%s%s", + scr_txt_marker[color], + line + ); return 0; } scope(success) { @@ -140,7 +150,7 @@ scope(success) { scope(failure) { } scope(exit) { - destroy(contents_arbitrary_max_length_set); + destroy(contents); destroy(object); destroy(processing); destroy(biblio_arr_json); @@ -153,14 +163,16 @@ auto dochead_metadata = parseJSON(header_metadata_jsonstr).object; *** scope :scope: #+name: abs_loop_body_00 #+BEGIN_SRC d -/* scope */ +/+ scope +/ scope(exit) { } scope(failure) { - writeln(__FILE__, ":", __LINE__, " failed here:"); - writeln(" line: ", line); - writeln(" is : ", object["is"]); - writeln(" node: ", node); + writefln( + "%s:%s failed here: \n line: %s", + __FILE__, + __LINE__, + line, + ); } line = replaceAll(line, rgx.true_dollar, "$$$$"); // dollar represented as $$ needed to stop submatching on $ @@ -171,7 +183,11 @@ debug(source) { // source lines } debug(srclines) { if (!line.empty) { // source lines, not empty - writeln(scr_txt_marker["green"], line); + writefln( + "%s%s", + scr_txt_marker["green"], + line + ); } } #+END_SRC @@ -179,9 +195,9 @@ debug(srclines) { #+name: abs_loop_body_00 #+BEGIN_SRC d if ((!line.empty) && (ft["ocn_status_multi_obj"] == 0)) { -/* not multi-line object, check whether ocn is on or turned off */ +/+ not multi-line object, check whether ocn is on or turned off +/ if (match(line, rgx.ocn_block_marks)) { - /* switch off ocn */ + /+ switch off ocn +/ if (match(line, rgx.ocn_off_block)) { ft["ocn_status_multi_obj"] = 1; debug(ocnoff) { @@ -223,7 +239,7 @@ if ((!line.empty) && (ft["ocn_status_multi_obj"] == 0)) { #+name: abs_loop_body_00 #+BEGIN_SRC d if (ft["code"] == 1) { -/* block object: code */ +/+ block object: code +/ if (ft["curly_code"] == 1) { if (auto m = match(line, rgx.block_curly_code_close)) { debug(code) { // code (curly) close @@ -258,7 +274,7 @@ if (ft["code"] == 1) { #+name: abs_loop_body_00 #+BEGIN_SRC d } else if (!match(line, rgx.regular_parse_skip)) { -/* object other than code block object (includes regular text paragraph) */ +/+ object other than code block object (includes regular text paragraph) +/ #+END_SRC ***** within block group [+1] :block:active: ****** within block group: biblio :biblio: @@ -268,21 +284,20 @@ if (((match(line, rgx.heading_biblio) || (ft["heading_biblio"] == 1))) && (!match(line, rgx.heading)) && (!match(line, rgx.comment))) { -/* within block object: biblio */ +/+ within block object: biblio +/ if (match(line, rgx.heading_biblio)) { ft["heading_biblio"] = 1; } if (empty(line) && (bib_entry == 0)) { - count_biblio_entry++; + ++count_biblio_entry; + biblio_arr_json ~= biblio_entry_tags_jsonstr; bib_entry = 1; } debug(biblio) { - writeln( + writefln( + "%s * %s %s", scr_txt_color["yellow"], - "* ", scr_txt_color["off"], - to!string(count_biblio_entry), - " ", line ); } @@ -291,7 +306,7 @@ if (((match(line, rgx.heading_biblio) bib_entry = 0; st=to!string(bt.captures[1]); biblio_tag_entry=to!string(bt.captures[2]); - JSONValue j = parseJSON(biblio_arr_json[count_biblio_entry]); + JSONValue j = parseJSON(biblio_arr_json[count_biblio_entry-1]); // core.exception.RangeError@lib/sdp/ao_abstract_doc_source.d(288): Range violation (LDC) [: same for 343], fix to subtract 1 done! if (match(st, rgx.biblio_abbreviations)) { biblio_tag_name=biblio_tag_map[st]; } else { @@ -334,18 +349,17 @@ if (((match(line, rgx.heading_biblio) auto s = to!string(j); s = j.toString(); debug(biblio) { - writeln( + writefln( + "%s* %s%s: %s\n%s", scr_txt_color["red"], - "* ", scr_txt_color["off"], biblio_tag_name, - ": ", - biblio_tag_entry + biblio_tag_entry, + j[biblio_tag_name] ); - writeln(biblio_arr_json[count_biblio_entry]); writeln(j[biblio_tag_name], ":", j[biblio_tag_name]); } - biblio_arr_json[count_biblio_entry] = s; + biblio_arr_json[count_biblio_entry-1] = s; biblio_tag_entry=""; } #+END_SRC @@ -353,14 +367,14 @@ if (((match(line, rgx.heading_biblio) #+name: abs_loop_body_non_code_obj #+BEGIN_SRC d } else if (ft["poem"] == 1) { -/* within block object: poem */ +/+ 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 debug(poem) { // poem (curly) close - writeln( + writefln( + "%s* [poem curly] %s%s", scr_txt_color["red"], - "* [poem curly] ", scr_txt_color["off"], line ); @@ -370,10 +384,10 @@ if (((match(line, rgx.heading_biblio) } debug(poem) { // poem (curly) close writeln(__LINE__); - writeln( + writefln( + "%s%s %s", scr_txt_marker["fuchsia"], ocn, - " ", line ); } @@ -392,7 +406,7 @@ if (((match(line, rgx.heading_biblio) obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -424,10 +438,12 @@ if (((match(line, rgx.heading_biblio) verse_line=1; object["obj"] = processing["verse"]; debug(poem) { // poem verse - writeln(scr_txt_marker["green"], - ocn, - " curly\n", - object["obj"]); + writefln( + "%s%s curly\n%s", + scr_txt_marker["green"], + ocn, + object["obj"] + ); } processing.remove("verse"); object["is"] = "verse"; @@ -440,7 +456,7 @@ if (((match(line, rgx.heading_biblio) ); object["markup"] = obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -460,9 +476,9 @@ if (((match(line, rgx.heading_biblio) if (auto m = match(line, rgx.block_tic_close)) { // tic_poem_close object["obj"]="verse"; // check that this is as you please debug(poem) { // poem (curly) close - writeln( + writefln( + "%s* [poem tic] %s%s", scr_txt_color["red"], - "* [poem tic] ", scr_txt_color["off"], line ); @@ -481,7 +497,7 @@ if (((match(line, rgx.heading_biblio) obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -513,10 +529,12 @@ if (((match(line, rgx.heading_biblio) verse_line=1; object["obj"] = processing["verse"]; debug(poem) { // poem (tic) close - writeln(scr_txt_marker["green"], - ocn, - " tic\n", - object["obj"]); + writefln( + "%s%s tic\n%s", + scr_txt_marker["green"], + ocn, + object["obj"] + ); } processing.remove("verse"); object["is"] = "verse"; @@ -532,7 +550,7 @@ if (((match(line, rgx.heading_biblio) obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -553,7 +571,7 @@ if (((match(line, rgx.heading_biblio) ****** within block group: group :group: #+name: abs_loop_body_non_code_obj #+BEGIN_SRC d -/* within block object: group */ +/+ within block object: group +/ } else if (ft["group"] == 1) { if (ft["curly_group"] == 1) { if (auto m = match(line, rgx.block_curly_group_close)) { @@ -589,7 +607,7 @@ if (((match(line, rgx.heading_biblio) #+name: abs_loop_body_non_code_obj #+BEGIN_SRC d } else if (ft["block"] == 1) { -/* within block object: block */ +/+ within block object: block +/ if (ft["curly_block"] == 1) { if (auto m = match(line, rgx.block_curly_block_close)) { debug(block) { // block (curly) close @@ -624,7 +642,7 @@ if (((match(line, rgx.heading_biblio) #+name: abs_loop_body_non_code_obj #+BEGIN_SRC d } else if (ft["quote"] == 1) { -/* within block object: quote */ +/+ within block object: quote +/ if (ft["curly_quote"] == 1) { if (auto m = match(line, rgx.block_curly_quote_close)) { debug(quote) { // quote (curly) close @@ -659,7 +677,7 @@ if (((match(line, rgx.heading_biblio) #+name: abs_loop_body_non_code_obj #+BEGIN_SRC d } else if (ft["table"] == 1) { -/* within block object: table */ +/+ within block object: table +/ if (ft["curly_table"] == 1) { if (auto m = match(line, rgx.block_curly_table_close)) { debug(table) { // table (curly) close @@ -694,7 +712,7 @@ if (((match(line, rgx.heading_biblio) #+name: abs_loop_body_non_code_obj #+BEGIN_SRC d } else { -/* not within a block group */ +/+ not within a block group +/ #+END_SRC ****** assert #+name: abs_loop_body_open_block_obj @@ -711,11 +729,11 @@ assertions_flag_types_block_status_none_or_closed(ft); #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d if (auto m = match(line, rgx.block_curly_code_open)) { -/* curly code open */ +/+ curly code open +/ debug(code) { // code (curly) open - writeln( + writefln( + "%s* [code curly] %s%s", scr_txt_color["blue"], - "* [code curly] ", scr_txt_color["off"], line ); @@ -728,7 +746,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_curly_poem_open)) { -/* curly poem open */ +/+ curly poem open +/ object.remove("obj"); object.remove("markup"); object.remove("is"); @@ -736,9 +754,9 @@ if (auto m = match(line, rgx.block_curly_code_open)) { object.remove("bookindex"); processing.remove("verse"); debug(poem) { // poem (curly) open - writeln( + writefln( + "%s* [poem curly] %s%s", scr_txt_color["red"], - "* [poem curly] ", scr_txt_color["off"], line ); @@ -753,11 +771,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_curly_group_open)) { -/* curly group open */ +/+ curly group open +/ debug(group) { // group (curly) open - writeln( + writefln( + "%s* [group curly] %s%s", scr_txt_color["blue"], - "* [group curly] ", scr_txt_color["off"], line ); @@ -770,11 +788,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_curly_block_open)) { -/* curly block open */ +/+ curly block open +/ debug(block) { // block (curly) open - writeln( + writefln( + "%s* [block curly] %s%s", scr_txt_color["blue"], - "* [block curly] ", scr_txt_color["off"], line ); @@ -787,11 +805,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_curly_quote_open)) { -/* curly quote open */ +/+ curly quote open +/ debug(quote) { // quote (curly) open - writeln( + writefln( + "%s* [quote curly] %s%s", scr_txt_color["blue"], - "* [quote curly] ", scr_txt_color["off"], line ); @@ -804,11 +822,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_curly_table_open)) { -/* curly table open */ +/+ curly table open +/ debug(table) { // table (curly) open - writeln( + writefln( + "%s* [table curly] %s%s", scr_txt_color["blue"], - "* [table curly] ", scr_txt_color["off"], line ); @@ -822,11 +840,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_tic_code_open)) { -/* tic code open */ +/+ tic code open +/ debug(code) { // code (tic) open - writeln( + writefln( + "%s* [code tic] %s%s", scr_txt_color["blue"], - "* [code tic] ", scr_txt_color["off"], line ); @@ -839,7 +857,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_tic_poem_open)) { -/* tic poem open */ +/+ tic poem open +/ object.remove("obj"); object.remove("markup"); object.remove("is"); @@ -847,9 +865,9 @@ if (auto m = match(line, rgx.block_curly_code_open)) { object.remove("bookindex"); processing.remove("verse"); debug(poem) { // poem (tic) open - writeln( + writefln( + "%s* [poem tic] %s%s", scr_txt_color["red"], - "* [poem tic] ", scr_txt_color["off"], line ); @@ -864,11 +882,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_tic_group_open)) { -/* tic group open */ +/+ tic group open +/ debug(group) { // group (tic) open - writeln( + writefln( + "%s* [group tic] %s%s", scr_txt_color["blue"], - "* [group tic] ", scr_txt_color["off"], line ); @@ -881,11 +899,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_tic_block_open)) { -/* tic block open */ +/+ tic block open +/ debug(block) { // block (tic) open - writeln( + writefln( + "%s* [block tic] %s%s", scr_txt_color["blue"], - "* [block tic] ", scr_txt_color["off"], line ); @@ -898,11 +916,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_tic_quote_open)) { -/* tic quote open */ +/+ tic quote open +/ debug(quote) { // quote (tic) open - writeln( + writefln( + "%s* [quote tic] %s%s", scr_txt_color["blue"], - "* [quote tic] ", scr_txt_color["off"], line ); @@ -915,11 +933,11 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_open_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.block_tic_table_open)) { -/* tic table open */ +/+ tic table open +/ debug(table) { // table (tic) open - writeln( + writefln( + "%s* [table tic] %s%s", scr_txt_color["blue"], - "* [table tic] ", scr_txt_color["off"], line ); @@ -932,8 +950,8 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (!line.empty) { -/* line not empty */ -/* non blocks (headers, paragraphs) & closed blocks */ +/+ line not empty +/ +/+ non blocks (headers, paragraphs) & closed blocks +/ #+END_SRC ******* asserts :assert: #+name: abs_loop_body_not_block_obj @@ -964,11 +982,13 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d if (auto m = match(line, rgx.book_index)) { - /* match 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" + writefln( + "%s* [bookindex] %s%s\n", + scr_txt_color["blue"], + scr_txt_color["off"], + to!string(m.captures[1]), ); // writeln(scr_txt_marker["blue"], to!string(m.captures[1]), "\n"); } @@ -978,24 +998,24 @@ if (auto m = match(line, rgx.block_curly_code_open)) { ft["book_index"] = 1; book_idx_tmp = to!string(m.captures[1]); debug(bookindexmatch) { // book index - writeln( + writefln( + "%s* [bookindex] %s%s\n", scr_txt_color["blue"], - "* [bookindex] ", scr_txt_color["off"], - book_idx_tmp, "\n" + book_idx_tmp, ); } } else if (ft["book_index"] == 1 ) { - /* book_index flag set */ + /+ 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]); debug(bookindexmatch) { // book index - writeln( + writefln( + "%s* [bookindex] %s%s\n", scr_txt_color["blue"], - "* [bookindex] ", scr_txt_color["off"], - book_idx_tmp, "\n" + book_idx_tmp, ); } book_idx_tmp = ""; @@ -1007,18 +1027,18 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else { - /* not book_index */ + /+ not book_index +/ #+END_SRC ******** matched: comment :comment:match: #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d if (auto m = match(line, rgx.comment)) { - /* matched comment */ + /+ matched comment +/ debug(comment) { tell_l("blue", line); } object["obj"] ~= line ~= "\n"; - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_comment(strip(object["obj"])); object.remove("obj"); object.remove("markup"); @@ -1041,7 +1061,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.header_make)) { - /* matched header_make */ + /+ matched header_make +/ debug(header1) { // header tell_l("yellow", line); } @@ -1057,7 +1077,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (auto m = match(line, rgx.header_metadata)) { - /* matched header_metadata */ + /+ matched header_metadata +/ debug(header1) { // header tell_l("yellow", line); } @@ -1074,9 +1094,9 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+BEGIN_SRC d } else if (ft["header_make"] == 1 && (line_occur["header_make"] > 0)) { - /* header_make flag set */ + /+ header_make flag set +/ if (auto m = match(line, rgx.header_sub)) { - /* sub-header */ + /+ sub-header +/ debug(header1) { tell_l("yellow", line); } @@ -1089,9 +1109,9 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+BEGIN_SRC d } else if (ft["header_metadata"] == 1 && (line_occur["header_metadata"] > 0)) { - /* header_metadata flag set */ + /+ header_metadata flag set +/ if (auto m = match(line, rgx.header_sub)) { - /* sub-header */ + /+ sub-header +/ debug(header1) { tell_l("yellow", line); } @@ -1106,14 +1126,14 @@ if (auto m = match(line, rgx.block_curly_code_open)) { && (line_occur["heading"] == 0)) && ((ft["para"] == 0) && (ft["heading"] == 0))) { - /* heading or para but neither flag nor line exists */ + /+ heading or para but neither flag nor line exists +/ #+END_SRC ********* headings found :heading: #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d if ((to!string(dochead_make["make"]["headings"]).length > 2) && (ft["make_headings"] == 0)) { - /* headings found */ + /+ headings found +/ debug(headingsfound) { writeln(dochead_make["make"]["headings"]); } @@ -1186,7 +1206,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { && (line_occur["heading"] == 0)) && ((ft["para"] == 0) && (ft["heading"] == 0))) { - /* heading make set */ + /+ heading make set +/ if (match(line, rgx_h_B)) { line = "B~ " ~ line; debug(headingsfound) { @@ -1235,7 +1255,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d if (auto m = match(line, rgx.heading)) { - /* heading match */ + /+ heading match +/ ft["heading"] = 1; ft["header"] = 0; ft["header_make"] = 0; @@ -1362,7 +1382,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["para"] == 0) { - /* para matches */ + /+ para matches +/ if (auto m = match(line, rgx.para_indent)) { debug(paraindent) { // para indent tell_l("blue", line); @@ -1413,7 +1433,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["header_make"] > 0) { - /* header_make */ + /+ header_make +/ // should be caught by sub-header debug(header) { tell_l("red", line); @@ -1425,7 +1445,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["header_metadata"] > 0) { - /* header_metadata */ + /+ header_metadata +/ // should be caught by sub-header debug(header) { // para tell_l("red", line); @@ -1437,7 +1457,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["heading"] > 0) { - /* heading */ + /+ heading +/ debug(heading) { // heading tell_l("blue", line); } @@ -1448,7 +1468,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["para"] > 0) { - /* paragraph */ + /+ paragraph +/ debug(para) { tell_l("blue", line); } @@ -1461,7 +1481,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else if (ft["blocks"] == 2) { -/* line empty, with blocks flag */ +/+ line empty, with blocks flag +/ assert( line.empty, "line should be empty" @@ -1490,7 +1510,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -1520,7 +1540,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { heading_pointer-1, object["is"] ); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block_ocn_string( "poem", "", @@ -1554,7 +1574,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -1587,7 +1607,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -1620,7 +1640,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -1654,7 +1674,7 @@ if (auto m = match(line, rgx.block_curly_code_open)) { obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_block( object["is"], object["markup"], @@ -1676,12 +1696,12 @@ if (auto m = match(line, rgx.block_curly_code_open)) { #+name: abs_loop_body_not_block_obj #+BEGIN_SRC d } else { -/* line empty */ +/+ line empty +/ #+END_SRC ******* assert line empty :assert: #+name: abs_loop_body_not_block_obj_line_empty #+BEGIN_SRC d -/* line.empty, post contents, empty variables: */ +/+ line.empty, post contents, empty variables: +/ assert( line.empty, "line should be empty" @@ -1696,7 +1716,7 @@ assert( #+BEGIN_SRC d if ((ft["header_make"] == 1) && (line_occur["header_make"] > 0)) { -/* header_make instructions (current line empty) */ +/+ 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)); @@ -1721,7 +1741,7 @@ if ((ft["header_make"] == 1) #+BEGIN_SRC d } else if ((ft["header_metadata"] == 1) && (line_occur["header_metadata"] > 0)) { -/* header_metadata (current line empty) */ +/+ 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)); @@ -1748,7 +1768,7 @@ if ((ft["header_make"] == 1) #+BEGIN_SRC d } else if ((ft["heading"] == 1) && (line_occur["heading"] > 0)) { -/* heading object (current line empty) */ +/+ heading object (current line empty) +/ ocn = ocn_emit(ft["ocn_status"]); object["bookindex"] = ("bookindex" in object) ? object["bookindex"] : ""; @@ -1769,7 +1789,7 @@ if ((ft["header_make"] == 1) object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); heading_pointer++; - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_heading( ft["ocn_status"], object["markup"], @@ -1805,7 +1825,7 @@ if ((ft["header_make"] == 1) #+name: abs_loop_body_not_block_obj_line_empty #+BEGIN_SRC d } else if ((ft["para"] == 1) && (line_occur["para"] > 0)) { -/* paragraph object (current line empty) */ +/+ paragraph object (current line empty) +/ ocn = ocn_emit(ft["ocn_status"]); object["bookindex"] = ("bookindex" in object) ? object["bookindex"] : ""; @@ -1824,7 +1844,7 @@ if ((ft["header_make"] == 1) obj_im.obj_inline_markup(object["is"], object["obj"]); object["attrib"] = obj_att.obj_attributes(object["is"], object["obj"], node); - contents_arbitrary_max_length_set[counter] = + contents ~= set_oa.contents_para( object["is"], object["markup"], @@ -1871,16 +1891,19 @@ if ((ft["header_make"] == 1) *** regular text objects #+name: abs_loop_body_01 #+BEGIN_SRC d -if (((contents_arbitrary_max_length_set[counter-1]["is"] == "para") -|| (contents_arbitrary_max_length_set[counter-1]["is"] == "heading")) +if (((contents[$-1]["is"] == "para") +|| (contents[$-1]["is"] == "heading")) && (counter-1 > previous_count)) { - if (match(contents_arbitrary_max_length_set[counter-1]["obj"], + if (match(contents[$-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); + previous_count=contents.length -1; + notesection.gather_notes_for_endnote_section( + contents, + contents.length -1 + ); } } #+END_SRC @@ -1891,30 +1914,32 @@ if (((contents_arbitrary_max_length_set[counter-1]["is"] == "para") debug(objectrelated2) { // check tell_l("blue", line); } -/* +/+ 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); + writefln( + "%s %s", + __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(); +auto biblio_unsorted_incomplete = biblio_arr_json.dup; +auto biblio = Bibliography(); +auto biblio_ordered = biblio.bibliography(biblio_unsorted_incomplete, bib_arr_json); +auto bi = BookIndexReportSection(); auto bi_tuple = bi.bookindex_build_section(bookindex_unordered_hashes, ocn); static assert(!isTypeTuple!(bi_tuple)); @@ -1962,10 +1987,10 @@ debug(heading) { // heading spc=""; break; } - writeln( - spc, "* ", " ", + writefln( + "%s* $s\n %s", + spc, strip(o["obj"]), - "\n ", o["attrib"] ); // tell_l("yellow", spc, strip(o["obj"])); @@ -1990,17 +2015,19 @@ return t; ** code structure: :ao_abstract_doc_source.d: #+name: tangle_ao_abstract_doc_source #+BEGIN_SRC d :tangle ../lib/sdp/ao_abstract_doc_source.d -/* +/+ document abstraction ao_abstract_doc_source.d -*/ ++/ mixin template SiSUdocAbstraction() { - class Abstraction { - /* abstract marked up document */ + private: + struct Abstraction { + /+ ↓ abstract marked up document +/ auto abstract_doc_source(char[][] markup_sourcefile_content) { <> + /+ ↓ loop markup document/text line by line +/ foreach (line; markup_sourcefile_content) { - /* loop markup document/text line by line */ + /+ ↓ markup document/text line by line +/ <> <> <> @@ -2008,8 +2035,8 @@ mixin template SiSUdocAbstraction() { <> <> <> - } // closed: loop markup document/text line by line - /* post loop markup document/text */ + } /+ ← closed: loop markup document/text line by line +/ + /+ ↓ post loop markup document/text +/ <> } } diff --git a/org/ao_assertions.org b/org/ao_assertions.org index 0502d46..948bb5e 100644 --- a/org/ao_assertions.org +++ b/org/ao_assertions.org @@ -122,7 +122,7 @@ mixin template AssertionsOnMarkupDocumentStructure() { assert(lv["h5"] == 0); assert(lv["h6"] == 0); assert(lv["h7"] == 0); - } else { + } else { // (lv["h0"] >0) assert(lv["h0"] == 0,"error should not enter level A a second time"); } break; @@ -244,9 +244,9 @@ mixin template AssertionsOnBlocks() { ** code structure: :ao_assertions.d: #+name: tangle_ao_assertions #+BEGIN_SRC d :tangle ../lib/sdp/ao_assertions.d -/* +/+ assertions ao_assertions.d -*/ ++/ <> #+END_SRC diff --git a/org/ao_defaults.org b/org/ao_defaults.org index 928bfa6..fc176d0 100644 --- a/org/ao_defaults.org +++ b/org/ao_defaults.org @@ -184,7 +184,7 @@ template SiSUheader() { ** template: flags regex initialize :regex_flags: #+name: ao_defaults_templates #+BEGIN_SRC d -/* regex flags */ +/+ regex flags +/ template SiSUrgxInitFlags() { int[string] flag_type = [ "make_headings" : 0, @@ -274,9 +274,77 @@ template SiSUbiblio() { #+name: ao_defaults_templates #+BEGIN_SRC d template InternalMarkup() { - class InternalMarkup { + struct InternalMarkup { auto en_a_o = "【"; auto en_a_c = "】"; auto en_b_o = "〖"; auto en_b_c = "〗"; + // auto segname_prefix_auto_num_extract = "c"; + // auto segname_prefix_auto_num_provide = "s"; + // auto segname_prefix_auto_num_other = "x"; + // auto ocn_id_char = ""; //'o'; now as before; remove for html5 + // auto note = "note_"; + // auto note_ref = "noteref_"; + // auto note_astx = "note_astx_"; + // auto note_ref_astx = "noteref_astx_"; + // auto note_plus = "note_plus_"; + // auto note_ref_plus = "noteref_plus_"; + // auto meta_o = "〔@"; auto meta_c = "〕"; + // auto lv_o_0 = 0; + // auto lv_o_1 = 1; + // auto lv_o_2 = 2; + // auto lv_o_3 = 3; + // auto lv_o_4 = 4; + // auto lv_o_5 = 5; + // auto lv_o_6 = 6; + // auto lv_o_7 = 7; + // auto lv_o_8 = 8; + // auto lv_o_9 = 9; + // auto lv_o = "〔"; auto lv_c = "〕"; + // auto bl_o = "〔"; auto bl_c = "〕"; // block text mark + // auto gr_o = "〔"; auto gr_c = "〕"; // group text mark #REPLACE & RETIRE + // auto id_o = "〔"; auto id_c = "〕"; // object id mark + // auto tc_o = "『"; auto tc_c = "』"; // table row mark #Mx[:tc_c]="』\n" + // auto tc_p = "┆'" + // auto pa_o = "〔"; auto pa_c = "〕"; // affects paragraph mark + // auto mk_o = "〔"; auto mk_c = "〕"; // generic mark + // auto gl_o = "〔"; auto gl_c = "〕"; // glyph + // auto fa_o = "〔"; auto fa_o_c = "¤"; auto fa_c_o = "¤"; auto fa_c = "〕"; + // auto idx_o = "▩"; auto idx_c = "▩"; + // auto nbsp = "░"; // '▭ ' + // auto br_line = "╱"; // lB ▌ 9612 ┘ ¶ + // auto br_nl = "╲"; // lB ▌ 』 ┘ + // auto br_paragraph = "█"; // FB █ 9608 # PP ∥ 8741 #▐ #'┘' #'¶' #FB █ 9608 lB ▌ 9612 RB ▐ 9616 + // auto br_obj = "break_obj"; + // auto br_page_line = "▭"; + // auto br_page = "┼"; + // auto br_page_new = "╋"; + // auto lnk_o = "⌠"; lnk_c = "⌡"; // '⌈' '⌋' '⌠' '⌡' #Mx[:lnk_o= '◁'; Mx[:lnk_c= '▷' #‹ › + // auto url_o = "◘"; auto url_c = "◙"; + // auto rel_o = "⌈"; auto rel_c = "⌋"; + // auto tag_o = "⌊"; auto tag_c = "⌉"; + // auto sm_set_o = "◢"; auto sm_set_c = "◣"; + // auto sm_subset_o = "◢"; auto sm_subset_c = "◣"; + // auto vline = "┆"; // ¦ | + // auto src_bold_o = "!{"; auto src_bold_c = "}!"; + // auto src_italics_o = "/{"; auto src_italics_c = "}/"; + // auto src_underscore_o = "_{"; auto src_underscore_c = "}_"; + // auto src_cite_o = ""{"; auto src_cite_c = "}""; + // auto src_insert_o = "+{"; auto src_insert_c = "}+"; + // auto src_strike_o = "-{"; auto src_strike_c = "}-"; + // auto src_superscript_o = "^{"; auto src_superscript_c = "}^"; + // auto src_subscript_o = ";{"; auto src_subscript_c = "}'" + // auto src_hilite_o = "*{"; auto src_hilite_c = "}*"; + // auto src_monospace_o = "#{"; auto src_monospace_c = "}#"; + // auto srcrgx_bold_o = "\\!\\{"; auto srcrgx_bold_c = "\\}\\!"; + // auto srcrgx_italics_o = "\\/\\{"; auto srcrgx_italics_c = "\\}\\/"; + // auto srcrgx_underscore_o = "_\\{"; auto srcrgx_underscore_c = "\\}_"; + // auto srcrgx_cite_o = "\"\\{"; auto srcrgx_cite_c = "\\}\""; + // auto srcrgx_insert_o = "\\+\\{"; auto srcrgx_insert_c = "\\}\\+"; + // auto srcrgx_strike_o = "\\-\\{"; auto srcrgx_strike_c = "\\}\\-"; + // auto srcrgx_superscript_o = "\\^\\{"; auto srcrgx_superscript_c = "\\}\\^"; + // auto srcrgx_subscript_o = ",\\{"; auto srcrgx_subscript_c = "\\},"; + // auto srcrgx_hilite_o = "\\*\\{"; auto srcrgx_hilite_c = "\\}\\*"; + // auto srcrgx_monospace_o = "\\#\\{"; auto srcrgx_monospace_c = "\\}\\#"; + // ⊹ } } #+END_SRC @@ -285,9 +353,9 @@ template InternalMarkup() { ** code structure: :ao_defaults.d: #+name: tangle_ao_defaults #+BEGIN_SRC d :tangle ../lib/sdp/ao_defaults.d -/* +/+ defaults ao_defaults.d -*/ ++/ <> #+END_SRC diff --git a/org/ao_emitter.org b/org/ao_emitter.org new file mode 100644 index 0000000..0ecbc2e --- /dev/null +++ b/org/ao_emitter.org @@ -0,0 +1,1568 @@ +#+TITLE: sdp emitters & interfaces +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:dev:ao: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +* emitters +[[./sdp.org][sdp]] +ao_emitter.d +various emitters and their interfaces (where available) +** command line interface/instructions +#+name: ao_emitter +#+BEGIN_SRC d +struct CLI { + string[string] extract_actions(string cmdlnins, string[string] actions) + in { } + body { + switch (cmdlnins) { + case "--no-assert": + actions["assert"] = "no"; + break; + default: + break; + } + return actions; + } +} +#+END_SRC +** ocn +#+name: ao_emitter +#+BEGIN_SRC d +struct OCNemitter { +// class OCNemitter : AssertOCN { + int ocn, ocn_; + int ocn_emitter(int ocn_status_flag) + in { assert(ocn_status_flag <= 2); } + body { + if (ocn_status_flag == 0) { + ocn=++ocn_; + } else { + ocn=0; + } + assert(ocn >= 0); + return ocn; + } + invariant() { + } +} +#+END_SRC +** object attributes +#+name: ao_emitter +#+BEGIN_SRC d +struct ObjAttributes { +// class ObjAttributes : AssertObjAttributes { + string[string] obj_txt; + string para_and_blocks(string obj_txt_in) + in { } + body { + auto rgx = Rgx(); + obj_txt["munge"]=obj_txt_in; + if (match(obj_txt_in, rgx.para_bullet)) { + obj_txt["attrib"] =" \"bullet\": \"true\"," + ~ " \"indent_first\": 0," + ~ " \"indent_rest\": 0,"; + } else if (auto m = match(obj_txt_in, rgx.para_bullet_indent)) { + obj_txt["attrib"] =" \"bullet\": \"true\"," + ~ " \"indent_first\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; + } else if (auto m = match(obj_txt_in, rgx.para_indent_hang)) { + obj_txt["attrib"] =" \"bullet\": \"false\"," + ~ " \"indent_first\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[2]) ~ ","; + } else if (auto m = match(obj_txt_in, rgx.para_indent)) { + obj_txt["attrib"] =" \"bullet\": \"false\"," + ~ " \"indent_first\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; + } else { + obj_txt["attrib"] =" \"bullet\": \"false\"," + ~ " \"indent_first\": 0," + ~ " \"indent_rest\": 0,"; + } + return obj_txt["attrib"]; + } + string para(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"para\""; + return obj_txt["attrib"]; + } + invariant() { + } + string heading(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"heading\""; + // obj_txt["struct"]=; + return obj_txt["attrib"]; + } + invariant() { + } + string header_make(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"head\"," + ~ " \"of\": \"header\"," + ~ " \"is\": \"header_make\""; + return obj_txt["attrib"]; + } + invariant() { + } + string header_metadata(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"head\"," + ~ " \"of\": \"header\"," + ~ " \"is\": \"header_metadata\""; + return obj_txt["attrib"]; + } + invariant() { + } + string code(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"code\""; + return obj_txt["attrib"]; + } + invariant() { + } + string group(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"group\""; + return obj_txt["attrib"]; + } + invariant() { + } + string block(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"block\""; + return obj_txt["attrib"]; + } + invariant() { + } + string verse(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"verse\""; + return obj_txt["attrib"]; + } + invariant() { + } + string quote(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"quote\""; + return obj_txt["attrib"]; + } + invariant() { + } + string table(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"table\""; + return obj_txt["attrib"]; + } + invariant() { + } + string comment(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["attrib"] = " \"use\": \"comment\"," + ~ " \"of\": \"comment\"," + ~ " \"is\": \"comment\""; + return obj_txt["attrib"]; + } + invariant() { + } +} +#+END_SRC +** object inline markup munge +#+name: ao_emitter +#+BEGIN_SRC d +struct ObjInlineMarkupMunge { +// struct ObjInlineMarkupMunge : AssertObjInlineMarkup { + string[string] obj_txt; + int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; + string obj_txt_out, tail, note; + private auto initialize_note_numbers() { + n_foot = 0; + n_foot_reg = 0; + n_foot_sp_asterisk = 0; + n_foot_sp_plus = 0; + } + private auto object_notes_(string obj_txt_in) + in { } + body { + auto rgx = Rgx(); + auto mkup = InternalMarkup(); + obj_txt_out = ""; + tail = ""; + obj_txt_in = replaceAll( + obj_txt_in, + rgx.inline_notes_curly_sp_asterisk, + (mkup.en_a_o ~ "*" ~ " $1" ~ mkup.en_a_c) + ); + obj_txt_in = + replaceAll( + obj_txt_in, + rgx.inline_notes_curly_sp_plus, + (mkup.en_a_o ~ "+" ~ " $1" ~ mkup.en_a_c) + ); + obj_txt_in = + replaceAll( + obj_txt_in, + rgx.inline_notes_curly, + (mkup.en_a_o ~ " $1" ~ mkup.en_a_c) + ); + if (match(obj_txt_in, rgx.inline_notes_al_gen)) { + foreach(m; matchAll(obj_txt_in, rgx.inline_text_and_note_al)) { + if (match(obj_txt_in, rgx.inline_al_delimiter_open_asterisk)) { + n_foot_sp_asterisk++; + n_foot=n_foot_sp_asterisk; + } else if (match(obj_txt_in, rgx.inline_al_delimiter_open_plus)) { + n_foot_sp_plus++; + n_foot=n_foot_sp_plus; + } else { + n_foot_reg++; + n_foot=n_foot_reg; + } + obj_txt_out ~= replaceFirst( + m.hit, + rgx.inline_al_delimiter_open_regular, + (mkup.en_a_o ~ to!string(n_foot)) + ); + tail = m.post; + // if (!empty(m.post)) { + // tail = m.post; + // } else { + // tail = ""; + // } + } + } else { + obj_txt_out = obj_txt_in; + } + debug(footnotes) { + writeln(obj_txt_out, tail); + } + obj_txt_out = obj_txt_out ~ tail; + debug(footnotesdone) { + foreach(m; matchAll(obj_txt_out, + (mkup.en_a_o ~ `\s*(.+?)` ~ mkup.en_a_c))) { + writeln(m.captures[1]); + writeln(m.hit); + } + } + return obj_txt_out; + } + string para(string obj_txt_in) + in { } + body { + auto rgx = Rgx(); + obj_txt["munge"]=obj_txt_in; + obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.para_attribs, ""); + obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.ocn_off_all, ""); + obj_txt["munge"]=object_notes_(obj_txt["munge"]); + debug(munge) { + writeln(__LINE__); + writeln(obj_txt_in); + writeln(__LINE__); + writeln(to!string(obj_txt["munge"])); + } + return obj_txt["munge"]; + } + string heading(string obj_txt_in) + in { } + body { + auto rgx = Rgx(); + obj_txt["munge"]=obj_txt_in; + obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading, ""); + obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.ocn_off_all, ""); + obj_txt["munge"]=object_notes_(obj_txt["munge"]); + debug(munge) { + writeln(__LINE__); + writeln(obj_txt_in); + writeln(__LINE__); + writeln(to!string(obj_txt["munge"])); + } + return obj_txt["munge"]; + } + invariant() { + } + string header_make(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string header_metadata(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string code(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string group(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["munge"]=object_notes_(obj_txt["munge"]); + return obj_txt["munge"]; + } + invariant() { + } + string block(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["munge"]=object_notes_(obj_txt["munge"]); + return obj_txt["munge"]; + } + invariant() { + } + string verse(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + obj_txt["munge"]=object_notes_(obj_txt["munge"]); + return obj_txt["munge"]; + } + invariant() { + } + string quote(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string table(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string comment(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } +} +#+END_SRC +** object inline markup +#+name: ao_emitter +#+BEGIN_SRC d +struct ObjInlineMarkup { +// struct ObjInlineMarkup : AssertObjInlineMarkup { + auto munge = ObjInlineMarkupMunge(); + string[string] obj_txt; + string obj_inline_markup(string obj_is_, string obj_raw) + in { } + body { + obj_txt["munge"]=obj_raw.dup; + obj_txt["munge"]=(match(obj_is_, ctRegex!(`verse|code`))) + ? obj_txt["munge"] + : strip(obj_txt["munge"]); + switch (obj_is_) { + case "header_make": + obj_txt["munge"]=munge.header_make(obj_txt["munge"]); + break; + case "header_metadata": + obj_txt["munge"]=munge.header_metadata(obj_txt["munge"]); + break; + case "heading": + obj_txt["munge"]=munge.heading(obj_txt["munge"]); + break; + case "para": + obj_txt["munge"]=munge.para(obj_txt["munge"]); + break; + case "code": + obj_txt["munge"]=munge.code(obj_txt["munge"]); + break; + case "group": + obj_txt["munge"]=munge.group(obj_txt["munge"]); + break; + case "block": + obj_txt["munge"]=munge.block(obj_txt["munge"]); + break; + case "verse": + obj_txt["munge"]=munge.verse(obj_txt["munge"]); + break; + case "quote": + obj_txt["munge"]=munge.quote(obj_txt["munge"]); + break; + case "table": + obj_txt["munge"]=munge.table(obj_txt["munge"]); + break; + case "comment": + obj_txt["munge"]=munge.comment(obj_txt["munge"]); + break; + case "doc_end_reset": + munge.initialize_note_numbers(); + break; + default: + break; + } + return obj_txt["munge"]; + } + invariant() { + } +} +#+END_SRC +** object attrib +#+name: ao_emitter +#+BEGIN_SRC d +struct ObjAttrib { +// struct ObjAttrib : AssertObjAttrib { +// auto sink = appender!(char[])(); + auto attrib = ObjAttributes(); + string[string] obj_attrib; + string obj_attributes(string obj_is_, string obj_raw, string node) + in { } + body { + // string s = "{ \"language\": \"D\", \"rating\": 3.14, \"code\": \"42\" }"; + scope(exit) { + // destroy(obj_is_); + destroy(obj_raw); + destroy(node); + } + JSONValue node_j = parseJSON(node); + obj_attrib.remove("json"); + obj_attrib["json"] ="{"; + switch (obj_is_) { + case "header_make": + obj_attrib["json"] ~= attrib.header_make(obj_raw); + break; + case "header_metadata": + obj_attrib["json"] ~= attrib.header_metadata(obj_raw); + break; + case "heading": + obj_attrib["json"] ~= attrib.heading(obj_raw); // + break; + case "para": + obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) + ~ attrib.para(obj_raw); + break; + case "code": + obj_attrib["json"] ~= attrib.code(obj_raw); + break; + case "group": + obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) + ~ attrib.group(obj_raw); + break; + case "block": + obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) + ~ attrib.block(obj_raw); + break; + case "verse": + obj_attrib["json"] ~= attrib.verse(obj_raw); + break; + case "quote": + obj_attrib["json"] ~= attrib.quote(obj_raw); + break; + case "table": + obj_attrib["json"] ~= attrib.table(obj_raw); + break; + case "comment": + obj_attrib["json"] ~= attrib.comment(obj_raw); + break; + default: + obj_attrib["json"] ~= attrib.para(obj_raw); + break; + } + obj_attrib["json"] ~=" }"; + JSONValue oa_j = parseJSON(obj_attrib["json"]); + assert( + (oa_j.type == JSON_TYPE.OBJECT) && + (node_j.type == JSON_TYPE.OBJECT) + ); + if (obj_is_ == "heading") { + oa_j.object["ocn"] = node_j["ocn"]; + oa_j.object["lvn"] = node_j["lvn"]; + oa_j.object["lcn"] = node_j["lcn"]; + oa_j.object["heading_pointer"] = + node_j["heading_pointer"]; // check + oa_j.object["doc_object_pointer"] = + node_j["doc_object_pointer"]; // check + } + oa_j.object["parent_ocn"] = node_j["parent_ocn"]; + oa_j.object["parent_lvn"] = node_j["parent_lvn"]; + obj_attrib["json"] = oa_j.toString(); + debug(structattrib) { + if (oa_j["is"].str() == "heading") { + // writeln(__LINE__); + writeln(obj_attrib["json"]); + // writeln(node); + writeln( + "is: ", oa_j["is"].str(), + "; ocn: ", oa_j["ocn"].integer() + ); + } + } + // obj_attrib["json"]="{}"; + return obj_attrib["json"]; + } + invariant() { + } +} +#+END_SRC +** header document metadata in json +#+name: ao_emitter +#+BEGIN_SRC d +struct HeaderDocMetadataMakeJson { +// class HeaderMetadataMakeHash : AssertHeaderMetadataMakeJson { + auto rgx = Rgx(); + string hm, hs; + auto header_metadata_and_make_jsonstr( + string header, + JSONValue[string] dochead_metadata, + JSONValue[string] dochead_make + ) + in { } + body { + scope(exit) { + destroy(header); + destroy(dochead_metadata); + destroy(dochead_make); + } + if (auto t = match(header, rgx.head_main)) { + char[][] obj_spl = split( + cast(char[]) header, + rgx.line_delimiter_ws_strip + ); + auto hm = to!string(t.captures[1]); + if (match(hm, rgx.main_headers)) { + foreach (line; obj_spl) { + if (auto m = match(line, rgx.head_main)) { + if (!empty(m.captures[2])) { + if (hm == "creator") { + dochead_metadata[hm]["author"].str = + to!string(m.captures[2]); + } else if (hm == "title") { + dochead_metadata[hm]["main"].str = + to!string(m.captures[2]); + } else if (hm == "publisher") { + dochead_metadata[hm]["name"].str = + to!string(m.captures[2]); + } + } + } else if (auto s = match(line, rgx.head_sub)) { + if (!empty(s.captures[2])) { + auto hs = to!string(s.captures[1]); + if ((hm == "make" ) + && (dochead_make[hm].type() == JSON_TYPE.OBJECT)) { + switch (hm) { + case "make": + if (match(hs, rgx.subhead_make)) { + if (dochead_make[hm][hs].type() == JSON_TYPE.STRING) { + dochead_make[hm][hs].str = to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + default: + break; + } + } else if (dochead_metadata[hm].type() == JSON_TYPE.OBJECT) { + switch (hm) { + case "creator": + if (match(hs, rgx.subhead_creator)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "title": + if (match(hs, rgx.subhead_title)) { + if ((hs == "subtitle") + && (dochead_metadata[hm]["sub"].type() == JSON_TYPE.STRING)) { + dochead_metadata[hm]["sub"].str = + to!string(s.captures[2]); + } else if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "rights": + if (match(hs, rgx.subhead_rights)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "date": + if (match(hs, rgx.subhead_date)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "original": + if (match(hs, rgx.subhead_original)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "classify": + if (match(hs, rgx.subhead_classify)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "identifier": + if (match(hs, rgx.subhead_identifier)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "notes": + if (match(hs, rgx.subhead_notes)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "publisher": + if (match(hs, rgx.subhead_publisher)) { + if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + dochead_metadata[hm][hs].str = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "links": + destroy(hm); + destroy(hs); + // if (match(hs, rgx.subhead_links)) { + // if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { + // dochead_metadata[hm][hs].str = to!string(s.captures[2]); + // } + // } else { + // writeln("not a valid header type:", hm, ":", hs); + // destroy(hm); + // destroy(hs); + // } + break; + default: + break; + } + } + } + } + } + } else { + writeln("not a valid header type:", hm); + } + } + auto t = tuple(dochead_metadata, dochead_make); + static assert(!isTypeTuple!(t)); + return t; + } + // invariant() { + // } +} +#+END_SRC +** header document metadata as hash +#+name: ao_emitter +#+BEGIN_SRC d +class HeaderMetadataMakeHash { +// class HeaderMetadataMakeHash : AssertHeaderMetadataMakeHash { + auto rgx = Rgx(); + string header_main; + string[string] head; + string[string] header_topic_hash(string header) + in { } + body { + if (auto t = match(header, rgx.head_main)) { + char[][] obj_spl = split( + cast(char[]) header, + rgx.line_delimiter_ws_strip + ); + auto header_main = to!string(t.captures[1]); + head[header_main] = "{"; + foreach (line; obj_spl) { + if (auto m = match(line, rgx.head_main)) { + if (!empty(m.captures[2])) { + head[header_main] ~= + "\"" ~ header_main ~ + "\": \"" ~ + to!string(m.captures[2]) ~ + "\","; + } + } else if (auto s = match(line, rgx.head_sub)) { + head[header_main] ~= "\"" ~ s.captures[1] ~ "\":"; + if (!empty(s.captures[2])) { + head[header_main] ~= "\"" ~ s.captures[2] ~ "\","; + } + } + } + head[header_main] = replaceFirst( + head[header_main], + rgx.tailing_comma, + "" + ); + head[header_main] ~= "}"; + debug(headerjson) { + JSONValue j = parseJSON(head[header_main]); + assert( + (j.type == JSON_TYPE.OBJECT) + ); + } + } + return head; + } + invariant() { + } +} +#+END_SRC +** book index nugget hash +#+name: ao_emitter +#+BEGIN_SRC d +struct BookIndexNuggetHash { +// class BookIndexNuggetHash : AssertBookIndexNuggetHash { + string main_term, sub_term, sub_term_bits; + uint ocn_offset, ocn_endpoint; + string[] ocns; + string[][string][string] bi; + string[][string][string] hash_nugget; + string[] bi_main_terms_split_arr; + string[][string][string] bookindex_nugget_hash(string bookindex, int ocn) + in { + debug(bookindexraw) { + mixin ScreenTxtColors; + if (!bookindex.empty) { + writeln( + scr_txt_color["blue"], "* [bookindex] ", scr_txt_color["off"], + "[", to!string(ocn), "] ", bookindex + ); + } + } + } + body { + auto rgx = Rgx(); + if (!bookindex.empty) { + auto bi_main_terms_split_arr = + split(bookindex, rgx.bi_main_terms_split); + foreach (bi_main_terms_content; bi_main_terms_split_arr) { + auto bi_main_term_and_rest = + split(bi_main_terms_content, rgx.bi_main_term_plus_rest_split); + if (auto m = match( + bi_main_term_and_rest[0], + rgx.bi_term_and_ocns_match) + ) { + main_term = strip(m.captures[1]); + ocn_offset = to!uint(m.captures[2]); + ocn_endpoint=(ocn + ocn_offset); + ocns ~= (to!string(ocn) ~ "-" ~ to!string(ocn_endpoint)); + } else { + main_term = strip(bi_main_term_and_rest[0]); + ocns ~= to!string(ocn); + } + bi[main_term]["_a"] ~= ocns; + ocns=null; + if (bi_main_term_and_rest.length > 1) { + auto bi_sub_terms_split_arr = + split( + bi_main_term_and_rest[1], + rgx.bi_sub_terms_plus_ocn_offset_split + ); + foreach (sub_terms_bits; bi_sub_terms_split_arr) { + if (auto m = match(sub_terms_bits, rgx.bi_term_and_ocns_match)) { + sub_term = strip(m.captures[1]); + ocn_offset = to!uint(m.captures[2]); + ocn_endpoint=(ocn + ocn_offset); + ocns ~= (to!string(ocn) ~ " - " ~ to!string(ocn_endpoint)); + } else { + sub_term = strip(sub_terms_bits); + ocns ~= to!string(ocn); + } + if (!empty(sub_term)) { + bi[main_term][sub_term] ~= ocns; + } + ocns=null; + } + } + // ocns=null; + } + } + hash_nugget = bi; + // bi=null; // bi.init; // use to empty for each next object; else, harvest hashes at the end of the document + return hash_nugget; + } + invariant() { + } +} +#+END_SRC +** book index report +#+name: ao_emitter +#+BEGIN_SRC d +struct BookIndexReport { +// class BookIndexReport : AssertBookIndexReport { + int mkn, skn; + auto bookindex_report_sorted( + string[][string][string] bookindex_unordered_hashes + ) { + auto mainkeys=bookindex_unordered_hashes.byKey.array. + sort!("toLower(a) < toLower(b)", SwapStrategy.stable).release; + foreach (mainkey; mainkeys) { + auto subkeys=bookindex_unordered_hashes[mainkey].byKey.array. + sort!("toLower(a) < toLower(b)", SwapStrategy.stable).release; + foreach (subkey; subkeys) { + debug(bookindex) { + writeln( + mainkey, ": ", + subkey, ": ", + to!string(bookindex_unordered_hashes[mainkey][subkey]) + ); + } + // bookindex_the[mkn][mainkey][skn][subkey] ~= (bookindex_unordered_hashes[mainkey][subkey]); + skn++; + } + mkn++; + } + // return bookindex_the; + } +} +#+END_SRC +** book index report indented +#+name: ao_emitter +#+BEGIN_SRC d +struct BookIndexReportIndent { + int mkn, skn; + auto bookindex_report_indented( + string[][string][string] bookindex_unordered_hashes + ) { + auto mainkeys= + bookindex_unordered_hashes.byKey.array.sort().release; + foreach (mainkey; mainkeys) { + debug(bookindex) { + writeln(mainkey); + } + auto subkeys= + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + debug(bookindex) { + writeln(" ", subkey); + writeln(" ", to!string( + bookindex_unordered_hashes[mainkey][subkey] + )); + } + // bookindex_the[mkn][mainkey][skn][subkey] ~= (bookindex_unordered_hashes[mainkey][subkey]); + skn++; + } + mkn++; + } + } +} +#+END_SRC +** book index report section +#+name: ao_emitter +#+BEGIN_SRC d +struct BookIndexReportSection { + mixin ObjectSetters; + int mkn, skn; + auto rgx = Rgx(); + auto bookindex_write_section( + string[][string][string] bookindex_unordered_hashes + ) { + auto mainkeys=bookindex_unordered_hashes.byKey.array.sort().release; + foreach (mainkey; mainkeys) { + write("_0_1 !{", mainkey, "}! "); + foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { + auto go = replaceAll(ref_, rgx.book_index_go, "$1"); + write(" {", ref_, "}#", go, ", "); + } + writeln(" \\\\"); + bookindex_unordered_hashes[mainkey].remove("_a"); + auto subkeys= + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + write(" ", subkey, ", "); + foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { + auto go = replaceAll(ref_, rgx.book_index_go, "$1"); + write(" {", ref_, "}#", go, ", "); + } + writeln(" \\\\"); + skn++; + } + mkn++; + } + } + auto bookindex_build_section( + string[][string][string] bookindex_unordered_hashes, + int ocn + ) { + string type; + int type_heading; + string lev, lvn, lcn; + string attrib; + string indent_first; + string indent_second; + auto set_oa = ObjectAbstractSet(); + auto mainkeys = + bookindex_unordered_hashes.byKey.array.sort().release; + string bi_tmp; + string[string][] bookindex; + writeln(mainkeys.length); + // B~ Book Index + type_heading=1; + bi_tmp = "Book Index"; + attrib=""; + lev="B"; + lvn="1"; + lcn="1"; + bookindex ~= + set_oa.contents_heading( + type_heading, + bi_tmp, + attrib, + ocn, + lev, + lvn, + lcn + ); + ocn++; + mkn++; + // 1~ Index + type_heading=1; + bi_tmp = "Index"; + attrib=""; + lev="1"; + lvn="4"; + lcn="2"; + bookindex ~= + set_oa.contents_heading( + type_heading, + bi_tmp, + attrib, + ocn, + lev, + lvn, + lcn + ); + ocn++; + mkn++; + foreach (mainkey; mainkeys) { + bi_tmp = "!{" ~ mainkey ~ "}! "; + // bi_tmp = "_0_1 !{" ~ mainkey ~ "}! "; + foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { + auto go = replaceAll(ref_, rgx.book_index_go, "$1"); + bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; + } + bi_tmp ~= " \\\\\n "; + bookindex_unordered_hashes[mainkey].remove("_a"); + auto subkeys = + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + bi_tmp ~= subkey ~ ", "; + foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { + auto go = replaceAll(ref_, rgx.book_index_go, "$1"); + bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; + } + bi_tmp ~= " \\\\\n "; + skn++; + } + bi_tmp = replaceFirst(bi_tmp, rgx.trailing_linebreak, ""); + type="para"; + attrib=""; + indent_first = "0"; + indent_second = "1"; + attrib=""; + bookindex ~= + set_oa.contents_para( + type, + bi_tmp, + attrib, + ocn, + indent_first, + indent_second, + false + ); + ocn++; + mkn++; + } + auto t = tuple(bookindex, ocn); + return t; + } + auto bookindex_build_section_( + string[][string][string] bookindex_unordered_hashes + ) { + auto mainkeys = + bookindex_unordered_hashes.byKey.array.sort().release; + string bi_tmp; + string[] bookindex; + // int bi_num; + writeln(mainkeys.length); + foreach (mainkey; mainkeys) { + bi_tmp = "_0_1 !{" ~ mainkey ~ "}! "; + foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { + auto go = replaceAll(ref_, rgx.book_index_go, "$1"); + bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; + } + bi_tmp ~= " \\\\\n "; + bookindex_unordered_hashes[mainkey].remove("_a"); + auto subkeys = + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + bi_tmp ~= subkey ~ ", "; + // bi_tmp ~= " " ~ subkey ~ ", "; + foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { + auto go = replaceAll(ref_, rgx.book_index_go, "$1"); + bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; + } + bi_tmp ~= " \\\\\n "; + skn++; + } + bi_tmp = replaceFirst(bi_tmp, rgx.trailing_linebreak, ""); + bookindex ~= bi_tmp; + mkn++; + } + return bookindex; + } +} +#+END_SRC +** (end)notes section +#+name: ao_emitter +#+BEGIN_SRC d +struct NotesSection { + mixin ObjectSetters; + string object_notes; + ulong previous_count; + int mkn; + auto rgx = Rgx(); + private auto gather_notes_for_endnote_section( + string[string][] contents_arbitrary_max_length_set, + ulong counter + ) + in { + // endnotes/ footnotes for + // doc objects other than paragraphs & headings + // various forms of grouped text + assert((contents_arbitrary_max_length_set[counter]["is"] == "para") + || (contents_arbitrary_max_length_set[counter]["is"] == "heading")); + assert(counter > previous_count); + previous_count=counter; + assert( + match(contents_arbitrary_max_length_set[counter]["obj"], + rgx.inline_notes_delimiter_al_regular_number_note) + ); + } + body { + foreach(m; + matchAll(contents_arbitrary_max_length_set[counter]["obj"], + rgx.inline_notes_delimiter_al_regular_number_note)) { + debug(endnotes_build) { + writeln( + "{^{", m.captures[1], ".}^}#noteref_", m.captures[1], " ", + m.captures[2]); // sometimes need segment name (segmented html & epub) + // writeln("{^{", m.captures[1], ".}^}#", contents_arbitrary_max_length_set[counter]["ocn"], " ", m.captures[2]); + } + object_notes ~= + "{^{" ~ m.captures[1] ~ ".}^}#noteref_" ~ + m.captures[1] ~ " " ~ m.captures[2] ~ "』"; + } + return object_notes; + } + private auto gathered_notes() + in { + } + body { + string[] endnotes_; + if (object_notes.length > 1) { + endnotes_ = (split(object_notes, rgx.break_string))[0..$-1]; + } + return endnotes_; + } + private auto endnote_objects(int ocn) + in { + } + body { + auto set_oa = ObjectAbstractSet(); + string[string][] endnotes; + auto endnotes_ = gathered_notes(); + // auto endnotes_ = (split(object_notes, rgx.break_string))[0..$-1]; + string type; + int type_heading; + string lev, lvn, lcn; + string attrib; + string indent_first; + string indent_second; + // B~ Endnotes + type_heading=1; + attrib=""; + lev="B"; + lvn="1"; + lcn="1"; + endnotes ~= + set_oa.contents_heading( + type_heading, + "Endnotes", + attrib, + ocn, + lev, + lvn, + lcn + ); + ocn++; + mkn++; + // 1~ Endnotes + type_heading=1; + attrib=""; + lev="1"; + lvn="4"; + lcn="2"; + endnotes ~= + set_oa.contents_heading( + type_heading, + "Endnotes", + attrib, + ocn, + lev, + lvn, + lcn + ); + ocn++; + mkn++; + foreach (endnote; endnotes_) { + type="para"; + attrib=""; + indent_first = "0"; + indent_second = "0"; + attrib=""; + endnotes ~= + set_oa.contents_para( + type, + endnote, + attrib, + ocn, + indent_first, + indent_second, + false + ); + ocn++; + mkn++; + } + auto t = tuple(endnotes, ocn); + return t; + } +} +#+END_SRC +** bibliography +#+name: ao_emitter +#+BEGIN_SRC d +struct Bibliography { + public JSONValue[] bibliography(ref string[] biblio_unsorted_incomplete, ref JSONValue[] bib_arr_json) + in { } + body { + JSONValue[] biblio_unsorted = + biblio_unsorted_complete(biblio_unsorted_incomplete, bib_arr_json); + JSONValue[] biblio_sorted = biblio_sort(biblio_unsorted); + biblio_debug(biblio_sorted); + return biblio_sorted; + } + final private JSONValue[] biblio_unsorted_complete( + string[] biblio_unordered, + ref JSONValue[] bib_arr_json + ) { + // JSONValue[] bib_arr_json; + // int count_biblio_entry; + // count_biblio_entry=0; // watch + foreach (bibent; biblio_unordered) { + // update bib to include deemed_author, needed for: + // sort_bibliography_array_by_deemed_author_year_title + // either: sort on multiple fields, or; create such sort field + JSONValue j = parseJSON(bibent); + if (!empty(j["fulltitle"].str)) { + if (!empty(j["author_raw"].str)) { + j["deemed_author"]=j["author_arr"][0]; + } else if (!empty(j["editor_raw"].str)) { + j["deemed_author"]=j["editor_arr"][0]; + } + j["sortby_deemed_author_year_title"] = ( + j["deemed_author"].str ~ + "; " ~ + j["year"].str ~ + "; " ~ + j["fulltitle"].str + ); + // bib[count_biblio_entry] = j.toString(); + } + bib_arr_json ~= j; + // count_biblio_entry++; + // bib_arr_json[count_biblio_entry] = j; + // count_biblio_entry++; + } + JSONValue[] biblio_unsorted_array_of_json_objects = + bib_arr_json.dup; + return biblio_unsorted_array_of_json_objects; + } + final private JSONValue[] biblio_sort(JSONValue[] biblio_unordered) { + JSONValue[] biblio_sorted; + biblio_sorted = + sort!((a, b){ + return ((a["sortby_deemed_author_year_title"].str) < (b["sortby_deemed_author_year_title"].str)); + })(biblio_unordered).array; + debug(bibliosorted) { + foreach (j; biblio_sorted) { + if (!empty(j["fulltitle"].str)) { + writeln(j["sortby_deemed_author_year_title"]); + // writeln(j["deemed_author"], " (", j["author"], ") ", j["fulltitle"]); + } + } + } + return biblio_sorted; + } + auto biblio_debug(JSONValue[] biblio_sorted) { + debug(biblio) { + foreach (j; biblio_sorted) { + if (!empty(j["fulltitle"].str)) { + writeln(j["sortby_deemed_author_year_title"]); + } + } + } + } +} +#+END_SRC +** node structure metadata +#+name: ao_emitter +#+BEGIN_SRC d +struct NodeStructureMetadata { +// class NodeStructureMetadata : AssertNodeJSON { + int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; + uint ocn; + uint[string] p_; // p_ parent_ + string node; + string node_emitter( + string lvn, + int ocn_, + int counter_, + int pointer_, + string is_ + ) + in { + auto rgx = Rgx(); + assert(is_ != "heading"); + assert(to!int(ocn_) >= 0); + } + body { + // scope(failure) { + // writeln(__FILE__, ":", __LINE__, " failed here:"); + // writeln(" is : ", is_); + // writeln(" node: ", node); + // } + assert(is_ != "heading"); // should not be necessary + assert(to!int(ocn_) >= 0); // should not be necessary + uint ocn=to!uint(ocn_); + if (lv7 > 0) { + p_["lvn"] = 7; p_["ocn"] = lv7; + } else if (lv6 > 0) { + p_["lvn"] = 6; p_["ocn"] = lv6; + } else if (lv5 > 0) { + p_["lvn"] = 5; p_["ocn"] = lv5; + } else { + p_["lvn"] = 4; p_["ocn"] = lv4; + } + node=("{ " ~ + "\"is\": \"" ~ is_ ~ "\"" ~ + ", \"heading_pointer\": " ~ to!string(pointer_) ~ + ", \"doc_object_pointer\": " ~ to!string(counter_) ~ + ", \"ocn\": " ~ to!string(ocn_) ~ + ", \"parent_ocn\": " ~ to!string(p_["ocn"]) ~ + ", \"parent_lvn\": " ~ to!string(p_["lvn"]) ~ + " }" + ); + debug(node) { + mixin ScreenTxtColors; + if (match(lvn, rgx.levels_numbered_headings)) { + writeln(scr_txt_marker["yellow"], to!string(node)); + } else { + writeln(scr_txt_marker["white"], to!string(node)); + } + } + JSONValue j = parseJSON(node); + assert(j["parent_lvn"].integer >= 4); + assert(j["parent_lvn"].integer <= 7); + assert(j["parent_ocn"].integer >= 0); + return node; + } + invariant() { + } +#+END_SRC + +#+name: ao_emitter +#+BEGIN_SRC d + string node_emitter_heading( + string lvn, + string lcn, + int ocn_, + int counter_, + int pointer_, + string is_ + ) + in { + auto rgx = Rgx(); + assert(is_ == "heading"); + assert(to!uint(ocn_) >= 0); + assert( + match(lvn, rgx.levels_numbered), + ("not a valid heading level: " ~ lvn ~ " at " ~ to!string(ocn_)) + ); + // assert(to!uint(ocn_) >= 0); + if (match(lvn, rgx.levels_numbered)) { + if (to!uint(lvn) == 0) { + assert(to!uint(ocn_) == 1); + // writeln(lvn); + } + } + } + body { + // scope(failure) { + // writeln(__FILE__, ":", __LINE__, " failed here:"); + // writeln(" is : ", is_); + // writeln(" node: ", node); + // } + auto rgx = Rgx(); + uint ocn=to!uint(ocn_); + switch (lvn) { // switch (to!string(lv)) { + case "0": + lv=0; + lv0=ocn; lv1=0; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lvn"] = 0; p_["ocn"] = 0; + break; + case "1": + lv=1; + lv1=ocn; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lvn"] = 0; p_["ocn"] = lv0; + break; + case "2": + lv=2; + lv2=ocn; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lvn"] = 1; p_["ocn"] = lv1; + break; + case "3": + lv=3; + lv3=ocn; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lvn"] = 2; p_["ocn"] = lv2; + break; + case "4": + lv=4; + lv4=ocn; lv5=0; lv6=0; lv7=0; + if (lv3 > 0) { + p_["lvn"] = 3; p_["ocn"] = lv3; + } else if (lv2 > 0) { + p_["lvn"] = 2; p_["ocn"] = lv2; + } else if (lv1 > 0) { + p_["lvn"] = 1; p_["ocn"] = lv1; + } else { + p_["lvn"] = 0; p_["ocn"] = lv0; + } + break; + case "5": + lv=5; + lv5=ocn; lv6=0; lv7=0; + p_["lvn"] = 4; p_["ocn"] = lv4; + break; + case "6": + lv=6; + lv6=ocn; lv7=0; + p_["lvn"] = 5; p_["ocn"] = lv5; + break; + case "7": + lv=7; + lv7=ocn; + p_["lvn"] = 6; p_["ocn"] = lv6; + break; + default: + // if (lv7 > 0) { + // p_["lvn"] = 7; p_["ocn"] = lv7; + // } else if (lv6 > 0) { + // p_["lvn"] = 6; p_["ocn"] = lv6; + // } else if (lv5 > 0) { + // p_["lvn"] = 5; p_["ocn"] = lv5; + // } else { + // p_["lvn"] = 4; p_["ocn"] = lv4; + // } + break; + } + node=("{ " ~ + "\"is\": \"" ~ is_ ~ "\"" ~ + ", \"heading_pointer\": " ~ to!string(pointer_) ~ + ", \"doc_object_pointer\": " ~ to!string(counter_) ~ + ", \"ocn\": " ~ to!string(ocn_) ~ + ", \"lvn\": " ~ to!string(lvn) ~ + ", \"lcn\": " ~ to!string(lcn) ~ + ", \"parent_ocn\": " ~ to!string(p_["ocn"]) ~ + ", \"parent_lvn\": " ~ to!string(p_["lvn"]) ~ + " }" + ); + debug(heading) { + mixin ScreenTxtColors; + if (match(lvn, rgx.levels_numbered_headings)) { + writeln(scr_txt_marker["yellow"], to!string(node)); + } + } + debug(node) { + mixin ScreenTxtColors; + if (match(lvn, rgx.levels_numbered_headings)) { + writeln(scr_txt_marker["yellow"], to!string(node)); + } else { + writeln(scr_txt_marker["white"], to!string(node)); + } + } + JSONValue j = parseJSON(node); + assert(j["parent_lvn"].integer <= 7); + assert(j["parent_ocn"].integer >= 0); + if (match(lvn, rgx.levels_numbered_headings)) { + assert(j["lvn"].integer <= 7); + assert(j["ocn"].integer >= 0); + if (j["parent_lvn"].integer > 0) { + assert(j["parent_lvn"].integer < j["lvn"].integer); + if (j["ocn"].integer != 0) { + assert(j["parent_ocn"].integer < j["ocn"].integer); + } + } + if (j["lvn"].integer == 0) { + assert(j["parent_lvn"].integer == 0); + } else if (j["lvn"].integer == 1) { + assert(j["parent_lvn"].integer == 0); + } else if (j["lvn"].integer == 2) { + assert(j["parent_lvn"].integer == 1); + } else if (j["lvn"].integer == 3) { + assert(j["parent_lvn"].integer == 2); + } else if (j["lvn"].integer == 4) { + assert(j["parent_lvn"].integer <= 3); + } else if (j["lvn"].integer == 5) { + assert(j["parent_lvn"].integer == 4); + } else if (j["lvn"].integer == 6) { + assert(j["parent_lvn"].integer == 5); + } else if (j["lvn"].integer == 7) { + assert(j["parent_lvn"].integer == 6); + } else if (j["lvn"].integer == 8) { + // writeln(j["parent_lvn"].integer); + // assert(j["parent_lvn"].integer >= 4); + // assert(j["parent_lvn"].integer <= 7); + } + } + return node; + } + invariant() { + } +} +#+END_SRC + +* tangles :tangle: +** code structure: :ao_emitter.d: +#+name: tangle_ao_emitter +#+BEGIN_SRC d :tangle ../lib/sdp/ao_emitter.d +/+ + emitters + ao_emitters.d ++/ +mixin template Emitters() { + mixin InternalMarkup; + <> +} +#+END_SRC diff --git a/org/ao_emitters_and_interfaces.org b/org/ao_emitters_and_interfaces.org deleted file mode 100644 index 74b80fc..0000000 --- a/org/ao_emitters_and_interfaces.org +++ /dev/null @@ -1,1601 +0,0 @@ -#+TITLE: sdp emitters & interfaces -#+AUTHOR: Ralph Amissah -#+EMAIL: ralph.amissah@gmail.com -#+STARTUP: indent -#+LANGUAGE: en -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+FILETAGS: :sdp:rel:ao: -#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) - -* emitters & interfaces -[[./sdp.org][sdp]] [[./][org/]] -ao_interface.d -ao_emitter.d -various emitters and their interfaces (where available) -** e: command line interface/instructions -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class CLI { - string[string] extract_actions(string cmdlnins, string[string] actions) - in { } - body { - switch (cmdlnins) { - case "--no-assert": - actions["assert"] = "no"; - break; - default: - break; - } - return actions; - } -} -#+END_SRC -** e&i: ocn -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class OCNemitter : AssertOCN { - int ocn, ocn_; - int ocn_emitter(int ocn_status_flag) - in { assert(ocn_status_flag <= 2); } - body { - if (ocn_status_flag == 0) { - ocn=++ocn_; - } else { - ocn=0; - } - return ocn; - } - invariant() { - } -} -#+END_SRC -*** interface assert :interface:assert: -#+name: ao_interface -#+BEGIN_SRC d -interface AssertOCN { - int ocn_emitter(int ocn_status_flag) - in { assert(ocn_status_flag <= 2); } - out(ocn) { assert(ocn >= 0); } -} -#+END_SRC -** e: object attributes -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class ObjAttributes { - string[string] obj_txt; - string para_and_blocks(string obj_txt_in) - in { } - body { - auto rgx = new Rgx(); - obj_txt["munge"]=obj_txt_in; - if (match(obj_txt_in, rgx.para_bullet)) { - obj_txt["attrib"] =" \"bullet\": \"true\"," - ~ " \"indent_first\": 0," - ~ " \"indent_rest\": 0,"; - } else if (auto m = match(obj_txt_in, rgx.para_bullet_indent)) { - obj_txt["attrib"] =" \"bullet\": \"true\"," - ~ " \"indent_first\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; - } else if (auto m = match(obj_txt_in, rgx.para_indent_hang)) { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_first\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[2]) ~ ","; - } else if (auto m = match(obj_txt_in, rgx.para_indent)) { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_first\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; - } else { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_first\": 0," - ~ " \"indent_rest\": 0,"; - } - return obj_txt["attrib"]; - } - string para(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"para\"," - ~ " \"is\": \"para\""; - return obj_txt["attrib"]; - } - invariant() { - } - string heading(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"para\"," - ~ " \"is\": \"heading\""; - return obj_txt["attrib"]; - } - invariant() { - } - string header_make(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"head\"," - ~ " \"of\": \"header\"," - ~ " \"is\": \"header_make\""; - return obj_txt["attrib"]; - } - invariant() { - } - string header_metadata(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"head\"," - ~ " \"of\": \"header\"," - ~ " \"is\": \"header_metadata\""; - return obj_txt["attrib"]; - } - invariant() { - } - string code(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"code\""; - return obj_txt["attrib"]; - } - invariant() { - } - string group(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"group\""; - return obj_txt["attrib"]; - } - invariant() { - } - string block(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"block\""; - return obj_txt["attrib"]; - } - invariant() { - } - string verse(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"verse\""; - return obj_txt["attrib"]; - } - invariant() { - } - string quote(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"quote\""; - return obj_txt["attrib"]; - } - invariant() { - } - string table(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"table\""; - return obj_txt["attrib"]; - } - invariant() { - } - string comment(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["attrib"] = " \"use\": \"comment\"," - ~ " \"of\": \"comment\"," - ~ " \"is\": \"comment\""; - return obj_txt["attrib"]; - } - invariant() { - } -} -#+END_SRC -** e: object inline markup munge -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class ObjInlineMarkupMunge { - string[string] obj_txt; - int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; - string obj_txt_out, tail, note; - private auto initialize_note_numbers() { - n_foot = 0; - n_foot_reg = 0; - n_foot_sp_asterisk = 0; - n_foot_sp_plus = 0; - } - private auto object_notes_(string obj_txt_in) - in { } - body { - auto rgx = new Rgx(); - auto mkup = new InternalMarkup(); - obj_txt_out = ""; - tail = ""; - obj_txt_in = replaceAll( - obj_txt_in, - rgx.inline_notes_curly_sp_asterisk, - (mkup.en_a_o ~ "*" ~ " $1" ~ mkup.en_a_c) - ); - obj_txt_in = - replaceAll( - obj_txt_in, - rgx.inline_notes_curly_sp_plus, - (mkup.en_a_o ~ "+" ~ " $1" ~ mkup.en_a_c) - ); - obj_txt_in = - replaceAll( - obj_txt_in, - rgx.inline_notes_curly, - (mkup.en_a_o ~ " $1" ~ mkup.en_a_c) - ); - if (match(obj_txt_in, rgx.inline_notes_al_gen)) { - foreach(m; matchAll(obj_txt_in, rgx.inline_text_and_note_al)) { - if (match(obj_txt_in, rgx.inline_al_delimiter_open_asterisk)) { - n_foot_sp_asterisk++; - n_foot=n_foot_sp_asterisk; - } else if (match(obj_txt_in, rgx.inline_al_delimiter_open_plus)) { - n_foot_sp_plus++; - n_foot=n_foot_sp_plus; - } else { - n_foot_reg++; - n_foot=n_foot_reg; - } - obj_txt_out ~= replaceFirst( - m.hit, - rgx.inline_al_delimiter_open_regular, - (mkup.en_a_o ~ to!string(n_foot)) - ); - tail = m.post; - } - } else { - obj_txt_out = obj_txt_in; - } - debug(footnotes) { - writeln(obj_txt_out, tail); - } - obj_txt_out = obj_txt_out ~ tail; - debug(footnotesdone) { - foreach(m; matchAll(obj_txt_out, - (mkup.en_a_o ~ `\s*(.+?)` ~ mkup.en_a_c))) { - writeln(m.captures[1]); - writeln(m.hit); - } - } - return obj_txt_out; - } - string para(string obj_txt_in) - in { } - body { - auto rgx = new Rgx(); - obj_txt["munge"]=obj_txt_in; - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.para_attribs, ""); - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.ocn_off_all, ""); - obj_txt["munge"]=object_notes_(obj_txt["munge"]); - debug(munge) { - writeln(__LINE__); - writeln(obj_txt_in); - writeln(__LINE__); - writeln(to!string(obj_txt["munge"])); - } - return obj_txt["munge"]; - } - string heading(string obj_txt_in) - in { } - body { - auto rgx = new Rgx(); - obj_txt["munge"]=obj_txt_in; - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading, ""); - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.ocn_off_all, ""); - obj_txt["munge"]=object_notes_(obj_txt["munge"]); - debug(munge) { - writeln(__LINE__); - writeln(obj_txt_in); - writeln(__LINE__); - writeln(to!string(obj_txt["munge"])); - } - return obj_txt["munge"]; - } - invariant() { - } - string header_make(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string header_metadata(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string code(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string group(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["munge"]=object_notes_(obj_txt["munge"]); - return obj_txt["munge"]; - } - invariant() { - } - string block(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["munge"]=object_notes_(obj_txt["munge"]); - return obj_txt["munge"]; - } - invariant() { - } - string verse(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - obj_txt["munge"]=object_notes_(obj_txt["munge"]); - return obj_txt["munge"]; - } - invariant() { - } - string quote(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string table(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string comment(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } -} -#+END_SRC -** e&i: object inline markup -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class ObjInlineMarkup : AssertObjInlineMarkup { - auto munge = new ObjInlineMarkupMunge(); - string[string] obj_txt; - string obj_inline_markup(string obj_is_, string obj_raw) - in { } - body { - obj_txt["munge"]=obj_raw.dup; - obj_txt["munge"]=(match(obj_is_, ctRegex!(`verse|code`))) - ? obj_txt["munge"] - : strip(obj_txt["munge"]); - switch (obj_is_) { - case "header_make": - obj_txt["munge"]=munge.header_make(obj_txt["munge"]); - break; - case "header_metadata": - obj_txt["munge"]=munge.header_metadata(obj_txt["munge"]); - break; - case "heading": - obj_txt["munge"]=munge.heading(obj_txt["munge"]); - break; - case "para": - obj_txt["munge"]=munge.para(obj_txt["munge"]); - break; - case "code": - obj_txt["munge"]=munge.code(obj_txt["munge"]); - break; - case "group": - obj_txt["munge"]=munge.group(obj_txt["munge"]); - break; - case "block": - obj_txt["munge"]=munge.block(obj_txt["munge"]); - break; - case "verse": - obj_txt["munge"]=munge.verse(obj_txt["munge"]); - break; - case "quote": - obj_txt["munge"]=munge.quote(obj_txt["munge"]); - break; - case "table": - obj_txt["munge"]=munge.table(obj_txt["munge"]); - break; - case "comment": - obj_txt["munge"]=munge.comment(obj_txt["munge"]); - break; - case "doc_end_reset": - munge.initialize_note_numbers(); - break; - default: - break; - } - return obj_txt["munge"]; - } - invariant() { - } -} -#+END_SRC -*** interface assert :interface:assert: -#+name: ao_interface -#+BEGIN_SRC d -interface AssertObjInlineMarkup { - string obj_inline_markup(string obj_raw, string obj_type_) - in { - } - out(inline_markup) { - } -} -#+END_SRC -** e&i: object attrib -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class ObjAttrib : AssertObjAttrib { - auto attrib = new ObjAttributes(); - string[string] obj_attrib; - string obj_attributes(string obj_is_, string obj_raw, string node) - in { } - body { - scope(exit) { - destroy(obj_raw); - destroy(node); - } - JSONValue node_j = parseJSON(node); - obj_attrib.remove("json"); - obj_attrib["json"] ="{"; - switch (obj_is_) { - case "header_make": - obj_attrib["json"] ~= attrib.header_make(obj_raw); - break; - case "header_metadata": - obj_attrib["json"] ~= attrib.header_metadata(obj_raw); - break; - case "heading": - obj_attrib["json"] ~= attrib.heading(obj_raw); // - break; - case "para": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.para(obj_raw); - break; - case "code": - obj_attrib["json"] ~= attrib.code(obj_raw); - break; - case "group": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.group(obj_raw); - break; - case "block": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.block(obj_raw); - break; - case "verse": - obj_attrib["json"] ~= attrib.verse(obj_raw); - break; - case "quote": - obj_attrib["json"] ~= attrib.quote(obj_raw); - break; - case "table": - obj_attrib["json"] ~= attrib.table(obj_raw); - break; - case "comment": - obj_attrib["json"] ~= attrib.comment(obj_raw); - break; - default: - obj_attrib["json"] ~= attrib.para(obj_raw); - break; - } - obj_attrib["json"] ~=" }"; - JSONValue oa_j = parseJSON(obj_attrib["json"]); - assert( - (oa_j.type == JSON_TYPE.OBJECT) && - (node_j.type == JSON_TYPE.OBJECT) - ); - if (obj_is_ == "heading") { - oa_j.object["ocn"] = node_j["ocn"]; - oa_j.object["lvn"] = node_j["lvn"]; - oa_j.object["lcn"] = node_j["lcn"]; - oa_j.object["heading_pointer"] = - node_j["heading_pointer"]; // check - oa_j.object["doc_object_pointer"] = - node_j["doc_object_pointer"]; // check - } - oa_j.object["parent_ocn"] = node_j["parent_ocn"]; - oa_j.object["parent_lvn"] = node_j["parent_lvn"]; - obj_attrib["json"] = oa_j.toString(); - debug(structattrib) { - if (oa_j["is"].str() == "heading") { - writeln(obj_attrib["json"]); - writeln( - "is: ", oa_j["is"].str(), - "; ocn: ", oa_j["ocn"].integer() - ); - } - } - return obj_attrib["json"]; - } - invariant() { - } -} -#+END_SRC -*** interface assert :interface:assert: -#+name: ao_interface -#+BEGIN_SRC d -interface AssertObjAttrib { - string obj_attributes(string obj_raw, string node, string obj_type_) - in { - } - out(obj_attrib_json) { - } -} -#+END_SRC -** e: header document metadata in json -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class HeaderDocMetadataMakeJson { - auto rgx = new Rgx(); - string hm, hs; - auto header_metadata_and_make_jsonstr( - string header, - JSONValue[string] dochead_metadata, - JSONValue[string] dochead_make - ) - in { } - body { - scope(exit) { - destroy(header); - destroy(dochead_metadata); - destroy(dochead_make); - } - if (auto t = match(header, rgx.head_main)) { - char[][] obj_spl = split( - cast(char[]) header, - rgx.line_delimiter_ws_strip - ); - auto hm = to!string(t.captures[1]); - if (match(hm, rgx.main_headers)) { - foreach (line; obj_spl) { - if (auto m = match(line, rgx.head_main)) { - if (!empty(m.captures[2])) { - if (hm == "creator") { - dochead_metadata[hm]["author"].str = - to!string(m.captures[2]); - } else if (hm == "title") { - dochead_metadata[hm]["main"].str = - to!string(m.captures[2]); - } else if (hm == "publisher") { - dochead_metadata[hm]["name"].str = - to!string(m.captures[2]); - } - } - } else if (auto s = match(line, rgx.head_sub)) { - if (!empty(s.captures[2])) { - auto hs = to!string(s.captures[1]); - if ((hm == "make" ) - && (dochead_make[hm].type() == JSON_TYPE.OBJECT)) { - switch (hm) { - case "make": - if (match(hs, rgx.subhead_make)) { - if (dochead_make[hm][hs].type() == JSON_TYPE.STRING) { - dochead_make[hm][hs].str = to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - default: - break; - } - } else if (dochead_metadata[hm].type() == JSON_TYPE.OBJECT) { - switch (hm) { - case "creator": - if (match(hs, rgx.subhead_creator)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "title": - if (match(hs, rgx.subhead_title)) { - if ((hs == "subtitle") - && (dochead_metadata[hm]["sub"].type() == JSON_TYPE.STRING)) { - dochead_metadata[hm]["sub"].str = - to!string(s.captures[2]); - } else if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "rights": - if (match(hs, rgx.subhead_rights)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "date": - if (match(hs, rgx.subhead_date)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "original": - if (match(hs, rgx.subhead_original)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "classify": - if (match(hs, rgx.subhead_classify)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "identifier": - if (match(hs, rgx.subhead_identifier)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "notes": - if (match(hs, rgx.subhead_notes)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "publisher": - if (match(hs, rgx.subhead_publisher)) { - if (dochead_metadata[hm][hs].type() == JSON_TYPE.STRING) { - dochead_metadata[hm][hs].str = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "links": - destroy(hm); - destroy(hs); - break; - default: - break; - } - } - } - } - } - } else { - writeln("not a valid header type:", hm); - } - } - auto t = tuple(dochead_metadata, dochead_make); - static assert(!isTypeTuple!(t)); - return t; - } -} -#+END_SRC -** e: header document metadata as hash -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class HeaderMetadataMakeHash { - auto rgx = new Rgx(); - string header_main; - string[string] head; - string[string] header_topic_hash(string header) - in { } - body { - if (auto t = match(header, rgx.head_main)) { - char[][] obj_spl = split( - cast(char[]) header, - rgx.line_delimiter_ws_strip - ); - auto header_main = to!string(t.captures[1]); - head[header_main] = "{"; - foreach (line; obj_spl) { - if (auto m = match(line, rgx.head_main)) { - if (!empty(m.captures[2])) { - head[header_main] ~= - "\"" ~ header_main ~ - "\": \"" ~ - to!string(m.captures[2]) ~ - "\","; - } - } else if (auto s = match(line, rgx.head_sub)) { - head[header_main] ~= "\"" ~ s.captures[1] ~ "\":"; - if (!empty(s.captures[2])) { - head[header_main] ~= "\"" ~ s.captures[2] ~ "\","; - } - } - } - head[header_main] = replaceFirst( - head[header_main], - rgx.tailing_comma, - "" - ); - head[header_main] ~= "}"; - debug(headerjson) { - JSONValue j = parseJSON(head[header_main]); - assert( - (j.type == JSON_TYPE.OBJECT) - ); - } - } - return head; - } - invariant() { - } -} -#+END_SRC -** e&i: book index nugget hash -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class BookIndexNuggetHash : AssertBookIndexNuggetHash { - string main_term, sub_term, sub_term_bits; - uint ocn_offset, ocn_endpoint; - string[] ocns; - string[][string][string] bi; - string[][string][string] hash_nugget; - string[] bi_main_terms_split_arr; - string[][string][string] bookindex_nugget_hash(string bookindex, int ocn) - in { } - body { - auto rgx = new Rgx(); - if (!bookindex.empty) { - auto bi_main_terms_split_arr = - split(bookindex, rgx.bi_main_terms_split); - foreach (bi_main_terms_content; bi_main_terms_split_arr) { - auto bi_main_term_and_rest = - split(bi_main_terms_content, rgx.bi_main_term_plus_rest_split); - if (auto m = match( - bi_main_term_and_rest[0], - rgx.bi_term_and_ocns_match) - ) { - main_term = strip(m.captures[1]); - ocn_offset = to!uint(m.captures[2]); - ocn_endpoint=(ocn + ocn_offset); - ocns ~= (to!string(ocn) ~ "-" ~ to!string(ocn_endpoint)); - } else { - main_term = strip(bi_main_term_and_rest[0]); - ocns ~= to!string(ocn); - } - bi[main_term]["_a"] ~= ocns; - ocns=null; - if (bi_main_term_and_rest.length > 1) { - auto bi_sub_terms_split_arr = - split( - bi_main_term_and_rest[1], - rgx.bi_sub_terms_plus_ocn_offset_split - ); - foreach (sub_terms_bits; bi_sub_terms_split_arr) { - if (auto m = match(sub_terms_bits, rgx.bi_term_and_ocns_match)) { - sub_term = strip(m.captures[1]); - ocn_offset = to!uint(m.captures[2]); - ocn_endpoint=(ocn + ocn_offset); - ocns ~= (to!string(ocn) ~ " - " ~ to!string(ocn_endpoint)); - } else { - sub_term = strip(sub_terms_bits); - ocns ~= to!string(ocn); - } - if (!empty(sub_term)) { - bi[main_term][sub_term] ~= ocns; - } - ocns=null; - } - } - } - } - hash_nugget = bi; - return hash_nugget; - } - invariant() { - } -} -#+END_SRC -*** interface assert :interface:assert: -#+name: ao_interface -#+BEGIN_SRC d -interface AssertBookIndexNuggetHash { - string[][string][string] bookindex_nugget_hash(string bookindex, int ocn) - in { - debug(bookindexraw) { - mixin ScreenTxtColors; - if (!bookindex.empty) { - writeln( - scr_txt_color["blue"], "* [bookindex] ", scr_txt_color["off"], - "[", to!string(ocn), "] ", bookindex - ); - } - } - } - out(hash_nugget) { - } -} -#+END_SRC -** e&i: book index report -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class BookIndexReport { - int mkn, skn; - auto bookindex_report_sorted( - string[][string][string] bookindex_unordered_hashes - ) { - auto mainkeys=bookindex_unordered_hashes.byKey.array. - sort!("toLower(a) < toLower(b)", SwapStrategy.stable).release; - foreach (mainkey; mainkeys) { - auto subkeys=bookindex_unordered_hashes[mainkey].byKey.array. - sort!("toLower(a) < toLower(b)", SwapStrategy.stable).release; - foreach (subkey; subkeys) { - debug(bookindex) { - writeln( - mainkey, ": ", - subkey, ": ", - to!string(bookindex_unordered_hashes[mainkey][subkey]) - ); - } - skn++; - } - mkn++; - } - } -} -#+END_SRC -*** interface assert :interface:assert: -#+name: ao_interface -#+BEGIN_SRC d -interface AssertBookIndexReport { - string[][string][][string][] bookindex_nugget_hash(string[][string][string] bookindex_unordered_hashes) - in { - } -} -#+END_SRC -** e: book index report indented -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class BookIndexReportIndent { - int mkn, skn; - auto bookindex_report_indented( - string[][string][string] bookindex_unordered_hashes - ) { - auto mainkeys= - bookindex_unordered_hashes.byKey.array.sort().release; - foreach (mainkey; mainkeys) { - debug(bookindex) { - writeln(mainkey); - } - auto subkeys= - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - debug(bookindex) { - writeln(" ", subkey); - writeln(" ", to!string( - bookindex_unordered_hashes[mainkey][subkey] - )); - } - skn++; - } - mkn++; - } - } -} -#+END_SRC -** e: book index report section -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class BookIndexReportSection { - mixin ObjectSetters; - int mkn, skn; - auto rgx = new Rgx(); - auto bookindex_write_section( - string[][string][string] bookindex_unordered_hashes - ) { - auto mainkeys=bookindex_unordered_hashes.byKey.array.sort().release; - foreach (mainkey; mainkeys) { - write("_0_1 !{", mainkey, "}! "); - foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { - auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - write(" {", ref_, "}#", go, ", "); - } - writeln(" \\\\"); - bookindex_unordered_hashes[mainkey].remove("_a"); - auto subkeys= - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - write(" ", subkey, ", "); - foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { - auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - write(" {", ref_, "}#", go, ", "); - } - writeln(" \\\\"); - skn++; - } - mkn++; - } - } - auto bookindex_build_section( - string[][string][string] bookindex_unordered_hashes, - int ocn - ) { - string type; - int type_heading; - string lev, lvn, lcn; - string attrib; - string indent_first; - string indent_second; - auto set_oa = new ObjectAbstractSet(); - auto mainkeys = - bookindex_unordered_hashes.byKey.array.sort().release; - string bi_tmp; - string[string][1024] bookindex_arbitrary_max_length_set; - writeln(mainkeys.length); - type_heading=1; - bi_tmp = "Book Index"; - attrib=""; - lev="B"; - lvn="1"; - lcn="1"; - bookindex_arbitrary_max_length_set[mkn] = - set_oa.contents_heading( - type_heading, - bi_tmp, - attrib, - ocn, - lev, - lvn, - lcn - ); - ocn++; - mkn++; - type_heading=1; - bi_tmp = "Index"; - attrib=""; - lev="1"; - lvn="4"; - lcn="2"; - bookindex_arbitrary_max_length_set[mkn] = - set_oa.contents_heading( - type_heading, - bi_tmp, - attrib, - ocn, - lev, - lvn, - lcn - ); - ocn++; - mkn++; - foreach (mainkey; mainkeys) { - bi_tmp = "!{" ~ mainkey ~ "}! "; - foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { - auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; - } - bi_tmp ~= " \\\\\n "; - bookindex_unordered_hashes[mainkey].remove("_a"); - auto subkeys = - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - bi_tmp ~= subkey ~ ", "; - foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { - auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; - } - bi_tmp ~= " \\\\\n "; - skn++; - } - bi_tmp = replaceFirst(bi_tmp, rgx.trailing_linebreak, ""); - type="para"; - attrib=""; - indent_first = "0"; - indent_second = "1"; - attrib=""; - bookindex_arbitrary_max_length_set[mkn] = - set_oa.contents_para( - type, - bi_tmp, - attrib, - ocn, - indent_first, - indent_second, - false - ); - ocn++; - mkn++; - } - auto bookindex = - bookindex_arbitrary_max_length_set[0..mkn].dup; - auto t = tuple(bookindex, ocn); - return t; - } - auto bookindex_build_section_( - string[][string][string] bookindex_unordered_hashes - ) { - auto mainkeys = - bookindex_unordered_hashes.byKey.array.sort().release; - string bi_tmp; - string[1024] bookindex_arbitrary_max_length_set; - writeln(mainkeys.length); - foreach (mainkey; mainkeys) { - bi_tmp = "_0_1 !{" ~ mainkey ~ "}! "; - foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { - auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; - } - bi_tmp ~= " \\\\\n "; - bookindex_unordered_hashes[mainkey].remove("_a"); - auto subkeys = - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - bi_tmp ~= subkey ~ ", "; - foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { - auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; - } - bi_tmp ~= " \\\\\n "; - skn++; - } - bi_tmp = replaceFirst(bi_tmp, rgx.trailing_linebreak, ""); - bookindex_arbitrary_max_length_set[mkn] = bi_tmp; - mkn++; - } - auto bookindex = - bookindex_arbitrary_max_length_set[0..mkn].dup; - return bookindex; - } -} -#+END_SRC -** e: (end)notes section -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class NotesSection { - mixin ObjectSetters; - string object_notes; - int previous_count; - int mkn; - auto rgx = new Rgx(); - private auto gather_notes_for_endnote_section( - string[string][131072] contents_arbitrary_max_length_set, - int counter - ) - in { - // endnotes/ footnotes for - // doc objects other than paragraphs & headings - // various forms of grouped text - assert((contents_arbitrary_max_length_set[counter]["is"] == "para") - || (contents_arbitrary_max_length_set[counter]["is"] == "heading")); - assert(counter > previous_count); - previous_count=counter; - assert( - match(contents_arbitrary_max_length_set[counter]["obj"], - rgx.inline_notes_delimiter_al_regular_number_note) - ); - } - body { - foreach(m; - matchAll(contents_arbitrary_max_length_set[counter]["obj"], - rgx.inline_notes_delimiter_al_regular_number_note)) { - debug(endnotes_build) { - writeln( - "{^{", m.captures[1], ".}^}#noteref_", m.captures[1], " ", - m.captures[2]); // sometimes need segment name (segmented html & epub) - } - object_notes ~= - "{^{" ~ m.captures[1] ~ ".}^}#noteref_" ~ - m.captures[1] ~ " " ~ m.captures[2] ~ "』"; - } - return object_notes; - } - private auto gathered_notes() - in { - } - body { - string[] endnotes_; - if (object_notes.length > 1) { - endnotes_ = (split(object_notes, rgx.break_string))[0..$-1]; - } - return endnotes_; - } - private auto endnote_objects(int ocn) - in { - } - body { - auto set_oa = new ObjectAbstractSet(); - string[string][1024] endnotes_arbitrary_max_length_set; - auto endnotes_ = gathered_notes(); - string type; - int type_heading; - string lev, lvn, lcn; - string attrib; - string indent_first; - string indent_second; - type_heading=1; - attrib=""; - lev="B"; - lvn="1"; - lcn="1"; - endnotes_arbitrary_max_length_set[mkn] = - set_oa.contents_heading( - type_heading, - "Endnotes", - attrib, - ocn, - lev, - lvn, - lcn - ); - ocn++; - mkn++; - type_heading=1; - attrib=""; - lev="1"; - lvn="4"; - lcn="2"; - endnotes_arbitrary_max_length_set[mkn] = - set_oa.contents_heading( - type_heading, - "Endnotes", - attrib, - ocn, - lev, - lvn, - lcn - ); - ocn++; - mkn++; - foreach (endnote; endnotes_) { - type="para"; - attrib=""; - indent_first = "0"; - indent_second = "0"; - attrib=""; - endnotes_arbitrary_max_length_set[mkn] = - set_oa.contents_para( - type, - endnote, - attrib, - ocn, - indent_first, - indent_second, - false - ); - ocn++; - mkn++; - } - auto endnotes = - endnotes_arbitrary_max_length_set[0..mkn].dup; - auto t = tuple(endnotes, ocn); - return t; - } -} -#+END_SRC -** e: bibliography -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class Bibliography { - public JSONValue[] bibliography(string[] biblio_unsorted_incomplete) - in { } - body { - JSONValue[] biblio_unsorted = - biblio_unsorted_complete(biblio_unsorted_incomplete); - JSONValue[] biblio_sorted = biblio_sort(biblio_unsorted); - biblio_debug(biblio_sorted); - return biblio_sorted; - } - final private JSONValue[] biblio_unsorted_complete( - string[] biblio_unordered - ) { - JSONValue[1024] bib_arr_json; - int count_biblio_entry; - count_biblio_entry=0; - foreach (bibent; biblio_unordered) { - // update bib to include deemed_author, needed for: - // sort_bibliography_array_by_deemed_author_year_title - // either: sort on multiple fields, or; create such sort field - JSONValue j = parseJSON(bibent); - if (!empty(j["fulltitle"].str)) { - if (!empty(j["author_raw"].str)) { - j["deemed_author"]=j["author_arr"][0]; - } else if (!empty(j["editor_raw"].str)) { - j["deemed_author"]=j["editor_arr"][0]; - } - j["sortby_deemed_author_year_title"] = ( - j["deemed_author"].str ~ - "; " ~ - j["year"].str ~ - "; " ~ - j["fulltitle"].str - ); - } - bib_arr_json[count_biblio_entry] = j; - count_biblio_entry++; - } - JSONValue[] biblio_unsorted_array_of_json_objects = - bib_arr_json[0..(count_biblio_entry)].dup; - return biblio_unsorted_array_of_json_objects; - } - final private JSONValue[] biblio_sort(JSONValue[] biblio_unordered) { - JSONValue[] biblio_sorted; - biblio_sorted = - sort!((a, b){ - return ((a["sortby_deemed_author_year_title"].str) < (b["sortby_deemed_author_year_title"].str)); - })(biblio_unordered).array; - debug(bibliosorted) { - foreach (j; biblio_sorted) { - if (!empty(j["fulltitle"].str)) { - writeln(j["sortby_deemed_author_year_title"]); - } - } - } - return biblio_sorted; - } - auto biblio_debug(JSONValue[] biblio_sorted) { - debug(biblio) { - foreach (j; biblio_sorted) { - if (!empty(j["fulltitle"].str)) { - writeln(j["sortby_deemed_author_year_title"]); - } - } - } - } -} -#+END_SRC -** e&i: node structure metadata -*** emitter :emitter: -#+name: ao_emitter -#+BEGIN_SRC d -class NodeStructureMetadata : AssertNodeJSON { - int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; - uint ocn; - uint[string] p_; // p_ parent_ - string node; - string node_emitter( - string lvn, - int ocn_, - int counter_, - int pointer_, - string is_ - ) - in { - auto rgx = new Rgx(); - } - body { - assert(is_ != "heading"); // should not be necessary - assert(to!int(ocn_) >= 0); // should not be necessary - uint ocn=to!uint(ocn_); - if (lv7 > 0) { - p_["lvn"] = 7; p_["ocn"] = lv7; - } else if (lv6 > 0) { - p_["lvn"] = 6; p_["ocn"] = lv6; - } else if (lv5 > 0) { - p_["lvn"] = 5; p_["ocn"] = lv5; - } else { - p_["lvn"] = 4; p_["ocn"] = lv4; - } - node=("{ " ~ - "\"is\": \"" ~ is_ ~ "\"" ~ - ", \"heading_pointer\": " ~ to!string(pointer_) ~ - ", \"doc_object_pointer\": " ~ to!string(counter_) ~ - ", \"ocn\": " ~ to!string(ocn_) ~ - ", \"parent_ocn\": " ~ to!string(p_["ocn"]) ~ - ", \"parent_lvn\": " ~ to!string(p_["lvn"]) ~ - " }" - ); - return node; - } - invariant() { - } - string node_emitter_heading( - string lvn, - string lcn, - int ocn_, - int counter_, - int pointer_, - string is_ - ) - in { - auto rgx = new Rgx(); - } - body { - uint ocn=to!uint(ocn_); - switch (lvn) { // switch (to!string(lv)) { - case "0": - lv=0; - lv0=ocn; lv1=0; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lvn"] = 0; p_["ocn"] = 0; - break; - case "1": - lv=1; - lv1=ocn; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lvn"] = 0; p_["ocn"] = lv0; - break; - case "2": - lv=2; - lv2=ocn; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lvn"] = 1; p_["ocn"] = lv1; - break; - case "3": - lv=3; - lv3=ocn; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lvn"] = 2; p_["ocn"] = lv2; - break; - case "4": - lv=4; - lv4=ocn; lv5=0; lv6=0; lv7=0; - if (lv3 > 0) { - p_["lvn"] = 3; p_["ocn"] = lv3; - } else if (lv2 > 0) { - p_["lvn"] = 2; p_["ocn"] = lv2; - } else if (lv1 > 0) { - p_["lvn"] = 1; p_["ocn"] = lv1; - } else { - p_["lvn"] = 0; p_["ocn"] = lv0; - } - break; - case "5": - lv=5; - lv5=ocn; lv6=0; lv7=0; - p_["lvn"] = 4; p_["ocn"] = lv4; - break; - case "6": - lv=6; - lv6=ocn; lv7=0; - p_["lvn"] = 5; p_["ocn"] = lv5; - break; - case "7": - lv=7; - lv7=ocn; - p_["lvn"] = 6; p_["ocn"] = lv6; - break; - default: - break; - } - node=("{ " ~ - "\"is\": \"" ~ is_ ~ "\"" ~ - ", \"heading_pointer\": " ~ to!string(pointer_) ~ - ", \"doc_object_pointer\": " ~ to!string(counter_) ~ - ", \"ocn\": " ~ to!string(ocn_) ~ - ", \"lvn\": " ~ to!string(lvn) ~ - ", \"lcn\": " ~ to!string(lcn) ~ - ", \"parent_ocn\": " ~ to!string(p_["ocn"]) ~ - ", \"parent_lvn\": " ~ to!string(p_["lvn"]) ~ - " }" - ); - return node; - } - invariant() { - } -} -#+END_SRC - -*** interface assert :interface:assert: -#+name: ao_interface -#+BEGIN_SRC d -interface AssertNodeJSON { - string node_emitter( - string lvn, - int ocn_, - int counter_, - int pointer_, - string is_ - ) - in { - auto rgx = new Rgx(); - assert(is_ != "heading"); - assert(to!int(ocn_) >= 0); - } - out(node) { - debug(node) { - mixin ScreenTxtColors; - if (match(lvn, rgx.levels_numbered_headings)) { - writeln(scr_txt_marker["yellow"], to!string(node)); - } else { - writeln(scr_txt_marker["white"], to!string(node)); - } - } - JSONValue j = parseJSON(node); - assert(j["parent_lvn"].integer >= 4); - assert(j["parent_lvn"].integer <= 7); - assert(j["parent_ocn"].integer >= 0); - } - string node_emitter_heading( - string lvn, - string lcn, - int ocn_, - int counter_, - int pointer_, - string is_ - ) - in { - auto rgx = new Rgx(); - assert(is_ == "heading"); - assert(to!uint(ocn_) >= 0); - assert( - match(lvn, rgx.levels_numbered), - ("not a valid heading level: " ~ lvn ~ " at " ~ to!string(ocn_)) - ); - if (match(lvn, rgx.levels_numbered)) { - if (to!uint(lvn) == 0) { - assert(to!uint(ocn_) == 1); - } - } - } - out(node) { - auto rgx = new Rgx(); - debug(heading) { - mixin ScreenTxtColors; - if (match(lvn, rgx.levels_numbered_headings)) { - writeln(scr_txt_marker["yellow"], to!string(node)); - } - } - debug(node) { - mixin ScreenTxtColors; - if (match(lvn, rgx.levels_numbered_headings)) { - writeln(scr_txt_marker["yellow"], to!string(node)); - } else { - writeln(scr_txt_marker["white"], to!string(node)); - } - } - JSONValue j = parseJSON(node); - assert(j["parent_lvn"].integer <= 7); - assert(j["parent_ocn"].integer >= 0); - if (match(lvn, rgx.levels_numbered_headings)) { - assert(j["lvn"].integer <= 7); - assert(j["ocn"].integer >= 0); - if (j["parent_lvn"].integer > 0) { - assert(j["parent_lvn"].integer < j["lvn"].integer); - if (j["ocn"].integer != 0) { - assert(j["parent_ocn"].integer < j["ocn"].integer); - } - } - if (j["lvn"].integer == 0) { - assert(j["parent_lvn"].integer == 0); - } else if (j["lvn"].integer == 1) { - assert(j["parent_lvn"].integer == 0); - } else if (j["lvn"].integer == 2) { - assert(j["parent_lvn"].integer == 1); - } else if (j["lvn"].integer == 3) { - assert(j["parent_lvn"].integer == 2); - } else if (j["lvn"].integer == 4) { - assert(j["parent_lvn"].integer <= 3); - } else if (j["lvn"].integer == 5) { - assert(j["parent_lvn"].integer == 4); - } else if (j["lvn"].integer == 6) { - assert(j["parent_lvn"].integer == 5); - } else if (j["lvn"].integer == 7) { - assert(j["parent_lvn"].integer == 6); - } else if (j["lvn"].integer == 8) { - } - } - } -} -#+END_SRC -* tangles :tangle: -** code structure: :ao_emitter.d: -#+name: tangle_ao_emitter -#+BEGIN_SRC d :tangle ../lib/sdp/ao_emitter.d -/* - emitters - ao_emitters.d -*/ -mixin template Emitters() { - mixin InternalMarkup; - <> -} -#+END_SRC -** code structure: :ao_interface.d: -#+name: tangle_ao_interface -#+BEGIN_SRC d :tangle ../lib/sdp/ao_interface.d -/* - interface - ao_interface.d -*/ -mixin template Interfaces() { - <> -} -#+END_SRC diff --git a/org/ao_object_setter.org b/org/ao_object_setter.org index 51dd9bc..2ee9423 100644 --- a/org/ao_object_setter.org +++ b/org/ao_object_setter.org @@ -15,6 +15,25 @@ * object setter :object:set: [[./sdp.org][sdp]] [[./][org/]] ** struct :struct: +#+name: ao_object_setter +#+BEGIN_SRC d +mixin Structs; +#+END_SRC +** comment :comment: +#+name: ao_object_setter +#+BEGIN_SRC d +ObjComposite contents_comment_new(in string object) { + ObjComposite object_set; + object_set.use = "comment"; + object_set.of = "comment"; + object_set.is_a = "comment"; + object_set.object = object; + // does not have .attrib; + // does not have .ocn + return object_set; +} +#+END_SRC + #+name: ao_object_setter #+BEGIN_SRC d string[string] contents_comment(in string object) { @@ -27,6 +46,32 @@ string[string] contents_comment(in string object) { } #+END_SRC ** heading :heading: +#+name: ao_object_setter +#+BEGIN_SRC d +ObjComposite contents_heading_new( + in int type, + in string object, + in string attrib, + in int ocn, + in string lev, + in string lvn, + in string lcn, +) { + ObjComposite object_set; + object_set.use = "content"; + object_set.of = "para"; + object_set.is_a = "heading"; + object_set.object = object; + object_set.ocn = (ocn==0) ? "" : to!string(ocn); + object_set.attrib = attrib; + object_set.heading.type = to!string(type); + object_set.heading.lev = to!string(lev); + object_set.heading.lvn = to!string(lvn); + object_set.heading.lcn = to!string(lcn); + return object_set; +} +#+END_SRC + #+name: ao_object_setter #+BEGIN_SRC d string[string] contents_heading( @@ -53,10 +98,36 @@ string[string] contents_heading( } #+END_SRC ** para :para: + +#+name: ao_object_setter +#+BEGIN_SRC d +ObjComposite contents_para_new( + in string is_a, + in string object, + in string attrib, + in int ocn, + in string indent_first, + in string indent_second, + in bool bullet +) { + ObjComposite object_set; + object_set.use = "content"; + object_set.of = "para"; + object_set.is_a = "heading"; + object_set.object = object; + object_set.ocn = (ocn==0) ? "" : to!string(ocn); + object_set.attrib = attrib; + object_set.para.indent_first = indent_first; + object_set.para.indent_second = indent_second; + object_set.para.bullet = to!string(bullet); + return object_set; +} +#+END_SRC + #+name: ao_object_setter #+BEGIN_SRC d string[string] contents_para( - in string type, + in string is_a, in string object, in string attrib, in int ocn, @@ -67,7 +138,7 @@ string[string] contents_para( string[string] object_set; object_set["use"] = "content"; object_set["of"] = "para"; - object_set["is"] = type; + object_set["is"] = is_a; object_set["obj"] = object; object_set["ocn"] = (ocn==0) ? "" : to!string(ocn); object_set["indent_first"] = indent_first; @@ -78,6 +149,26 @@ string[string] contents_para( } #+END_SRC ** block :block: +#+name: ao_object_setter +#+BEGIN_SRC d +ObjComposite contents_block_new( + in string type, + in string object, + in string attrib, + in int ocn +) { + ObjComposite object_set; + // does not have .attrib; + object_set.use = "content"; + object_set.of = "block"; + object_set.is_a = type; + object_set.object = object; + object_set.ocn = (ocn==0) ? "" : to!string(ocn); + object_set.attrib = attrib; + return object_set; +} +#+END_SRC + #+name: ao_object_setter #+BEGIN_SRC d string[string] contents_block( @@ -97,6 +188,26 @@ string[string] contents_block( } #+END_SRC ** block ocn string :block: +#+name: ao_object_setter +#+BEGIN_SRC d +ObjComposite contents_block_ocn_string_new( + in string type, + in string object, + in string ocn, + in string node +) { + ObjComposite object_set; + object_set.use = "content"; + object_set.of = "block"; + object_set.is_a = type; + object_set.object = object; + object_set.ocn = ocn; + object_set.block_ocn_string.node = node; + // object_set.attrib = attrib; + return object_set; +} +#+END_SRC + #+name: ao_object_setter #+BEGIN_SRC d string[string] contents_block_ocn_string( @@ -120,12 +231,12 @@ string[string] contents_block_ocn_string( ** code structure: :ao_object_setter.d: #+name: tangle_ao_object_setter #+BEGIN_SRC d :tangle ../lib/sdp/ao_object_setter.d -/* +/+ object setter ao_object_setter.d -*/ ++/ mixin template ObjectSetters() { - class ObjectAbstractSet { + struct ObjectAbstractSet { import std.conv : to; <> } diff --git a/org/ao_output_debugs.org b/org/ao_output_debugs.org index 5fd0d98..3f9b59f 100644 --- a/org/ao_output_debugs.org +++ b/org/ao_output_debugs.org @@ -18,11 +18,17 @@ #+name: ao_output_debugs #+BEGIN_SRC d debug(parent) { - writeln(__FILE__, ":", __LINE__); + writefln( + "%s:%s", + __FILE__, + __LINE__, + ); foreach (obj; contents) { if (obj["use"] == "content") { if (obj["is"] == "heading") { - writeln(scr_txt_marker["cyan"], + writefln( + "%s%s node: %s heading: %s %s", + scr_txt_marker["cyan"], obj["ocn"], " node: ", obj["node"], " heading: ", obj["lvn"], @@ -34,18 +40,45 @@ debug(parent) { } } #+END_SRC +** (dumpdoc) :objects: +#+name: ao_output_debugs +#+BEGIN_SRC d +debug(dumpdoc) { + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); + foreach (obj; contents) { + if (obj["use"] == "content") { + writefln( + "[%s][%s]\n%s", + obj["ocn"], + obj["is"], + obj["obj"] + ); + } + } +} +#+END_SRC ** (objects) :objects: #+name: ao_output_debugs #+BEGIN_SRC d debug(objects) { - writeln("-------------------------------"); - writeln(__FILE__, ":", __LINE__); + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); foreach (obj; contents) { if (obj["use"] == "content") { - writeln( + writefln( + "%s* [%s][%s] %s%s", scr_txt_color["green"], - "* [", obj["ocn"], "]", - "[", obj["is"], "] ", + obj["ocn"], + obj["is"], scr_txt_color["off"], obj["obj"] ); @@ -57,17 +90,21 @@ debug(objects) { #+name: ao_output_debugs #+BEGIN_SRC d debug(headermakejson) { - writeln("document header, metadata & make instructions:"); - writeln(dochead); - writeln(pointer_head_main); + writefln( + "%s\n%s\n%s", + "document header, metadata & make instructions:", + dochead, + pointer_head_main, + ); foreach (main_header; pointer_head_main) { switch (main_header) { case "make": foreach (sub_header; pointer_head_sub_make) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln( - main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -83,16 +120,21 @@ debug(headermakejson) { #+name: ao_output_debugs #+BEGIN_SRC d debug(headermetadatajson) { - writeln("document header, metadata & make instructions:"); - writeln(dochead); - writeln(pointer_head_main); + writefln( + "%s\n%s\n%s", + "document header, metadata & make instructions:", + dochead, + pointer_head_main, + ); foreach (main_header; pointer_head_main) { switch (main_header) { case "creator": foreach (sub_header; pointer_head_sub_creator) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -101,8 +143,10 @@ debug(headermetadatajson) { case "title": foreach (sub_header; pointer_head_sub_title) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -111,8 +155,10 @@ debug(headermetadatajson) { case "rights": foreach (sub_header; pointer_head_sub_rights) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -121,8 +167,10 @@ debug(headermetadatajson) { case "date": foreach (sub_header; pointer_head_sub_date) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -131,8 +179,10 @@ debug(headermetadatajson) { case "original": foreach (sub_header; pointer_head_sub_original) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -141,8 +191,10 @@ debug(headermetadatajson) { case "classify": foreach (sub_header; pointer_head_sub_classify) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -151,8 +203,10 @@ debug(headermetadatajson) { case "identifier": foreach (sub_header; pointer_head_sub_identifier) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -161,8 +215,10 @@ debug(headermetadatajson) { case "notes": foreach (sub_header; pointer_head_sub_notes) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -171,8 +227,10 @@ debug(headermetadatajson) { case "publisher": foreach (sub_header; pointer_head_sub_publisher) { if (to!string(dochead[main_header][sub_header]).length > 2) { - writeln(main_header, ":", - sub_header, ": ", + writefln( + "%s:%s: %s", + main_header, + sub_header, dochead[main_header][sub_header] ); } @@ -188,9 +246,13 @@ debug(headermetadatajson) { #+name: ao_output_debugs #+BEGIN_SRC d debug(bookindex) { - writeln("-------------------------------"); - writeln(__FILE__, ":", __LINE__); - auto bookindex = new BookIndexReport(); + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); + auto bookindex = BookIndexReport(); bookindex.bookindex_report_sorted(bookindex_unordered_hashes); } #+END_SRC @@ -219,28 +281,39 @@ debug(checkdoc) { #+name: ao_output_debugs_summary #+BEGIN_SRC d debug(headings) { - writeln("-------------------------------"); - writeln(__FILE__, ":", __LINE__); + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); foreach (obj; contents) { if (obj["is"] == "heading") { - writeln( + writefln( + "%s%s~ [%s] %s", scr_txt_marker["yellow"], - obj["lev"], "~ ", - "[", obj["ocn"], "] ", + obj["lev"], + obj["ocn"], + // "[", obj["is"], "] ", obj["obj"] ); } } } -writeln( +writefln( + "%s%s%s\n%s\n%s%s\n%s%s\n%s%s\n%s:%s", scr_txt_color["green"], "-------------------------------", scr_txt_color["off"], - "\n", fn_src, - "\nlength contents array: ", contents.length, - "\nlast ocn: ", check["last_ocn"], - "\nlength bookindex: ", bookindex_unordered_hashes.length, - "\n", __FILE__, ":", __LINE__, + fn_src, + "length contents array: ", + contents.length, + "last ocn: ", + check["last_ocn"], + "length bookindex: ", + bookindex_unordered_hashes.length, + __FILE__, + __LINE__, ); #+END_SRC *** compare number of ocn for known sisu markup output (checkdoc) @@ -377,12 +450,12 @@ debug(checkdoc) { ** code structure: :ao_output_debugs.d: #+name: tangle_ao_output_debugs #+BEGIN_SRC d :tangle ../lib/sdp/ao_output_debugs.d -/* +/+ output debugs ao_output_debugs.d -*/ ++/ template SiSUoutputDebugs() { - class SDPoutputDebugs { + struct SDPoutputDebugs { auto abstract_doc_source_debugs( string[string][] contents, JSONValue[string] docmake, @@ -394,7 +467,7 @@ template SiSUoutputDebugs() { ) { mixin RgxInit; mixin ScreenTxtColors; - auto rgx = new Rgx(); + auto rgx = Rgx(); <> <> } diff --git a/org/ao_read_markup_source.org b/org/ao_read_markup_source.org index e1fbc8d..08f1b45 100644 --- a/org/ao_read_markup_source.org +++ b/org/ao_read_markup_source.org @@ -85,13 +85,13 @@ final char[][] markupSourceContentRawLineArray(in char[] fn_src) { ** code structure: :ao_read_markup_source.d: #+name: tangle_ao_read_markup_source #+BEGIN_SRC d :tangle ../lib/sdp/ao_read_markup_source.d -/* +/+ read markup source ao_read_markup_source.d -*/ ++/ mixin template SiSUmarkupRaw() { - class MarkupRaw { - auto rgx = new Rgx(); + struct MarkupRaw { + auto rgx = Rgx(); <> } } diff --git a/org/ao_rgx.org b/org/ao_rgx.org index 1292bf8..7306cd3 100644 --- a/org/ao_rgx.org +++ b/org/ao_rgx.org @@ -17,7 +17,7 @@ ** misc :misc: #+name: ao_rgx #+BEGIN_SRC d -/* misc */ +/+ misc +/ static flag_action = ctRegex!(`^(--[a-z][a-z0-9-]+)$`); static flag_action_str = ctRegex!(` (--[a-z][a-z0-9-]+)`); static src_pth = ctRegex!(`^([a-zA-Z0-9._-]+/)*([a-zA-Z0-9._-]+[.]ss[tm])$`); @@ -42,20 +42,20 @@ static levels_numbered_headings = ctRegex!(`^[0-7]$`); ** markup insert file :insert:file: #+name: ao_rgx #+BEGIN_SRC d -/* insert markup file */ +/+ insert markup file +/ static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); // static insert_ssi_or_sst_fn = ctRegex!(`^<<\s*[a-zA-Z0-9._-]+[.]ss[ti]`); #+END_SRC ** comments :comment: #+name: ao_rgx #+BEGIN_SRC d -/* comments */ +/+ comments +/ static comment = ctRegex!(`^%+ `); #+END_SRC ** header :header: #+name: ao_rgx #+BEGIN_SRC d -/* header */ +/+ header +/ static header = ctRegex!(`^@([a-z_]+):(?:\s|$)`); static header_make = ctRegex!(`^@(make):(?:\s|$)`); static header_metadata = ctRegex!(`^@([a-z_]+):(?:\s|$)`); @@ -66,7 +66,7 @@ static head_sub = ctRegex!(`^[ ]*:([a-z_]+):\s+(.+)`, "m"); ** header & paragraph operators :paragraph:operator: #+name: ao_rgx #+BEGIN_SRC d -/* heading & paragraph operators */ +/+ heading & paragraph operators +/ static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?) `); static heading_marker = ctRegex!(`^:?([A-D1-4])[~]`); static heading_title = ctRegex!(`^:?[A-D1-4][~][a-z0-9_.-]*[?]?\s+(.+?)$`); @@ -82,7 +82,7 @@ static para_attribs = ctRegex!(`^_(([0-9])(_([0-9]))?|_([1-9])?[*]) `); ** blocked markup tics :block:tic: #+name: ao_rgx #+BEGIN_SRC d -/* blocked markup tics */ +/+ blocked markup tics +/ static block_tic_code_open = ctRegex!("^`{3} (code)"); static block_tic_poem_open = ctRegex!("^`{3} (poem)"); static block_tic_group_open = ctRegex!("^`{3} (group)"); @@ -94,7 +94,7 @@ static block_tic_close = ctRegex!("^(`{3})$","m"); ** blocked markup curly :block:curly: #+name: ao_rgx #+BEGIN_SRC d -/* blocked markup curly */ +/+ blocked markup curly +/ static block_curly_code_open = ctRegex!(`^(code[{].*?$)`); static block_curly_code_close = ctRegex!(`^([}]code)`); static block_curly_poem_open = ctRegex!(`^(poem[{].*?$)`); @@ -111,7 +111,7 @@ static block_curly_table_close = ctRegex!(`^([}]table)`); ** inline markup font face mod :inline:font:face: #+name: ao_rgx #+BEGIN_SRC d -/* inline markup font face mod */ +/+ inline markup font face mod +/ static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`); static inline_bold = ctRegex!(`!\{(?P.+?)\}!`); static inline_italics = ctRegex!(`/\{(?P.+?)\}/`); @@ -124,7 +124,7 @@ static inline_mono = ctRegex!(`#\{(?P.+?)\}#`); ** inline markup footnotes :inline:footnote: #+name: ao_rgx #+BEGIN_SRC d -/* inline markup footnotes */ +/+ inline markup footnotes +/ static true_dollar = ctRegex!(`\$`, "gm"); static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); @@ -155,7 +155,7 @@ static inline_note_square_delimiters = ctRegex!(`(~\[\s*)(.+?)(\]~)`, "m ** inline markup book index :inline:bookindex: #+name: ao_rgx #+BEGIN_SRC d -/* inline markup book index */ +/+ inline markup book index +/ static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); // strip @@ -163,7 +163,7 @@ static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); // strip ** no ocn object :ocn:off:object: #+name: ao_rgx #+BEGIN_SRC d -/* no ocn object */ +/+ no ocn object +/ static ocn_off = ctRegex!(`~#$`, "m"); static ocn_off_dh = ctRegex!(`-#$`, "m"); static ocn_off_all = ctRegex!(`[~-]#$`, "m"); @@ -171,7 +171,7 @@ static ocn_off_all = ctRegex!(`[~-]#$`, "m"); ** no ocn block :ocn:off:block: #+name: ao_rgx #+BEGIN_SRC d -/* no ocn block */ +/+ no ocn block +/ static ocn_off_block = ctRegex!(`^--~#$`); static ocn_off_block_dh = ctRegex!(`^---#$`); static ocn_off_block_close = ctRegex!(`^--\+#$`); @@ -181,13 +181,13 @@ static ocn_block_marks = ctRegex!(`^--[+~-]#$`); ** ignore outside code blocks :block:code: #+name: ao_rgx #+BEGIN_SRC d -/* ignore outside code blocks */ +/+ ignore outside code blocks +/ static regular_parse_skip = ctRegex!(`^(--[+~-]#|-[\\]{2}-|=[.\\]{2}=)$`); // not structural info #+END_SRC ** line & page breaks :break: #+name: ao_rgx #+BEGIN_SRC d -/* line & page breaks */ +/+ line & page breaks +/ static break_line_within_object = ctRegex!(`[\\]{2}( |$)`); // static break_line_break_within_object = ctRegex!(`( |^)[\\]{2}( |$)`); static break_page = ctRegex!(`^-[\\]{2}-$`); @@ -200,13 +200,13 @@ static parent = ctRegex!(`([0-7]):([0-9]+)`); ** json :json: #+name: ao_rgx #+BEGIN_SRC d -/* json */ +/+ json +/ static tailing_comma = ctRegex!(`,$`, "m"); #+END_SRC ** head :header: #+name: ao_rgx #+BEGIN_SRC d -/* head */ +/+ head +/ static main_headers = ctRegex!(`^(?:creator|title|rights|date|original|classify|identifier|notes|publisher|make|links)$`, "m"); static subhead_creator = ctRegex!(`^(?:author|translator|illustrator)$`, "m"); static subhead_title = ctRegex!(`^(?:main|sub(?:title)?|full|language|edition|note)$`, "m"); @@ -222,14 +222,14 @@ static subhead_make = ctRegex!(`^(?:cover_image|home_button_image|h ** biblio tags :biblio:tags: #+name: ao_rgx #+BEGIN_SRC d -/* biblio tags */ +/+ biblio tags +/ static biblio_tags = ctRegex!(`^(is|au|author_raw|author|author_arr|editor_raw|ed|editor_arr|ti|title|subtitle|fulltitle|lng|language|trans|src|jo|journal|in|vol|volume|edn|edition|yr|year|pl|place|pb|pub|publisher|url|pg|pages|note|short_name|id):\s+(.+)`); static biblio_abbreviations = ctRegex!(`^(au|ed|ti|lng|jo|vol|edn|yr|pl|pb|pub|pg|pgs|sn)$`); #+END_SRC ** bookindex split :bookindex:split: #+name: ao_rgx #+BEGIN_SRC d -/* bookindex split */ +/+ bookindex split +/ static bi_main_terms_split = ctRegex!(`\s*;\s*`); static bi_main_term_plus_rest_split = ctRegex!(`\s*:\s*`); static bi_sub_terms_plus_ocn_offset_split = ctRegex!(`\s*\|\s*`); @@ -239,12 +239,12 @@ static bi_term_and_ocns_match = ctRegex!(`^(.+?)\+(\d+)`); ** code structure: :ao_rgx.d: #+name: tangle_ao_rgx #+BEGIN_SRC d :tangle ../lib/sdp/ao_rgx.d -/* +/+ regex ao_rgx.d -*/ ++/ mixin template RgxInit() { - class Rgx { + struct Rgx { <> } } diff --git a/org/ao_scan_inserts.org b/org/ao_scan_inserts.org index 930d875..2b76960 100644 --- a/org/ao_scan_inserts.org +++ b/org/ao_scan_inserts.org @@ -19,16 +19,10 @@ *** scan subdoc source #+name: ao_inserts_scan #+BEGIN_SRC d -char[][100000] cont_arbitrary_max_length_set_; -auto ft0 = flag_type.dup; +char[][] contents_insert; auto ft1 = flag_type.dup; -string[string] processing; -uint[string] line_occur; -auto obj_im = new ObjInlineMarkup(); -auto obj_att = new ObjAttrib(); -int[string] counter; counter["add"]=0; mixin ScreenTxtColors; -auto rgx = new Rgx(); +auto rgx = Rgx(); int tell_l(string color, in char[] line) { writeln(scr_txt_marker[color], line); return 0; @@ -36,6 +30,7 @@ int tell_l(string color, in char[] line) { auto fn_pth_full = match(fn_src, rgx.src_pth); auto markup_src_file_path = fn_pth_full.captures[1]; #+END_SRC + *** loop insert (sub-document) #+name: ao_inserts_scan_loop #+BEGIN_SRC d @@ -45,44 +40,36 @@ if (ft1["curly_code"] == 1) { if (auto m = match(line, rgx.block_curly_code_close)) { ft1["curly_code"] = 0; } - cont_arbitrary_max_length_set_[counter["add"]] = line; - ++counter["add"]; ++add; + contents_insert ~= line; } else if (auto m = match(line, rgx.block_curly_code_open)) { ft1["curly_code"] = 1; ft1["header_make"] = 0; ft1["header_metadata"] = 0; - cont_arbitrary_max_length_set_[counter["add"]] = line; - ++counter["add"]; ++add; + contents_insert ~= line; } else if (ft1["tic_code"] == 1) { ft1["header_make"] = 0; ft1["header_metadata"] = 0; if (auto m = match(line, rgx.block_tic_close)) { ft1["tic_code"] = 0; } - cont_arbitrary_max_length_set_[counter["add"]] = line; - ++counter["add"]; ++add; + contents_insert ~= line; } else if (auto m = match(line, rgx.block_tic_code_open)) { ft1["tic_code"] = 1; ft1["header_make"] = 0; ft1["header_metadata"] = 0; - cont_arbitrary_max_length_set_[counter["add"]] = line; - ++counter["add"]; ++add; + contents_insert ~= line; } else if ( - (ft1["header_make"] == 1) && (line_occur["header_make"] > 0) + (ft1["header_make"] == 1) && match(line, rgx.header_sub) ) { ft1["header_make"] = 1; ft1["header_metadata"] = 0; - ++line_occur["header_make"]; - ++counter["add"]; } else if ( - (ft1["header_metadata"] == 1) && (line_occur["header_metadata"] > 0) + (ft1["header_metadata"] == 1) && match(line, rgx.header_sub) ) { ft1["header_metadata"] = 1; ft1["header_make"] = 0; - ++line_occur["header_metadata"]; - ++counter["add"]; } else if (auto m = match(line, rgx.insert_src_fn_ssi_or_sst)) { ft1["header_make"] = 0; ft1["header_metadata"] = 0; @@ -90,7 +77,7 @@ if (ft1["curly_code"] == 1) { auto insert_sub_pth = m.captures[1]; auto fn_src_insert = (markup_src_file_path ~ insert_sub_pth ~ insert_fn); - auto raw = new MarkupRaw(); + auto raw = MarkupRaw(); auto markup_sourcesubfile_insert_content = raw.markupInsertSourceContentRawLineArray(fn_src_insert); debug(insert) { // insert file @@ -102,7 +89,7 @@ if (ft1["curly_code"] == 1) { markup_sourcesubfile_insert_content.length ); } - auto ins = new Inserts(); + auto ins = Inserts(); /+ 1. load file, 2. read lines; @@ -115,31 +102,24 @@ if (ft1["curly_code"] == 1) { } else { ft1["header_make"] = 0; ft1["header_metadata"] = 0; - cont_arbitrary_max_length_set_[counter["add"]] = line; - ++counter["add"]; ++add; + contents_insert ~= line; } #+END_SRC + *** post loop #+name: ao_inserts_scan_post #+BEGIN_SRC d -auto contents_ = cont_arbitrary_max_length_set_[0 .. counter["add"]].dup; -auto t = tuple(contents_, add); -return t; +return contents_insert; #+END_SRC ** scan document source :scan_src: *** scan doc source #+name: ao_doc_scan #+BEGIN_SRC d -char[][100000] cont_arbitrary_max_length_set; // 2000 pg * 50 lines -string[string] processing; -uint[string] line_occur; -auto obj_im = new ObjInlineMarkup(); -auto obj_att = new ObjAttrib(); +char[][] contents; auto ft = flag_type.dup; -int add; mixin ScreenTxtColors; -auto rgx = new Rgx(); +auto rgx = Rgx(); int tell_l(string color, in char[] line) { writeln(scr_txt_marker[color], line); return 0; @@ -147,6 +127,7 @@ int tell_l(string color, in char[] line) { auto fn_pth_full = match(fn_src, rgx.src_pth); auto markup_src_file_path = fn_pth_full.captures[1]; #+END_SRC + *** loop insert (document) #+name: ao_doc_scan_loop #+BEGIN_SRC d @@ -156,49 +137,42 @@ if (ft["curly_code"] == 1) { if (auto m = match(line, rgx.block_curly_code_close)) { ft["curly_code"] = 0; } - cont_arbitrary_max_length_set[add] = line; - ++add; + contents ~= line; } else if (auto m = match(line, rgx.block_curly_code_open)) { ft["curly_code"] = 1; ft["header_make"] = 0; ft["header_metadata"] = 0; - cont_arbitrary_max_length_set[add] = line; - ++add; + contents ~= line; } else if (ft["tic_code"] == 1) { ft["header_make"] = 0; ft["header_metadata"] = 0; if (auto m = match(line, rgx.block_tic_close)) { ft["tic_code"] = 0; } - cont_arbitrary_max_length_set[add] = line; - ++add; + contents ~= line; } else if (auto m = match(line, rgx.block_tic_code_open)) { ft["tic_code"] = 1; ft["header_make"] = 0; ft["header_metadata"] = 0; - cont_arbitrary_max_length_set[add] = line; -} else if ((ft["header_make"] == 1) -&& (line_occur["header_make"] > 0) -&& match(line, rgx.header_sub)) { - ++line_occur["header_make"]; - cont_arbitrary_max_length_set[add] = line; - ++add; -} else if ((ft["header_metadata"] == 1) -&& (line_occur["header_metadata"] > 0) -&& match(line, rgx.header_sub)) { - ++line_occur["header_metadata"]; - cont_arbitrary_max_length_set[add] = line; - ++add; + contents ~= line; +} else if ( + (ft["header_make"] == 1) + && match(line, rgx.header_sub) +) { + contents ~= line; +} else if ( + (ft["header_metadata"] == 1) + && match(line, rgx.header_sub) +) { + contents ~= line; } else if (auto m = match(line, rgx.header_make)) { ft["header_make"] = 1; - ++line_occur["header_make"]; - cont_arbitrary_max_length_set[add] = line; - ++add; + ft["header_metadata"] = 0; + contents ~= line; } else if (auto m = match(line, rgx.header_metadata)) { + ft["header_make"] = 0; ft["header_metadata"] = 1; - ++line_occur["header_metadata"]; - cont_arbitrary_max_length_set[add] = line; - ++add; + contents ~= line; } else if (auto m = match(line, rgx.insert_src_fn_ssi_or_sst)) { ft["header_make"] = 0; ft["header_metadata"] = 0; @@ -206,7 +180,7 @@ if (ft["curly_code"] == 1) { auto insert_sub_pth = m.captures[1]; auto fn_src_insert = (markup_src_file_path ~ insert_sub_pth ~ insert_fn); - auto raw = new MarkupRaw(); + auto raw = MarkupRaw(); auto markup_sourcefile_insert_content = raw.markupInsertSourceContentRawLineArray(fn_src_insert); debug(insert) { // insert file @@ -217,15 +191,12 @@ if (ft["curly_code"] == 1) { markup_sourcefile_insert_content.length ); } - auto ins = new Inserts(); - auto t = ins.scan_subdoc_source( - markup_sourcefile_insert_content, to!string(fn_src_insert), add + auto ins = Inserts(); + auto contents_insert = ins.scan_subdoc_source( + markup_sourcefile_insert_content, + to!string(fn_src_insert) ); - static assert(!isTypeTuple!(t)); - auto tmparr = t[0]; - auto addsub = t[1]; - cont_arbitrary_max_length_set[add .. addsub-1] = tmparr[0 .. $-1]; - add=addsub; + contents ~= contents_insert; /+ 1. load file, 2. read lines; @@ -238,18 +209,16 @@ if (ft["curly_code"] == 1) { } else { ft["header_make"] = 0; ft["header_metadata"] = 0; - cont_arbitrary_max_length_set[add] = line; - ++add; + contents ~= line; } #+END_SRC + *** post loop #+name: ao_doc_scan_post #+BEGIN_SRC d -auto contents = cont_arbitrary_max_length_set[0..add].dup; debug(insert) { // insert file writeln(__LINE__); writeln(contents.length); - writeln(add); } return contents; #+END_SRC @@ -263,9 +232,11 @@ return contents; ao_inserts.d +/ mixin template SiSUdocInserts() { - class Inserts { + private: + struct Inserts { auto scan_subdoc_source( - char[][] markup_sourcefile_insert_content, string fn_src, int add + char[][] markup_sourcefile_insert_content, + string fn_src ) { <> foreach (line; markup_sourcefile_insert_content) { @@ -273,7 +244,10 @@ mixin template SiSUdocInserts() { } // end src subdoc (inserts) loop <> } - auto scan_doc_source(char[][] markup_sourcefile_content, string fn_src) { + auto scan_doc_source( + char[][] markup_sourcefile_content, + string fn_src + ) { <> foreach (line; markup_sourcefile_content) { <> diff --git a/org/ao_structs.org b/org/ao_structs.org new file mode 100644 index 0000000..9350eb5 --- /dev/null +++ b/org/ao_structs.org @@ -0,0 +1,71 @@ +#+TITLE: sdp structs +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:dev:ao: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +* structs :struct: +[[./sdp.org][sdp]] + +** initialize +#+name: structs +#+BEGIN_SRC d +/+ structs +/ + +mixin template Structs() { + struct ObjHeading { + string type; + string lev; + string lvn; + string lcn; + } + struct ObjPara { + string indent_first; + string indent_second; + string bullet; + } + struct ObjComment { + // does not have .attrib; + // does not have .ocn + } + struct ObjBlock { + } + struct ObjBlockOcnString { + // does not have .attrib; + string node; + } + struct ObjComposite { + // size_t id; + string use; + string of; + string is_a; + string object; + string ocn; + string attrib; + // int ocn; + ObjHeading heading; + ObjPara para; + ObjBlock block; + ObjBlockOcnString block_ocn_string; + } +} +#+END_SRC + +* tangles :tangle: +** code structure: :ao_structs.d: +#+name: tangle_ao_structs +#+BEGIN_SRC d :tangle ../lib/sdp/ao_structs.d +/+ + structs + ao_structs.d ++/ +<> +#+END_SRC diff --git a/org/ao_utils.org b/org/ao_utils.org index 2d29628..3e1e42d 100644 --- a/org/ao_utils.org +++ b/org/ao_utils.org @@ -104,10 +104,10 @@ writefln("Inside function %s at file %s, line %s", ** code structure: :ao_util.d: #+name: tangle_ao_utils #+BEGIN_SRC d :tangle ../lib/sdp/ao_utils.d -/* +/+ utils ao_util.d -*/ ++/ mixin template ScreenTxtColors() { <> } diff --git a/org/compile_time_info.org b/org/compile_time_info.org new file mode 100644 index 0000000..d733d0b --- /dev/null +++ b/org/compile_time_info.org @@ -0,0 +1,101 @@ +#+TITLE: sdp compile time info +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:niu:compile:info: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +* compilation info :compile: +[[../maker.org][maker.org makefile]] +[[./sdp.org][sdp hub]] [[./][org/]] + +e.g. do on linux bsd osx not windows: +version(Windows) {} else { ... } + +*** complile time os +OS type shows during compilation + +**** set os flags +#+name: sdp_compile_time_info +#+BEGIN_SRC d +version(Windows) { + pragma(msg, "[ Windows compilation ]"); + enum os = "Windows"; +} else version(OSX) { + pragma(msg, "[ Mac OS X POSIX System compilation ]"); + enum os = "OSX"; +} else version(linux) { + pragma(msg, "[ Linux POSIX System compilation ]"); + enum os = "Linux"; +} else version(FreeBSD) { + pragma(msg, "[ FreeBSD POSIX System compilation ]"); + enum os = "FreeBSD"; +} else version(OpenBSD) { + pragma(msg, "[ OpenBSD POSIX System compilation ]"); + enum os = "OpenBSD"; +} else version(NetBSD) { + pragma(msg, "[ NetBSD POSIX System compilation ]"); + enum os = "NetBSD"; +} else version(DragonFlyBSD) { + pragma(msg, "[ DragonFlyBSD POSIX System compilation ]"); + enum os = "DragonFlyBSD"; +} else version(POSIX) { + pragma(msg, "[ POSIX System compilation ]"); + enum os = "POSIX"; +} else { + static assert(0, "OS not listed"); +} +#+END_SRC + +*** complile time static if os +OS type compiled in and shows during program run + +**** report os flag (set) (not used here) +#+BEGIN_SRC d +static if(sysWindows) { + writeln("Windows"); +} else static if(sysOSX) { + writeln("OSX"); +} else static if(sysLinux) { + writeln("Linux"); +} else static if(sysFreeBSD) { + writeln("FreeBSD"); +} else static if(sysOpenBSD) { + writeln("OpenBSD"); +} else static if(sysNetBSD) { + writeln("NetBSD"); +} else static if(sysDragonFlyBSD) { + writeln("DragonFlyBSD"); +} else { + writeln("other"); +} +#+END_SRC + +*** 64 bit compilation? +#+name: sdp_compile_time_info +#+BEGIN_SRC d +version(D_LP64) { + enum bits = "64 bit"; +} else { + enum bits = "32 bit"; +} +#+END_SRC + +* tangles :tangle: +** code structure :sdp.d: +#+begin_src d :tangle ../lib/sdp/compile_time_info.d +/+ + compile_time_info + compile_time_info.d ++/ +mixin template CompileTimeInfo() { + <> +} +#+end_src diff --git a/org/sdp.org b/org/sdp.org index bd0ad84..e8e100a 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -17,20 +17,34 @@ Deal with imports. Take command line instructions and process files as instructed. +** TODO version, (version.txt) set version (with structure) :version: + +#+NAME: version_txt +#+BEGIN_SRC d +struct Version { + int major; + int minor; + int patch; +} +enum ver = Version(1, 0, 0); +#+END_SRC + ** imports :import: +[[./compile_time_info.org][compile time info]] [[./ao_abstract_doc_source.org][ao_abstract_doc_source]] [[./ao_assertions.org][ao_assertions]] [[./ao_defaults.org][ao_defaults]] -[[./ao_emitters_and_interfaces.org][ao_emitters_and_interfaces: ao_emitter; ao_interface]] +[[./ao_emitter.org][ao_emitter]] [[./ao_read_markup_source.org][ao_read_markup_source]] -// [[./ao_read_markup_source.org][ao_read_markup_source]] [[./ao_object_setter.org][ao_object_setter]] [[./ao_output_debugs.org][ao_output_debugs]] [[./ao_rgx.org][ao_rgx]] [[./ao_scan_inserts.org][ao_scan_inserts]] +[[./ao_structs.org][ao_structs]] [[./ao_utils.org][ao_utils]] -#+name: sdp_imports +*** std :import:std: +#+NAME: sdp_imports #+BEGIN_SRC d /+ sdp sisu document parser +/ import @@ -50,24 +64,60 @@ import std.typecons, std.utf, // std.variant, + std.conv : to; +#+END_SRC + +*** sdp :import:sdp: +**** TODO lib/sdp.d +#+NAME: sdp_imports_use +#+BEGIN_SRC d +/+ sdp sisu document parser +/ +import + lib.sdp.compile_time_info, // sdp/compile_time_info.d lib.sdp.ao_abstract_doc_source, // sdp/ao_abstract_doc_source.d lib.sdp.ao_assertions, // sdp/ao_assertions.d lib.sdp.ao_defaults, // sdp/ao_defaults.d lib.sdp.ao_emitter, // sdp/ao_emitter.d - lib.sdp.ao_interface, // sdp/ao_interface.d - lib.sdp.ao_read_markup_source, // sdp/ao_read_markup_source.d + lib.sdp.ao_read_markup_source, // sdp/ao_read_markup_source.d lib.sdp.ao_object_setter, // sdp/ao_object_setter.d lib.sdp.ao_output_debugs, // sdp/ao_output_debugs.d lib.sdp.ao_rgx, // sdp/ao_rgx.d lib.sdp.ao_scan_inserts, // sdp/ao_scan_inserts.d + lib.sdp.ao_structs, // sdp/ao_structs.d lib.sdp.ao_utils; // sdp/ao_utils.d // std.conv; -import std.conv : to; +#+END_SRC + +**** TODO lib/sdp/std.d (rdmd) :rdmd: +#+NAME: sdp_imports_rdmd +#+BEGIN_SRC d +/+ sdp sisu document parser +/ +import + compile_time_info, // compile_time_info.d + ao_abstract_doc_source, // ao_abstract_doc_source.d + ao_assertions, // ao_assertions.d + ao_defaults, // ao_defaults.d + ao_emitter, // ao_emitter.d + ao_read_markup_source, // sdp/ao_read_markup_source.d + ao_object_setter, // ao_object_setter.d + ao_output_debugs, // ao_output_debugs.d + ao_rgx, // ao_rgx.d + ao_scan_inserts, // ao_scan_inserts.d + ao_structs, // ao_structs.d + ao_utils; // ao_utils.d + // std.conv; +#+END_SRC + +*** version.txt :version: +#+NAME: sdp_version_mixin +#+BEGIN_SRC d +// import std.stdio; +mixin(import("version.txt")); #+END_SRC ** argv [+3] :argv: *** argv mixins & init -#+name: sdp_argv +#+NAME: sdp_argv #+BEGIN_SRC d mixin SiSUheader; mixin SiSUbiblio; @@ -77,10 +127,10 @@ mixin SiSUdocInserts; mixin SiSUdocAbstraction; mixin SiSUoutputDebugs; mixin ScreenTxtColors; -auto cli = new CLI(); -auto raw = new MarkupRaw(); -auto abs = new Abstraction(); -auto dbg = new SDPoutputDebugs(); +auto cli = CLI(); +auto raw = MarkupRaw(); +auto abs = Abstraction(); +auto dbg = SDPoutputDebugs(); // struct DocumentParts { // string[string][] contents; // JSONValue[string] metadata_json; @@ -88,47 +138,60 @@ auto dbg = new SDPoutputDebugs(); // string[][string][string] bookindex_unordered_hashes; // JSONValue[] biblio; // } -char[][] msc; -string[1000] fns_src; +string[] fns_src; string flag_action; string[string] actions; -int file_count; actions = [ "assert" : "yes", ]; -auto rgx = new Rgx(); +auto rgx = Rgx(); scope(success) { debug(checkdoc) { - writeln( + writefln( + "%s~ run complete, ok ~ %s (sdp-%s.%s.%s, %s v%s, %s %s)", scr_txt_color["cyan"], - "~ run complete, ok ~ ", scr_txt_color["off"], + ver.major, + ver.minor, + ver.patch, + __VENDOR__, + __VERSION__, + bits, + os, ); } - // writeln("0"); + // stderr.writeln("0"); } scope(failure) { - debug(checkdoc) { - writeln( + debug(checkdoc) { + writefln( + "%s~ run failure ~%s", scr_txt_color["fuchsia"], - "~ run failure ~", scr_txt_color["off"], + ); + } + // stderr.writeln("1"); +} +scope(exit) { + debug(checkdoc) { + writefln( + "(%s v%s)", + __VENDOR__, + __VERSION__, ); } - // writeln("1"); } #+END_SRC *** argv loop -#+name: sdp_argv +#+NAME: sdp_argv #+BEGIN_SRC d foreach(cmdlnins; argv) { if (match(cmdlnins, rgx.flag_action)) { flag_action ~= " " ~ cmdlnins; actions = cli.extract_actions(cmdlnins, actions); } else if (match(cmdlnins, rgx.src_pth)) { - fns_src[file_count] = cmdlnins; - file_count++; + fns_src ~= cmdlnins; } } #+END_SRC @@ -136,29 +199,38 @@ foreach(cmdlnins; argv) { *** each file [+2] :file: **** filename provided [+1] ***** scope :scope: -#+name: sdp_each_file_do +#+NAME: sdp_each_file_do #+BEGIN_SRC d scope(success) { debug(checkdoc) { - writeln( + writefln( + "%s~ document complete, ok ~%s %s", scr_txt_color["green"], - "~ document complete, ok ~ ", scr_txt_color["off"], fn_src ); } - // writeln("0"); + // stderr.writeln("0"); } scope(failure) { debug(checkdoc) { - writeln( + writefln( + "%s~ document run failure ~%s (%s v%s)\n\t%s", scr_txt_color["red"], - "~ document run failure ~", scr_txt_color["off"], + __VENDOR__, + __VERSION__, + fn_src + ); + } + // stderr.writeln("1"); +} +scope(exit) { + debug(checkdoc) { + writeln( fn_src ); } - // writeln("1"); } enforce( match(fn_src, rgx.src_pth), @@ -167,9 +239,9 @@ enforce( #+END_SRC ***** read file :file:read: -[[./ao_read_markup_source.org][ao_read_markup_source]] +[[./ao_markup_source_raw.org][ao_markup_source_raw]] -#+name: sdp_each_file_do +#+NAME: sdp_each_file_do #+BEGIN_SRC d auto markup_sourcefile_content = raw.markupSourceContentRawLineArray(fn_src); // alternative call @@ -181,7 +253,10 @@ debug(insert) { auto m = match(fn_src, rgx.src_pth); // auto m = match(fn_src, rgx.src_pth); auto markup_src_file_path = m.captures[1]; - writeln("markup source file path: ", markup_src_file_path); // writeln(m.captures[1]); + writefln( + "markup source file path: %s", + markup_src_file_path + ); // writeln(m.captures[1]); writeln(m.captures[2]); } #+END_SRC @@ -189,32 +264,35 @@ debug(insert) { ****** incorporate any inserts [[./ao_scan_inserts.org][ao_scan_inserts]] -#+name: sdp_each_file_do +#+NAME: sdp_each_file_do #+BEGIN_SRC d if (match(fn_src, rgx.src_fn_master)) { -/+ if master file scan document source for document imports (inserted sub-documents) +/ - auto ins = new Inserts(); - auto markup_master_sourcefile_content = +/+ if master file .ssm + scan document source for document imports + (inserted sub-documents) ++/ + auto ins = Inserts(); + markup_sourcefile_content = ins.scan_doc_source(markup_sourcefile_content, fn_src); - msc = markup_master_sourcefile_content; -} else if (match(fn_src, rgx.src_fn)) { - msc = markup_sourcefile_content; -} else { +} else if (!match(fn_src, rgx.src_fn)) { writeln("not a recognized filename"); } debug(raw) { - foreach (line; msc) { + foreach (line; markup_sourcefile_content) { writeln(line); } } #+END_SRC ***** send for processing :processing: -#+name: sdp_each_file_do +#+NAME: sdp_each_file_do #+BEGIN_SRC d -/+ process document ao_abstract_doc_source SiSUdocAbstraction::Abstraction return abstraction as tuple +/ +/+ process document ao_abstract_doc_source + SiSUdocAbstraction::Abstraction + return abstraction as tuple ++/ auto t = - abs.abstract_doc_source(msc); + abs.abstract_doc_source(markup_sourcefile_content); static assert(!isTypeTuple!(t)); auto contents = t[0]; // static assert(!isIterable!(contents)); @@ -226,7 +304,7 @@ auto biblio = t[4]; #+END_SRC ***** debug document parts (checkdoc) -#+name: sdp_each_file_do +#+NAME: sdp_each_file_do #+BEGIN_SRC d // DocumentParts debug(checkdoc) { @@ -245,10 +323,10 @@ debug(checkdoc) { #+END_SRC ***** on exit -#+name: sdp_each_file_do +#+NAME: sdp_each_file_do #+BEGIN_SRC d scope(exit) { - destroy(msc); + destroy(markup_sourcefile_content); destroy(t); destroy(contents); destroy(make_json); @@ -260,25 +338,29 @@ scope(exit) { #+END_SRC **** no filename provided -#+name: sdp_no_filename_provided +#+NAME: sdp_no_filename_provided #+BEGIN_SRC d -/* no recognized filename provided */ +/+ no recognized filename provided +/ writeln("no recognized filename"); break; // terminate, stop #+END_SRC * tangles :tangle: -** code structure :sdp.d: -#+name: tangle_sdp +** sdp code structure :sdp.d: +*** TODO lib/sdp.d #+BEGIN_SRC d :tangle ../lib/sdp.d :shebang #!/usr/bin/env rdmd -/* +/+ sdp sdp.d -*/ ++/ <> -mixin RgxInit; mixin Interfaces; mixin Emitters; +<> +<> +mixin CompileTimeInfo; +mixin RgxInit; mixin Emitters; void main(string[] argv) { + <> <> foreach(fn_src; fns_src) { if (!empty(fn_src)) { @@ -289,3 +371,18 @@ void main(string[] argv) { } } #+end_src + +** version.txt :version: + +*** TODO lib/version.txt +#+BEGIN_SRC d :tangle ../lib/version.txt +/+ obt - org generated file +/ +<> +#+END_SRC + +*** TODO lib/sdp/version.txt :rdmd: +#+BEGIN_SRC d :tangle ../lib/sdp/version.txt +/+ obt - org generated file +/ +// [used by rdmd] +<> +#+END_SRC -- cgit v1.2.3