From cdaba1c73f0555e1128a7a35addddcfaf715dbde Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 22 Mar 2017 14:54:07 -0400 Subject: 0.13.7 tables ao and html output, poem html output --- src/sdp/ao_abstract_doc_source.d | 938 +++++++++++++++++++++++++-------------- 1 file changed, 604 insertions(+), 334 deletions(-) (limited to 'src/sdp/ao_abstract_doc_source.d') diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index a277a61..de3d575 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -557,6 +557,10 @@ template SiSUdocAbstraction() { type["ocn_status"] = TriState.off; } continue; + } else if (type["quote"] == TriState.on) { + /+ within block object: quote +/ + _quote_block_(line, an_object, type); + continue; /+ within block object: group +/ } else if (type["group"] == TriState.on) { /+ within block object: group +/ @@ -570,13 +574,9 @@ template SiSUdocAbstraction() { /+ within block object: poem +/ _poem_block_(line, an_object, type, cntr, obj_cite_number_poem, dochead_make_aa); continue; - } else if (type["quote"] == TriState.on) { - /+ within block object: quote +/ - _quote_block_(line, an_object, type); - continue; } else if (type["table"] == TriState.on) { /+ within block object: table +/ - _table_block_(line, an_object, type); + _table_block_(line, an_object, type, dochead_make_aa); continue; } else { /+ not within a block group +/ @@ -1688,8 +1688,12 @@ template SiSUdocAbstraction() { static assert(is(typeof(obj_cite_number_poem) == string[string])); } auto rgx = Rgx(); - if (line.matchFirst(rgx.block_curly_code_open)) { + string code_block_syntax = ""; + bool code_block_numbered = false; + if (auto m = line.matchFirst(rgx.block_curly_code_open)) { /+ curly code open +/ + code_block_syntax = (m.captures[1]) ? m.captures[1].to!string : ""; + code_block_numbered = (m.captures[2] == "#") ? true : false; debug(code) { // code (curly) open writefln( "* [code curly] %s", @@ -1746,7 +1750,7 @@ template SiSUdocAbstraction() { type["blocks"] = TriState.on; type["quote"] = TriState.on; type["curly_quote"] = TriState.on; - } else if (line.matchFirst(rgx.block_curly_table_open)) { + } else if (auto m = line.matchFirst(rgx.block_curly_table_open)) { /+ curly table open +/ debug(table) { // table (curly) open writefln( @@ -1754,11 +1758,22 @@ template SiSUdocAbstraction() { line ); } - type["blocks"] = TriState.on; - type["table"] = TriState.on; - type["curly_table"] = TriState.on; - } else if (line.matchFirst(rgx.block_tic_code_open)) { + an_object["table_head"] = m.captures[1].to!string; + an_object["block_type"] = "curly"; + type["blocks"] = TriState.on; + type["table"] = TriState.on; + type["curly_table"] = TriState.on; + } else if (auto m = line.matchFirst(rgx.block_curly_table_special_markup)) { + /+ table: special table block markup syntax! +/ + an_object["table_head"] = m.captures[1].to!string; + an_object["block_type"] = "special"; + type["blocks"] = TriState.on; + type["table"] = TriState.on; + type["curly_table_special_markup"] = TriState.on; + } else if (auto m = line.matchFirst(rgx.block_tic_code_open)) { /+ tic code open +/ + code_block_syntax = (m.captures[1]) ? m.captures[1].to!string : ""; + code_block_numbered = (m.captures[2] == "#") ? true : false; debug(code) { // code (tic) open writefln( "* [code tic] %s", @@ -1814,7 +1829,7 @@ template SiSUdocAbstraction() { type["blocks"] = TriState.on; type["quote"] = TriState.on; type["tic_quote"] = TriState.on; - } else if (line.matchFirst(rgx.block_tic_table_open)) { + } else if (auto m = line.matchFirst(rgx.block_tic_table_open)) { /+ tic table open +/ debug(table) { // table (tic) open writefln( @@ -1822,12 +1837,14 @@ template SiSUdocAbstraction() { line ); } - type["blocks"] = TriState.on; - type["table"] = TriState.on; - type["tic_table"] = TriState.on; + an_object["table_head"] = m.captures[1].to!string; + an_object["block_type"] = "tic"; + type["blocks"] = TriState.on; + type["table"] = TriState.on; + type["tic_table"] = TriState.on; } } - void _code_block_(L,O,T)( + void _quote_block_(L,O,T)( return ref L line, return ref O an_object, return ref T type @@ -1838,181 +1855,36 @@ template SiSUdocAbstraction() { static assert(is(typeof(type) == int[string])); } auto rgx = Rgx(); - if (type["curly_code"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_code_close)) { - debug(code) { // code (curly) close + if (type["curly_quote"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_quote_close)) { + debug(quote) { // quote (curly) close writeln(line); } - type["blocks"] = TriState.closing; - type["code"] = TriState.closing; - type["curly_code"] = TriState.off; + type["blocks"] = TriState.closing; + type["quote"] = TriState.closing; + type["curly_quote"] = TriState.off; } else { - debug(code) { // code (curly) line + debug(quote) { writeln(line); } - an_object[an_object_key] ~= line ~= "\n"; // code (curly) line + an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) } - } else if (type["tic_code"] == TriState.on) { + } else if (type["tic_quote"] == TriState.on) { if (line.matchFirst(rgx.block_tic_close)) { - debug(code) { // code (tic) close + debug(quote) { // quote (tic) close writeln(line); } - type["blocks"] = TriState.closing; - type["code"] = TriState.closing; - type["tic_code"] = TriState.off; + type["blocks"] = TriState.closing; + type["quote"] = TriState.closing; + type["tic_quote"] = TriState.off; } else { - debug(code) { // code (tic) line - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // code (tic) line - } - } - } - final string biblio_tag_map(A)(A abr) { - debug(asserts) { - static assert(is(typeof(abr) == string)); - } - auto btm = [ - "au" : "author_raw", - "ed" : "editor_raw", - "ti" : "fulltitle", - "lng" : "language", - "jo" : "journal", - "vol" : "volume", - "edn" : "edition", - "yr" : "year", - "pl" : "place", - "pb" : "publisher", - "pub" : "publisher", - "pg" : "pages", - "pgs" : "pages", - "sn" : "short_name" - ]; - return btm[abr]; - } - void _biblio_block_( - char[] line, - return ref int[string] type, - return ref int bib_entry, - return ref string biblio_entry_str_json, - return ref string[] biblio_arr_json - ) { - mixin SiSUbiblio; - auto jsn = BibJsnStr(); - auto rgx = Rgx(); - if (line.matchFirst(rgx.heading_biblio)) { - type["biblio_section"] = TriState.on; - type["blurb_section"] = State.off; - type["glossary_section"] = State.off; - } - if (line.empty) { - debug { - debug(biblioblock) { - writeln("---"); - } - debug(biblioblockinclude) { - writeln(biblio_entry_str_json.length); - } - } - if ((bib_entry == State.off) - && (biblio_entry_str_json.empty)) { - bib_entry = State.on; - biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; - } else if (!(biblio_entry_str_json.empty)) { - bib_entry = State.off; - if (!(biblio_entry_str_json == jsn.biblio_entry_tags_jsonstr)) { - auto biblio_entry = parseJSON(biblio_entry_str_json); - if (biblio_entry["fulltitle"].str.empty) { - writeln("check problem entry (Title missing): ", biblio_entry_str_json); - } else if ((biblio_entry["author_raw"].str.empty) && (biblio_entry["editor_raw"].str.empty)) { - writeln("check problem entry (No author and no editor): ", biblio_entry_str_json); - } else { - biblio_arr_json ~= biblio_entry_str_json; - } - biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; - } - } else { // CHECK ERROR - writeln("?? 2. ERROR ", biblio_entry_str_json, "??"); - biblio_entry_str_json = ""; - } - } else if (line.matchFirst(rgx.biblio_tags)) { - debug(biblioblock) { - writeln(line); - } - auto bt = line.match(rgx.biblio_tags); - bib_entry = State.off; - st = bt.captures[1].to!string; - auto header_tag_value=(bt.captures[2]).to!string; - JSONValue j = parseJSON(biblio_entry_str_json); - biblio_tag_name = (st.match(rgx.biblio_abbreviations)) - ? (biblio_tag_map(st)) - : st; - j.object[biblio_tag_name] = header_tag_value; - debug(bibliounsortedcheckduplicates) { - writeln(biblio_tag_name, ": ", header_tag_value); - writeln("--"); - } - switch (biblio_tag_name) { - case "author_raw": // author_arr author (fn sn) - j["author_arr"] = - header_tag_value.split(rgx.arr_delimiter); - string tmp; - biblioAuthorLoop: - foreach (au; j["author_arr"].array) { - if (auto x = au.str.match(rgx.name_delimiter)) { - tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; - } else { - tmp ~= au.str; - } - } - tmp = (tmp).replace(rgx.trailing_comma, ""); - j["author"].str = tmp; - goto default; - case "editor_raw": // editor_arr editor (fn sn) - j["editor_arr"] = - header_tag_value.split(rgx.arr_delimiter); - string tmp; - biblioEditorLoop: - foreach (ed; j["editor_arr"].array) { - if (auto x = ed.str.match(rgx.name_delimiter)) { - tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; - } else { - tmp ~= ed.str; - } - } - tmp = (tmp).replace(rgx.trailing_comma, ""); - j["editor"].str = tmp; - goto default; - case "fulltitle": // title & subtitle - goto default; - default: - break; - } - auto s = j.toString(); - debug(biblio1) { - writefln( - "* %s: %s\n%s", - biblio_tag_name, - biblio_tag_entry, - j[biblio_tag_name] - ); - } - if (line.match(rgx.comment)) { - writeln("ERROR", line, "COMMENT"); - writeln("ERROR", s, "%%"); - } - if (!(match(line, rgx.comment))) { - debug(biblioblockinclude) { + debug(quote) { writeln(line); } - biblio_entry_str_json = s; - } else { - biblio_entry_str_json = ""; + an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) } - header_tag_value=""; } } - // void _group_block_(L,O,T)( return ref L line, return ref O an_object, @@ -2114,47 +1986,50 @@ template SiSUdocAbstraction() { auto rgx = Rgx(); if (type["curly_poem"] == TriState.on) { if (line.matchFirst(rgx.block_curly_poem_close)) { - an_object[an_object_key]="verse"; - debug(poem) { // poem (curly) close - writefln( - "* [poem curly] %s", - line - ); - } - if (processing.length > 0) { - an_object[an_object_key] = processing["verse"]; - } - debug(poem) { // poem (curly) close - writeln(__LINE__); - writefln( - "* %s %s", - obj_cite_number, - line - ); - } - if (an_object.length > 0) { - debug(poem) { // poem (curly) close - writeln( + if (an_object_key in an_object + || processing.length > 0) { + an_object[an_object_key] = ""; + debug(poem) { // poem (curly) close + writefln( + "* [poem curly] %s", + line + ); + } + if (processing.length > 0) { + an_object[an_object_key] = processing["verse"]; + } + debug(poem) { // poem (curly) close + writeln(__LINE__); + writefln( + "* %s %s", obj_cite_number, - an_object[an_object_key] + line ); } - an_object["is"] = "verse"; - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "verse"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; + if (an_object.length > 0) { + debug(poem) { // poem (curly) close + writeln( + obj_cite_number, + an_object[an_object_key] + ); + } + an_object["is"] = "verse"; + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "verse"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + } object_reset(an_object); processing.remove("verse"); ++cntr; @@ -2185,7 +2060,7 @@ template SiSUdocAbstraction() { ); } processing.remove("verse"); - an_object["is"] = "verse"; + an_object["is"] = "verse"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, segment_anchor_tag_that_object_belongs_to, @@ -2232,7 +2107,7 @@ template SiSUdocAbstraction() { writeln(obj_cite_number, line); } processing.remove("verse"); - an_object["is"] = "verse"; + an_object["is"] = "verse"; auto substantive_obj_misc_tuple = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; @@ -2277,7 +2152,7 @@ template SiSUdocAbstraction() { ); } processing.remove("verse"); - an_object["is"] = "verse"; + an_object["is"] = "verse"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -2309,7 +2184,7 @@ template SiSUdocAbstraction() { } } } - void _quote_block_(L,O,T)( + void _code_block_(L,O,T)( return ref L line, return ref O an_object, return ref T type @@ -2320,40 +2195,41 @@ template SiSUdocAbstraction() { static assert(is(typeof(type) == int[string])); } auto rgx = Rgx(); - if (type["curly_quote"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_quote_close)) { - debug(quote) { // quote (curly) close + if (type["curly_code"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_code_close)) { + debug(code) { // code (curly) close writeln(line); } - type["blocks"] = TriState.closing; - type["quote"] = TriState.closing; - type["curly_quote"] = TriState.off; + type["blocks"] = TriState.closing; + type["code"] = TriState.closing; + type["curly_code"] = TriState.off; } else { - debug(quote) { + debug(code) { // code (curly) line writeln(line); } - an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) + an_object[an_object_key] ~= line ~= "\n"; // code (curly) line } - } else if (type["tic_quote"] == TriState.on) { + } else if (type["tic_code"] == TriState.on) { if (line.matchFirst(rgx.block_tic_close)) { - debug(quote) { // quote (tic) close + debug(code) { // code (tic) close writeln(line); } - type["blocks"] = TriState.closing; - type["quote"] = TriState.closing; - type["tic_quote"] = TriState.off; + type["blocks"] = TriState.closing; + type["code"] = TriState.closing; + type["tic_code"] = TriState.off; } else { - debug(quote) { + debug(code) { // code (tic) line writeln(line); } - an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) + an_object[an_object_key] ~= line ~= "\n"; // code (tic) line } } } - void _table_block_(L,O,T)( + void _table_block_(L,O,T,Ma)( return ref L line, return ref O an_object, - return ref T type + return ref T type, + return ref Ma dochead_make_aa ) { debug(asserts) { static assert(is(typeof(line) == char[])); @@ -2366,31 +2242,232 @@ template SiSUdocAbstraction() { debug(table) { // table (curly) close writeln(line); } - type["blocks"] = TriState.closing; - type["table"] = TriState.closing; - type["curly_table"] = TriState.off; - } else { - debug(table) { // table - writeln(line); + type["blocks"] = TriState.closing; + type["table"] = TriState.closing; + type["curly_table"] = TriState.off; + } else { + debug(table) { // table + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + } + } else if (type["curly_table_special_markup"] == TriState.on) { + if (line.empty) { + type["blocks"] = TriState.off; + type["table"] = TriState.off; + type["curly_table_special_markup"] = TriState.off; + _table_closed_make_special_notation_table_( + line, + an_object, + the_document_body_section, + obj_cite_number, + comp_obj_heading, + cntr, + type, + dochead_make_aa + ); + } else { + debug(table) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; + } + } else if (type["tic_table"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + debug(table) { // table (tic) close + writeln(line); + } + type["blocks"] = TriState.closing; + type["table"] = TriState.closing; + type["tic_table"] = TriState.off; + } else { + debug(table) { // table + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + } + } + } + final string biblio_tag_map(A)(A abr) { + debug(asserts) { + static assert(is(typeof(abr) == string)); + } + auto btm = [ + "au" : "author_raw", + "ed" : "editor_raw", + "ti" : "fulltitle", + "lng" : "language", + "jo" : "journal", + "vol" : "volume", + "edn" : "edition", + "yr" : "year", + "pl" : "place", + "pb" : "publisher", + "pub" : "publisher", + "pg" : "pages", + "pgs" : "pages", + "sn" : "short_name" + ]; + return btm[abr]; + } + void _biblio_block_( + char[] line, + return ref int[string] type, + return ref int bib_entry, + return ref string biblio_entry_str_json, + return ref string[] biblio_arr_json + ) { + mixin SiSUbiblio; + auto jsn = BibJsnStr(); + auto rgx = Rgx(); + if (line.matchFirst(rgx.heading_biblio)) { + type["biblio_section"] = TriState.on; + type["blurb_section"] = State.off; + type["glossary_section"] = State.off; + } + if (line.empty) { + debug { + debug(biblioblock) { + writeln("---"); + } + debug(biblioblockinclude) { + writeln(biblio_entry_str_json.length); + } + } + if ((bib_entry == State.off) + && (biblio_entry_str_json.empty)) { + bib_entry = State.on; + biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; + } else if (!(biblio_entry_str_json.empty)) { + bib_entry = State.off; + if (!(biblio_entry_str_json == jsn.biblio_entry_tags_jsonstr)) { + auto biblio_entry = parseJSON(biblio_entry_str_json); + if (biblio_entry["fulltitle"].str.empty) { + writeln("check problem entry (Title missing): ", biblio_entry_str_json); + } else if ((biblio_entry["author_raw"].str.empty) && (biblio_entry["editor_raw"].str.empty)) { + writeln("check problem entry (No author and no editor): ", biblio_entry_str_json); + } else { + biblio_arr_json ~= biblio_entry_str_json; + } + biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; + } + } else { // CHECK ERROR + writeln("?? 2. ERROR ", biblio_entry_str_json, "??"); + biblio_entry_str_json = ""; + } + } else if (line.matchFirst(rgx.biblio_tags)) { + debug(biblioblock) { + writeln(line); + } + auto bt = line.match(rgx.biblio_tags); + bib_entry = State.off; + st = bt.captures[1].to!string; + auto header_tag_value=(bt.captures[2]).to!string; + JSONValue j = parseJSON(biblio_entry_str_json); + biblio_tag_name = (st.match(rgx.biblio_abbreviations)) + ? (biblio_tag_map(st)) + : st; + j.object[biblio_tag_name] = header_tag_value; + debug(bibliounsortedcheckduplicates) { + writeln(biblio_tag_name, ": ", header_tag_value); + writeln("--"); + } + switch (biblio_tag_name) { + case "author_raw": // author_arr author (fn sn) + j["author_arr"] = + header_tag_value.split(rgx.arr_delimiter); + string tmp; + biblioAuthorLoop: + foreach (au; j["author_arr"].array) { + if (auto x = au.str.match(rgx.name_delimiter)) { + tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; + } else { + tmp ~= au.str; + } + } + tmp = (tmp).replace(rgx.trailing_comma, ""); + j["author"].str = tmp; + goto default; + case "editor_raw": // editor_arr editor (fn sn) + j["editor_arr"] = + header_tag_value.split(rgx.arr_delimiter); + string tmp; + biblioEditorLoop: + foreach (ed; j["editor_arr"].array) { + if (auto x = ed.str.match(rgx.name_delimiter)) { + tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; + } else { + tmp ~= ed.str; + } } - an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + tmp = (tmp).replace(rgx.trailing_comma, ""); + j["editor"].str = tmp; + goto default; + case "fulltitle": // title & subtitle + goto default; + default: + break; } - } else if (type["tic_table"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - debug(table) { // table (tic) close + auto s = j.toString(); + debug(biblio1) { + writefln( + "* %s: %s\n%s", + biblio_tag_name, + biblio_tag_entry, + j[biblio_tag_name] + ); + } + if (line.match(rgx.comment)) { + writeln("ERROR", line, "COMMENT"); + writeln("ERROR", s, "%%"); + } + if (!(match(line, rgx.comment))) { + debug(biblioblockinclude) { writeln(line); } - type["blocks"] = TriState.closing; - type["table"] = TriState.closing; - type["tic_table"] = TriState.off; + biblio_entry_str_json = s; } else { - debug(table) { // table - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + biblio_entry_str_json = ""; } + header_tag_value=""; } } + // + void _table_closed_make_special_notation_table_( + char[] line, + return ref string[string] an_object, + return ref ObjGenericComposite[] the_document_body_section, + return ref int obj_cite_number, + return ref ObjGenericComposite _comp_obj_heading, + return ref int cntr, + return ref int[string] type, + string[string][string] dochead_make_aa, + ) { + comp_obj_block = comp_obj_block.init; + obj_cite_number = + ocn_emit(type["ocn_status"]); + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + "table" + ); + an_object["is"] = "table"; + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, "body_nugget", dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block = table_instructions(comp_obj_block, an_object["table_head"]); + comp_obj_block = table_substantive_munge_special(comp_obj_block, an_object["substantive"]); + the_document_body_section ~= comp_obj_block; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } void _block_flag_line_empty_(B)( B bookindex_extract_hash, char[] line, @@ -2414,7 +2491,7 @@ template SiSUdocAbstraction() { "code block status: closed" ); assertions_flag_types_block_status_none_or_closed(type); - if (type["group"] == TriState.closing) { + if (type["quote"] == TriState.closing) { obj_cite_number = ocn_emit(type["ocn_status"]); an_object["bookindex_nugget"] = @@ -2425,7 +2502,7 @@ template SiSUdocAbstraction() { obj_cite_number, segment_anchor_tag_that_object_belongs_to ); - an_object["is"] = "group"; + an_object["is"] = "quote"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -2442,7 +2519,7 @@ template SiSUdocAbstraction() { comp_obj_block = comp_obj_block.init; comp_obj_block.use = "body"; comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "group"; + comp_obj_block.is_a = "quote"; comp_obj_block.ocn = obj_cite_number; comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; comp_obj_block.text = an_object["substantive"]; @@ -2451,12 +2528,13 @@ template SiSUdocAbstraction() { comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; the_document_body_section ~= comp_obj_block; type["blocks"] = TriState.off; - type["group"] = TriState.off; + type["table"] = TriState.off; object_reset(an_object); processing.remove("verse"); ++cntr; - } else if (type["block"] == TriState.closing) { - obj_cite_number = ocn_emit(type["ocn_status"]); + } else if (type["group"] == TriState.closing) { + obj_cite_number = + ocn_emit(type["ocn_status"]); an_object["bookindex_nugget"] = ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; bookindex_unordered_hashes = @@ -2465,7 +2543,7 @@ template SiSUdocAbstraction() { obj_cite_number, segment_anchor_tag_that_object_belongs_to ); - an_object["is"] = "block"; + an_object["is"] = "group"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -2474,7 +2552,7 @@ template SiSUdocAbstraction() { cntr, heading_ptr-1, an_object["is"] - ); + ); auto substantive_obj_misc_tuple = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; @@ -2482,7 +2560,7 @@ template SiSUdocAbstraction() { comp_obj_block = comp_obj_block.init; comp_obj_block.use = "body"; comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "block"; + comp_obj_block.is_a = "group"; comp_obj_block.ocn = obj_cite_number; comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; comp_obj_block.text = an_object["substantive"]; @@ -2491,13 +2569,12 @@ template SiSUdocAbstraction() { comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; the_document_body_section ~= comp_obj_block; type["blocks"] = TriState.off; - type["block"] = TriState.off; + type["group"] = TriState.off; object_reset(an_object); processing.remove("verse"); ++cntr; - } else if (type["code"] == TriState.closing) { - obj_cite_number = - ocn_emit(type["ocn_status"]); + } else if (type["block"] == TriState.closing) { + obj_cite_number = ocn_emit(type["ocn_status"]); an_object["bookindex_nugget"] = ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; bookindex_unordered_hashes = @@ -2506,7 +2583,7 @@ template SiSUdocAbstraction() { obj_cite_number, segment_anchor_tag_that_object_belongs_to ); - an_object["is"] = "code"; + an_object["is"] = "block"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -2515,24 +2592,24 @@ template SiSUdocAbstraction() { cntr, heading_ptr-1, an_object["is"] - ); + ); auto substantive_obj_misc_tuple = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_code = comp_obj_code.init; - comp_obj_code.use = "body"; - comp_obj_code.is_of = "block"; - comp_obj_code.is_a = "code"; - comp_obj_code.ocn = obj_cite_number; - comp_obj_code.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_code.text = an_object["substantive"]; - comp_obj_code.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_code.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_code.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_code; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "block"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; type["blocks"] = TriState.off; - type["code"] = TriState.off; + type["block"] = TriState.off; object_reset(an_object); processing.remove("verse"); ++cntr; @@ -2545,7 +2622,7 @@ template SiSUdocAbstraction() { obj_cite_number, segment_anchor_tag_that_object_belongs_to ); - an_object["is"] = "verse"; // check also + an_object["is"] = "verse"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -2567,7 +2644,7 @@ template SiSUdocAbstraction() { type["poem"] = TriState.off; object_reset(an_object); processing.remove("verse"); - } else if (type["quote"] == TriState.closing) { + } else if (type["code"] == TriState.closing) { obj_cite_number = ocn_emit(type["ocn_status"]); an_object["bookindex_nugget"] = @@ -2578,7 +2655,7 @@ template SiSUdocAbstraction() { obj_cite_number, segment_anchor_tag_that_object_belongs_to ); - an_object["is"] = "quote"; + an_object["is"] = "code"; auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -2589,26 +2666,27 @@ template SiSUdocAbstraction() { an_object["is"] ); auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); // ... - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; // ... + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "quote"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; + comp_obj_code = comp_obj_code.init; + comp_obj_code.use = "body"; + comp_obj_code.is_of = "block"; + comp_obj_code.is_a = "code"; + comp_obj_code.ocn = obj_cite_number; + comp_obj_code.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_code.text = an_object["substantive"]; + comp_obj_code.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_code.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_code.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_code; + type["blocks"] = TriState.off; + type["code"] = TriState.off; object_reset(an_object); processing.remove("verse"); ++cntr; - type["blocks"] = TriState.off; - type["quote"] = TriState.off; } else if (type["table"] == TriState.closing) { + comp_obj_block = comp_obj_block.init; obj_cite_number = ocn_emit(type["ocn_status"]); an_object["bookindex_nugget"] = @@ -2632,17 +2710,11 @@ template SiSUdocAbstraction() { auto substantive_obj_misc_tuple = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "table"; comp_obj_block.ocn = obj_cite_number; comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + comp_obj_block = table_instructions(comp_obj_block, an_object["table_head"]); + comp_obj_block = table_substantive_munge(comp_obj_block, an_object["substantive"]); the_document_body_section ~= comp_obj_block; type["blocks"] = TriState.off; type["table"] = TriState.off; @@ -3092,6 +3164,203 @@ template SiSUdocAbstraction() { } return textline; } + auto table_instructions(O,H)( + return ref O table_object, + return ref H table_head, + ) { + auto rgx = Rgx(); + table_object.use = "body"; + table_object.is_of = "block"; + table_object.is_a = "table"; + table_object.inline_notes_reg = false; + table_object.inline_notes_star = false; + table_object.inline_links = false; + if (auto m = table_head.matchFirst(rgx.table_head_instructions)) { + table_object.table_heading = ((m["c_heading"].length > 0) && (m["c_heading"] == "h")) ? true : false; + table_object.table_number_of_columns = ((m["c_num"].length > 0) && (m["c_num"].to!int > 0)) ? m["c_num"].to!int : 0; // double check, may be obsolete + foreach (cw; m["c_widths"].matchAll(rgx.table_col_widths)) { + auto x = cw.hit.matchFirst(rgx.table_col_widths_and_alignment); + table_object.table_column_widths ~= x["width"].to!int; + table_object.table_column_aligns ~= (x["align"].empty) ? "" : x["align"]; + } + } + return table_object; + } + auto table_array_munge(O,T)( + return ref O table_object, + return ref T table_array, + ) { + auto rgx = Rgx(); + auto mng = InlineMarkup(); + string _table_substantive; + ulong col_num; + ulong col_num_; + ulong col_num_chk = 0; + foreach(idx_r, row; table_array) { + debug(table_dev) { + writeln("row ", idx_r); + } + col_num_ = 0; + if (col_num == 0 + || col_num < row.length) { + col_num = row.length; + } + if (col_num_chk == 0) { + col_num_chk = col_num; + } else if (col_num == 1) { + debug(table_dev) { + writeln("table note: "); + } + } else if (col_num_chk != col_num) { + debug(table_dev) { + writeln("warning irregular number of columns: ", col_num_chk, " != ", col_num); + } + } else { + } + foreach(idx_c, col; row) { + debug(table_dev) { + write(idx_c, ", "); + } + col_num_ = idx_c; + _table_substantive ~= col ~ mng.tc_s; + if (idx_r == 0 && comp_obj_block.table_heading) { + } else if (idx_r == 1 && col.match(rgx.numeric_col)) { + if ((comp_obj_block.table_column_aligns.length > idx_c) + && (comp_obj_block.table_column_aligns[idx_c].matchFirst(rgx.table_col_align_match))) { + comp_obj_block.table_column_aligns[idx_c] + = comp_obj_block.table_column_aligns[idx_c]; + } else if (comp_obj_block.table_column_aligns.length > idx_c) { + comp_obj_block.table_column_aligns[idx_c] = "r"; + } else { + comp_obj_block.table_column_aligns ~= "r"; + } + } else if (idx_r == 1) { + if ((comp_obj_block.table_column_aligns.length > idx_c) + && (comp_obj_block.table_column_aligns[idx_c].matchFirst(rgx.table_col_align_match))) { + comp_obj_block.table_column_aligns[idx_c] + = comp_obj_block.table_column_aligns[idx_c]; + } else if (comp_obj_block.table_column_aligns.length > idx_c) { + comp_obj_block.table_column_aligns[idx_c] = "l"; + } else { + comp_obj_block.table_column_aligns ~= "l"; + } + } + } + debug(table_dev) { + writeln(""); + } + if (col_num_chk > 0 && (col_num != col_num_chk)) { + } else if (col_num == col_num_chk){ + } else { + col_num_chk = col_num; + } + _table_substantive = _table_substantive.replaceFirst(rgx.table_col_separator_nl, "\n"); + } + if (comp_obj_block.table_number_of_columns != col_num) { + if (comp_obj_block.table_number_of_columns == 0) { + comp_obj_block.table_number_of_columns = (col_num).to!int; + } else { + debug(table_dev) { + writeln(comp_obj_block.table_number_of_columns, " != ", col_num); + } + } + } + if (table_object.table_number_of_columns == 0 + && table_object.table_column_widths.length > 0) { + writeln(__LINE__, " ERROR"); + } + if (table_object.table_number_of_columns > 0 + && table_object.table_column_widths.length == 0) { + double col_w = (100.00 / table_object.table_number_of_columns); + foreach (i; 0..table_object.table_number_of_columns) { + table_object.table_column_widths ~= col_w; + } + } else if (table_object.table_number_of_columns + != table_object.table_column_widths.length) { + debug(table_dev) { + writeln(m.hit); // further logic required + } + if (table_object.table_number_of_columns > table_object.table_column_widths.length) { + double col_w = (100.00 - (table_object.table_column_widths).sum) + / (table_object.table_number_of_columns - table_object.table_column_widths.length); + foreach (i; 0..table_object.table_column_widths.length) { + table_object.table_column_widths ~= col_w; + } + foreach (i; 0..(table_object.table_number_of_columns - table_object.table_column_widths.length)) { + table_object.table_column_widths ~= col_w; + } + } else if (table_object.table_number_of_columns < table_object.table_column_widths.length) { + writeln(__LINE__, " warning, ERROR"); + } + } + if (table_object.table_column_widths.sum > 101 + || table_object.table_column_widths.sum < 95 ) { + writeln("sum: ", table_object.table_column_widths.sum, + ", array: ", table_object.table_column_widths, + ", cols: ", table_object.table_number_of_columns); + writeln(_table_substantive); + } + debug(table_res) { + writeln("aligns: ", comp_obj_block.table_column_aligns, "\n", + "no. of columns: ", comp_obj_block.table_number_of_columns, "\n", + "col widths: ", comp_obj_block.table_column_widths, + " sum: ", comp_obj_block.table_column_widths.sum, "\n", + _table_substantive); + } + comp_obj_block.text = _table_substantive; + return table_object; + } + auto table_array_munge_open_close(O,T)( + return ref O table_object, + return ref T table_array, + ) { + auto rgx = Rgx(); + auto mng = InlineMarkup(); + string _table_substantive; + foreach(row; table_array) { + foreach(col; row) { + _table_substantive ~= mng.tc_o ~ col ~ mng.tc_c; + } + _table_substantive ~= "\n"; + } + debug(table_dev) { + writeln(_table_substantive); + } + comp_obj_block.text = _table_substantive; + return table_object; + } + auto table_substantive_munge(O,T)( + return ref O table_object, + return ref T table_substantive, + ) { + auto rgx = Rgx(); + auto munge = ObjInlineMarkupMunge(); + string[] _table_rows = (table_substantive).split(rgx.table_row_delimiter); + string[] _table_cols; + string[][] _table; + foreach(col; _table_rows) { + _table_cols = col.split(rgx.table_col_delimiter); + _table ~= _table_cols; + } + table_object = table_array_munge(table_object, _table); + return table_object; + } + auto table_substantive_munge_special(O,T)( + return ref O table_object, + return ref T table_substantive, + ) { + auto rgx = Rgx(); + auto munge = ObjInlineMarkupMunge(); + string[] _table_rows = (table_substantive).split(rgx.table_row_delimiter_special); + string[] _table_cols; + string[][] _table; + foreach(col; _table_rows) { + _table_cols = col.split(rgx.table_col_delimiter_special); + _table ~= _table_cols; + } + table_object = table_array_munge(table_object, _table); + return table_object; + } /+ abstraction functions ↑ +/ /+ ↓ abstraction function emitters +/ struct OCNemitter { @@ -3252,10 +3521,11 @@ template SiSUdocAbstraction() { rgx.inline_notes_curly_sp_asterisk, (mkup.en_a_o ~ "*" ~ " $1" ~ mkup.en_a_c) ); - obj_txt_in = obj_txt_in.replaceAll( - rgx.inline_notes_curly_sp_plus, - (mkup.en_a_o ~ "+" ~ " $1" ~ mkup.en_a_c) - ); + obj_txt_in = + obj_txt_in.replaceAll( + rgx.inline_notes_curly_sp_plus, + (mkup.en_a_o ~ "+" ~ " $1" ~ mkup.en_a_c) + ); /+ url matched +/ if (obj_txt_in.match(rgx.inline_url)) { urls = true; @@ -3331,6 +3601,18 @@ template SiSUdocAbstraction() { } return t; } + string munge_quote(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } auto munge_group(string obj_txt_in) in { } body { @@ -3373,7 +3655,7 @@ template SiSUdocAbstraction() { } } body { - obj_txt_in = (obj_txt_in).replaceAll(rgx.two_spaces, mkup.nbsp ~ mkup.nbsp); + obj_txt_in = (obj_txt_in).replaceAll(rgx.space, mkup.nbsp); obj_txt["munge"] = obj_txt_in; return obj_txt["munge"]; } @@ -3391,18 +3673,6 @@ template SiSUdocAbstraction() { } invariant() { } - string munge_quote(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } string munge_comment(Ot)(Ot obj_txt_in) in { debug(asserts) { @@ -4018,7 +4288,7 @@ template SiSUdocAbstraction() { } invariant() { } - string _group(Ot)(Ot obj_txt_in) + string _quote(Ot)(Ot obj_txt_in) in { debug(asserts) { static assert(is(typeof(obj_txt_in) == string)); @@ -4027,12 +4297,12 @@ template SiSUdocAbstraction() { body { _obj_attributes = " \"use\": \"content\"," ~ " \"of\": \"block\"," - ~ " \"is\": \"group\""; + ~ " \"is\": \"quote\""; return _obj_attributes; } invariant() { } - string _block(Ot)(Ot obj_txt_in) + string _group(Ot)(Ot obj_txt_in) in { debug(asserts) { static assert(is(typeof(obj_txt_in) == string)); @@ -4041,12 +4311,12 @@ template SiSUdocAbstraction() { body { _obj_attributes = " \"use\": \"content\"," ~ " \"of\": \"block\"," - ~ " \"is\": \"block\""; + ~ " \"is\": \"group\""; return _obj_attributes; } invariant() { } - string _verse(Ot)(Ot obj_txt_in) + string _block(Ot)(Ot obj_txt_in) in { debug(asserts) { static assert(is(typeof(obj_txt_in) == string)); @@ -4055,12 +4325,12 @@ template SiSUdocAbstraction() { body { _obj_attributes = " \"use\": \"content\"," ~ " \"of\": \"block\"," - ~ " \"is\": \"verse\""; + ~ " \"is\": \"block\""; return _obj_attributes; } invariant() { } - string _code(Ot)(Ot obj_txt_in) + string _verse(Ot)(Ot obj_txt_in) in { debug(asserts) { static assert(is(typeof(obj_txt_in) == string)); @@ -4069,12 +4339,12 @@ template SiSUdocAbstraction() { body { _obj_attributes = " \"use\": \"content\"," ~ " \"of\": \"block\"," - ~ " \"is\": \"code\""; + ~ " \"is\": \"verse\""; return _obj_attributes; } invariant() { } - string _table(Ot)(Ot obj_txt_in) + string _code(Ot)(Ot obj_txt_in) in { debug(asserts) { static assert(is(typeof(obj_txt_in) == string)); @@ -4083,12 +4353,12 @@ template SiSUdocAbstraction() { body { _obj_attributes = " \"use\": \"content\"," ~ " \"of\": \"block\"," - ~ " \"is\": \"table\""; + ~ " \"is\": \"code\""; return _obj_attributes; } invariant() { } - string _quote(Ot)(Ot obj_txt_in) + string _table(Ot)(Ot obj_txt_in) in { debug(asserts) { static assert(is(typeof(obj_txt_in) == string)); @@ -4097,7 +4367,7 @@ template SiSUdocAbstraction() { body { _obj_attributes = " \"use\": \"content\"," ~ " \"of\": \"block\"," - ~ " \"is\": \"quote\""; + ~ " \"is\": \"table\""; return _obj_attributes; } invariant() { -- cgit v1.2.3