From 951d136957c14bed5581a11fe41bdebd174d5ce8 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 2 Jul 2016 00:22:17 -0400 Subject: file renaming, whitespace cleaning --- src/sdp/ao_abstract_doc_source.d | 23 --- src/sdp/ao_conf_make_meta.d | 25 +++ src/sdp/ao_conf_make_meta_native.d | 320 +++++++++++++++++++++++++++++++++++++ src/sdp/ao_conf_make_meta_sdlang.d | 209 ++++++++++++++++++++++++ src/sdp/ao_header_extract.d | 25 --- src/sdp/ao_header_extract_native.d | 320 ------------------------------------- src/sdp/ao_header_extract_sdlang.d | 209 ------------------------ src/sdp/ao_object_setter.d | 1 - src/sdp/ao_rgx.d | 2 - 9 files changed, 554 insertions(+), 580 deletions(-) create mode 100644 src/sdp/ao_conf_make_meta.d create mode 100644 src/sdp/ao_conf_make_meta_native.d create mode 100644 src/sdp/ao_conf_make_meta_sdlang.d delete mode 100644 src/sdp/ao_header_extract.d delete mode 100644 src/sdp/ao_header_extract_native.d delete mode 100644 src/sdp/ao_header_extract_sdlang.d (limited to 'src/sdp') diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index 27a78b7..067e920 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -5,14 +5,12 @@ template SiSUdocAbstraction() { private: struct Abstraction { - /+ ↓ abstraction imports +/ import ao_defaults, // sdp/ao_defaults.d ao_object_setter, // sdp/ao_object_setter.d ao_rgx, // sdp/ao_rgx.d ao_ansi_colors; // sdp/ao_ansi_colors.d - /+ ↓ abstraction mixins +/ mixin ObjectSetter; mixin InternalMarkup; @@ -20,17 +18,13 @@ template SiSUdocAbstraction() { // // mixin AssertionsOnBlocks; // mixin SiSUbiblio; // issue // mixin SiSUheader; - /+ ↓ abstraction struct init +/ /+ initialize +/ - auto rgx = Rgx(); ObjComposite[] contents_the_objects; - string[string] an_object, processing; auto set_abstract_object = ObjectAbstractSet(); auto note_section = NotesSection(); - /+ enum +/ enum State { off, on } enum TriState { off, on, closing } // make aware, possibility of third state @@ -47,33 +41,27 @@ template SiSUdocAbstraction() { content_non_header } // header section A-D; header text 1-4 enum DocStructCollapsedHeading { lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7 } // not yet used - /+ biblio variables +/ string biblio_tag_name, biblio_tag_entry, st; string[] biblio_arr_json; JSONValue[] bib_arr_json; int bib_entry; - /+ counters +/ long counter, previous_count; int[string] line_occur; int verse_line, heading_pointer; - /+ paragraph attributes +/ string[string] indent; bool bullet = true; string content_non_header = "8"; - auto obj_im = ObjInlineMarkup(); auto obj_att = ObjAttrib(); - /+ ocn +/ int obj_cite_number, obj_cite_number_; auto object_citation_number = OCNemitter(); int obj_cite_number_emit(int obj_cite_number_status_flag) { return object_citation_number.obj_cite_number_emitter(obj_cite_number_status_flag); } - /+ book index variables +/ string book_idx_tmp; string[][string][string] bookindex_unordered_hashes; @@ -81,7 +69,6 @@ template SiSUdocAbstraction() { string[][string][string] bkidx_hash(string bookindex_section, int obj_cite_number) { return bookindex_extract_hash.bookindex_nugget_hash(bookindex_section, obj_cite_number); } - /+ node +/ string node; auto node_construct = NodeStructureMetadata(); @@ -118,7 +105,6 @@ template SiSUdocAbstraction() { ); } // mixin SiSUdocAbstractionFunctions; - /+ ↓ abstract marked up document +/ auto abstract_doc_source( char[][] markup_sourcefile_content, @@ -206,11 +192,9 @@ template SiSUdocAbstraction() { "h_4": regex(r"^(none)") ]; /+ abstraction init ↑ +/ - /+ ↓ loop markup document/text line by line +/ srcDocLoop: foreach (line; markup_sourcefile_content) { - /+ ↓ markup document/text line by line +/ /+ scope +/ scope(exit) { @@ -510,7 +494,6 @@ template SiSUdocAbstraction() { } } } /+ ← closed: loop markup document/text line by line +/ - /+ ↓ post loop markup document/text +/ debug(objectrelated2) { // check tell_l("blue", line); @@ -644,9 +627,7 @@ template SiSUdocAbstraction() { ); return t; /+ post loop markup document/text ↑ +/ - } /+ ← closed: abstract doc source +/ - /+ ↓ abstraction functions +/ auto object_reset(ref string[string] an_object) { an_object.remove("obj"); @@ -1960,7 +1941,6 @@ template SiSUdocAbstraction() { } } /+ abstraction functions ↑ +/ - /+ ↓ abstraction function emitters +/ struct OCNemitter { // class OCNemitter : AssertOCN { @@ -3174,7 +3154,6 @@ template SiSUdocAbstraction() { } } /+ abstraction functions emitters ↑ +/ - /+ ↓ abstraction functions assertions +/ auto assertions_doc_structure(string[string] an_object, int[string] lv) { if (lv["h3"] > State.off) { @@ -3371,7 +3350,5 @@ template SiSUdocAbstraction() { "block status: off or closing"); } /+ abstraction functions assertions ↑ +/ - } /+ ← closed: struct Abstraction +/ - } /+ ← closed: template SiSUdocAbstraction +/ diff --git a/src/sdp/ao_conf_make_meta.d b/src/sdp/ao_conf_make_meta.d new file mode 100644 index 0000000..f78d7c4 --- /dev/null +++ b/src/sdp/ao_conf_make_meta.d @@ -0,0 +1,25 @@ +/+ + extract native/orig header return associative array ++/ +template SiSUheaderExtractHub() { + private import + std.regex; + private import + ao_rgx; + struct HeaderDocMetadataAndMake { + mixin SiSUheaderExtractNative; + mixin SiSUheaderExtractSDLang; + auto rgx = Rgx(); + private auto headerContentAA(char[] header_src, string[string][string] conf_doc_make_aa) { + auto head_native = HeaderDocMetadataAndMakeNativeToAA(); + auto head_sdlang = HeaderExtractSDL(); + writeln(__LINE__); + auto header_make_and_meta_tuple = (match(header_src, rgx.native_header_meta_title)) + ? (head_native.headerNativeToAA(header_src)) + : (head_sdlang.headerSDLangToAA(header_src, conf_doc_make_aa)); + writeln(__LINE__); + static assert(!isTypeTuple!(header_make_and_meta_tuple)); + return header_make_and_meta_tuple; + } + } +} diff --git a/src/sdp/ao_conf_make_meta_native.d b/src/sdp/ao_conf_make_meta_native.d new file mode 100644 index 0000000..7bcf965 --- /dev/null +++ b/src/sdp/ao_conf_make_meta_native.d @@ -0,0 +1,320 @@ +/+ + extract native/orig header return associative array ++/ +template SiSUheaderExtractNative() { + private import + std.exception, + std.regex, + std.utf, + std.conv : to; + private import + ao_rgx; + struct HeaderDocMetadataAndMakeNativeToAA { + mixin SiSUregisters; + mixin SiSUrgxInitFlags; + mixin RgxInit; + auto rgx = Rgx(); + enum State { off, on } + string hm, hs; + auto header_metadata_and_make_aa( + string header, + string[string][string] dochead_meta, + string[string][string] dochead_make + ) + in { } + body { + scope(exit) { + destroy(header); + destroy(dochead_meta); + destroy(dochead_make); + } + if (auto t = match(header, rgx.native_header_main)) { + char[][] header_obj_spl = split( + cast(char[]) header, + rgx.line_delimiter_ws_strip + ); + auto hm = to!string(t.captures[1]); + if (match(hm, rgx.main_headers)) { + foreach (line; header_obj_spl) { + if (auto m = match(line, rgx.native_header_main)) { + if (!empty(m.captures[2])) { + if (hm == "creator") { + dochead_meta[hm]["author"] = + to!string(m.captures[2]); + } else if (hm == "title") { + dochead_meta[hm]["main"] = + to!string(m.captures[2]); + } else if (hm == "publisher") { + dochead_meta[hm]["name"] = + to!string(m.captures[2]); + } + } + } else if (auto s = match(line, rgx.native_header_sub)) { + if (!empty(s.captures[2])) { + auto hs = to!string(s.captures[1]); + if ((hm == "make" ) + && (dochead_make[hm])) { + switch (hm) { + case "make": + if (match(hs, rgx.native_subhead_make)) { + if (dochead_make[hm][hs]) { + dochead_make[hm][hs] = to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + default: + break; + } + } else if (dochead_meta[hm]) { + switch (hm) { + case "creator": + if (match(hs, rgx.native_subhead_creator)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "title": + if (match(hs, rgx.native_subhead_title)) { + if ((hs == "subtitle") + && (dochead_meta[hm]["sub"])) { + dochead_meta[hm]["sub"] = + to!string(s.captures[2]); + } else if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "rights": + if (match(hs, rgx.native_subhead_rights)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "date": + if (match(hs, rgx.native_subhead_date)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "original": + if (match(hs, rgx.native_subhead_original)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "classify": + if (match(hs, rgx.native_subhead_classify)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "identifier": + if (match(hs, rgx.native_subhead_identifier)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "notes": + if (match(hs, rgx.native_subhead_notes)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "publisher": + if (match(hs, rgx.native_subhead_publisher)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "links": + destroy(hm); + destroy(hs); + // if (match(hs, rgx.native_subhead_links)) { + // if (dochead_meta[hm][hs]) { + // dochead_meta[hm][hs] = to!string(s.captures[2]); + // } + // } else { + // writeln("not a valid header type:", hm, ":", hs); + // destroy(hm); + // destroy(hs); + // } + break; + default: + break; + } + } + } + } + } + } else { + writeln("not a valid header type:", hm); + } + } + auto t = tuple(dochead_meta, dochead_make); + static assert(!isTypeTuple!(t)); + return t; + } + private auto native_header_extract( + char[] line, + ref int[string] line_occur, + ref string[string] an_object, + ref int[string] type + ) { + if (matchFirst(line, rgx.native_header_make)) { /+ matched header_make +/ + debug(header1) { /+ writeln(line); +/ } + type["header"] = State.on; + type["header_make"] = State.on; + type["header_meta"] = State.off; + ++line_occur["header_make"]; + an_object["obj"] ~= line ~= "\n"; + } else if (matchFirst(line, rgx.native_header)) { /+ matched header_metadata +/ + /+ (generic header match and not previously caught by header_make) +/ + debug(header1) { /+ writeln(line); +/ } + type["header"] = State.on; + type["header_make"] = State.off; + type["header_meta"] = State.on; + ++line_occur["header_meta"]; + an_object["obj"] ~= line ~= "\n"; + } else if (type["header_make"] == State.on + && (line_occur["header_make"] > State.off)) { /+ header_make flag set +/ + if (matchFirst(line, rgx.native_header_sub)) { /+ sub-header +/ + debug(header1) { /+ writeln(line); +/ } + ++line_occur["header_make"]; + an_object["obj"] ~= line ~= "\n"; + } + } else if (type["header_meta"] == State.on + && (line_occur["header_meta"] > State.off)) { /+ header_metadata flag set +/ + if (matchFirst(line, rgx.native_header_sub)) { /+ sub-header +/ + debug(header1) { /+ writeln(line); +/ } + ++line_occur["header_meta"]; + an_object["obj"] ~= line ~= "\n"; + } + } + return an_object; + } + auto header_reset_states_common( + ref int[string] line_occur, + ref string[string] an_object, + ref int[string] type + ) { + // line_occur["header"] = State.off; + line_occur["header_make"] = State.off; + line_occur["header_meta"] = State.off; + type["header"] = State.off; + // type["header_make"] = State.off; + // type["header_meta"] = State.off; + an_object.remove("obj"); + an_object.remove("is"); + an_object.remove("attrib"); + } + private auto headerNativeToAA(in char[] src_header) { + auto type = flags_type_init; + type = [ + "header" : State.off, + "header_make" : State.off, + "header_meta" : State.off, + ]; + string[string] an_object; + int[string] line_occur; + auto dochead_make = make_aa; + auto dochead_meta = meta_aa; + auto set_header = HeaderDocMetadataAndMakeNativeToAA(); + char[][] source_header_arr = + split(cast(char[]) src_header, rgx.line_delimiter); + foreach(header_line; source_header_arr) { + if (auto m = matchFirst(header_line, rgx.comment)) { + /+ matched comment +/ + debug(comment) { + // tell_l("blue", header_line); + } + header_reset_states_common(line_occur, an_object, type); + // type["header_make"] = State.off; + // type["header_meta"] = State.off; + } else if ((matchFirst(header_line, rgx.native_header)) + || (type["header_make"] == State.on + && (line_occur["header_make"] > State.off)) + || (type["header_meta"] == State.on + && (line_occur["header_meta"] > State.off))) { + if (header_line.length == 0) { + /+ header_make instructions (current line empty) +/ + auto dochead_metadata_and_make = + set_header.header_metadata_and_make_aa(strip(an_object["obj"]), dochead_meta, dochead_make); + static assert(!isTypeTuple!(dochead_metadata_and_make)); + dochead_meta = dochead_metadata_and_make[0]; + dochead_make = dochead_metadata_and_make[1]; + header_reset_states_common(line_occur, an_object, type); + type["header_make"] = State.off; + type["header_meta"] = State.off; + writeln(dochead_metadata_and_make); + } else { + an_object = native_header_extract(header_line, line_occur, an_object, type); + } + } else { + // writeln(__LINE__); + } + } + auto t = tuple( + dochead_make, + dochead_meta, + ); + return t; + } + } +} diff --git a/src/sdp/ao_conf_make_meta_sdlang.d b/src/sdp/ao_conf_make_meta_sdlang.d new file mode 100644 index 0000000..16a36e9 --- /dev/null +++ b/src/sdp/ao_conf_make_meta_sdlang.d @@ -0,0 +1,209 @@ +/+ + extract sdl header return sdl ++/ +template SiSUheaderExtractSDLang() { + private import + std.regex; + private import + ao_rgx; + struct HeaderExtractSDL { + mixin SiSUregisters; + mixin RgxInit; + auto rgx = Rgx(); + private auto sdlangToAAmake(string[string][string] conf, Tag conf_sdlang) { + foreach (maintag, subtags; conf) { + foreach (subtag, content; subtags) { + if (!(conf_sdlang.maybe.tags[maintag].empty)) { + if (!(conf_sdlang.tags[maintag][0].maybe.attributes[subtag].empty) + && (conf_sdlang.tags[maintag][0].attributes[subtag][0].value.length > 1)) { + writeln(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); + conf[maintag][subtag] = + to!string(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); + } + } + } + } + return conf; + } + private auto configSettingsSDLangToAAmake(Tag conf_sdlang) { + auto conf = sdlangToAAmake(conf_aa, conf_sdlang); + return conf; + } + private auto documentMakeSDLangToAAmake(Tag document_make_sdlang) { + auto dochead_make = sdlangToAAmake(make_aa, document_make_sdlang); + /+ + hm = "links"; + if (!(document_make_sdlang.maybe.tags[hm].empty)) { + /+ TODO + stuff to fix + +/ + // hs = "link"; + // if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty) + // && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + // writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value); + // dochead_meta[hm][hs] = + // to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value); + // } + } + +/ + // writeln(dochead_make); + return dochead_make; + } + final private auto headerMakeSDLang(in string src_header) { + scope(failure) { + stderr.writefln( + "%s\n%s\n%s:%s failed here:\n src_header: %s", + __MODULE__, __FUNCTION__, + __FILE__, __LINE__, + src_header, + ); + } + Tag sdl_root_header; + try { + sdl_root_header = parseSource(src_header); + } + catch(SDLangParseException e) { + stderr.writeln("SDLang problem with this document header:"); + stderr.writeln(src_header); + // Error messages of the form: + // myFile.sdl(5:28): Error: Invalid integer suffix. + stderr.writeln(e.msg); + } + debug(sdlang) { + writeln("header SDL:"); + writeln(sdl_root_header.toSDLDocument()); + } + return sdl_root_header; + } + private auto headerSDLangGet(in char[] src_header) { + char[][] source_header_arr = + split(cast(char[]) src_header, rgx.line_delimiter); + char[] header_clean; + // TODO + foreach(header_line; source_header_arr) { + if (!match(header_line, rgx.comments)) { + header_clean ~= header_line ~ "\n"; + // writeln(header_line); + } + } + /+ get sdlang tags +/ + auto header_sdlang=headerMakeSDLang(to!string(header_clean)); + debug(sdlang) { + writeln("--------------"); + stdout.rawWrite( header_sdlang.toSDLDocument() ); + writeln("--------------"); + Value test = header_sdlang.tags["title"][0].values[0]; + assert(test == typeid(string)); + writeln(header_sdlang.maybe.tags["title"]); + writeln(header_sdlang.maybe.tags["title"][0].maybe.attributes["subtitle"]); + } + return header_sdlang; // sdlang.ast.Tag + } + private auto headerSDLangToAAmake(Tag header_sdlang, string[string][string] dochead_make) { + dochead_make = sdlangToAAmake(dochead_make, header_sdlang); + auto dochead_meta = sdlangToAAmake(meta_aa, header_sdlang); + /+ + /+ dochead +/ + string hm; + string hs; + /+ meta +/ + auto dochead_meta = meta_aa; + hm = "title"; + if (!(header_sdlang.maybe.tags[hm].empty)) { + /+ TODO Title REQUIRED +/ + hs = "main"; + if (!(header_sdlang.tags[hm].empty) + && (header_sdlang.tags[hm][0].values[0].length > 1)) { + writeln(header_sdlang.tags[hm][0].values[0]); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].values[0]); + // to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + } else if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) + && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + } else { + writeln("Required header metadata Title, missing"); + } + hs = "sub"; + if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) + && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + } else if (!(header_sdlang.tags[hm][0].maybe.attributes["subtitle"].empty) + && (header_sdlang.tags[hm][0].attributes["subtitle"][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes["subtitle"][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes["subtitle"][0].value); + } + // full title composite (main + sub) + // hs = "full"; + // dochead_meta[hm][hs] = dochead_meta[hm]["main"] ~ dochead_meta[hm]["sub"]; + hs = "language"; + if (!(header_sdlang.tags[hm][0].maybe.attributes["lang"].empty) + && (header_sdlang.tags[hm][0].attributes["lang"][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes["lang"][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes["lang"][0].value); + } else if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) + && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + } + } + hm = "creator"; + if (!(header_sdlang.maybe.tags[hm].empty)) { + /+ Creator / Author REQUIRED +/ + /+ TODO + - decide on representation for & deal with multiple authors; + - author(s) full name; + - author(s) surname & other parts + +/ + hs = "author"; + if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) + && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + } + } + hm = "links"; + if (!(header_sdlang.maybe.tags[hm].empty)) { + /+ TODO + stuff to fix + +/ + // hs = "link"; + // if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) + // && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + // writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); + // dochead_meta[hm][hs] = + // to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + // } + } + hm = "publisher"; + if (!(header_sdlang.maybe.tags[hm].empty)) { + hs = "name"; + if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) + && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { + writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); + dochead_meta[hm][hs] = + to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); + } + } + } + +/ + auto t = tuple(dochead_make, dochead_meta); + static assert(!isTypeTuple!(t)); + return t; + } + private auto headerSDLangToAA(char[] header_sdlang_src, string[string][string] conf_doc_make_aa) { + auto header_sdlang_tag = headerSDLangGet(header_sdlang_src); // sdlang.ast.Tag + auto header_aa_tuple = headerSDLangToAAmake(header_sdlang_tag, conf_doc_make_aa); + return header_aa_tuple; + } + + } +} diff --git a/src/sdp/ao_header_extract.d b/src/sdp/ao_header_extract.d deleted file mode 100644 index f78d7c4..0000000 --- a/src/sdp/ao_header_extract.d +++ /dev/null @@ -1,25 +0,0 @@ -/+ - extract native/orig header return associative array -+/ -template SiSUheaderExtractHub() { - private import - std.regex; - private import - ao_rgx; - struct HeaderDocMetadataAndMake { - mixin SiSUheaderExtractNative; - mixin SiSUheaderExtractSDLang; - auto rgx = Rgx(); - private auto headerContentAA(char[] header_src, string[string][string] conf_doc_make_aa) { - auto head_native = HeaderDocMetadataAndMakeNativeToAA(); - auto head_sdlang = HeaderExtractSDL(); - writeln(__LINE__); - auto header_make_and_meta_tuple = (match(header_src, rgx.native_header_meta_title)) - ? (head_native.headerNativeToAA(header_src)) - : (head_sdlang.headerSDLangToAA(header_src, conf_doc_make_aa)); - writeln(__LINE__); - static assert(!isTypeTuple!(header_make_and_meta_tuple)); - return header_make_and_meta_tuple; - } - } -} diff --git a/src/sdp/ao_header_extract_native.d b/src/sdp/ao_header_extract_native.d deleted file mode 100644 index 7bcf965..0000000 --- a/src/sdp/ao_header_extract_native.d +++ /dev/null @@ -1,320 +0,0 @@ -/+ - extract native/orig header return associative array -+/ -template SiSUheaderExtractNative() { - private import - std.exception, - std.regex, - std.utf, - std.conv : to; - private import - ao_rgx; - struct HeaderDocMetadataAndMakeNativeToAA { - mixin SiSUregisters; - mixin SiSUrgxInitFlags; - mixin RgxInit; - auto rgx = Rgx(); - enum State { off, on } - string hm, hs; - auto header_metadata_and_make_aa( - string header, - string[string][string] dochead_meta, - string[string][string] dochead_make - ) - in { } - body { - scope(exit) { - destroy(header); - destroy(dochead_meta); - destroy(dochead_make); - } - if (auto t = match(header, rgx.native_header_main)) { - char[][] header_obj_spl = split( - cast(char[]) header, - rgx.line_delimiter_ws_strip - ); - auto hm = to!string(t.captures[1]); - if (match(hm, rgx.main_headers)) { - foreach (line; header_obj_spl) { - if (auto m = match(line, rgx.native_header_main)) { - if (!empty(m.captures[2])) { - if (hm == "creator") { - dochead_meta[hm]["author"] = - to!string(m.captures[2]); - } else if (hm == "title") { - dochead_meta[hm]["main"] = - to!string(m.captures[2]); - } else if (hm == "publisher") { - dochead_meta[hm]["name"] = - to!string(m.captures[2]); - } - } - } else if (auto s = match(line, rgx.native_header_sub)) { - if (!empty(s.captures[2])) { - auto hs = to!string(s.captures[1]); - if ((hm == "make" ) - && (dochead_make[hm])) { - switch (hm) { - case "make": - if (match(hs, rgx.native_subhead_make)) { - if (dochead_make[hm][hs]) { - dochead_make[hm][hs] = to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - default: - break; - } - } else if (dochead_meta[hm]) { - switch (hm) { - case "creator": - if (match(hs, rgx.native_subhead_creator)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "title": - if (match(hs, rgx.native_subhead_title)) { - if ((hs == "subtitle") - && (dochead_meta[hm]["sub"])) { - dochead_meta[hm]["sub"] = - to!string(s.captures[2]); - } else if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "rights": - if (match(hs, rgx.native_subhead_rights)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "date": - if (match(hs, rgx.native_subhead_date)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "original": - if (match(hs, rgx.native_subhead_original)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "classify": - if (match(hs, rgx.native_subhead_classify)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "identifier": - if (match(hs, rgx.native_subhead_identifier)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "notes": - if (match(hs, rgx.native_subhead_notes)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "publisher": - if (match(hs, rgx.native_subhead_publisher)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "links": - destroy(hm); - destroy(hs); - // if (match(hs, rgx.native_subhead_links)) { - // if (dochead_meta[hm][hs]) { - // dochead_meta[hm][hs] = to!string(s.captures[2]); - // } - // } else { - // writeln("not a valid header type:", hm, ":", hs); - // destroy(hm); - // destroy(hs); - // } - break; - default: - break; - } - } - } - } - } - } else { - writeln("not a valid header type:", hm); - } - } - auto t = tuple(dochead_meta, dochead_make); - static assert(!isTypeTuple!(t)); - return t; - } - private auto native_header_extract( - char[] line, - ref int[string] line_occur, - ref string[string] an_object, - ref int[string] type - ) { - if (matchFirst(line, rgx.native_header_make)) { /+ matched header_make +/ - debug(header1) { /+ writeln(line); +/ } - type["header"] = State.on; - type["header_make"] = State.on; - type["header_meta"] = State.off; - ++line_occur["header_make"]; - an_object["obj"] ~= line ~= "\n"; - } else if (matchFirst(line, rgx.native_header)) { /+ matched header_metadata +/ - /+ (generic header match and not previously caught by header_make) +/ - debug(header1) { /+ writeln(line); +/ } - type["header"] = State.on; - type["header_make"] = State.off; - type["header_meta"] = State.on; - ++line_occur["header_meta"]; - an_object["obj"] ~= line ~= "\n"; - } else if (type["header_make"] == State.on - && (line_occur["header_make"] > State.off)) { /+ header_make flag set +/ - if (matchFirst(line, rgx.native_header_sub)) { /+ sub-header +/ - debug(header1) { /+ writeln(line); +/ } - ++line_occur["header_make"]; - an_object["obj"] ~= line ~= "\n"; - } - } else if (type["header_meta"] == State.on - && (line_occur["header_meta"] > State.off)) { /+ header_metadata flag set +/ - if (matchFirst(line, rgx.native_header_sub)) { /+ sub-header +/ - debug(header1) { /+ writeln(line); +/ } - ++line_occur["header_meta"]; - an_object["obj"] ~= line ~= "\n"; - } - } - return an_object; - } - auto header_reset_states_common( - ref int[string] line_occur, - ref string[string] an_object, - ref int[string] type - ) { - // line_occur["header"] = State.off; - line_occur["header_make"] = State.off; - line_occur["header_meta"] = State.off; - type["header"] = State.off; - // type["header_make"] = State.off; - // type["header_meta"] = State.off; - an_object.remove("obj"); - an_object.remove("is"); - an_object.remove("attrib"); - } - private auto headerNativeToAA(in char[] src_header) { - auto type = flags_type_init; - type = [ - "header" : State.off, - "header_make" : State.off, - "header_meta" : State.off, - ]; - string[string] an_object; - int[string] line_occur; - auto dochead_make = make_aa; - auto dochead_meta = meta_aa; - auto set_header = HeaderDocMetadataAndMakeNativeToAA(); - char[][] source_header_arr = - split(cast(char[]) src_header, rgx.line_delimiter); - foreach(header_line; source_header_arr) { - if (auto m = matchFirst(header_line, rgx.comment)) { - /+ matched comment +/ - debug(comment) { - // tell_l("blue", header_line); - } - header_reset_states_common(line_occur, an_object, type); - // type["header_make"] = State.off; - // type["header_meta"] = State.off; - } else if ((matchFirst(header_line, rgx.native_header)) - || (type["header_make"] == State.on - && (line_occur["header_make"] > State.off)) - || (type["header_meta"] == State.on - && (line_occur["header_meta"] > State.off))) { - if (header_line.length == 0) { - /+ header_make instructions (current line empty) +/ - auto dochead_metadata_and_make = - set_header.header_metadata_and_make_aa(strip(an_object["obj"]), dochead_meta, dochead_make); - static assert(!isTypeTuple!(dochead_metadata_and_make)); - dochead_meta = dochead_metadata_and_make[0]; - dochead_make = dochead_metadata_and_make[1]; - header_reset_states_common(line_occur, an_object, type); - type["header_make"] = State.off; - type["header_meta"] = State.off; - writeln(dochead_metadata_and_make); - } else { - an_object = native_header_extract(header_line, line_occur, an_object, type); - } - } else { - // writeln(__LINE__); - } - } - auto t = tuple( - dochead_make, - dochead_meta, - ); - return t; - } - } -} diff --git a/src/sdp/ao_header_extract_sdlang.d b/src/sdp/ao_header_extract_sdlang.d deleted file mode 100644 index 16a36e9..0000000 --- a/src/sdp/ao_header_extract_sdlang.d +++ /dev/null @@ -1,209 +0,0 @@ -/+ - extract sdl header return sdl -+/ -template SiSUheaderExtractSDLang() { - private import - std.regex; - private import - ao_rgx; - struct HeaderExtractSDL { - mixin SiSUregisters; - mixin RgxInit; - auto rgx = Rgx(); - private auto sdlangToAAmake(string[string][string] conf, Tag conf_sdlang) { - foreach (maintag, subtags; conf) { - foreach (subtag, content; subtags) { - if (!(conf_sdlang.maybe.tags[maintag].empty)) { - if (!(conf_sdlang.tags[maintag][0].maybe.attributes[subtag].empty) - && (conf_sdlang.tags[maintag][0].attributes[subtag][0].value.length > 1)) { - writeln(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); - conf[maintag][subtag] = - to!string(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); - } - } - } - } - return conf; - } - private auto configSettingsSDLangToAAmake(Tag conf_sdlang) { - auto conf = sdlangToAAmake(conf_aa, conf_sdlang); - return conf; - } - private auto documentMakeSDLangToAAmake(Tag document_make_sdlang) { - auto dochead_make = sdlangToAAmake(make_aa, document_make_sdlang); - /+ - hm = "links"; - if (!(document_make_sdlang.maybe.tags[hm].empty)) { - /+ TODO - stuff to fix - +/ - // hs = "link"; - // if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty) - // && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - // writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value); - // dochead_meta[hm][hs] = - // to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value); - // } - } - +/ - // writeln(dochead_make); - return dochead_make; - } - final private auto headerMakeSDLang(in string src_header) { - scope(failure) { - stderr.writefln( - "%s\n%s\n%s:%s failed here:\n src_header: %s", - __MODULE__, __FUNCTION__, - __FILE__, __LINE__, - src_header, - ); - } - Tag sdl_root_header; - try { - sdl_root_header = parseSource(src_header); - } - catch(SDLangParseException e) { - stderr.writeln("SDLang problem with this document header:"); - stderr.writeln(src_header); - // Error messages of the form: - // myFile.sdl(5:28): Error: Invalid integer suffix. - stderr.writeln(e.msg); - } - debug(sdlang) { - writeln("header SDL:"); - writeln(sdl_root_header.toSDLDocument()); - } - return sdl_root_header; - } - private auto headerSDLangGet(in char[] src_header) { - char[][] source_header_arr = - split(cast(char[]) src_header, rgx.line_delimiter); - char[] header_clean; - // TODO - foreach(header_line; source_header_arr) { - if (!match(header_line, rgx.comments)) { - header_clean ~= header_line ~ "\n"; - // writeln(header_line); - } - } - /+ get sdlang tags +/ - auto header_sdlang=headerMakeSDLang(to!string(header_clean)); - debug(sdlang) { - writeln("--------------"); - stdout.rawWrite( header_sdlang.toSDLDocument() ); - writeln("--------------"); - Value test = header_sdlang.tags["title"][0].values[0]; - assert(test == typeid(string)); - writeln(header_sdlang.maybe.tags["title"]); - writeln(header_sdlang.maybe.tags["title"][0].maybe.attributes["subtitle"]); - } - return header_sdlang; // sdlang.ast.Tag - } - private auto headerSDLangToAAmake(Tag header_sdlang, string[string][string] dochead_make) { - dochead_make = sdlangToAAmake(dochead_make, header_sdlang); - auto dochead_meta = sdlangToAAmake(meta_aa, header_sdlang); - /+ - /+ dochead +/ - string hm; - string hs; - /+ meta +/ - auto dochead_meta = meta_aa; - hm = "title"; - if (!(header_sdlang.maybe.tags[hm].empty)) { - /+ TODO Title REQUIRED +/ - hs = "main"; - if (!(header_sdlang.tags[hm].empty) - && (header_sdlang.tags[hm][0].values[0].length > 1)) { - writeln(header_sdlang.tags[hm][0].values[0]); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].values[0]); - // to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - } else if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) - && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - } else { - writeln("Required header metadata Title, missing"); - } - hs = "sub"; - if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) - && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - } else if (!(header_sdlang.tags[hm][0].maybe.attributes["subtitle"].empty) - && (header_sdlang.tags[hm][0].attributes["subtitle"][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes["subtitle"][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes["subtitle"][0].value); - } - // full title composite (main + sub) - // hs = "full"; - // dochead_meta[hm][hs] = dochead_meta[hm]["main"] ~ dochead_meta[hm]["sub"]; - hs = "language"; - if (!(header_sdlang.tags[hm][0].maybe.attributes["lang"].empty) - && (header_sdlang.tags[hm][0].attributes["lang"][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes["lang"][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes["lang"][0].value); - } else if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) - && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - } - } - hm = "creator"; - if (!(header_sdlang.maybe.tags[hm].empty)) { - /+ Creator / Author REQUIRED +/ - /+ TODO - - decide on representation for & deal with multiple authors; - - author(s) full name; - - author(s) surname & other parts - +/ - hs = "author"; - if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) - && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - } - } - hm = "links"; - if (!(header_sdlang.maybe.tags[hm].empty)) { - /+ TODO - stuff to fix - +/ - // hs = "link"; - // if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) - // && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - // writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); - // dochead_meta[hm][hs] = - // to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - // } - } - hm = "publisher"; - if (!(header_sdlang.maybe.tags[hm].empty)) { - hs = "name"; - if (!(header_sdlang.tags[hm][0].maybe.attributes[hs].empty) - && (header_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) { - writeln(header_sdlang.tags[hm][0].attributes[hs][0].value); - dochead_meta[hm][hs] = - to!string(header_sdlang.tags[hm][0].attributes[hs][0].value); - } - } - } - +/ - auto t = tuple(dochead_make, dochead_meta); - static assert(!isTypeTuple!(t)); - return t; - } - private auto headerSDLangToAA(char[] header_sdlang_src, string[string][string] conf_doc_make_aa) { - auto header_sdlang_tag = headerSDLangGet(header_sdlang_src); // sdlang.ast.Tag - auto header_aa_tuple = headerSDLangToAAmake(header_sdlang_tag, conf_doc_make_aa); - return header_aa_tuple; - } - - } -} diff --git a/src/sdp/ao_object_setter.d b/src/sdp/ao_object_setter.d index 4492e8a..96932eb 100644 --- a/src/sdp/ao_object_setter.d +++ b/src/sdp/ao_object_setter.d @@ -40,7 +40,6 @@ template ObjectSetter() { struct ObjCompositeArr { ObjComposite[] oca; } - /+ structs setter +/ struct ObjectAbstractSet { import std.conv : to; diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index 4e282ee..bb032ea 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -125,10 +125,8 @@ template RgxInit() { static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "m"); static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "m"); - static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); - static inline_curly_delimiter_open_regular = ctRegex!(`~\{\s*`, "m"); static inline_curly_delimiter_close_regular = ctRegex!(`\s*\}~`, "m"); static inline_curly_delimiter_open_and_close_regular = ctRegex!(`~\{\s*|\s*\}~`, "m"); -- cgit v1.2.3