aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2017-07-04 07:36:45 -0400
committerRalph Amissah <ralph@amissah.com>2019-04-10 15:14:14 -0400
commit203fa77f01c460b60ea50342676a55c4a80b5a42 (patch)
tree4d28d14dafa2395ed1e52f36e5bd88649ff34cde /src/sdp
parentoutput_hub sqlite introduce structure (diff)
sdl extract and composite conf (make)doc-reform_v0.0.17
Diffstat (limited to 'src/sdp')
-rw-r--r--src/sdp/ao/abstraction.d49
-rw-r--r--src/sdp/ao/composite_make.d109
-rw-r--r--src/sdp/ao/conf_make_meta.d14
-rw-r--r--src/sdp/ao/conf_make_meta_sdlang.d122
-rw-r--r--src/sdp/ao/rgx.d3
-rwxr-xr-xsrc/sdp/sdp.d12
6 files changed, 205 insertions, 104 deletions
diff --git a/src/sdp/ao/abstraction.d b/src/sdp/ao/abstraction.d
index 317f841..b25f354 100644
--- a/src/sdp/ao/abstraction.d
+++ b/src/sdp/ao/abstraction.d
@@ -8,6 +8,7 @@ template SiSUabstraction() {
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,
@@ -20,7 +21,7 @@ template SiSUabstraction() {
sdp.output.paths_source;
mixin SiSUrgxInit;
mixin SiSUregisters;
- mixin SiSUheaderExtractSDLang;
+ mixin SiSUextractSDLang;
mixin SiSUnode;
mixin SiSUbiblio;
mixin SiSUrgxInitFlags;
@@ -30,11 +31,10 @@ template SiSUabstraction() {
enum docAbst { doc_abstraction, section_keys, segnames, segnames_0_4, images }
auto rgx = Rgx();
auto SiSUabstraction(Fn,O,E)(Fn fn_src, O opts, E env){
- 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);
/+ ↓ read file (filename with path) +/
/+ ↓ file tuple of header and content +/
auto _header_body_inserts =
@@ -48,9 +48,20 @@ template SiSUabstraction() {
}
/+ ↓ 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);
+ auto _make_config = compositeMkCnf!()(
+ conf_composite_static_aa,
+ _make_and_meta_tup[makeMeta.make],
+ // opts,
+ );
+ auto _make_and_conf_composite_static_plus_docheader_aa = compositeMkCnfAA!()(
+ conf_aa_empty,
+ conf_composite_static_aa,
+ _make_and_meta_tup[makeMeta.make],
+ opts,
+ );
/+ ↓ document abstraction: process document, return abstraction as tuple +/
auto da = SiSUdocAbstraction!()(
_header_body_inserts[headBody.body_content],
@@ -79,12 +90,16 @@ template SiSUabstraction() {
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() {
@@ -92,8 +107,12 @@ template SiSUabstraction() {
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() {
@@ -113,14 +132,6 @@ template SiSUabstraction() {
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();
auto t = tuple(doc_abstraction, doc_matters);
diff --git a/src/sdp/ao/composite_make.d b/src/sdp/ao/composite_make.d
new file mode 100644
index 0000000..c9df4a8
--- /dev/null
+++ b/src/sdp/ao/composite_make.d
@@ -0,0 +1,109 @@
+/++
+ output hub<BR>
+ check & generate output types requested
++/
+module sdp.ao.composite_make;
+template compositeMkCnf() {
+ import sdp.ao;
+ import std.array;
+ 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();
+ }
+}
+/++
+ output hub<BR>
+ check & generate output types requested
++/
+template compositeMkCnfAA() {
+ import sdp.ao;
+ import std.array;
+ 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;
+ }
+}
diff --git a/src/sdp/ao/conf_make_meta.d b/src/sdp/ao/conf_make_meta.d
index 0f6d27d..1d7d86d 100644
--- a/src/sdp/ao/conf_make_meta.d
+++ b/src/sdp/ao/conf_make_meta.d
@@ -9,7 +9,7 @@
program internally. Moved to associative array.
+/
module sdp.ao.conf_make_meta;
-template SiSUheaderExtractHub() {
+template docHeaderMakeAndMetaTupExtractAndConvertToAA() {
import
std.exception,
std.regex,
@@ -25,21 +25,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;
diff --git a/src/sdp/ao/conf_make_meta_sdlang.d b/src/sdp/ao/conf_make_meta_sdlang.d
index 7e7dd62..f9fb17d 100644
--- a/src/sdp/ao/conf_make_meta_sdlang.d
+++ b/src/sdp/ao/conf_make_meta_sdlang.d
@@ -3,7 +3,7 @@
extract sdlang header return sdlang
+/
module sdp.ao.conf_make_meta_sdlang;
-template SiSUheaderExtractSDLang() {
+template SiSUextractSDLang() {
import
std.exception,
std.regex,
@@ -16,72 +16,37 @@ template SiSUheaderExtractSDLang() {
import
sdp.ao.defaults,
sdp.ao.rgx;
- struct HeaderExtractSDL {
+ struct extractSDL {
mixin SiSUregisters;
mixin SiSUrgxInit;
auto rgx = Rgx();
- 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;
- }
- private auto configSettingsSDLangToAAmake(Tag)(Tag conf_sdlang) {
- auto conf = sdlangToAAheaderMakeMeta(conf_aa_empty, conf_sdlang);
- return conf;
- }
- private auto documentMakeSDLangToAAmake(Tag)(Tag document_make_sdlang) {
- auto dochead_make = sdlangToAAheaderMakeMeta(conf_aa_empty, document_make_sdlang);
- return dochead_make;
- }
- 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);
@@ -102,30 +67,50 @@ template SiSUheaderExtractSDLang() {
}
}
}
- return sdl_root_header;
+ return sdl_root_header; // sdlang.ast.Tag
}
- 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;
}
- 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");
@@ -166,14 +151,5 @@ template SiSUheaderExtractSDLang() {
static assert(t.length==2);
return t;
}
- 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;
- }
}
}
diff --git a/src/sdp/ao/rgx.d b/src/sdp/ao/rgx.d
index a5e7a9c..595087d 100644
--- a/src/sdp/ao/rgx.d
+++ b/src/sdp/ao/rgx.d
@@ -38,6 +38,9 @@ template SiSUrgxInit() {
static comment = ctRegex!(`^%+ `);
static comments = ctRegex!(`^%+ |^%+$`);
/+ header +/
+ static make_simple_substitutions_rb = ctRegex!(`(?P<substitution>/(?P<match>.+?)/,[ ]*['"](?P<replace>.+?)['"])`);
+ static make_simple_substitutions_d = ctRegex!(`(?P<substitution>``(?P<match>.+?)``,[ ]*['"](?P<replace>.+?)['"])`);
+ /+ header +/
static main_headers =
ctRegex!(`^(?:creator|title|rights|date|original|classify|identifier|notes|publisher|make|links)$`, "m");
static native_header = ctRegex!(`^@([a-z_]+):(?:\s|$)`);
diff --git a/src/sdp/sdp.d b/src/sdp/sdp.d
index 891c23f..0b90096 100755
--- a/src/sdp/sdp.d
+++ b/src/sdp/sdp.d
@@ -16,6 +16,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,
@@ -32,7 +33,7 @@ mixin CompileTimeInfo;
void main(string[] args) {
mixin SiSUrgxInit;
mixin SiSUregisters;
- mixin SiSUheaderExtractSDLang;
+ mixin SiSUextractSDLang;
mixin SiSUnode;
mixin SiSUbiblio;
mixin SiSUrgxInitFlags;
@@ -151,11 +152,10 @@ void main(string[] args) {
"pwd" : environment["PWD"],
"home" : environment["HOME"],
];
- 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);
if (!(opts["skip-output"])) {
outputHubOp!()(opts);
}