diff options
| author | Ralph Amissah <ralph@amissah.com> | 2016-04-24 22:08:24 -0400 | 
|---|---|---|
| committer | Ralph Amissah <ralph@amissah.com> | 2016-04-24 22:08:24 -0400 | 
| commit | ed302d1be74d2b4e69ee4b6e3834637ed531eaea (patch) | |
| tree | 0f605c3756788d2fda6fe0782a7a472172a285b9 /lib/sdp/ao_emitter.d | |
| parent | base ... tag (diff) | |
step1doc-reform_v0.0.1
Diffstat (limited to 'lib/sdp/ao_emitter.d')
| -rw-r--r-- | lib/sdp/ao_emitter.d | 274 | 
1 files changed, 213 insertions, 61 deletions
| diff --git a/lib/sdp/ao_emitter.d b/lib/sdp/ao_emitter.d index c9b1a7e..7ed9fa8 100644 --- a/lib/sdp/ao_emitter.d +++ b/lib/sdp/ao_emitter.d @@ -1,10 +1,10 @@ -/* +/+    emitters    ao_emitters.d -*/ ++/  mixin template Emitters() {    mixin InternalMarkup; -  class CLI { +  struct CLI {      string[string] extract_actions(string cmdlnins, string[string] actions)      in { }      body { @@ -18,7 +18,8 @@ mixin template Emitters() {        return actions;      }    } -  class OCNemitter : AssertOCN { +  struct OCNemitter { +  // class OCNemitter : AssertOCN {      int ocn, ocn_;      int ocn_emitter(int ocn_status_flag)      in { assert(ocn_status_flag <= 2); } @@ -28,17 +29,19 @@ mixin template Emitters() {        } else {          ocn=0;        } +      assert(ocn >= 0);        return ocn;      }      invariant() {      }    } -  class ObjAttributes { +  struct ObjAttributes { +  // class ObjAttributes : AssertObjAttributes {      string[string] obj_txt;      string para_and_blocks(string obj_txt_in)      in { }      body { -      auto rgx = new Rgx(); +      auto rgx = Rgx();        obj_txt["munge"]=obj_txt_in;        if (match(obj_txt_in, rgx.para_bullet)) {          obj_txt["attrib"] =" \"bullet\": \"true\"," @@ -81,6 +84,7 @@ mixin template Emitters() {        obj_txt["attrib"] = " \"use\": \"content\","        ~ " \"of\": \"para\","        ~ " \"is\": \"heading\""; +      // obj_txt["struct"]=;        return obj_txt["attrib"];      }      invariant() { @@ -185,7 +189,8 @@ mixin template Emitters() {      invariant() {      }    } -  class ObjInlineMarkupMunge { +  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; @@ -198,8 +203,8 @@ mixin template Emitters() {      private auto object_notes_(string obj_txt_in)      in { }      body { -      auto rgx = new Rgx(); -      auto mkup = new InternalMarkup(); +      auto rgx = Rgx(); +      auto mkup = InternalMarkup();        obj_txt_out = "";        tail = "";        obj_txt_in = replaceAll( @@ -237,6 +242,11 @@ mixin template Emitters() {              (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; @@ -257,7 +267,7 @@ mixin template Emitters() {      string para(string obj_txt_in)      in { }      body { -      auto rgx = new Rgx(); +      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, ""); @@ -273,7 +283,7 @@ mixin template Emitters() {      string heading(string obj_txt_in)      in { }      body { -      auto rgx = new Rgx(); +      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, ""); @@ -364,8 +374,9 @@ mixin template Emitters() {      invariant() {      }    } -  class ObjInlineMarkup : AssertObjInlineMarkup { -    auto munge = new ObjInlineMarkupMunge(); +  struct ObjInlineMarkup { +  // struct ObjInlineMarkup : AssertObjInlineMarkup { +    auto munge = ObjInlineMarkupMunge();      string[string] obj_txt;      string obj_inline_markup(string obj_is_, string obj_raw)      in { } @@ -419,13 +430,17 @@ mixin template Emitters() {      invariant() {      }    } -  class ObjAttrib : AssertObjAttrib { -    auto attrib = new ObjAttributes(); +  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);        } @@ -493,20 +508,24 @@ mixin template Emitters() {        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() {      }    } -  class HeaderDocMetadataMakeJson { -    auto rgx = new Rgx(); +  struct HeaderDocMetadataMakeJson { +  // class HeaderMetadataMakeHash : AssertHeaderMetadataMakeJson { +    auto rgx = Rgx();      string hm, hs;      auto header_metadata_and_make_jsonstr(        string header, @@ -678,6 +697,15 @@ mixin template Emitters() {                    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; @@ -694,9 +722,12 @@ mixin template Emitters() {        static assert(!isTypeTuple!(t));        return t;      } +    // invariant() { +    // }    }    class HeaderMetadataMakeHash { -    auto rgx = new Rgx(); +  // class HeaderMetadataMakeHash : AssertHeaderMetadataMakeHash { +    auto rgx = Rgx();      string header_main;      string[string] head;      string[string] header_topic_hash(string header) @@ -743,7 +774,8 @@ mixin template Emitters() {      invariant() {      }    } -  class BookIndexNuggetHash : AssertBookIndexNuggetHash { +  struct BookIndexNuggetHash { +  // class BookIndexNuggetHash : AssertBookIndexNuggetHash {      string main_term, sub_term, sub_term_bits;      uint ocn_offset, ocn_endpoint;      string[] ocns; @@ -751,9 +783,19 @@ mixin template Emitters() {      string[][string][string] hash_nugget;      string[] bi_main_terms_split_arr;      string[][string][string] bookindex_nugget_hash(string bookindex, int ocn) -    in { } +    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 = new Rgx(); +      auto rgx = Rgx();        if (!bookindex.empty) {          auto bi_main_terms_split_arr =            split(bookindex, rgx.bi_main_terms_split); @@ -796,15 +838,18 @@ mixin template Emitters() {                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() {      }    } -  class BookIndexReport { +  struct BookIndexReport { +  // class BookIndexReport : AssertBookIndexReport {      int mkn, skn;      auto bookindex_report_sorted(        string[][string][string] bookindex_unordered_hashes @@ -822,13 +867,15 @@ mixin template Emitters() {                to!string(bookindex_unordered_hashes[mainkey][subkey])              );            } +          // bookindex_the[mkn][mainkey][skn][subkey] ~= (bookindex_unordered_hashes[mainkey][subkey]);            skn++;          }          mkn++;        } +      // return bookindex_the;      }    } -  class BookIndexReportIndent { +  struct BookIndexReportIndent {      int mkn, skn;      auto bookindex_report_indented(        string[][string][string] bookindex_unordered_hashes @@ -848,16 +895,17 @@ mixin template Emitters() {                bookindex_unordered_hashes[mainkey][subkey]              ));            } +          // bookindex_the[mkn][mainkey][skn][subkey] ~= (bookindex_unordered_hashes[mainkey][subkey]);            skn++;          }          mkn++;        }      }    } -  class BookIndexReportSection { +  struct BookIndexReportSection {      mixin ObjectSetters;      int mkn, skn; -    auto rgx = new Rgx(); +    auto rgx = Rgx();      auto bookindex_write_section(        string[][string][string] bookindex_unordered_hashes      ) { @@ -894,19 +942,20 @@ mixin template Emitters() {        string attrib;        string indent_first;        string indent_second; -      auto set_oa = new ObjectAbstractSet(); +      auto set_oa = ObjectAbstractSet();        auto mainkeys =          bookindex_unordered_hashes.byKey.array.sort().release;        string bi_tmp; -      string[string][1024] bookindex_arbitrary_max_length_set; +      string[string][] bookindex;        writeln(mainkeys.length); +      // B~ Book Index        type_heading=1;        bi_tmp = "Book Index";        attrib="";        lev="B";        lvn="1";        lcn="1"; -      bookindex_arbitrary_max_length_set[mkn] = +      bookindex ~=          set_oa.contents_heading(            type_heading,            bi_tmp, @@ -918,13 +967,14 @@ mixin template Emitters() {          );        ocn++;        mkn++; +      // 1~ Index        type_heading=1;        bi_tmp = "Index";        attrib="";        lev="1";        lvn="4";        lcn="2"; -      bookindex_arbitrary_max_length_set[mkn] = +      bookindex ~=          set_oa.contents_heading(            type_heading,            bi_tmp, @@ -938,6 +988,7 @@ mixin template Emitters() {        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 ~ ", "; @@ -961,7 +1012,7 @@ mixin template Emitters() {          indent_first = "0";          indent_second = "1";          attrib=""; -        bookindex_arbitrary_max_length_set[mkn] = +        bookindex ~=            set_oa.contents_para(              type,              bi_tmp, @@ -974,8 +1025,6 @@ mixin template Emitters() {          ocn++;          mkn++;        } -      auto bookindex = -        bookindex_arbitrary_max_length_set[0..mkn].dup;        auto t = tuple(bookindex, ocn);        return t;      } @@ -985,7 +1034,8 @@ mixin template Emitters() {        auto mainkeys =          bookindex_unordered_hashes.byKey.array.sort().release;        string bi_tmp; -      string[1024] bookindex_arbitrary_max_length_set; +      string[] bookindex; +      // int bi_num;        writeln(mainkeys.length);        foreach (mainkey; mainkeys) {          bi_tmp = "_0_1 !{" ~ mainkey ~ "}! "; @@ -999,6 +1049,7 @@ mixin template Emitters() {            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 ~ ", "; @@ -1007,23 +1058,21 @@ mixin template Emitters() {            skn++;          }          bi_tmp = replaceFirst(bi_tmp, rgx.trailing_linebreak, ""); -        bookindex_arbitrary_max_length_set[mkn] = bi_tmp; +        bookindex ~= bi_tmp;          mkn++;        } -      auto bookindex = -        bookindex_arbitrary_max_length_set[0..mkn].dup;        return bookindex;      }    } -  class NotesSection { +  struct NotesSection {      mixin ObjectSetters;      string object_notes; -    int previous_count; +    ulong previous_count;      int mkn; -    auto rgx = new Rgx(); +    auto rgx = Rgx();      private auto gather_notes_for_endnote_section( -      string[string][131072] contents_arbitrary_max_length_set, -      int counter +      string[string][] contents_arbitrary_max_length_set, +      ulong counter      )      in {        // endnotes/ footnotes for @@ -1046,6 +1095,7 @@ mixin template Emitters() {            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_" ~ @@ -1067,21 +1117,23 @@ mixin template Emitters() {      in {      }      body { -      auto set_oa = new ObjectAbstractSet(); -      string[string][1024] endnotes_arbitrary_max_length_set; +      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_arbitrary_max_length_set[mkn] = +      endnotes ~=          set_oa.contents_heading(            type_heading,            "Endnotes", @@ -1093,12 +1145,13 @@ mixin template Emitters() {          );        ocn++;        mkn++; +      // 1~ Endnotes        type_heading=1;        attrib="";        lev="1";        lvn="4";        lcn="2"; -      endnotes_arbitrary_max_length_set[mkn] = +      endnotes ~=          set_oa.contents_heading(            type_heading,            "Endnotes", @@ -1116,7 +1169,7 @@ mixin template Emitters() {          indent_first = "0";          indent_second = "0";          attrib=""; -        endnotes_arbitrary_max_length_set[mkn] = +        endnotes ~=            set_oa.contents_para(              type,              endnote, @@ -1129,28 +1182,27 @@ mixin template Emitters() {          ocn++;          mkn++;        } -      auto endnotes = -        endnotes_arbitrary_max_length_set[0..mkn].dup;        auto t = tuple(endnotes, ocn);        return t;      }    } -  class Bibliography { -    public JSONValue[] bibliography(string[] biblio_unsorted_incomplete) +  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); +        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 +      string[] biblio_unordered, +      ref JSONValue[] bib_arr_json      ) { -      JSONValue[1024] bib_arr_json; -      int count_biblio_entry; -      count_biblio_entry=0; +      // 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 @@ -1169,12 +1221,15 @@ mixin template Emitters() {               "; "  ~               j["fulltitle"].str            ); +          // bib[count_biblio_entry] = j.toString();          } -        bib_arr_json[count_biblio_entry] = j; -        count_biblio_entry++; +        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[0..(count_biblio_entry)].dup; +        bib_arr_json.dup;        return biblio_unsorted_array_of_json_objects;      }      final private JSONValue[] biblio_sort(JSONValue[] biblio_unordered) { @@ -1187,6 +1242,7 @@ mixin template Emitters() {          foreach (j; biblio_sorted) {            if (!empty(j["fulltitle"].str)) {              writeln(j["sortby_deemed_author_year_title"]); +            // writeln(j["deemed_author"], " (", j["author"], ") ",  j["fulltitle"]);            }          }        } @@ -1202,7 +1258,8 @@ mixin template Emitters() {        }      }    } -  class NodeStructureMetadata : AssertNodeJSON { +  struct NodeStructureMetadata { +  // class NodeStructureMetadata : AssertNodeJSON {      int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7;      uint ocn;      uint[string] p_; // p_ parent_ @@ -1215,9 +1272,16 @@ mixin template Emitters() {        string is_      )      in { -      auto rgx = new Rgx(); +      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_); @@ -1239,6 +1303,18 @@ mixin template Emitters() {          ", \"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() { @@ -1252,9 +1328,28 @@ mixin template Emitters() {        string is_      )      in { -      auto rgx = new Rgx(); +      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": @@ -1306,6 +1401,15 @@ mixin template Emitters() {          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=("{ " ~ @@ -1319,6 +1423,54 @@ mixin template Emitters() {          ", \"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() { | 
