From 203fa77f01c460b60ea50342676a55c4a80b5a42 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 4 Jul 2017 07:36:45 -0400 Subject: sdl extract and composite conf (make) --- org/ao_conf_make_meta.org | 304 +++++++++++++++++++++++++++++----------------- org/default_regex.org | 9 ++ org/sdp.org | 69 +++++++---- 3 files changed, 246 insertions(+), 136 deletions(-) (limited to 'org') diff --git a/org/ao_conf_make_meta.org b/org/ao_conf_make_meta.org index 8cd73d9..25bcd4d 100644 --- a/org/ao_conf_make_meta.org +++ b/org/ao_conf_make_meta.org @@ -15,7 +15,7 @@ #+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) [[./sdp.org][sdp]] [[./][org/]] -* 0. Header Hub :module:sdp:ao_conf_make_meta: +* 0. header extract (native & sdlang) to AA :module:sdp:ao_conf_make_meta: ** module template #+BEGIN_SRC d :tangle ../src/sdp/ao/conf_make_meta.d @@ -30,7 +30,7 @@ program internally. Moved to associative array. +/ module sdp.ao.conf_make_meta; -template SiSUheaderExtractHub() { +template docHeaderMakeAndMetaTupExtractAndConvertToAA() { import std.exception, std.regex, @@ -46,21 +46,23 @@ template SiSUheaderExtractHub() { sdp.ao.rgx; mixin SiSUrgxInit; mixin SiSUheaderExtractNative; - mixin SiSUheaderExtractSDLang; + mixin SiSUextractSDLang; auto rgx = Rgx(); - auto SiSUheaderExtractHub(Src, DocMake)( + auto docHeaderMakeAndMetaTupExtractAndConvertToAA(DocMake, Src)( + DocMake conf_doc_make_aa, Src header_src, - DocMake conf_doc_make_aa ) { debug(asserts){ static assert(is(typeof(header_src) == char[])); static assert(is(typeof(conf_doc_make_aa) == string[string][string])); } auto head_native = HeaderDocMetadataAndMakeNativeToAA(); - auto head_sdlang = HeaderExtractSDL(); + auto header_sdlang_tag = (!(header_src.match(rgx.native_header_meta_title))) + ? extractSDL().docHeaderSDLtagGet(header_src) // sdlang.ast.Tag + : null; auto header_make_and_meta_tuple = (header_src.match(rgx.native_header_meta_title)) ? (head_native.headerNativeToAA(header_src)) - : (head_sdlang.headerSDLangToAA(header_src, conf_doc_make_aa)); + : (extractSDL().docHeaderSDLtoAA(conf_doc_make_aa, header_sdlang_tag)); static assert(!isTypeTuple!(header_make_and_meta_tuple)); static assert(header_make_and_meta_tuple.length==2); return header_make_and_meta_tuple; @@ -68,8 +70,8 @@ template SiSUheaderExtractHub() { } #+END_SRC -* A. header sdlang (extract) :module:sdp:ao_conf_make_meta_sdlang: -** module template +* A. module sdlang :module:sdp:ao_conf_make_meta_sdlang: +** 0. module template #+BEGIN_SRC d :tangle ../src/sdp/ao/conf_make_meta_sdlang.d /++ @@ -77,7 +79,7 @@ template SiSUheaderExtractHub() { extract sdlang header return sdlang +/ module sdp.ao.conf_make_meta_sdlang; -template SiSUheaderExtractSDLang() { +template SiSUextractSDLang() { import std.exception, std.regex, @@ -90,7 +92,7 @@ template SiSUheaderExtractSDLang() { import sdp.ao.defaults, sdp.ao.rgx; - struct HeaderExtractSDL { + struct extractSDL { mixin SiSUregisters; mixin SiSUrgxInit; auto rgx = Rgx(); @@ -99,92 +101,37 @@ template SiSUheaderExtractSDLang() { } #+END_SRC -** entry points -*** _sdlang to associative array_ +** 1. sdlang header _extract root Tag_ :sdlang:root:tag: #+name: ao_conf_make_meta_sdl #+BEGIN_SRC d -private auto sdlangToAAheaderMakeMeta(C,Tag)(C conf, Tag conf_sdlang) { +private auto docHeaderSDLtagGet(Hs)(Hs src_header) { debug(asserts){ - static assert(is(typeof(conf) == string[string][string])); + static assert(is(typeof(src_header) == char[])); } - foreach (maintag, subtags; conf) { - foreach (subtag, content; subtags) { - if (maintag in conf_sdlang.maybe.tags) { - Tag _maintag = conf_sdlang.getTag(maintag); - if ((subtag in _maintag.maybe.tags) - && (_maintag.getTagValues(subtag).length > 0)) { - debug(headersdlang) { - writeln(__LINE__, ": ", maintag, ":", subtag, ": ", _maintag.getTagValues(subtag)[0]); - } - if (_maintag.getTagValues(subtag).length == 1) { - conf[maintag][subtag] = - (_maintag.getTagValues(subtag)[0]).to!string; - } else if (_maintag.getTagValues(subtag).length > 1) { - foreach (st; _maintag.getTagValues(subtag)) { - conf[maintag][subtag] ~= - st.to!string ~ ";"; - } - } - } else if ((subtag in _maintag.maybe.attributes) - && (_maintag.maybe.attributes[subtag][0].value.length > 0)) { - debug(headersdlang) { - writeln(__LINE__, ": ", maintag, ":", subtag, ": ", conf_sdlang.tags[maintag][0].attributes[subtag][0].value); - } - conf[maintag][subtag] = - (conf_sdlang.tags[maintag][0].attributes[subtag][0].value).to!string; - } - } + char[][] source_header_arr = + (cast(char[]) src_header).split(rgx.newline_eol_delimiter); + char[] _src_header; + foreach(header_line; source_header_arr) { + if (!match(header_line, rgx.comments)) { + _src_header ~= header_line ~ "\n"; } } - return conf; -} -#+END_SRC - -*** _conf settings_ sdlang - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -private auto configSettingsSDLangToAAmake(Tag)(Tag conf_sdlang) { - auto conf = sdlangToAAheaderMakeMeta(conf_aa_empty, conf_sdlang); - return conf; -} -#+END_SRC - -*** _conf make_ sdlang - -#+name: ao_conf_make_meta_sdl -#+BEGIN_SRC d -private auto documentMakeSDLangToAAmake(Tag)(Tag document_make_sdlang) { - auto dochead_make = sdlangToAAheaderMakeMeta(conf_aa_empty, document_make_sdlang); - return dochead_make; -} -#+END_SRC - -** header :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(Hs)(Hs src_header) { - debug(asserts){ - static assert(is(typeof(src_header) == string)); - } scope(failure) { stderr.writefln( - "%s\n%s\n%s:%s failed here:\n src_header: %s", + "%s\n%s\n%s:%s failed here:\n _src_header: %s", __MODULE__, __FUNCTION__, __FILE__, __LINE__, - src_header, + _src_header, ); } Tag sdl_root_header; try { - sdl_root_header = parseSource(src_header); + sdl_root_header = parseSource(_src_header.to!string); } catch(ParseException e) { stderr.writeln("SDLang problem with this document header:"); - stderr.writeln(src_header); + stderr.writeln(_src_header); // Error messages of the form: // myFile.sdl(5:28): Error: Invalid integer suffix. stderr.writeln(e.msg); @@ -205,42 +152,62 @@ final private auto headerMakeSDLang(Hs)(Hs src_header) { } } } - return sdl_root_header; + return sdl_root_header; // sdlang.ast.Tag } #+END_SRC -*** sdlang header _src text get_ :sdlang:get:src: +** 2a. _sdlang to associative array_ #+name: ao_conf_make_meta_sdl #+BEGIN_SRC d -private auto headerSDLangGet(Hs)(Hs src_header) { +private auto sdlangToAA(C,Tag)(C conf, Tag conf_sdlang) { debug(asserts){ - static assert(is(typeof(src_header) == char[])); + static assert(is(typeof(conf) == string[string][string])); } - char[][] source_header_arr = - (cast(char[]) src_header).split(rgx.newline_eol_delimiter); - char[] header_clean; - foreach(header_line; source_header_arr) { - if (!match(header_line, rgx.comments)) { - header_clean ~= header_line ~ "\n"; + foreach (maintag, subtags; conf) { + /+ writeln(__LINE__, ": ", maintag, ":- ", subtags); +/ + foreach (subtag, content; subtags) { + if (maintag in conf_sdlang.maybe.tags) { + Tag _maintag = conf_sdlang.getTag(maintag); + if ((subtag in _maintag.maybe.tags) + && (_maintag.getTagValues(subtag).length > 0)) { + debug(headersdlang) { + writeln(__LINE__, ": ", maintag, ":", subtag, ": ", _maintag.getTagValues(subtag)[0]); + } + if (_maintag.getTagValues(subtag).length == 1) { + conf[maintag][subtag] = + (_maintag.getTagValues(subtag)[0]).to!string; + } else if (_maintag.getTagValues(subtag).length > 1) { + foreach (st; _maintag.getTagValues(subtag)) { + conf[maintag][subtag] ~= + st.to!string ~ ";"; + } + } + } else if ((subtag in _maintag.maybe.attributes) + && (_maintag.maybe.attributes[subtag][0].value.length > 0)) { + debug(headersdlang) { + writeln(__LINE__, ": ", maintag, ":", subtag, ": ", conf_sdlang.tags[maintag][0].attributes[subtag][0].value); + } + conf[maintag][subtag] = + (conf_sdlang.tags[maintag][0].attributes[subtag][0].value).to!string; + } + } } } - /+ get sdlang tags +/ - auto header_sdlang=headerMakeSDLang(to!string(header_clean)); - return header_sdlang; // sdlang.ast.Tag + return conf; } #+END_SRC -*** sdlang header to _associative array_ make sdlTag in :sdlang:aa: +** 2b. sdlang header to _associative array_ make sdlTag in :sdlang:aa: #+name: ao_conf_make_meta_sdl #+BEGIN_SRC d -private auto headerSDLangToAAmake(Tag,Ma)(Tag header_sdlang, Ma dochead_make) { +private auto docHeaderSDLtoAA(Ma, Tag)(Ma dochead_make, Tag header_sdlang) { debug(asserts){ static assert(is(typeof(dochead_make) == string[string][string])); } - dochead_make = sdlangToAAheaderMakeMeta(dochead_make, header_sdlang); - auto dochead_meta = sdlangToAAheaderMakeMeta(meta_aa_empty, header_sdlang); + dochead_make = sdlangToAA(dochead_make, header_sdlang); + auto dochead_meta = sdlangToAA(meta_aa_empty, header_sdlang); if (dochead_meta["title"]["main"].empty) { { Tag _maintag = header_sdlang.getTag("title"); @@ -283,23 +250,8 @@ private auto headerSDLangToAAmake(Tag,Ma)(Tag header_sdlang, Ma dochead_make) { } #+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(Hs,Ma)(Hs header_sdlang_src, Ma conf_doc_make_aa) { - debug(asserts){ - static assert(is(typeof(header_sdlang_src) == char[])); - static assert(is(typeof(conf_doc_make_aa) == string[string][string])); - } - auto header_sdlang_tag = headerSDLangGet(header_sdlang_src); - auto header_aa_tuple = headerSDLangToAAmake(header_sdlang_tag, conf_doc_make_aa); - return header_aa_tuple; -} -#+END_SRC - -* B. header native :module:sdp:ao_conf_make_meta_native: -** Header Native :header:native:markup_header_extract_native: +* B. module native document header :module:sdp:ao_conf_make_meta_native: +** module template #+BEGIN_SRC d :tangle ../src/sdp/ao/conf_make_meta_native.d /++ @@ -658,3 +610,129 @@ private auto headerNativeToAA(Hn)(Hn src_header) { return t; } #+END_SRC + +* 0. composite make :module:sdp:ao_composite_make: +** TODO 0. template +*** composite make + +#+BEGIN_SRC d :tangle ../src/sdp/ao/composite_make.d +/++ + output hub
+ check & generate output types requested ++/ +module sdp.ao.composite_make; +template compositeMkCnf() { + <> + mixin SiSUrgxInit; + string[] _substitutions; + string[string][] _sub; + string _bold; + string _italics; + string _emphasis; + auto compositeMkCnf(Mks...)(Mks makes) { + foreach (make; makes) { + auto rgx = Rgx(); + if (auto z = "make" in make) { + if (auto x = "substitute" in *z) { + foreach (m; (*x).matchAll(rgx.make_simple_substitutions_d)) { + _sub ~= ["match": (m["match"]), "replace": (m["replace"])]; + _substitutions ~= format("`%s`,\"%s\"", + m["match"], + m["replace"], + ); + } + foreach (m; (*x).matchAll(rgx.make_simple_substitutions_rb)) { + _sub ~= ["match": (m["match"]), "replace": (m["replace"])]; + _substitutions ~= format("`%s`,\"%s\"", + m["match"], + m["replace"], + ); + } + } + if (auto x = "bold" in *z) { + _bold = (*x).to!string; + } + if (auto x = "italics" in *z) { + _italics = (*x).to!string; + } + if (auto x = "emphasis" in *z) { + _emphasis = (*x).to!string; + } + } + } + struct _composite_make { + auto substitutions() { + auto _k = _sub; + return _k; + } + auto substitute() { + auto _k = _substitutions; + return _k; + } + auto italics() { + auto _k = _italics; + return _k; + } + auto bold() { + auto _k = _bold; + return _k; + } + auto emphasis() { + auto _k = _emphasis; + return _k; + } + } + return _composite_make(); + } +} +#+END_SRC + +*** composite make aa +#+BEGIN_SRC d :tangle ../src/sdp/ao/composite_make.d +/++ + output hub
+ check & generate output types requested ++/ +template compositeMkCnfAA() { + <> + mixin SiSUrgxInit; + string[] _substitutions; + string[string][] _sub; + auto rgx = Rgx(); + auto compositeMkCnfAA(Mks...)(Mks makes) { + /+ + - skip.first_make which is the "composite make output" + - pass config files as associative arrays, + - skip.last_make which is getopt, treat separately + +/ + auto _composite_make = makes[0]; + auto _opts = makes[$-1]; + foreach (make; makes[1..$-1]) { + if (auto z = "make" in make) { // document head: make (part of individual document) + if (auto x = "substitute" in *z) { + _composite_make["make"]["substitute"] = *x; + } + if (auto x = "italics" in *z) { + _composite_make["make"]["italics"] = *x; + } + if (auto x = "bold" in *z) { + _composite_make["make"]["bold"] = *x; + } + if (auto x = "emphasis" in *z) { + _composite_make["make"]["emphasis"] = *x; + } + } + } + /+ logic for adding _opts make instructions to _composite make +/ + return _composite_make; + } +} +#+END_SRC + +** initialize / imports + +#+name: imports +#+BEGIN_SRC d +import sdp.ao; +import std.array; +#+END_SRC diff --git a/org/default_regex.org b/org/default_regex.org index 04abbad..e1f8d26 100644 --- a/org/default_regex.org +++ b/org/default_regex.org @@ -83,6 +83,15 @@ static comment = ctRegex!(`^%+ `); static comments = ctRegex!(`^%+ |^%+$`); #+END_SRC +** config + +#+name: ao_rgx +#+BEGIN_SRC d +/+ header +/ +static make_simple_substitutions_rb = ctRegex!(`(?P/(?P.+?)/,[ ]*['"](?P.+?)['"])`); +static make_simple_substitutions_d = ctRegex!(`(?P``(?P.+?)``,[ ]*['"](?P.+?)['"])`); +#+END_SRC + ** native headers *** native header :native:header: diff --git a/org/sdp.org b/org/sdp.org index f813c5d..d4e40b4 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -99,6 +99,7 @@ import import sdp.ao.abstraction_summary, sdp.ao.abstract_doc_source, + sdp.ao.composite_make, sdp.ao.conf_make_meta, // sdp.ao.conf_make_meta_native, sdp.ao.conf_make_meta_sdlang, @@ -161,7 +162,7 @@ mixin CompileTimeInfo; #+BEGIN_SRC d mixin SiSUrgxInit; mixin SiSUregisters; -mixin SiSUheaderExtractSDLang; +mixin SiSUextractSDLang; mixin SiSUnode; mixin SiSUbiblio; mixin SiSUrgxInitFlags; @@ -315,11 +316,10 @@ auto env = [ #+NAME: sdp_conf_files #+BEGIN_SRC d -auto sdl_root_configuration = configRead!()("conf.sdl", env); -auto sdl_root_doc_make = configRead!()("sisu_document_make", env); -auto confsdl = HeaderExtractSDL(); -auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration); -auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); +auto sdl_root_config_share = configRead!()("config_local", env); +auto sdl_root_config_local = configRead!()("config_share", env); +auto conf_composite_static_aa = extractSDL().sdlangToAA(conf_aa_empty, sdl_root_config_share); +conf_composite_static_aa = extractSDL().sdlangToAA(conf_composite_static_aa, sdl_root_config_local); #+END_SRC ** 2a. actions independed of processing files @@ -432,7 +432,7 @@ writeln("no recognized filename"); break; // terminate, stop #+END_SRC -* 2. _document abstraction functions_ :module:sdp:abstraction: +* 2. _document abstraction functions_ :module:sdp:abstraction: ** 0. module template #+BEGIN_SRC d :tangle ../src/sdp/ao/abstraction.d @@ -502,12 +502,35 @@ debug(header_and_body) { #+BEGIN_SRC d /+ ↓ split header into make and meta +/ auto _make_and_meta_tup = - SiSUheaderExtractHub!()(_header_body_inserts[headBody.header], conf_doc_make_aa); + docHeaderMakeAndMetaTupExtractAndConvertToAA!()(conf_composite_static_aa, _header_body_inserts[headBody.header]); static assert(!isTypeTuple!(_make_and_meta_tup)); static assert(_make_and_meta_tup.length==2); #+END_SRC -** 3. _document abstraction, tuple_ (pre-output-processing) :processing: +** 3. composite make & settings? + +#+NAME: sdp_each_file_do_document_abstraction +#+BEGIN_SRC d +auto _make_config = compositeMkCnf!()( + conf_composite_static_aa, + _make_and_meta_tup[makeMeta.make], + // opts, +); +#+END_SRC + +** composite config & make (files & doc header) aa + +#+NAME: sdp_each_file_do_document_abstraction +#+BEGIN_SRC d +auto _make_and_conf_composite_static_plus_docheader_aa = compositeMkCnfAA!()( + conf_aa_empty, + conf_composite_static_aa, + _make_and_meta_tup[makeMeta.make], + opts, +); +#+END_SRC + +** 4. _document abstraction, tuple_ (pre-output-processing) :processing: - [[./ao_doc_abstraction.org][ao_doc_abstraction]] - prepare the document abstraction used in downstream processing @@ -539,7 +562,7 @@ string[] _doc_epub_segnames_0_4 = da[docAbst.segnames_0_4]; auto _images = da[docAbst.images]; #+END_SRC -** 4. _document matters_ (doc info gathered, various sources) +** 5. _document matters_ (doc info gathered, various sources) - prepare document_matters, miscellany about processing and the document of use in downstream processing @@ -560,12 +583,16 @@ struct DocumentMatters { string[] _k = _doc_epub_segnames_0_4; return _k; } + auto dochead_meta() { + string[string][string] _k = _make_and_meta_tup[makeMeta.meta]; + return _k; + } auto dochead_make() { string[string][string] _k = _make_and_meta_tup[makeMeta.make]; return _k; } - auto dochead_meta() { - string[string][string] _k = _make_and_meta_tup[makeMeta.meta]; + auto source_filename() { + string _k = fn_src; return _k; } auto src_path_info() { @@ -573,8 +600,12 @@ struct DocumentMatters { auto _k = SiSUpathsSRC!()(_pwd, fn_src); return _k; } - auto source_filename() { - string _k = fn_src; + auto opt_action() { + bool[string] _k = opts; + return _k; + } + auto environment() { + auto _k = env; return _k; } auto language() { @@ -594,19 +625,11 @@ struct DocumentMatters { auto _k = _images; return _k; } - auto opt_action() { - bool[string] _k = opts; - return _k; - } - auto environment() { - auto _k = env; - return _k; - } } auto doc_matters = DocumentMatters(); #+END_SRC -* 3. document abstraction _summary_ :module:sdp:abstraction_summary: +* 3. document abstraction _summary_ :module:sdp:abstraction_summary: ** 0. module template #+BEGIN_SRC d :tangle ../src/sdp/ao/abstraction_summary.d -- cgit v1.2.3