From c8c141d8abf715c9a697d2e3dd949d4621cfea7b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 29 Jan 2017 11:57:41 -0500 Subject: 0.12.1 abstraction template --- src/sdp.d | 93 ++++++------------------ src/sdp/abstraction.d | 121 +++++++++++++++++++++++++++++++ src/sdp/ao_read_config_files.d | 160 +++++++++++++++++++++++++---------------- src/sdp/ao_read_source_files.d | 9 ++- 4 files changed, 246 insertions(+), 137 deletions(-) create mode 100644 src/sdp/abstraction.d (limited to 'src') diff --git a/src/sdp.d b/src/sdp.d index 20133cd..fb5728e 100755 --- a/src/sdp.d +++ b/src/sdp.d @@ -2,9 +2,11 @@ /+ sdp +/ -/+ sdp: sisu document parser, see http://sisudoc.org +/ import compile_time_info, + abstraction; +/+ sdp: sisu document parser, see http://sisudoc.org +/ +import ao_abstract_doc_source, ao_conf_make_meta, ao_conf_make_meta_native, @@ -47,7 +49,6 @@ void main(string[] args) { mixin SiSUnode; mixin SiSUbiblio; mixin SiSUrgxInitFlags; - mixin SiSUconfigSDLangHub; mixin outputHub; /+ struct DocumentParts { @@ -161,9 +162,12 @@ void main(string[] args) { arg_unrecognized ~= " " ~ arg; } } - auto conf = ConfigHub(); - auto sdl_root_configuration = conf.configSDLang("conf.sdl"); - auto sdl_root_doc_make = conf.configSDLang("sisu_document_make"); + auto env = [ + "pwd" : environment["PWD"], + "home" : environment["HOME"], + ]; + auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); + auto sdl_root_doc_make = ConfigHub!()("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); @@ -191,69 +195,12 @@ void main(string[] args) { match(fn_src, rgx.src_pth), "not a sisu markup filename" ); - /+ ↓ read file (filename with path) +/ - /+ ↓ file tuple of header and content +/ - auto _0_header_1_body_content_2_insert_filelist_tuple = - SiSUmarkupRaw!()(fn_src); - static assert(!isTypeTuple!(_0_header_1_body_content_2_insert_filelist_tuple)); - static assert(_0_header_1_body_content_2_insert_filelist_tuple.length==3); - debug(header_and_body) { - writeln(header); - writeln(_0_header_1_body_content_2_insert_filelist_tuple.length); - writeln(_0_header_1_body_content_2_insert_filelist_tuple.length[1][0]); - } - /+ ↓ split header into make and meta +/ - auto _0_make_1_dochead_meta_tuple = - SiSUheaderExtractHub!()(_0_header_1_body_content_2_insert_filelist_tuple[0], conf_doc_make_aa); - static assert(!isTypeTuple!(_0_make_1_dochead_meta_tuple)); - static assert(_0_make_1_dochead_meta_tuple.length==2); - /+ ↓ document abstraction: process document, return abstraction as tuple +/ - auto t = SiSUdocAbstraction!()( - (_0_header_1_body_content_2_insert_filelist_tuple[1]), - (_0_make_1_dochead_meta_tuple[0]), - (_0_make_1_dochead_meta_tuple[1]), - _opt_action_bool - ); + auto t = + SiSUabstraction!()(fn_src, _opt_action_bool, env); static assert(!isTypeTuple!(t)); - static assert(t.length==3); - auto doc_abstraction = t[0]; // head ~ toc ~ contents ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb; - string[][string] _document_section_keys_sequenced = t[1]; - string[] _doc_html_segnames = t[2]; - struct DocumentMatters { - string[] keys_seq_seg() { - string[] _k = _document_section_keys_sequenced["seg"]; - return _k; - } - string[] keys_seq_scroll() { - string[] _k = _document_section_keys_sequenced["scroll"]; - return _k; - } - string[] segnames() { - string[] _k = _doc_html_segnames; - return _k; - } - auto dochead_make() { - string[string][string] _k = _0_make_1_dochead_meta_tuple[0]; - return _k; - } - auto dochead_meta() { - string[string][string] _k = _0_make_1_dochead_meta_tuple[1]; - return _k; - } - auto source_filename() { - string _k = fn_src; - return _k; - } - auto file_insert_list() { - string[] _k = _0_header_1_body_content_2_insert_filelist_tuple[2]; - return _k; - } - auto opt_action_bool() { - bool[string] _k = _opt_action_bool; - return _k; - } - } - auto doc_matters = DocumentMatters(); + static assert(t.length==2); + auto doc_abstraction = t[0]; + auto doc_matters = t[1]; /+ ↓ debugs +/ debug(checkdoc) { SiSUdebugs!()(doc_abstraction, doc_matters); @@ -269,16 +216,18 @@ void main(string[] args) { fn_src ); } - destroy(_0_header_1_body_content_2_insert_filelist_tuple); - destroy(t); - destroy(doc_abstraction); - destroy(_doc_html_segnames); + // destroy(_0_header_1_body_content_2_insert_filelist_tuple); + // destroy(t); + // destroy(doc_abstraction); + // // destroy(doc_ao_make_aa); + // // destroy(doc_ao_meta_aa); + // destroy(_doc_html_segnames); destroy(fn_src); } } else { /+ no recognized filename provided +/ writeln("no recognized filename"); - break; + break; // terminate, stop } } } diff --git a/src/sdp/abstraction.d b/src/sdp/abstraction.d new file mode 100644 index 0000000..d91618e --- /dev/null +++ b/src/sdp/abstraction.d @@ -0,0 +1,121 @@ +template SiSUabstraction() { + /+ sdp: sisu document parser, see http://sisudoc.org +/ + import + ao_abstract_doc_source, + ao_conf_make_meta, + ao_conf_make_meta_native, + ao_conf_make_meta_sdlang, + ao_defaults, + ao_output_debugs, + ao_read_config_files, + ao_read_source_files, + ao_rgx, + output_hub; + /+ sdlang http://sdlang.org +/ + import sdlang; // sdlang.d + /+ std +/ + private import + std.algorithm, + std.array, + std.container, + std.exception, + std.getopt, + std.json, + std.process, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.utf, + std.conv : to; + mixin SiSUrgxInit; + mixin SiSUregisters; + mixin SiSUheaderExtractSDLang; + mixin SiSUnode; + mixin SiSUbiblio; + mixin SiSUrgxInitFlags; + mixin outputHub; + // auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); + // auto sdl_root_doc_make = ConfigHub!()("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 rgx = Rgx(); + auto SiSUabstraction(Fn,O,E)(Fn fn_src, O opts, E env){ + auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); + auto sdl_root_doc_make = ConfigHub!()("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); + /+ ↓ read file (filename with path) +/ + /+ ↓ file tuple of header and content +/ + auto _0_header_1_body_content_2_insert_filelist_tuple = + SiSUmarkupRaw!()(fn_src); + static assert(!isTypeTuple!(_0_header_1_body_content_2_insert_filelist_tuple)); + static assert(_0_header_1_body_content_2_insert_filelist_tuple.length==3); + debug(header_and_body) { + writeln(header); + writeln(_0_header_1_body_content_2_insert_filelist_tuple.length); + writeln(_0_header_1_body_content_2_insert_filelist_tuple.length[1][0]); + } + /+ ↓ split header into make and meta +/ + auto _0_make_1_dochead_meta_tuple = + SiSUheaderExtractHub!()(_0_header_1_body_content_2_insert_filelist_tuple[0], conf_doc_make_aa); + static assert(!isTypeTuple!(_0_make_1_dochead_meta_tuple)); + static assert(_0_make_1_dochead_meta_tuple.length==2); + /+ ↓ document abstraction: process document, return abstraction as tuple +/ + auto da = SiSUdocAbstraction!()( + (_0_header_1_body_content_2_insert_filelist_tuple[1]), + (_0_make_1_dochead_meta_tuple[0]), + (_0_make_1_dochead_meta_tuple[1]), + opts + ); + static assert(!isTypeTuple!(da)); + static assert(da.length==3); + auto doc_abstraction = da[0]; // head ~ toc ~ contents ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb; + string[][string] _document_section_keys_sequenced = da[1]; + string[] _doc_html_segnames = da[2]; + struct DocumentMatters { + string[] keys_seq_seg() { + string[] _k = _document_section_keys_sequenced["seg"]; + return _k; + } + string[] keys_seq_scroll() { + string[] _k = _document_section_keys_sequenced["scroll"]; + return _k; + } + string[] segnames() { + string[] _k = _doc_html_segnames; + return _k; + } + auto dochead_make() { + string[string][string] _k = _0_make_1_dochead_meta_tuple[0]; + return _k; + } + auto dochead_meta() { + string[string][string] _k = _0_make_1_dochead_meta_tuple[1]; + return _k; + } + auto source_filename() { + string _k = fn_src; + return _k; + } + auto file_insert_list() { + string[] _k = _0_header_1_body_content_2_insert_filelist_tuple[2]; + return _k; + } + auto opt_action_bool() { + bool[string] _k = opts; + return _k; + } + } + auto doc_matters = DocumentMatters(); + auto t = tuple(doc_abstraction, doc_matters); + static assert(t.length==2); + return t; + } +} diff --git a/src/sdp/ao_read_config_files.d b/src/sdp/ao_read_config_files.d index 6308df2..2e1bca6 100644 --- a/src/sdp/ao_read_config_files.d +++ b/src/sdp/ao_read_config_files.d @@ -3,88 +3,122 @@ - read config files
ao_config_files.d +/ -template SiSUconfigIn() { +template ConfigIn() { private import + std.algorithm, + std.array, + std.container, std.exception, std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, std.utf, std.conv : to; - private - struct ConfigIn { - private import std.file; - final private string readInConfigFile(string conf_sdl) { - string dot_pwd = chainPath(to!string(environment["PWD"]), ".sisu").array; - string underscore_pwd = chainPath(to!string(environment["PWD"]), "_sisu").array; - string dot_home = chainPath(to!string(environment["HOME"]), ".sisu").array; - string[] possible_config_path_locations = [ - dot_pwd, - underscore_pwd, - dot_home, - "/etc/sisu" - ]; - string config_file_str; - foreach(pth; possible_config_path_locations) { - auto conf_file = format( - "%s/%s", - pth, - conf_sdl, - ); - try { - if (exists(conf_file)) { - debug(configfile) { - writeln(conf_file); - } - config_file_str = readText(conf_file); - break; + import std.file; + final string ConfigIn(C,E)(C conf_sdl, E env) { + string dot_pwd = chainPath(to!string(env["pwd"]), ".sisu").array; + string underscore_pwd = chainPath(to!string(env["pwd"]), "_sisu").array; + string dot_home = chainPath(to!string(env["home"]), ".sisu").array; + string[] possible_config_path_locations = [ + dot_pwd, + underscore_pwd, + dot_home, + "/etc/sisu" + ]; + string config_file_str; + foreach(pth; possible_config_path_locations) { + auto conf_file = format( + "%s/%s", + pth, + conf_sdl, + ); + try { + if (exists(conf_file)) { + debug(configfile) { + writeln(conf_file); } - } - catch (ErrnoException ex) { - } - catch (FileException ex) { + config_file_str = readText(conf_file); + break; } } - return config_file_str; + catch (ErrnoException ex) { + } + catch (FileException ex) { + } } + return config_file_str; } } /+ +/ -template SiSUconfigSDLang() { - struct ConfigSDLangRootTag { - private auto configSDLangRootTag(string configuration, string conf_sdl_filename) { - Tag sdl_root_conf; - try { - sdl_root_conf = parseSource(configuration); - } - catch(ParseException e) { - stderr.writeln("SDLang problem with content for ", conf_sdl_filename); - stderr.writeln(e.msg); - } - debug(sdlang) { - Value output_dir_structure_by = sdl_root_conf.tags["output_dir_structure_by"][0].values[0]; - assert(output_dir_structure_by.type == typeid(string)); - writeln(output_dir_structure_by); - writeln("conf SDL:"); - writeln(sdl_root_conf.toSDLDocument()); - } - return sdl_root_conf; +template ConfigSDLang() { + import sdlang; + private import + std.algorithm, + std.array, + std.container, + std.exception, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; + auto ConfigSDLang(string configuration, string conf_sdl_filename) { + Tag sdl_root_conf; + try { + sdl_root_conf = parseSource(configuration); } + catch(ParseException e) { + stderr.writeln("SDLang problem with content for ", conf_sdl_filename); + stderr.writeln(e.msg); + } + debug(sdlang) { + Value output_dir_structure_by = sdl_root_conf.tags["output_dir_structure_by"][0].values[0]; + assert(output_dir_structure_by.type == typeid(string)); + writeln(output_dir_structure_by); + writeln("conf SDL:"); + writeln(sdl_root_conf.toSDLDocument()); + } + return sdl_root_conf; } } /+ +/ -template SiSUconfigSDLangHub() { - mixin SiSUconfigIn; - mixin SiSUconfigSDLang; - struct ConfigHub { - final private auto configSDLang(string conf_sdl) { - auto conf_get = ConfigIn(); - auto configuration = conf_get.readInConfigFile(conf_sdl); - auto conf = ConfigSDLangRootTag(); - auto sdl_root = conf.configSDLangRootTag(configuration, conf_sdl); - return sdl_root; - } +template ConfigHub() { + private import + std.algorithm, + std.array, + std.container, + std.exception, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; + + final auto ConfigHub(C,E)(C conf_sdl, E env) { + auto configuration = ConfigIn!()(conf_sdl, env); + auto sdl_root = ConfigSDLang!()(configuration, conf_sdl); + return sdl_root; } } diff --git a/src/sdp/ao_read_source_files.d b/src/sdp/ao_read_source_files.d index c7616a2..a6c0199 100644 --- a/src/sdp/ao_read_source_files.d +++ b/src/sdp/ao_read_source_files.d @@ -7,13 +7,19 @@ template SiSUmarkupRaw() { private import ao_rgx; private import + std.algorithm, std.array, + std.container, std.exception, + std.stdio, + std.file, std.path, + std.range, std.regex, - std.stdio, + std.string, std.traits, std.typecons, + std.uni, std.utf, std.conv : to; mixin SiSUrgxInit; @@ -55,7 +61,6 @@ template SiSUmarkupRaw() { return t; } } - private struct MarkupRawUnit { private import std.file; final private string readInMarkupSource(in char[] fn_src) { -- cgit v1.2.3