From 2471669e0954080b2a13b4f87cf61a36b1bf86dd Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 7 Oct 2016 12:53:03 -0400 Subject: introduce a couple of unittests some re-organizing of obt --- org/ao_abstract_doc_source.org | 762 ++++++++++++++++++++++----------------- org/sdp.org | 1 - src/sdp.d | 1 - src/sdp/ao_abstract_doc_source.d | 660 +++++++++++++++++---------------- 4 files changed, 772 insertions(+), 652 deletions(-) diff --git a/org/ao_abstract_doc_source.org b/org/ao_abstract_doc_source.org index 5677baa..282223d 100644 --- a/org/ao_abstract_doc_source.org +++ b/org/ao_abstract_doc_source.org @@ -80,7 +80,7 @@ string[string] indent; bool bullet = true; string content_non_header = "8"; auto obj_im = ObjInlineMarkup(); -auto obj_att = ObjAttrib(); +auto obj_att = ObjAttributes(); /+ ocn +/ int obj_cite_number, obj_cite_number_; auto object_citation_number = OCNemitter(); @@ -2330,166 +2330,6 @@ struct OCNemitter { } #+END_SRC -**** object attributes :attributes: - -#+name: ao_emitters -#+BEGIN_SRC d -struct ObjAttributes { - string[string] obj_txt; - string para_and_blocks(string obj_txt_in) - in { } - body { - auto rgx = Rgx(); - obj_txt["munge"]=obj_txt_in; - if (matchFirst(obj_txt_in, rgx.para_bullet)) { - obj_txt["attrib"] =" \"bullet\": \"true\"," - ~ " \"indent_start\": 0," - ~ " \"indent_rest\": 0,"; - } else if (auto m = matchFirst(obj_txt_in, rgx.para_bullet_indent)) { - obj_txt["attrib"] =" \"bullet\": \"true\"," - ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; - } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent_hang)) { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[2]) ~ ","; - } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent)) { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; - } else { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_start\": 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() { - } - /+ revist +/ - // 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_meta(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 :markup:inline: #+name: ao_emitters @@ -2690,32 +2530,7 @@ struct ObjInlineMarkupMunge { struct ObjInlineMarkup { // struct ObjInlineMarkup : AssertObjInlineMarkup { auto munge = ObjInlineMarkupMunge(); -#+END_SRC - -***** make segment anchor tags if not provided :markup:inline:segment:anchor:tags: - -#+name: ao_emitters -#+BEGIN_SRC d string[string] obj_txt; - string make_segment_anchor_tags_if_none_provided(string munge_, string lev_) { - if (!(match(munge_, rgx.heading_anchor_tag))) { // if (anchor_tags_.length == 0) { - if (match(munge_, rgx.heading_identify_anchor_tag)) { - if (auto m = match(munge_, rgx.heading_extract_named_anchor_tag)) { - munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, - "$1~" ~ toLower(m.captures[1]) ~ "_" ~ m.captures[2] ~ " "); - } else if (auto m = match(munge_, rgx.heading_extract_unnamed_anchor_tag)) { - munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, - "$1~" ~ "s" ~ m.captures[1] ~ " "); - } - } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" - static __gshared uint heading_num_lev1 = 0; - heading_num_lev1 ++; - munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, - "$1~" ~ "x" ~ to!string(heading_num_lev1) ~ " "); - } - } - return munge_; - } #+END_SRC ***** object inline markup and anchor tags :markup:inline: @@ -2733,117 +2548,9 @@ struct ObjInlineMarkup { switch (obj_["is"]) { case "heading": static __gshared string anchor_tag = ""; - if (dochead_make_aa["make"]["num_top"].length > 0) { - if (!(match(obj_txt["munge"], rgx.heading_anchor_tag))) { - static __gshared uint heading_num_top_level=9; - static __gshared uint heading_num_depth=2; - static __gshared uint heading_num_0 = 0; - static __gshared uint heading_num_1 = 0; - static __gshared uint heading_num_2 = 0; - static __gshared uint heading_num_3 = 0; - static __gshared string heading_number_auto_composite = ""; - if (heading_num_top_level==9) { - if (dochead_make_aa["make"]["num_depth"].length > 0) { - heading_num_depth = to!uint(dochead_make_aa["make"]["num_depth"]); - } - switch (dochead_make_aa["make"]["num_top"]) { - case "A": - break; - case "B": - heading_num_top_level=1; - break; - case "C": - heading_num_top_level=2; - break; - case "D": - heading_num_top_level=3; - break; - case "1": - heading_num_top_level=4; - break; - case "2": - heading_num_top_level=5; - break; - case "3": - heading_num_top_level=6; - break; - case "4": - heading_num_top_level=7; - break; - default: - break; - } - } - /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ - if (heading_num_top_level > to!uint(obj_["lev_markup_number"])) { - heading_num_0 = 0; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == to!uint(obj_["lev_markup_number"])) { - heading_num_0 ++; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 1)) { - heading_num_1 ++; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 2)) { - heading_num_2 ++; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 3)) { - heading_num_3 ++; - } else { - } - if (heading_num_3 > 0) { - heading_number_auto_composite = - (heading_num_depth == 3) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) ~ "." ~ - to!string(heading_num_2) ~ "." ~ - to!string(heading_num_3) - ) - : ""; - } else if (heading_num_2 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 2) - && (heading_num_depth <= 3)) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) ~ "." ~ - to!string(heading_num_2) - ) - : ""; - } else if (heading_num_1 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 1) - && (heading_num_depth <= 3)) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) - ) - : ""; - } else if (heading_num_0 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 0) - && (heading_num_depth <= 3)) - ? (to!string(heading_num_0)) - : ""; - } else { - heading_number_auto_composite = ""; - } - debug(heading_number_auto) { - writeln(heading_number_auto_composite); - } - if (!empty(heading_number_auto_composite)) { - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading, - "$1~$2 " ~ heading_number_auto_composite ~ ". "); - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading_marker_missing_tag, - "$1~" ~ heading_number_auto_composite ~ " "); - } - } - } // WORK ON, you still need to ensure that level 1 anchor_tags are unique - obj_txt["munge"]=make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); + obj_txt["munge"]=_configured_auto_heading_numbering_and_segment_anchor_tags(obj_txt["munge"], obj_, dochead_make_aa); + obj_txt["munge"]=_make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); if (auto m = match(obj_txt["munge"], rgx.heading_anchor_tag)) { anchor_tag = m.captures[1]; anchor_tags_ ~=anchor_tag; @@ -2893,6 +2600,214 @@ struct ObjInlineMarkup { } #+END_SRC +***** private: +#+name: ao_emitters +#+BEGIN_SRC d +private: +#+END_SRC + +****** make heading number and segment anchor tags if instructed :markup:inline:segment:anchor:tags: + +#+name: ao_emitters +#+BEGIN_SRC d + static string _configured_auto_heading_numbering_and_segment_anchor_tags(string munge_, string[string] obj_, string[string][string] dochead_make_aa) { + if (dochead_make_aa["make"]["num_top"].length > 0) { + if (!(match(munge_, rgx.heading_anchor_tag))) { + static __gshared uint heading_num_top_level=9; + static __gshared uint heading_num_depth=2; + static __gshared uint heading_num_0 = 0; + static __gshared uint heading_num_1 = 0; + static __gshared uint heading_num_2 = 0; + static __gshared uint heading_num_3 = 0; + static __gshared string heading_number_auto_composite = ""; + if (heading_num_top_level==9) { + if (dochead_make_aa["make"]["num_depth"].length > 0) { + heading_num_depth = to!uint(dochead_make_aa["make"]["num_depth"]); + } + switch (dochead_make_aa["make"]["num_top"]) { + case "A": + break; + case "B": + heading_num_top_level=1; + break; + case "C": + heading_num_top_level=2; + break; + case "D": + heading_num_top_level=3; + break; + case "1": + heading_num_top_level=4; + break; + case "2": + heading_num_top_level=5; + break; + case "3": + heading_num_top_level=6; + break; + case "4": + heading_num_top_level=7; + break; + default: + break; + } + } + /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ + if (heading_num_top_level > to!uint(obj_["lev_markup_number"])) { + heading_num_0 = 0; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if (heading_num_top_level == to!uint(obj_["lev_markup_number"])) { + heading_num_0 ++; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 1)) { + heading_num_1 ++; + heading_num_2 = 0; + heading_num_3 = 0; + } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 2)) { + heading_num_2 ++; + heading_num_3 = 0; + } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 3)) { + heading_num_3 ++; + } else { + // + } + if (heading_num_3 > 0) { + heading_number_auto_composite = + (heading_num_depth == 3) + ? ( to!string(heading_num_0) ~ "." ~ + to!string(heading_num_1) ~ "." ~ + to!string(heading_num_2) ~ "." ~ + to!string(heading_num_3) + ) + : ""; + } else if (heading_num_2 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 2) + && (heading_num_depth <= 3)) + ? ( to!string(heading_num_0) ~ "." ~ + to!string(heading_num_1) ~ "." ~ + to!string(heading_num_2) + ) + : ""; + } else if (heading_num_1 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 1) + && (heading_num_depth <= 3)) + ? ( to!string(heading_num_0) ~ "." ~ + to!string(heading_num_1) + ) + : ""; + } else if (heading_num_0 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 0) + && (heading_num_depth <= 3)) + ? (to!string(heading_num_0)) + : ""; + } else { + heading_number_auto_composite = ""; + } + debug(heading_number_auto) { + writeln(heading_number_auto_composite); + } + if (!empty(heading_number_auto_composite)) { + munge_=replaceFirst(munge_, rgx.heading, + "$1~$2 " ~ heading_number_auto_composite ~ ". "); + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ heading_number_auto_composite ~ " "); + } + } + } + return munge_; + } +#+END_SRC + +******* unittests + +#+name: ao_emitters +#+BEGIN_SRC d +#+END_SRC + +****** make segment anchor tags if not provided :markup:inline:segment:anchor:tags: + +#+name: ao_emitters +#+BEGIN_SRC d + + static string _make_segment_anchor_tags_if_none_provided(string munge_, string lev_) { + if (!(match(munge_, rgx.heading_anchor_tag))) { // if (anchor_tags_.length == 0) { + if (match(munge_, rgx.heading_identify_anchor_tag)) { + if (auto m = match(munge_, rgx.heading_extract_named_anchor_tag)) { + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ toLower(m.captures[1]) ~ "_" ~ m.captures[2] ~ " "); + } else if (auto m = match(munge_, rgx.heading_extract_unnamed_anchor_tag)) { + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ "s" ~ m.captures[1] ~ " "); + } + } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" + static __gshared uint heading_num_lev1 = 0; + heading_num_lev1 ++; + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ "x" ~ to!string(heading_num_lev1) ~ " "); + } + } + return munge_; + } +#+END_SRC + +******* unittests + +#+name: ao_emitters +#+BEGIN_SRC d + unittest { + string txt_lev="1"; + string txt_in, txt_out; + + txt_in = "1~copyright Copyright"; + txt_out ="1~copyright Copyright"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + // assert(ObjInlineMarkup._make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in = "1~ 6. Writing Copyright Licenses"; + txt_out ="1~s6 6. Writing Copyright Licenses"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ 1. Reinforcing trends"; + txt_out= "1~s1 1. Reinforcing trends"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ 11 SCIENCE AS A COMMONS"; + txt_out= "1~s11 11 SCIENCE AS A COMMONS"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1"; + txt_out="1~chapter_1 Chapter 1"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1."; + txt_out="1~chapter_1 Chapter 1."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1: Done"; + txt_out="1~chapter_1 Chapter 1: Done"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; + txt_out= "1~chapter_11 Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ CHAPTER I."; + txt_out="1~x1 CHAPTER I."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ CHAPTER II."; + txt_out="1~x2 CHAPTER II."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + } +#+END_SRC + ***** close #+name: ao_emitters @@ -2904,9 +2819,8 @@ struct ObjInlineMarkup { ***** attributes structure open, public #+name: ao_emitters #+BEGIN_SRC d -struct ObjAttrib { - auto attrib = ObjAttributes(); - string[string] obj_attrib; +struct ObjAttributes { + string[string] _obj_attrib; string obj_attributes(string obj_is_, string obj_raw, string node) in { } body { @@ -2915,46 +2829,244 @@ struct ObjAttrib { destroy(obj_raw); destroy(node); } - JSONValue node_j = parseJSON(node); - obj_attrib.remove("json"); - obj_attrib["json"] ="{"; + _obj_attrib.remove("json"); + _obj_attrib["json"] ="{"; switch (obj_is_) { case "heading": - obj_attrib["json"] ~= attrib.heading(obj_raw); // + _obj_attrib["json"] ~= _heading(obj_raw); // break; case "para": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.para(obj_raw); + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _para(obj_raw); break; case "code": - obj_attrib["json"] ~= attrib.code(obj_raw); + _obj_attrib["json"] ~= _code(obj_raw); break; case "group": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.group(obj_raw); + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _group(obj_raw); break; case "block": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.block(obj_raw); + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _block(obj_raw); break; case "verse": - obj_attrib["json"] ~= attrib.verse(obj_raw); + _obj_attrib["json"] ~= _verse(obj_raw); break; case "quote": - obj_attrib["json"] ~= attrib.quote(obj_raw); + _obj_attrib["json"] ~= _quote(obj_raw); break; case "table": - obj_attrib["json"] ~= attrib.table(obj_raw); + _obj_attrib["json"] ~= _table(obj_raw); break; case "comment": - obj_attrib["json"] ~= attrib.comment(obj_raw); + _obj_attrib["json"] ~= _comment(obj_raw); break; default: - obj_attrib["json"] ~= attrib.para(obj_raw); + _obj_attrib["json"] ~= _para(obj_raw); break; } - obj_attrib["json"] ~=" }"; - JSONValue oa_j = parseJSON(obj_attrib["json"]); + _obj_attrib["json"] ~=" }"; + _obj_attrib["json"]=_set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, node); + debug(structattrib) { + if (oa_j["is"].str() == "heading") { + // writeln(__LINE__); + writeln(_obj_attrib["json"]); + // writeln(node); + writeln( + "is: ", oa_j["is"].str(), + "; obj_cite_number: ", oa_j["obj_cite_number"].integer() + ); + } + } + return _obj_attrib["json"]; + } + invariant() { + } +#+END_SRC + +***** private +#+name: ao_emitters +#+BEGIN_SRC d + private: + string _obj_attributes; +#+END_SRC + +****** attrubutes +******* para and block +#+name: ao_emitters +#+BEGIN_SRC d + string _para_and_blocks(string obj_txt_in) + in { } + body { + auto rgx = Rgx(); + if (matchFirst(obj_txt_in, rgx.para_bullet)) { + _obj_attributes =" \"bullet\": \"true\"," + ~ " \"indent_start\": 0," + ~ " \"indent_rest\": 0,"; + } else if (auto m = matchFirst(obj_txt_in, rgx.para_bullet_indent)) { + _obj_attributes =" \"bullet\": \"true\"," + ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; + } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent_hang)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[2]) ~ ","; + } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; + } else { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_start\": 0," + ~ " \"indent_rest\": 0,"; + } + return _obj_attributes; + } +#+END_SRC + +******* para +#+name: ao_emitters +#+BEGIN_SRC d + string _para(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"para\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* heading +#+name: ao_emitters +#+BEGIN_SRC d + string _heading(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"heading\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* code +#+name: ao_emitters +#+BEGIN_SRC d + string _code(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"code\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* group +#+name: ao_emitters +#+BEGIN_SRC d + string _group(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"group\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* block +#+name: ao_emitters +#+BEGIN_SRC d + string _block(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"block\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* verse +#+name: ao_emitters +#+BEGIN_SRC d + string _verse(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"verse\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* quote +#+name: ao_emitters +#+BEGIN_SRC d + string _quote(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"quote\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* table +#+name: ao_emitters +#+BEGIN_SRC d + string _table(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"table\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******* comment +#+name: ao_emitters +#+BEGIN_SRC d + string _comment(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"comment\"," + ~ " \"of\": \"comment\"," + ~ " \"is\": \"comment\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +****** set additional attribute values, parse as json + +#+name: ao_emitters +#+BEGIN_SRC d + string _set_additional_values_parse_as_json(string _obj_attrib, string obj_is_, string node) { + JSONValue oa_j = parseJSON(_obj_attrib); + JSONValue node_j = parseJSON(node); assert( (oa_j.type == JSON_TYPE.OBJECT) && (node_j.type == JSON_TYPE.OBJECT) @@ -2970,20 +3082,8 @@ struct ObjAttrib { } oa_j.object["parent_obj_cite_number"] = node_j["parent_obj_cite_number"]; oa_j.object["parent_lev_markup_number"] = node_j["parent_lev_markup_number"]; - obj_attrib["json"] = oa_j.toString(); - debug(structattrib) { - if (oa_j["is"].str() == "heading") { - writeln(obj_attrib["json"]); - writeln( - "is: ", oa_j["is"].str(), - "; obj_cite_number: ", oa_j["obj_cite_number"].integer() - ); - } - } - // obj_attrib["json"]="{}"; - return obj_attrib["json"]; - } - invariant() { + _obj_attrib = oa_j.toString(); + return _obj_attrib; } #+END_SRC diff --git a/org/sdp.org b/org/sdp.org index 954a1ef..47cecf8 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -443,7 +443,6 @@ void main(string[] args) { <> <> foreach(fn_src; fns_src) { - // foreach(fn_src; fns_src) { if (!empty(fn_src)) { <> } else { diff --git a/src/sdp.d b/src/sdp.d index 87393d9..62e2e8f 100755 --- a/src/sdp.d +++ b/src/sdp.d @@ -158,7 +158,6 @@ void main(string[] args) { auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration); auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); foreach(fn_src; fns_src) { - // foreach(fn_src; fns_src) { if (!empty(fn_src)) { scope(success) { debug(checkdoc) { diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index 595241a..5423513 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -54,7 +54,7 @@ template SiSUdocAbstraction() { bool bullet = true; string content_non_header = "8"; auto obj_im = ObjInlineMarkup(); - auto obj_att = ObjAttrib(); + auto obj_att = ObjAttributes(); /+ ocn +/ int obj_cite_number, obj_cite_number_; auto object_citation_number = OCNemitter(); @@ -1877,160 +1877,6 @@ template SiSUdocAbstraction() { invariant() { } } - struct ObjAttributes { - string[string] obj_txt; - string para_and_blocks(string obj_txt_in) - in { } - body { - auto rgx = Rgx(); - obj_txt["munge"]=obj_txt_in; - if (matchFirst(obj_txt_in, rgx.para_bullet)) { - obj_txt["attrib"] =" \"bullet\": \"true\"," - ~ " \"indent_start\": 0," - ~ " \"indent_rest\": 0,"; - } else if (auto m = matchFirst(obj_txt_in, rgx.para_bullet_indent)) { - obj_txt["attrib"] =" \"bullet\": \"true\"," - ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; - } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent_hang)) { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[2]) ~ ","; - } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent)) { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," - ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; - } else { - obj_txt["attrib"] =" \"bullet\": \"false\"," - ~ " \"indent_start\": 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() { - } - /+ revist +/ - // 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_meta(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() { - } - } struct ObjInlineMarkupMunge { // struct ObjInlineMarkupMunge : AssertObjInlineMarkup { string[string] obj_txt; @@ -2221,25 +2067,6 @@ template SiSUdocAbstraction() { // struct ObjInlineMarkup : AssertObjInlineMarkup { auto munge = ObjInlineMarkupMunge(); string[string] obj_txt; - string make_segment_anchor_tags_if_none_provided(string munge_, string lev_) { - if (!(match(munge_, rgx.heading_anchor_tag))) { // if (anchor_tags_.length == 0) { - if (match(munge_, rgx.heading_identify_anchor_tag)) { - if (auto m = match(munge_, rgx.heading_extract_named_anchor_tag)) { - munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, - "$1~" ~ toLower(m.captures[1]) ~ "_" ~ m.captures[2] ~ " "); - } else if (auto m = match(munge_, rgx.heading_extract_unnamed_anchor_tag)) { - munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, - "$1~" ~ "s" ~ m.captures[1] ~ " "); - } - } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" - static __gshared uint heading_num_lev1 = 0; - heading_num_lev1 ++; - munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, - "$1~" ~ "x" ~ to!string(heading_num_lev1) ~ " "); - } - } - return munge_; - } auto obj_inline_markup_and_anchor_tags(string[string] obj_, string[string][string] dochead_make_aa) in { } body { @@ -2251,117 +2078,9 @@ template SiSUdocAbstraction() { switch (obj_["is"]) { case "heading": static __gshared string anchor_tag = ""; - if (dochead_make_aa["make"]["num_top"].length > 0) { - if (!(match(obj_txt["munge"], rgx.heading_anchor_tag))) { - static __gshared uint heading_num_top_level=9; - static __gshared uint heading_num_depth=2; - static __gshared uint heading_num_0 = 0; - static __gshared uint heading_num_1 = 0; - static __gshared uint heading_num_2 = 0; - static __gshared uint heading_num_3 = 0; - static __gshared string heading_number_auto_composite = ""; - if (heading_num_top_level==9) { - if (dochead_make_aa["make"]["num_depth"].length > 0) { - heading_num_depth = to!uint(dochead_make_aa["make"]["num_depth"]); - } - switch (dochead_make_aa["make"]["num_top"]) { - case "A": - break; - case "B": - heading_num_top_level=1; - break; - case "C": - heading_num_top_level=2; - break; - case "D": - heading_num_top_level=3; - break; - case "1": - heading_num_top_level=4; - break; - case "2": - heading_num_top_level=5; - break; - case "3": - heading_num_top_level=6; - break; - case "4": - heading_num_top_level=7; - break; - default: - break; - } - } - /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ - if (heading_num_top_level > to!uint(obj_["lev_markup_number"])) { - heading_num_0 = 0; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == to!uint(obj_["lev_markup_number"])) { - heading_num_0 ++; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 1)) { - heading_num_1 ++; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 2)) { - heading_num_2 ++; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 3)) { - heading_num_3 ++; - } else { - } - if (heading_num_3 > 0) { - heading_number_auto_composite = - (heading_num_depth == 3) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) ~ "." ~ - to!string(heading_num_2) ~ "." ~ - to!string(heading_num_3) - ) - : ""; - } else if (heading_num_2 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 2) - && (heading_num_depth <= 3)) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) ~ "." ~ - to!string(heading_num_2) - ) - : ""; - } else if (heading_num_1 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 1) - && (heading_num_depth <= 3)) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) - ) - : ""; - } else if (heading_num_0 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 0) - && (heading_num_depth <= 3)) - ? (to!string(heading_num_0)) - : ""; - } else { - heading_number_auto_composite = ""; - } - debug(heading_number_auto) { - writeln(heading_number_auto_composite); - } - if (!empty(heading_number_auto_composite)) { - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading, - "$1~$2 " ~ heading_number_auto_composite ~ ". "); - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading_marker_missing_tag, - "$1~" ~ heading_number_auto_composite ~ " "); - } - } - } // WORK ON, you still need to ensure that level 1 anchor_tags are unique - obj_txt["munge"]=make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); + obj_txt["munge"]=_configured_auto_heading_numbering_and_segment_anchor_tags(obj_txt["munge"], obj_, dochead_make_aa); + obj_txt["munge"]=_make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); if (auto m = match(obj_txt["munge"], rgx.heading_anchor_tag)) { anchor_tag = m.captures[1]; anchor_tags_ ~=anchor_tag; @@ -2409,10 +2128,189 @@ template SiSUdocAbstraction() { } invariant() { } + private: + static string _configured_auto_heading_numbering_and_segment_anchor_tags(string munge_, string[string] obj_, string[string][string] dochead_make_aa) { + if (dochead_make_aa["make"]["num_top"].length > 0) { + if (!(match(munge_, rgx.heading_anchor_tag))) { + static __gshared uint heading_num_top_level=9; + static __gshared uint heading_num_depth=2; + static __gshared uint heading_num_0 = 0; + static __gshared uint heading_num_1 = 0; + static __gshared uint heading_num_2 = 0; + static __gshared uint heading_num_3 = 0; + static __gshared string heading_number_auto_composite = ""; + if (heading_num_top_level==9) { + if (dochead_make_aa["make"]["num_depth"].length > 0) { + heading_num_depth = to!uint(dochead_make_aa["make"]["num_depth"]); + } + switch (dochead_make_aa["make"]["num_top"]) { + case "A": + break; + case "B": + heading_num_top_level=1; + break; + case "C": + heading_num_top_level=2; + break; + case "D": + heading_num_top_level=3; + break; + case "1": + heading_num_top_level=4; + break; + case "2": + heading_num_top_level=5; + break; + case "3": + heading_num_top_level=6; + break; + case "4": + heading_num_top_level=7; + break; + default: + break; + } + } + /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ + if (heading_num_top_level > to!uint(obj_["lev_markup_number"])) { + heading_num_0 = 0; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if (heading_num_top_level == to!uint(obj_["lev_markup_number"])) { + heading_num_0 ++; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 1)) { + heading_num_1 ++; + heading_num_2 = 0; + heading_num_3 = 0; + } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 2)) { + heading_num_2 ++; + heading_num_3 = 0; + } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 3)) { + heading_num_3 ++; + } else { + // + } + if (heading_num_3 > 0) { + heading_number_auto_composite = + (heading_num_depth == 3) + ? ( to!string(heading_num_0) ~ "." ~ + to!string(heading_num_1) ~ "." ~ + to!string(heading_num_2) ~ "." ~ + to!string(heading_num_3) + ) + : ""; + } else if (heading_num_2 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 2) + && (heading_num_depth <= 3)) + ? ( to!string(heading_num_0) ~ "." ~ + to!string(heading_num_1) ~ "." ~ + to!string(heading_num_2) + ) + : ""; + } else if (heading_num_1 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 1) + && (heading_num_depth <= 3)) + ? ( to!string(heading_num_0) ~ "." ~ + to!string(heading_num_1) + ) + : ""; + } else if (heading_num_0 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 0) + && (heading_num_depth <= 3)) + ? (to!string(heading_num_0)) + : ""; + } else { + heading_number_auto_composite = ""; + } + debug(heading_number_auto) { + writeln(heading_number_auto_composite); + } + if (!empty(heading_number_auto_composite)) { + munge_=replaceFirst(munge_, rgx.heading, + "$1~$2 " ~ heading_number_auto_composite ~ ". "); + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ heading_number_auto_composite ~ " "); + } + } + } + return munge_; + } + + + static string _make_segment_anchor_tags_if_none_provided(string munge_, string lev_) { + if (!(match(munge_, rgx.heading_anchor_tag))) { // if (anchor_tags_.length == 0) { + if (match(munge_, rgx.heading_identify_anchor_tag)) { + if (auto m = match(munge_, rgx.heading_extract_named_anchor_tag)) { + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ toLower(m.captures[1]) ~ "_" ~ m.captures[2] ~ " "); + } else if (auto m = match(munge_, rgx.heading_extract_unnamed_anchor_tag)) { + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ "s" ~ m.captures[1] ~ " "); + } + } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" + static __gshared uint heading_num_lev1 = 0; + heading_num_lev1 ++; + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ "x" ~ to!string(heading_num_lev1) ~ " "); + } + } + return munge_; + } + unittest { + string txt_lev="1"; + string txt_in, txt_out; + + txt_in = "1~copyright Copyright"; + txt_out ="1~copyright Copyright"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + // assert(ObjInlineMarkup._make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in = "1~ 6. Writing Copyright Licenses"; + txt_out ="1~s6 6. Writing Copyright Licenses"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ 1. Reinforcing trends"; + txt_out= "1~s1 1. Reinforcing trends"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ 11 SCIENCE AS A COMMONS"; + txt_out= "1~s11 11 SCIENCE AS A COMMONS"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1"; + txt_out="1~chapter_1 Chapter 1"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1."; + txt_out="1~chapter_1 Chapter 1."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1: Done"; + txt_out="1~chapter_1 Chapter 1: Done"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; + txt_out= "1~chapter_11 Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ CHAPTER I."; + txt_out="1~x1 CHAPTER I."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ CHAPTER II."; + txt_out="1~x2 CHAPTER II."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + } } - struct ObjAttrib { - auto attrib = ObjAttributes(); - string[string] obj_attrib; + struct ObjAttributes { + string[string] _obj_attrib; string obj_attributes(string obj_is_, string obj_raw, string node) in { } body { @@ -2421,46 +2319,182 @@ template SiSUdocAbstraction() { destroy(obj_raw); destroy(node); } - JSONValue node_j = parseJSON(node); - obj_attrib.remove("json"); - obj_attrib["json"] ="{"; + _obj_attrib.remove("json"); + _obj_attrib["json"] ="{"; switch (obj_is_) { case "heading": - obj_attrib["json"] ~= attrib.heading(obj_raw); // + _obj_attrib["json"] ~= _heading(obj_raw); // break; case "para": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.para(obj_raw); + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _para(obj_raw); break; case "code": - obj_attrib["json"] ~= attrib.code(obj_raw); + _obj_attrib["json"] ~= _code(obj_raw); break; case "group": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.group(obj_raw); + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _group(obj_raw); break; case "block": - obj_attrib["json"] ~= attrib.para_and_blocks(obj_raw) - ~ attrib.block(obj_raw); + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _block(obj_raw); break; case "verse": - obj_attrib["json"] ~= attrib.verse(obj_raw); + _obj_attrib["json"] ~= _verse(obj_raw); break; case "quote": - obj_attrib["json"] ~= attrib.quote(obj_raw); + _obj_attrib["json"] ~= _quote(obj_raw); break; case "table": - obj_attrib["json"] ~= attrib.table(obj_raw); + _obj_attrib["json"] ~= _table(obj_raw); break; case "comment": - obj_attrib["json"] ~= attrib.comment(obj_raw); + _obj_attrib["json"] ~= _comment(obj_raw); break; default: - obj_attrib["json"] ~= attrib.para(obj_raw); + _obj_attrib["json"] ~= _para(obj_raw); break; } - obj_attrib["json"] ~=" }"; - JSONValue oa_j = parseJSON(obj_attrib["json"]); + _obj_attrib["json"] ~=" }"; + _obj_attrib["json"]=_set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, node); + debug(structattrib) { + if (oa_j["is"].str() == "heading") { + // writeln(__LINE__); + writeln(_obj_attrib["json"]); + // writeln(node); + writeln( + "is: ", oa_j["is"].str(), + "; obj_cite_number: ", oa_j["obj_cite_number"].integer() + ); + } + } + return _obj_attrib["json"]; + } + invariant() { + } + private: + string _obj_attributes; + string _para_and_blocks(string obj_txt_in) + in { } + body { + auto rgx = Rgx(); + if (matchFirst(obj_txt_in, rgx.para_bullet)) { + _obj_attributes =" \"bullet\": \"true\"," + ~ " \"indent_start\": 0," + ~ " \"indent_rest\": 0,"; + } else if (auto m = matchFirst(obj_txt_in, rgx.para_bullet_indent)) { + _obj_attributes =" \"bullet\": \"true\"," + ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; + } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent_hang)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[2]) ~ ","; + } else if (auto m = matchFirst(obj_txt_in, rgx.para_indent)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_start\": " ~ to!string(m.captures[1]) ~ "," + ~ " \"indent_rest\": " ~ to!string(m.captures[1]) ~ ","; + } else { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_start\": 0," + ~ " \"indent_rest\": 0,"; + } + return _obj_attributes; + } + string _para(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"para\""; + return _obj_attributes; + } + invariant() { + } + string _heading(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"heading\""; + return _obj_attributes; + } + invariant() { + } + string _code(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"code\""; + return _obj_attributes; + } + invariant() { + } + string _group(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"group\""; + return _obj_attributes; + } + invariant() { + } + string _block(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"block\""; + return _obj_attributes; + } + invariant() { + } + string _verse(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"verse\""; + return _obj_attributes; + } + invariant() { + } + string _quote(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"quote\""; + return _obj_attributes; + } + invariant() { + } + string _table(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"table\""; + return _obj_attributes; + } + invariant() { + } + string _comment(string obj_txt_in) + in { } + body { + _obj_attributes = " \"use\": \"comment\"," + ~ " \"of\": \"comment\"," + ~ " \"is\": \"comment\""; + return _obj_attributes; + } + invariant() { + } + string _set_additional_values_parse_as_json(string _obj_attrib, string obj_is_, string node) { + JSONValue oa_j = parseJSON(_obj_attrib); + JSONValue node_j = parseJSON(node); assert( (oa_j.type == JSON_TYPE.OBJECT) && (node_j.type == JSON_TYPE.OBJECT) @@ -2476,20 +2510,8 @@ template SiSUdocAbstraction() { } oa_j.object["parent_obj_cite_number"] = node_j["parent_obj_cite_number"]; oa_j.object["parent_lev_markup_number"] = node_j["parent_lev_markup_number"]; - obj_attrib["json"] = oa_j.toString(); - debug(structattrib) { - if (oa_j["is"].str() == "heading") { - writeln(obj_attrib["json"]); - writeln( - "is: ", oa_j["is"].str(), - "; obj_cite_number: ", oa_j["obj_cite_number"].integer() - ); - } - } - // obj_attrib["json"]="{}"; - return obj_attrib["json"]; - } - invariant() { + _obj_attrib = oa_j.toString(); + return _obj_attrib; } } struct BookIndexNuggetHash { -- cgit v1.2.3