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 --- org/ao_abstract_doc_source.org | 40 +-- org/ao_conf_make_meta.org | 665 +++++++++++++++++++++++++++++++++++++ org/ao_defaults.org | 48 ++- org/ao_header_extract.org | 665 ------------------------------------- org/ao_output_debugs.org | 20 ++ org/ao_read_source_files.org | 12 + org/compile_time_info.org | 4 + org/output.org | 10 +- org/sdp.org | 8 +- src/sdp.d | 15 +- 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 - 19 files changed, 1337 insertions(+), 1284 deletions(-) create mode 100644 org/ao_conf_make_meta.org delete mode 100644 org/ao_header_extract.org 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 diff --git a/org/ao_abstract_doc_source.org b/org/ao_abstract_doc_source.org index 1942b5e..75c581d 100644 --- a/org/ao_abstract_doc_source.org +++ b/org/ao_abstract_doc_source.org @@ -47,14 +47,11 @@ mixin InternalMarkup; #+name: abs_init_struct #+BEGIN_SRC d /+ 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 @@ -71,33 +68,27 @@ enum DocStructMarkupHeading { 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; @@ -105,7 +96,6 @@ auto bookindex_extract_hash = BookIndexNuggetHash(); 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(); @@ -400,6 +390,7 @@ if (matchFirst(line, rgx.block_open)) { #+END_SRC ******* asserts :assert: + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d assert( @@ -424,7 +415,9 @@ if (matchFirst(line, rgx.block_open)) { ); } #+END_SRC + ******* book index :bookindex: + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d if ((matchFirst(line, rgx.book_index)) @@ -435,12 +428,15 @@ if (matchFirst(line, rgx.block_open)) { #+END_SRC ******* not book index [+1] + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d } else { /+ not book_index +/ #+END_SRC + ******** matched: comment :comment:match: + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d if (auto m = matchFirst(line, rgx.comment)) { @@ -455,7 +451,9 @@ if (matchFirst(line, rgx.block_open)) { processing.remove("verse"); ++counter; #+END_SRC + ******** flag not set & line not exist: heading or para :heading:paragraph: + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d } else if (((line_occur["para"] == State.off) @@ -488,6 +486,7 @@ if (matchFirst(line, rgx.block_open)) { #+END_SRC ******** line exist: heading :heading: + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["heading"] > State.off) { @@ -498,7 +497,9 @@ if (matchFirst(line, rgx.block_open)) { an_object["obj"] ~= line ~= "\n"; ++line_occur["heading"]; #+END_SRC + ******** line exist: para :para: + #+name: abs_in_loop_body_not_block_obj #+BEGIN_SRC d } else if (line_occur["para"] > State.off) { @@ -511,6 +512,7 @@ if (matchFirst(line, rgx.block_open)) { } } #+END_SRC + ****** line empty, with block flag #+name: abs_in_loop_body_not_block_obj @@ -1996,7 +1998,6 @@ auto book_index( } #+END_SRC - ** heading or paragraph :heading:paragraph: *** heading found :heading: @@ -3467,6 +3468,7 @@ struct NodeStructureMetadata { #+END_SRC **** metadata (check) + #+name: ao_emitters #+BEGIN_SRC d string node_emitter_heading( @@ -3867,6 +3869,7 @@ auto assertions_flag_types_block_status_none_or_closed(int[string] type) { set abstracted objects for downstream processing ** structs :struct: + #+name: ao_structs #+BEGIN_SRC d struct HeadingAttrib { @@ -4026,16 +4029,12 @@ auto contents_block_obj_cite_number_string( template SiSUdocAbstraction() { private: struct Abstraction { - /+ ↓ abstraction imports +/ <> - /+ ↓ abstraction mixins +/ <> - /+ ↓ abstraction struct init +/ <> - /+ ↓ abstract marked up document +/ auto abstract_doc_source( char[][] markup_sourcefile_content, @@ -4045,11 +4044,9 @@ template SiSUdocAbstraction() { /+ ↓ abstraction init +/ <> /+ abstraction init ↑ +/ - /+ ↓ loop markup document/text line by line +/ srcDocLoop: foreach (line; markup_sourcefile_content) { - /+ ↓ markup document/text line by line +/ <> <> @@ -4059,29 +4056,23 @@ template SiSUdocAbstraction() { <> <> } /+ ← closed: loop markup document/text line by line +/ - /+ ↓ post loop markup document/text +/ <> /+ post loop markup document/text ↑ +/ - } /+ ← closed: abstract doc source +/ - /+ ↓ abstraction functions +/ <> /+ abstraction functions ↑ +/ - /+ ↓ abstraction function emitters +/ <> /+ abstraction functions emitters ↑ +/ - /+ ↓ abstraction functions assertions +/ <> /+ abstraction functions assertions ↑ +/ - } /+ ← closed: struct Abstraction +/ - } /+ ← closed: template SiSUdocAbstraction +/ #+END_SRC + ** ao_object_setter: :ao_object_setter.d: #+BEGIN_SRC d :tangle ../src/sdp/ao_object_setter.d @@ -4092,7 +4083,6 @@ template SiSUdocAbstraction() { template ObjectSetter() { /+ structs +/ <> - /+ structs setter +/ struct ObjectAbstractSet { import std.conv : to; diff --git a/org/ao_conf_make_meta.org b/org/ao_conf_make_meta.org new file mode 100644 index 0000000..f660147 --- /dev/null +++ b/org/ao_conf_make_meta.org @@ -0,0 +1,665 @@ +#+TITLE: sdp header extract +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:ao: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +* 0. sdlang to AA + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +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; +} +#+END_SRC + +* A. conf settings sdlang + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +private auto configSettingsSDLangToAAmake(Tag conf_sdlang) { + auto conf = sdlangToAAmake(conf_aa, conf_sdlang); + return conf; +} +#+END_SRC + +* B. conf make sdlang + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +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; +} +#+END_SRC + +* C.a. header native :header:native: + +// mixin SiSUheader; +// auto set_header = HeaderDocMetadataAndMakeNativeToAA(); // reintroduce + +** native header document metadata in associative array :aa: + +#+name: ao_markup_header_extract_native +#+BEGIN_SRC d +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; +} +#+END_SRC + +** native header extract to string object :string: + +#+name: ao_markup_header_extract_native +#+BEGIN_SRC d +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; +} +#+END_SRC + +** native header reset states :reset: + +#+name: ao_markup_header_extract_native +#+BEGIN_SRC d +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"); +} +#+END_SRC + +** hub: native header start :hub: + +#+name: ao_markup_header_extract_native +#+BEGIN_SRC d +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; +} +#+END_SRC + +* C.b. header sdlang :header:sdl: +** sdlang header parse and extract root Tag :sdlang:root:tag: + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +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; +} +#+END_SRC + +** sdlang header get :sdlang:get:src: + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +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 +} +#+END_SRC + +** sdlang header to associative array make sdlTag in :sdlang:aa: + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +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; +} +#+END_SRC + +** hub: get sdlang header and convert to associative array :hub:sdlang:aa: + +#+name: ao_conf_make_meta_sdl +#+BEGIN_SRC d +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; +} +#+END_SRC + +* tangles (code structure) :tangle: +** 1. Header Hub :ao_markup_header_extract: + +the header is passed as text (lopped off top of a sisu markup file until the +required first heading ^A~), determine whether is a native header or sdlang one +with a regex check if whether it contains the "native header" required tag/field +@title: then process accordingly as a "native header" or "sdlang header" +converting the metadata and make instructions to a common json format used by +program internally. Moved to associative array. + +#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta.d +/+ + 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; + } + } +} +#+END_SRC + +** 2a. Header Native :ao_markup_header_extract_native: + +#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_native.d +/+ + 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; + <> + } +} +#+END_SRC + +** 2b. Header SDLang :ao_markup_header_extract_sdlang: + +#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_sdlang.d +/+ + extract sdl header return sdl ++/ +template SiSUheaderExtractSDLang() { + private import + std.regex; + private import + ao_rgx; + struct HeaderExtractSDL { + mixin SiSUregisters; + mixin RgxInit; + auto rgx = Rgx(); + <> + <> + } +} +#+END_SRC diff --git a/org/ao_defaults.org b/org/ao_defaults.org index 3412ae8..a6baeb4 100644 --- a/org/ao_defaults.org +++ b/org/ao_defaults.org @@ -343,6 +343,7 @@ header. #+END_SRC ** template: flags regex initialize :regex_flags: + #+name: ao_defaults_templates #+BEGIN_SRC d /+ regex flags +/ @@ -383,7 +384,9 @@ template SiSUrgxInitFlags() { } } #+END_SRC + ** template: bibliography :biblio: + #+name: ao_defaults_templates #+BEGIN_SRC d template SiSUbiblio() { @@ -419,7 +422,9 @@ template SiSUbiblio() { }`; // is: book, article, magazine, newspaper, blog, other } #+END_SRC + ** template: internal markup :markup: + #+name: ao_defaults_templates #+BEGIN_SRC d template InternalMarkup() { @@ -502,7 +507,9 @@ template InternalMarkup() { * regex ctRegex :regex: [[./sdp.org][sdp]] [[./][org/]] + ** misc :misc: + #+name: ao_rgx #+BEGIN_SRC d /+ misc +/ @@ -525,7 +532,9 @@ static levels_markup = ctRegex!(`^[A-D1-4]$`); static levels_numbered = ctRegex!(`^[0-9]$`); static levels_numbered_headings = ctRegex!(`^[0-7]$`); #+END_SRC + ** filename (and path) matching (including markup insert file) :insert:file:path:filename: + #+name: ao_rgx #+BEGIN_SRC d static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); @@ -541,14 +550,18 @@ static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(? /+ insert markup file +/ // static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*([a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); #+END_SRC + ** comments :comment: + #+name: ao_rgx #+BEGIN_SRC d /+ comments +/ static comment = ctRegex!(`^%+ `); static comments = ctRegex!(`^%+ |^%+$`); #+END_SRC + ** native header :native:header: + #+name: ao_rgx #+BEGIN_SRC d /+ header +/ @@ -565,7 +578,9 @@ static native_header_meta_title = ctRegex!(`^@title:\s`, "m"); static variable_doc_title = ctRegex!(`@title`); static variable_doc_author = ctRegex!(`@author`); #+END_SRC + ** subheader :native:subheader: + #+name: ao_rgx #+BEGIN_SRC d /+ head +/ @@ -580,7 +595,9 @@ static native_subhead_notes = ctRegex!(`^(?:abstract|description)$`, static native_subhead_publisher = ctRegex!(`^(?:name)$`, "m"); static native_subhead_make = ctRegex!(`^(?:cover_image|home_button_image|home_button_text|footer|headings|num_top|breaks|substitute|bold|italics|emphasis|texpdf_font|css)$`, "m"); #+END_SRC + ** heading & paragraph operators :paragraph:operator: + #+name: ao_rgx #+BEGIN_SRC d /+ heading & paragraph operators +/ @@ -599,6 +616,7 @@ static para_attribs = ctRegex!(`^_(([0-9])(_([0-9]))?|_([1-9])?[*]) `); #+END_SRC ** blocked markup :block:tic: + #+name: ao_rgx #+BEGIN_SRC d /+ blocked markup +/ @@ -606,7 +624,9 @@ static block_open = ctRegex!("^((code|poem|group|block|quote|tabl // static block_open_less_code = ctRegex!("^(((poem|group|block|quote|table)[{].*?$)|`{3} (poem|group|block|quote|table))"); static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); #+END_SRC + ** blocked markup tics :block:tic: + #+name: ao_rgx #+BEGIN_SRC d /+ blocked markup tics +/ @@ -620,7 +640,9 @@ static block_tic_quote_open = ctRegex!("^`{3} (quote)"); static block_tic_table_open = ctRegex!("^`{3} (table)"); static block_tic_close = ctRegex!("^(`{3})$","m"); #+END_SRC + ** blocked markup curly :block:curly: + #+name: ao_rgx #+BEGIN_SRC d /+ blocked markup curly +/ @@ -639,7 +661,9 @@ static block_curly_quote_close = ctRegex!(`^([}]quote)`); static block_curly_table_open = ctRegex!(`^(table[{].*?$)`); static block_curly_table_close = ctRegex!(`^([}]table)`); #+END_SRC + ** inline markup font face mod :inline:font:face: + #+name: ao_rgx #+BEGIN_SRC d /+ inline markup font face mod +/ @@ -652,7 +676,9 @@ static inline_strike = ctRegex!(`-\{(?P.+?)\}-`); static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`); static inline_mono = ctRegex!(`#\{(?P.+?)\}#`); #+END_SRC + ** inline markup footnotes :inline:footnote: + #+name: ao_rgx #+BEGIN_SRC d /+ inline markup footnotes +/ @@ -667,10 +693,8 @@ static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); 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"); @@ -694,7 +718,9 @@ static inline_text_and_note_square_sp = ctRegex!(`(.+?)~\[[*+]+\s+(.+?)\] static inline_text_and_note_square = ctRegex!(`(.+?)~\[\s*(.+?)\]~`, "mg"); static inline_note_square_delimiters = ctRegex!(`(~\[\s*)(.+?)(\]~)`, "mg"); #+END_SRC + ** inline markup book index :inline:bookindex: + #+name: ao_rgx #+BEGIN_SRC d /+ inline markup book index +/ @@ -702,7 +728,9 @@ static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); // strip #+END_SRC + ** no obj_cite_number object :ocn:off:object: + #+name: ao_rgx #+BEGIN_SRC d /+ no obj_cite_number object +/ @@ -710,7 +738,9 @@ static obj_cite_number_off = ctRegex!(`~#$`, "m"); static obj_cite_number_off_dh = ctRegex!(`-#$`, "m"); static obj_cite_number_off_all = ctRegex!(`[~-]#$`, "m"); #+END_SRC + ** no obj_cite_number block :ocn:off:block: + #+name: ao_rgx #+BEGIN_SRC d /+ no obj_cite_number block +/ @@ -720,13 +750,17 @@ static obj_cite_number_off_block_close = ctRegex!(`^--\+#$`); // static auto_obj_cite_number_ignore = ctRegex!(`^[+~*$-]{3,}$`); // reminder static obj_cite_number_block_marks = ctRegex!(`^--[+~-]#$`); #+END_SRC + ** ignore outside code blocks :block:code: + #+name: ao_rgx #+BEGIN_SRC d /+ ignore outside code blocks +/ static skip_code_block_from_regular_parse = ctRegex!(`^(--[+~-]#|-[\\]{2}-|=[.\\]{2}=)$`); // not structural info #+END_SRC + ** line & page breaks :break: + #+name: ao_rgx #+BEGIN_SRC d /+ line & page breaks +/ @@ -739,13 +773,17 @@ static break_string = ctRegex!(`』`); // ancestry, parent static parent = ctRegex!(`([0-7]):([0-9]+)`); #+END_SRC + ** json :json: + #+name: ao_rgx #+BEGIN_SRC d /+ json +/ static tailing_comma = ctRegex!(`,$`, "m"); #+END_SRC + ** biblio tags :biblio:tags: + #+name: ao_rgx #+BEGIN_SRC d /+ biblio tags +/ @@ -753,7 +791,9 @@ static biblio_tags = ctRegex!(`^(is|au|author_raw|author|author_ar static biblio_abbreviations = ctRegex!(`^(au|ed|ti|lng|jo|vol|edn|yr|pl|pb|pub|pg|pgs|sn)$`); // static biblio_tags = ctRegex!(`^(is|author_raw|author|author_arr|editor_raw|editor_arr|title|subtitle|fulltitle|language|trans|src|journal|in|volume|edition|year|place|publisher|url|pages|note|short_name|id):\s+(.+)`); #+END_SRC + ** bookindex split :bookindex:split: + #+name: ao_rgx #+BEGIN_SRC d /+ bookindex split +/ @@ -764,6 +804,7 @@ static bi_term_and_obj_cite_numbers_match = ctRegex!(`^(.+?)\+(\d+)`); #+END_SRC * set colors for terminal :colors:terminal: + #+name: ao_ansi_colors #+BEGIN_SRC d string[string] scr_txt_color = [ @@ -838,6 +879,7 @@ string[string] scr_txt_marker = [ * tangles (code structure) :tangle: ** defaults: :ao_defaults.d: + #+name: tangle_ao_defaults #+BEGIN_SRC d :tangle ../src/sdp/ao_defaults.d /+ @@ -848,6 +890,7 @@ string[string] scr_txt_marker = [ #+END_SRC ** rgx: :ao_rgx.d: + #+name: tangle_ao_rgx #+BEGIN_SRC d :tangle ../src/sdp/ao_rgx.d /+ @@ -860,6 +903,7 @@ template RgxInit() { } } #+END_SRC + ** ansi_colors: :ao_ansi_colors.d: #+BEGIN_SRC d :tangle ../src/sdp/ao_ansi_colors.d diff --git a/org/ao_header_extract.org b/org/ao_header_extract.org deleted file mode 100644 index f660147..0000000 --- a/org/ao_header_extract.org +++ /dev/null @@ -1,665 +0,0 @@ -#+TITLE: sdp header extract -#+AUTHOR: Ralph Amissah -#+EMAIL: ralph.amissah@gmail.com -#+STARTUP: indent -#+LANGUAGE: en -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+FILETAGS: :sdp:rel:ao: -#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) - -[[./sdp.org][sdp]] [[./][org/]] -* 0. sdlang to AA - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -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; -} -#+END_SRC - -* A. conf settings sdlang - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -private auto configSettingsSDLangToAAmake(Tag conf_sdlang) { - auto conf = sdlangToAAmake(conf_aa, conf_sdlang); - return conf; -} -#+END_SRC - -* B. conf make sdlang - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -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; -} -#+END_SRC - -* C.a. header native :header:native: - -// mixin SiSUheader; -// auto set_header = HeaderDocMetadataAndMakeNativeToAA(); // reintroduce - -** native header document metadata in associative array :aa: - -#+name: ao_markup_header_extract_native -#+BEGIN_SRC d -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; -} -#+END_SRC - -** native header extract to string object :string: - -#+name: ao_markup_header_extract_native -#+BEGIN_SRC d -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; -} -#+END_SRC - -** native header reset states :reset: - -#+name: ao_markup_header_extract_native -#+BEGIN_SRC d -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"); -} -#+END_SRC - -** hub: native header start :hub: - -#+name: ao_markup_header_extract_native -#+BEGIN_SRC d -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; -} -#+END_SRC - -* C.b. header sdlang :header:sdl: -** sdlang header parse and extract root Tag :sdlang:root:tag: - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -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; -} -#+END_SRC - -** sdlang header get :sdlang:get:src: - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -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 -} -#+END_SRC - -** sdlang header to associative array make sdlTag in :sdlang:aa: - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -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; -} -#+END_SRC - -** hub: get sdlang header and convert to associative array :hub:sdlang:aa: - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -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; -} -#+END_SRC - -* tangles (code structure) :tangle: -** 1. Header Hub :ao_markup_header_extract: - -the header is passed as text (lopped off top of a sisu markup file until the -required first heading ^A~), determine whether is a native header or sdlang one -with a regex check if whether it contains the "native header" required tag/field -@title: then process accordingly as a "native header" or "sdlang header" -converting the metadata and make instructions to a common json format used by -program internally. Moved to associative array. - -#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta.d -/+ - 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; - } - } -} -#+END_SRC - -** 2a. Header Native :ao_markup_header_extract_native: - -#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_native.d -/+ - 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; - <> - } -} -#+END_SRC - -** 2b. Header SDLang :ao_markup_header_extract_sdlang: - -#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_sdlang.d -/+ - extract sdl header return sdl -+/ -template SiSUheaderExtractSDLang() { - private import - std.regex; - private import - ao_rgx; - struct HeaderExtractSDL { - mixin SiSUregisters; - mixin RgxInit; - auto rgx = Rgx(); - <> - <> - } -} -#+END_SRC diff --git a/org/ao_output_debugs.org b/org/ao_output_debugs.org index 7b84fdd..0f001e1 100644 --- a/org/ao_output_debugs.org +++ b/org/ao_output_debugs.org @@ -15,6 +15,7 @@ * output debugs :debug:output: [[./sdp.org][sdp]] [[./][org/]] ** (parent) :parent: + #+name: ao_output_debugs #+BEGIN_SRC d debug(parent) { @@ -40,7 +41,9 @@ debug(parent) { } } #+END_SRC + ** (dumpdoc) :objects: + #+name: ao_output_debugs #+BEGIN_SRC d debug(dumpdoc) { @@ -62,7 +65,9 @@ debug(dumpdoc) { } } #+END_SRC + ** (objects) :objects: + #+name: ao_output_debugs #+BEGIN_SRC d debug(objects) { @@ -86,7 +91,9 @@ debug(objects) { } } #+END_SRC + ** (headermakejson) :json:header: + #+name: ao_output_debugs #+BEGIN_SRC d debug(headermakejson) { @@ -116,7 +123,9 @@ debug(headermakejson) { } } #+END_SRC + ** (headermetadatajson) :json:header: + #+name: ao_output_debugs #+BEGIN_SRC d debug(headermetadatajson) { @@ -242,7 +251,9 @@ debug(headermetadatajson) { } } #+END_SRC + ** (bookindex) :bookindex: + #+name: ao_output_debugs #+BEGIN_SRC d debug(bookindex) { @@ -256,7 +267,9 @@ debug(bookindex) { bookindex.bookindex_report_sorted(bookindex_unordered_hashes); } #+END_SRC + ** (summary) [+1] :summary: + #+name: ao_output_debugs #+BEGIN_SRC d debug(summary) { @@ -264,7 +277,9 @@ debug(summary) { "last_obj_cite_number" : "NA [debug \"checkdoc\" not run]", ]; #+END_SRC + *** (checkdoc) :checkdoc: + #+name: ao_output_debugs_summary #+BEGIN_SRC d debug(checkdoc) { @@ -277,7 +292,9 @@ debug(checkdoc) { } } #+END_SRC + *** (headings) :headings: + #+name: ao_output_debugs_summary #+BEGIN_SRC d debug(headings) { @@ -316,7 +333,9 @@ writefln( __LINE__, ); #+END_SRC + *** compare number of obj_cite_number for known sisu markup output (checkdoc) + #+name: ao_output_debugs_summary #+BEGIN_SRC d debug(checkdoc) { @@ -450,6 +469,7 @@ debug(checkdoc) { * tangles :tangle: ** code structure: :ao_output_debugs.d: + #+name: tangle_ao_output_debugs #+BEGIN_SRC d :tangle ../src/sdp/ao_output_debugs.d /+ diff --git a/org/ao_read_source_files.org b/org/ao_read_source_files.org index c3c68ad..d61b677 100644 --- a/org/ao_read_source_files.org +++ b/org/ao_read_source_files.org @@ -17,6 +17,7 @@ ** [#A] read config file, source string :string: *** config file (conf.sdl & sisu_document_make) :file:config: + #+name: ao_config_file_in #+BEGIN_SRC d final private string readInConfigFile(string conf_sdl) { @@ -104,6 +105,7 @@ private auto configSDLangRootTag(string configuration, string conf_sdl_filename) #+END_SRC *** config file (conf.sdl & sisu_document_make) :file:config:hub: + #+name: ao_config_file_sdlang_hub #+BEGIN_SRC d final private auto configSDLang(string conf_sdl) { @@ -118,6 +120,7 @@ final private auto configSDLang(string conf_sdl) { * get markup source, read file :source:markup: ** [#A] read file, source string :string: + #+name: ao_markup_source_raw #+BEGIN_SRC d final private string readInMarkupSource(in string fn_src) { @@ -182,6 +185,7 @@ catch (ErrnoException ex) { } ** array[0..1]: split header content :array: + #+name: ao_markup_source_raw #+BEGIN_SRC d final private char[][] header0Content1(in string src_text) { @@ -193,6 +197,7 @@ final private char[][] header0Content1(in string src_text) { #+END_SRC ** source line array :array: + #+name: ao_markup_source_raw #+BEGIN_SRC d final private char[][] markupSourceLineArray(in char[] src_text) { @@ -242,6 +247,7 @@ final char[][] markupSourceContentRawLineArray(in string fn_src, Regex!(char) rg ** scan inserts (sub-document) source :scan_insert_src: *** scan subdoc source + #+name: ao_inserts_scan #+BEGIN_SRC d char[][] contents_insert; @@ -251,6 +257,7 @@ auto markup_src_file_path = fn_pth_full.captures[1]; #+END_SRC *** loop insert (sub-document) + #+name: ao_inserts_scan_loop #+BEGIN_SRC d if (type1["curly_code"] == 1) { @@ -328,6 +335,7 @@ if (type1["curly_code"] == 1) { #+END_SRC *** post loop + #+name: ao_inserts_scan_post #+BEGIN_SRC d return contents_insert; @@ -335,6 +343,7 @@ return contents_insert; ** scan document source :scan_src: *** scan doc source + #+name: ao_master_doc_scan_for_insert_filenames #+BEGIN_SRC d char[][] contents; @@ -342,7 +351,9 @@ auto type = flags_type_init; auto fn_pth_full = match(fn_src, rgx.src_pth); auto markup_src_file_path = fn_pth_full.captures[1]; #+END_SRC + *** loop master scan for inserts (insert documents) + #+name: ao_master_doc_scan_for_insert_filenames_loop #+BEGIN_SRC d if (type["curly_code"] == 1) { @@ -405,6 +416,7 @@ if (type["curly_code"] == 1) { #+END_SRC *** post loop + #+name: ao_master_doc_scan_for_insert_filenames_post #+BEGIN_SRC d debug(insert) { // insert file diff --git a/org/compile_time_info.org b/org/compile_time_info.org index 1c3ab0d..9fb5830 100644 --- a/org/compile_time_info.org +++ b/org/compile_time_info.org @@ -23,6 +23,7 @@ version(Windows) {} else { ... } OS type shows during compilation **** set os flags + #+name: sdp_compile_time_info #+BEGIN_SRC d version(Windows) { @@ -58,6 +59,7 @@ version(Windows) { OS type compiled in and shows during program run **** report os flag (set) (not used here) + #+BEGIN_SRC d static if(sysWindows) { writeln("Windows"); @@ -79,6 +81,7 @@ static if(sysWindows) { #+END_SRC *** 64 bit compilation? + #+name: sdp_compile_time_info #+BEGIN_SRC d version(D_LP64) { @@ -90,6 +93,7 @@ version(D_LP64) { * tangles :tangle: ** compile_time_info: :compile_time_info.d: + #+begin_src d :tangle ../src/sdp/compile_time_info.d /+ compile_time_info diff --git a/org/output.org b/org/output.org index e8187d6..69779f2 100644 --- a/org/output.org +++ b/org/output.org @@ -23,6 +23,7 @@ struct SDPoutputHTML { #+END_SRC *** css + #+name: output_html #+BEGIN_SRC d auto html_css() { @@ -1333,6 +1334,7 @@ struct SDPoutputHTML { *** html **** html functions + #+name: output_html #+BEGIN_SRC d auto html_toc(O)( @@ -1392,6 +1394,7 @@ struct SDPoutputHTML { #+END_SRC **** html scroll head & tail + #+name: output_html #+BEGIN_SRC d auto scroll_head() { @@ -1441,6 +1444,7 @@ struct SDPoutputHTML { #+END_SRC **** html scroll + #+name: output_html #+BEGIN_SRC d auto scroll(C)( @@ -1527,6 +1531,7 @@ struct SDPoutputHTML { ** pgsql :pgsql: * tangles :tangle: ** code structure: :output.d: + #+BEGIN_SRC d :tangle ../src/sdp/output_hub.d /+ output hub @@ -1537,7 +1542,8 @@ template SiSUoutputHub() { } #+END_SRC -** head +** example head + @@ -1568,8 +1574,6 @@ template SiSUoutputHub() { - - diff --git a/org/sdp.org b/org/sdp.org index 613e374..599d1c0 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -85,6 +85,7 @@ import [[./output_hub.org][output hub]] **** sdlang :import:sdlang: + #+NAME: imports_sdlang #+BEGIN_SRC d /+ sdlang http://sdlang.org +/ @@ -97,6 +98,7 @@ sdlang.exceptions; // std.conv; **** std :import:std: + #+NAME: imports_std #+BEGIN_SRC d /+ std +/ @@ -263,7 +265,6 @@ look into using getopt #+NAME: sdp_args #+BEGIN_SRC d - bool[string] opt_action_bool = [ "assertions" : false, "concordance" : false, @@ -341,6 +342,7 @@ auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); ** each file (loop) [+2] :loop:files: *** filename provided [+1] :file:process: **** loop scope :scope: + #+NAME: sdp_each_file_do #+BEGIN_SRC d scope(success) { @@ -384,6 +386,7 @@ debug(header_and_content) { #+END_SRC **** [#A] read doc header: metadata & make :doc:header:metadata:make: + #+NAME: sdp_each_file_do #+BEGIN_SRC d auto header_make_and_meta_tuple = head.headerContentAA(header, conf_doc_make_aa); @@ -393,6 +396,7 @@ string[string][string] dochead_meta_aa = header_make_and_meta_tuple[1]; #+END_SRC **** [#A] processing: document abstraction, tuple :processing: + #+NAME: sdp_each_file_do #+BEGIN_SRC d /+ ↓ process document, return abstraction as tuple +/ @@ -407,6 +411,7 @@ auto doc_ao_biblio = t[2]; **** TODO debug :debug: ***** [#A] debug document parts (checkdoc) :checkdoc: + #+NAME: sdp_each_file_do #+BEGIN_SRC d /+ ↓ document parts +/ @@ -440,6 +445,7 @@ output.hub( #+END_SRC **** on exit :scope:exit: + #+NAME: sdp_each_file_do #+BEGIN_SRC d scope(exit) { diff --git a/src/sdp.d b/src/sdp.d index 4d50343..f03b7de 100755 --- a/src/sdp.d +++ b/src/sdp.d @@ -8,10 +8,10 @@ import compile_time_info, // sdp/compile_time_info.d ao_abstract_doc_source, // sdp/ao_abstract_doc_source.d ao_ansi_colors, // sdp/ao_ansi_colors.d + ao_conf_make_meta, // sdp/ao_conf_make_meta.d + ao_conf_make_meta_native, // sdp/ao_conf_make_meta_native.d + ao_conf_make_meta_sdlang, // sdp/ao_conf_make_meta_sdlang.d ao_defaults, // sdp/ao_defaults.d - ao_header_extract, // sdp/ao_header_extract.d - ao_header_extract_native, // sdp/ao_header_extract_native.d - ao_header_extract_sdlang, // sdp/ao_header_extract_sdlang.d ao_output_debugs, // sdp/ao_output_debugs.d ao_read_config_files, // sdp/ao_read_config_files.d ao_read_source_files, // sdp/ao_read_source_files.d @@ -42,8 +42,8 @@ struct SDPoutput { auto ref const S contents, string[][string][string] bookindex_unordered_hashes, JSONValue[] biblio, - // JSONValue[string] dochead_make_json, - // JSONValue[string] dochead_meta_json, + string[string][string] dochead_make_json, + string[string][string] dochead_meta_json, string fn_src, bool[string] opt_action_bool ) { @@ -140,7 +140,6 @@ void main(string[] args) { ); } } - bool[string] opt_action_bool = [ "assertions" : false, "concordance" : false, @@ -270,8 +269,8 @@ void main(string[] args) { doc_ao_contents, doc_ao_bookindex_unordered_hashes, doc_ao_biblio, - // doc_ao_make_aa, - // doc_ao_meta_aa, + dochead_make_aa, + dochead_meta_aa, fn_src, opt_action_bool ); 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