diff options
author | Ralph Amissah <ralph@amissah.com> | 2017-07-04 07:36:45 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2019-04-10 15:14:14 -0400 |
commit | 203fa77f01c460b60ea50342676a55c4a80b5a42 (patch) | |
tree | 4d28d14dafa2395ed1e52f36e5bd88649ff34cde /src/sdp/ao/conf_make_meta_sdlang.d | |
parent | output_hub sqlite introduce structure (diff) |
sdl extract and composite conf (make)doc-reform_v0.0.17
Diffstat (limited to 'src/sdp/ao/conf_make_meta_sdlang.d')
-rw-r--r-- | src/sdp/ao/conf_make_meta_sdlang.d | 122 |
1 files changed, 49 insertions, 73 deletions
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; - } } } |