From e31e98f5cc3c2289ad47198a506d8d03a063512c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 7 May 2017 16:07:11 -0400 Subject: 0.15.0 named modules --- src/sdp.d | 230 ------------------------------------- src/sdp/abstraction.d | 25 ++-- src/sdp/abstraction_summary.d | 5 +- src/sdp/ao_abstract_doc_source.d | 9 +- src/sdp/ao_conf_make_meta.d | 7 +- src/sdp/ao_conf_make_meta_native.d | 5 +- src/sdp/ao_conf_make_meta_sdlang.d | 5 +- src/sdp/ao_defaults.d | 1 + src/sdp/ao_doc_debugs.d | 5 +- src/sdp/ao_object_setter.d | 1 + src/sdp/ao_read_config_files.d | 1 + src/sdp/ao_read_source_files.d | 5 +- src/sdp/ao_rgx.d | 3 +- src/sdp/compile_time_info.d | 1 + src/sdp/create_zip_file.d | 1 + src/sdp/defaults.d | 1 + src/sdp/output_epub3.d | 13 ++- src/sdp/output_html.d | 13 ++- src/sdp/output_hub.d | 17 +-- src/sdp/output_rgx.d | 3 +- src/sdp/output_xmls.d | 13 ++- src/sdp/output_xmls_css.d | 1 + src/sdp/paths_output.d | 3 +- src/sdp/paths_source.d | 3 +- src/sdp/source_sisupod.d | 11 +- src/sisu_d_parser.d | 230 +++++++++++++++++++++++++++++++++++++ 26 files changed, 318 insertions(+), 294 deletions(-) delete mode 100755 src/sdp.d create mode 100755 src/sisu_d_parser.d (limited to 'src') diff --git a/src/sdp.d b/src/sdp.d deleted file mode 100755 index ceb1e3b..0000000 --- a/src/sdp.d +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/env rdmd -/+ - sdp -+/ -import - compile_time_info, - abstraction; -/+ sdp: sisu document parser, see http://sisudoc.org +/ -import - abstraction_summary, - ao_abstract_doc_source, - ao_conf_make_meta, - ao_conf_make_meta_native, - ao_conf_make_meta_sdlang, - ao_defaults, - ao_doc_debugs, - ao_read_config_files, - ao_read_source_files, - ao_rgx, - output_hub, - paths_source; -/+ sdlang http://sdlang.org +/ -import sdlang; -/+ std +/ -private import - std.array, - std.exception, - std.getopt, - std.process, - std.stdio, - std.regex, - std.string, - std.traits, - std.typecons, - std.utf, - std.conv : to; - -mixin(import("version.txt")); -mixin CompileTimeInfo; -/++ A SiSU document parser writen in D. +/ -void main(string[] args) { - mixin SiSUrgxInit; - mixin SiSUregisters; - mixin SiSUheaderExtractSDLang; - mixin SiSUnode; - mixin SiSUbiblio; - mixin SiSUrgxInitFlags; - mixin outputHub; - string[] fns_src; - string flag_action; - string arg_unrecognized; - enum dAM { abstraction, matters } - auto rgx = Rgx(); - scope(success) { - debug(checkdoc) { - writefln( - "~ run complete, ok ~ (sdp-%s.%s.%s, %s v%s, %s %s)", - ver.major, ver.minor, ver.patch, - __VENDOR__, __VERSION__, - bits, os, - ); - } - } - scope(failure) { - debug(checkdoc) { - stderr.writefln( - "run failure", - ); - } - } - bool[string] _opt_action_bool = [ - "assertions" : false, - "concordance" : false, - "debug" : false, - "digest" : false, - "docbook" : false, - "epub" : false, - "html" : false, - "html_seg" : false, - "html_scroll" : false, - "manifest" : false, - "ocn" : true, - "odt" : false, - "pdf" : false, - "postgresql" : false, - "qrcode" : false, - "sisupod" : false, - "source" : false, - "sqlite" : false, - "text" : false, - "verbose" : false, - "xhtml" : false, - "xml_dom" : false, - "xml_sax" : false, - "section_toc" : true, - "section_body" : true, - "section_endnotes" : true, - "section_glossary" : true, - "section_biblio" : true, - "section_bookindex" : true, - "section_blurb" : true, - "backmatter" : true, - "skip_output" : false, - ]; - auto helpInfo = getopt(args, - std.getopt.config.passThrough, - "assert", "--assert set optional assertions on", &_opt_action_bool["assertions"], - "concordance", "--concordance file for document", &_opt_action_bool["concordance"], - "debug", "--debug only relevant when debug options compiled in", &_opt_action_bool["debug"], - "digest", "--digest hash digest for each object", &_opt_action_bool["digest"], - "docbook", "--docbook process docbook output", &_opt_action_bool["docbook"], - "epub", "--epub process epub output", &_opt_action_bool["epub"], - "html", "--html process html output", &_opt_action_bool["html"], - "html_seg", "--html-seg process html output", &_opt_action_bool["html_seg"], - "html_scroll", "--html-seg process html output", &_opt_action_bool["html_scroll"], - "manifest", "--manifest process manifest output", &_opt_action_bool["manifest"], - "ocn", "--ocn object cite numbers (default)", &_opt_action_bool["ocn"], - "odf", "--odf process odf:odt output", &_opt_action_bool["odt"], - "odt", "--odt process odf:odt output", &_opt_action_bool["odt"], - "pdf", "--pdf process pdf output", &_opt_action_bool["pdf"], - "pg", "--pg process postgresql output", &_opt_action_bool["postgresql"], - "postgresql", "--postgresql process postgresql output", &_opt_action_bool["postgresql"], - "qrcode", "--qrcode with document metadata", &_opt_action_bool["qrcode"], - "sisupod", "--sisupod sisupod source content bundled", &_opt_action_bool["sisupod"], - "source", "--source markup source text content", &_opt_action_bool["source"], - "sqlite", "--sqlite process sqlite output", &_opt_action_bool["sqlite"], - "text", "--text process text output", &_opt_action_bool["text"], - "txt", "--txt process text output", &_opt_action_bool["text"], - "verbose|v", "--verbose output to terminal", &_opt_action_bool["verbose"], - "xhtml", "--xhtml process xhtml output", &_opt_action_bool["xhtml"], - "xml-dom", "--xml-dom process xml dom output", &_opt_action_bool["xml_dom"], - "xml-sax", "--xml-sax process xml sax output", &_opt_action_bool["xml_sax"], - "section-toc", "--section-toc process table of contents (default)", &_opt_action_bool["section_toc"], - "section-body", "--section-body process document body (default)", &_opt_action_bool["section_body"], - "section-endnotes", "--section-endnotes process document endnotes (default)", &_opt_action_bool["section_endnotes"], - "section-glossary", "--section-glossary process document glossary (default)", &_opt_action_bool["section_glossary"], - "section-biblio", "--section-biblio process document biblio (default)", &_opt_action_bool["section_biblio"], - "section-bookindex", "--section-bookindex process document bookindex (default)", &_opt_action_bool["section_bookindex"], - "section-blurb", "--section-blurb process document blurb (default)", &_opt_action_bool["section_blurb"], - "backmatter", "--section-backmatter process document backmatter (default)", &_opt_action_bool["backmatter"], - "skip_output", "--skip-output", &_opt_action_bool["skip_output"], - ); - if (helpInfo.helpWanted) { - defaultGetoptPrinter("Some information about the program.", helpInfo.options); - } - foreach(arg; args) { - if (arg.match(rgx.flag_action)) { - flag_action ~= " " ~ arg; // flags not taken by getopt - } else if (arg.match(rgx.src_pth)) { - fns_src ~= arg; // gather input markup source file names for processing - } else { // anything remaining, unused - arg_unrecognized ~= " " ~ arg; - } - } - 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); - foreach(fn_src; fns_src) { - if (!empty(fn_src)) { - scope(success) { - debug(checkdoc) { - writefln( - "%s\n%s", - "~ document complete, ok ~", - "------------------------------------------------------------------", - ); - } - } - scope(failure) { - debug(checkdoc) { - stderr.writefln( - "~ document run failure ~ (%s v%s)\n\t%s", - __VENDOR__, __VERSION__, - fn_src - ); - } - } - enforce( - fn_src.match(rgx.src_pth), - "not a sisu markup filename" - ); - auto t = - SiSUabstraction!()(fn_src, _opt_action_bool, env); - static assert(!isTypeTuple!(t)); - static assert(t.length==2); - auto doc_abstraction = t[dAM.abstraction]; - auto doc_matters = t[dAM.matters]; - /+ ↓ debugs +/ - if (doc_matters.opt_action_bool["verbose"]) { - SiSUabstractionSummary!()(doc_abstraction, doc_matters); - } - /+ ↓ debugs +/ - if ((doc_matters.opt_action_bool["debug"]) - || (doc_matters.opt_action_bool["verbose"]) - ) { - SiSUdebugs!()(doc_abstraction, doc_matters); - } - /+ ↓ output hub +/ - if (!(_opt_action_bool["skip_output"])) { - outputHub!()(doc_abstraction, doc_matters); - } - scope(exit) { - debug(checkdoc) { - writefln( - "processed file: %s", - fn_src - ); - } - destroy(fn_src); - } - } else { - /+ no recognized filename provided +/ - writeln("no recognized filename"); - break; // terminate, stop - } - } -} -unittest { - /++ - name "sdp" - description "A SiSU document parser writen in D." - homepage "http://sisudoc.org" - +/ -} diff --git a/src/sdp/abstraction.d b/src/sdp/abstraction.d index 726513c..40cf4d3 100644 --- a/src/sdp/abstraction.d +++ b/src/sdp/abstraction.d @@ -1,18 +1,19 @@ +module sdp.abstraction; template SiSUabstraction() { /+ sdp: sisu document parser, see http://sisudoc.org +/ import - abstraction_summary, - ao_abstract_doc_source, - ao_conf_make_meta, - ao_conf_make_meta_native, - ao_conf_make_meta_sdlang, - ao_defaults, - ao_doc_debugs, - ao_read_config_files, - ao_read_source_files, - ao_rgx, - output_hub, - paths_source; + sdp.abstraction_summary, + sdp.ao_abstract_doc_source, + sdp.ao_conf_make_meta, + sdp.ao_conf_make_meta_native, + sdp.ao_conf_make_meta_sdlang, + sdp.ao_defaults, + sdp.ao_doc_debugs, + sdp.ao_read_config_files, + sdp.ao_read_source_files, + sdp.ao_rgx, + sdp.output_hub, + sdp.paths_source; /+ sdlang http://sdlang.org +/ import sdlang; /+ std +/ diff --git a/src/sdp/abstraction_summary.d b/src/sdp/abstraction_summary.d index fe97783..9532fc7 100644 --- a/src/sdp/abstraction_summary.d +++ b/src/sdp/abstraction_summary.d @@ -1,11 +1,12 @@ +module sdp.abstraction_summary; template SiSUabstractionSummary() { auto SiSUabstractionSummary(S,T)( auto return ref const S doc_abstraction, auto return ref T doc_matters, ) { import - ao_defaults, - ao_rgx; + sdp.ao_defaults, + sdp.ao_rgx; import std.array, std.exception, diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index baf13b8..ab7cc99 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -3,13 +3,14 @@ abstraction of sisu markup for downstream processing ao_abstract_doc_source.d +/ +module sdp.ao_abstract_doc_source; template SiSUdocAbstraction() { /+ ↓ abstraction imports +/ import - ao_defaults, - ao_object_setter, - ao_rgx, - output_hub; + sdp.ao_defaults, + sdp.ao_object_setter, + sdp.ao_rgx, + sdp.output_hub; private import std.algorithm, std.array, diff --git a/src/sdp/ao_conf_make_meta.d b/src/sdp/ao_conf_make_meta.d index b34b7f3..52cc98d 100644 --- a/src/sdp/ao_conf_make_meta.d +++ b/src/sdp/ao_conf_make_meta.d @@ -8,6 +8,7 @@ converting the metadata and make instructions to a common json format used by program internally. Moved to associative array. +/ +module sdp.ao_conf_make_meta; template SiSUheaderExtractHub() { private import std.exception, @@ -19,9 +20,9 @@ template SiSUheaderExtractHub() { std.conv : to; private import sdlang; private import - ao_rgx, - ao_conf_make_meta_native, - ao_conf_make_meta_sdlang; + sdp.ao_rgx, + sdp.ao_conf_make_meta_native, + sdp.ao_conf_make_meta_sdlang; mixin SiSUrgxInit; mixin SiSUheaderExtractNative; mixin SiSUheaderExtractSDLang; diff --git a/src/sdp/ao_conf_make_meta_native.d b/src/sdp/ao_conf_make_meta_native.d index 500be52..899b59f 100644 --- a/src/sdp/ao_conf_make_meta_native.d +++ b/src/sdp/ao_conf_make_meta_native.d @@ -2,6 +2,7 @@ native headers using
@title:
:subtitle:
type tags
extract native/orig header return associative array +/ +module sdp.ao_conf_make_meta_native; template SiSUheaderExtractNative() { private import std.exception, @@ -13,8 +14,8 @@ template SiSUheaderExtractNative() { std.utf, std.conv : to; private import - ao_rgx, - ao_defaults; + sdp.ao_rgx, + sdp.ao_defaults; struct HeaderDocMetadataAndMakeNativeToAA { mixin SiSUregisters; mixin SiSUrgxInitFlags; diff --git a/src/sdp/ao_conf_make_meta_sdlang.d b/src/sdp/ao_conf_make_meta_sdlang.d index 74bb996..1fb8993 100644 --- a/src/sdp/ao_conf_make_meta_sdlang.d +++ b/src/sdp/ao_conf_make_meta_sdlang.d @@ -2,6 +2,7 @@ sdlang headers
extract sdlang header return sdlang +/ +module sdp.ao_conf_make_meta_sdlang; template SiSUheaderExtractSDLang() { private import std.exception, @@ -13,8 +14,8 @@ template SiSUheaderExtractSDLang() { std.utf, std.conv : to; private import - ao_rgx, - ao_defaults; + sdp.ao_rgx, + sdp.ao_defaults; struct HeaderExtractSDL { mixin SiSUregisters; mixin SiSUrgxInit; diff --git a/src/sdp/ao_defaults.d b/src/sdp/ao_defaults.d index 363cc39..6363fdc 100644 --- a/src/sdp/ao_defaults.d +++ b/src/sdp/ao_defaults.d @@ -1,6 +1,7 @@ /++ default settings +/ +module sdp.ao_defaults; template SiSUregisters() { private import std.algorithm, diff --git a/src/sdp/ao_doc_debugs.d b/src/sdp/ao_doc_debugs.d index e650e5b..2c78c76 100644 --- a/src/sdp/ao_doc_debugs.d +++ b/src/sdp/ao_doc_debugs.d @@ -1,10 +1,11 @@ /++ output debugs +/ +module sdp.ao_doc_debugs; template SiSUdebugs() { import - ao_defaults, - ao_rgx; + sdp.ao_defaults, + sdp.ao_rgx; private import std.algorithm, std.array, diff --git a/src/sdp/ao_object_setter.d b/src/sdp/ao_object_setter.d index f09e64d..a5ddb4a 100644 --- a/src/sdp/ao_object_setter.d +++ b/src/sdp/ao_object_setter.d @@ -3,6 +3,7 @@ setting of sisu objects for downstream processing ao_object_setter.d +/ +module sdp.ao_object_setter; template ObjectSetter() { /+ structs +/ struct HeadingAttrib { diff --git a/src/sdp/ao_read_config_files.d b/src/sdp/ao_read_config_files.d index 2cdf861..b8d9890 100644 --- a/src/sdp/ao_read_config_files.d +++ b/src/sdp/ao_read_config_files.d @@ -3,6 +3,7 @@ - read config files
ao_config_files.d +/ +module sdp.ao_read_config_files; template ConfigIn() { private import std.algorithm, diff --git a/src/sdp/ao_read_source_files.d b/src/sdp/ao_read_source_files.d index 33e7987..b6ad942 100644 --- a/src/sdp/ao_read_source_files.d +++ b/src/sdp/ao_read_source_files.d @@ -3,9 +3,10 @@ - open markup files
- if master file scan for addional files to import/insert +/ +module sdp.ao_read_source_files; template SiSUrawMarkupContent() { private import - ao_rgx; + sdp.ao_rgx; private import std.algorithm, std.array, @@ -139,7 +140,7 @@ template SiSUrawMarkupContent() { } } struct Inserts { - private import ao_defaults; + private import sdp.ao_defaults; auto scan_subdoc_source( char[][] markup_sourcefile_insert_content, string fn_src diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index 38c7fae..29a96af 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -1,8 +1,9 @@ /++ regex: regular expressions used in sisu document parser +/ +module sdp.ao_rgx; template SiSUrgxInit() { - private import ao_defaults; + private import sdp.ao_defaults; struct Rgx { /+ misc +/ static true_dollar = ctRegex!(`\$`, "gm"); diff --git a/src/sdp/compile_time_info.d b/src/sdp/compile_time_info.d index 2b0151d..cf4d0a5 100644 --- a/src/sdp/compile_time_info.d +++ b/src/sdp/compile_time_info.d @@ -1,6 +1,7 @@ /++ compile_time_info +/ +module sdp.compile_time_info; template CompileTimeInfo() { version(Windows) { pragma(msg, "[ Windows compilation ]"); diff --git a/src/sdp/create_zip_file.d b/src/sdp/create_zip_file.d index 6ea55f4..93e85ee 100644 --- a/src/sdp/create_zip_file.d +++ b/src/sdp/create_zip_file.d @@ -1,3 +1,4 @@ +module sdp.create_zip_file; template createZipFile() { import std.file; import std.outbuffer; diff --git a/src/sdp/defaults.d b/src/sdp/defaults.d index d4e4220..a344f7f 100644 --- a/src/sdp/defaults.d +++ b/src/sdp/defaults.d @@ -1,6 +1,7 @@ /++ default settings +/ +module sdp.defaults; template InternalMarkup() { struct InlineMarkup { diff --git a/src/sdp/output_epub3.d b/src/sdp/output_epub3.d index 56f9be3..6cc496c 100644 --- a/src/sdp/output_epub3.d +++ b/src/sdp/output_epub3.d @@ -1,3 +1,4 @@ +module sdp.output_epub3; template outputEPub3() { private import std.algorithm, @@ -22,12 +23,12 @@ template outputEPub3() { std.zip, std.conv : to; import - create_zip_file, - defaults, - output_rgx, - output_xmls, - output_xmls_css, - paths_output; + sdp.create_zip_file, + sdp.defaults, + sdp.output_rgx, + sdp.output_xmls, + sdp.output_xmls_css, + sdp.paths_output; mixin InternalMarkup; mixin outputXHTMLs; string epub3_mimetypes() { diff --git a/src/sdp/output_html.d b/src/sdp/output_html.d index 363ff4a..41d68dd 100644 --- a/src/sdp/output_html.d +++ b/src/sdp/output_html.d @@ -1,3 +1,4 @@ +module sdp.output_html; template outputHTML() { private import std.algorithm, @@ -22,12 +23,12 @@ template outputHTML() { std.zip, std.conv : to; import - create_zip_file, - defaults, - output_rgx, - output_xmls, - output_xmls_css, - paths_output; + sdp.create_zip_file, + sdp.defaults, + sdp.output_rgx, + sdp.output_xmls, + sdp.output_xmls_css, + sdp.paths_output; mixin outputXHTMLs; void scroll(D,I)( diff --git a/src/sdp/output_hub.d b/src/sdp/output_hub.d index 389d187..ef8156c 100644 --- a/src/sdp/output_hub.d +++ b/src/sdp/output_hub.d @@ -2,6 +2,7 @@ output hub
check & generate output types requested +/ +module sdp.output_hub; template outputHub() { private import std.regex, @@ -22,14 +23,14 @@ template outputHub() { std.uni, std.utf; import - create_zip_file, - defaults, - output_epub3, - output_html, - output_rgx, - output_xmls, - paths_output, - source_sisupod; + sdp.defaults, + sdp.output_epub3, + sdp.output_html, + sdp.output_rgx, + sdp.output_xmls, + sdp.source_sisupod, + sdp.create_zip_file, + sdp.paths_output; void outputHub(D,I)(D doc_abstraction, I doc_matters) { mixin SiSUoutputRgxInit; auto rgx = Rgx(); diff --git a/src/sdp/output_rgx.d b/src/sdp/output_rgx.d index be0a91e..af0751e 100644 --- a/src/sdp/output_rgx.d +++ b/src/sdp/output_rgx.d @@ -1,8 +1,9 @@ /++ regex: regular expressions used in sisu document parser +/ +module sdp.output_rgx; template SiSUoutputRgxInit() { - private import defaults; + private import sdp.defaults; struct Rgx { static newline = ctRegex!("\n", "mg"); static strip_br = ctRegex!("^
\n|
\n*$"); diff --git a/src/sdp/output_xmls.d b/src/sdp/output_xmls.d index a408872..373a871 100644 --- a/src/sdp/output_xmls.d +++ b/src/sdp/output_xmls.d @@ -1,3 +1,4 @@ +module sdp.output_xmls; template outputXHTMLs() { private import std.algorithm, @@ -22,12 +23,12 @@ template outputXHTMLs() { std.zip, std.conv : to; import - create_zip_file, - defaults, - output_rgx, - output_xmls, - output_xmls_css, - paths_output; + sdp.create_zip_file, + sdp.defaults, + sdp.output_rgx, + sdp.output_xmls, + sdp.output_xmls_css, + sdp.paths_output; mixin SiSUoutputRgxInit; struct outputXHTMLs { auto rgx = Rgx(); diff --git a/src/sdp/output_xmls_css.d b/src/sdp/output_xmls_css.d index c746b16..eb1ab2b 100644 --- a/src/sdp/output_xmls_css.d +++ b/src/sdp/output_xmls_css.d @@ -1,6 +1,7 @@ /++ default css settings +/ +module sdp.output_xmls_css; template SiSUcss() { auto SiSUcss() { string css_shared=" diff --git a/src/sdp/paths_output.d b/src/sdp/paths_output.d index e9599db..ea68567 100644 --- a/src/sdp/paths_output.d +++ b/src/sdp/paths_output.d @@ -1,11 +1,12 @@ /++ default settings +/ +module sdp.paths_output; import std.array, std.path, std.regex, std.stdio; -import ao_rgx; +import sdp.ao_rgx; template SiSUpathsSisupod() { mixin SiSUrgxInit; auto rgx = Rgx(); diff --git a/src/sdp/paths_source.d b/src/sdp/paths_source.d index f60949d..b5a60e8 100644 --- a/src/sdp/paths_source.d +++ b/src/sdp/paths_source.d @@ -3,11 +3,12 @@ - read config files
ao_config_files.d +/ +module sdp.paths_source; import std.array, std.path, std.regex, std.stdio; -import ao_rgx; +import sdp.ao_rgx; template SiSUpathsSRC() { mixin SiSUrgxInit; auto rgx = Rgx(); diff --git a/src/sdp/source_sisupod.d b/src/sdp/source_sisupod.d index e5233ba..7babba3 100644 --- a/src/sdp/source_sisupod.d +++ b/src/sdp/source_sisupod.d @@ -1,3 +1,4 @@ +module sdp.source_sisupod; template SiSUpod() { private import std.algorithm, @@ -22,11 +23,11 @@ template SiSUpod() { std.zip, std.conv : to; import - create_zip_file, - defaults, - output_rgx, - output_xmls, - paths_output; + sdp.create_zip_file, + sdp.defaults, + sdp.output_rgx, + sdp.output_xmls, + sdp.paths_output; void SiSUpod(T)(T doc_matters) { debug(asserts) { // static assert(is(typeof(doc_matters) == tuple)); diff --git a/src/sisu_d_parser.d b/src/sisu_d_parser.d new file mode 100755 index 0000000..87b25e9 --- /dev/null +++ b/src/sisu_d_parser.d @@ -0,0 +1,230 @@ +#!/usr/bin/env rdmd +/+ + sdp ++/ +import + sdp.compile_time_info, + sdp.abstraction; +/+ sdp: sisu document parser, see http://sisudoc.org +/ +import + sdp.abstraction_summary, + sdp.ao_abstract_doc_source, + sdp.ao_conf_make_meta, + sdp.ao_conf_make_meta_native, + sdp.ao_conf_make_meta_sdlang, + sdp.ao_defaults, + sdp.ao_doc_debugs, + sdp.ao_read_config_files, + sdp.ao_read_source_files, + sdp.ao_rgx, + sdp.output_hub, + sdp.paths_source; +/+ sdlang http://sdlang.org +/ +import sdlang; +/+ std +/ +private import + std.array, + std.exception, + std.getopt, + std.process, + std.stdio, + std.regex, + std.string, + std.traits, + std.typecons, + std.utf, + std.conv : to; + +mixin(import("version.txt")); +mixin CompileTimeInfo; +/++ A SiSU document parser writen in D. +/ +void main(string[] args) { + mixin SiSUrgxInit; + mixin SiSUregisters; + mixin SiSUheaderExtractSDLang; + mixin SiSUnode; + mixin SiSUbiblio; + mixin SiSUrgxInitFlags; + mixin outputHub; + string[] fns_src; + string flag_action; + string arg_unrecognized; + enum dAM { abstraction, matters } + auto rgx = Rgx(); + scope(success) { + debug(checkdoc) { + writefln( + "~ run complete, ok ~ (sdp-%s.%s.%s, %s v%s, %s %s)", + ver.major, ver.minor, ver.patch, + __VENDOR__, __VERSION__, + bits, os, + ); + } + } + scope(failure) { + debug(checkdoc) { + stderr.writefln( + "run failure", + ); + } + } + bool[string] _opt_action_bool = [ + "assertions" : false, + "concordance" : false, + "debug" : false, + "digest" : false, + "docbook" : false, + "epub" : false, + "html" : false, + "html_seg" : false, + "html_scroll" : false, + "manifest" : false, + "ocn" : true, + "odt" : false, + "pdf" : false, + "postgresql" : false, + "qrcode" : false, + "sisupod" : false, + "source" : false, + "sqlite" : false, + "text" : false, + "verbose" : false, + "xhtml" : false, + "xml_dom" : false, + "xml_sax" : false, + "section_toc" : true, + "section_body" : true, + "section_endnotes" : true, + "section_glossary" : true, + "section_biblio" : true, + "section_bookindex" : true, + "section_blurb" : true, + "backmatter" : true, + "skip_output" : false, + ]; + auto helpInfo = getopt(args, + std.getopt.config.passThrough, + "assert", "--assert set optional assertions on", &_opt_action_bool["assertions"], + "concordance", "--concordance file for document", &_opt_action_bool["concordance"], + "debug", "--debug only relevant when debug options compiled in", &_opt_action_bool["debug"], + "digest", "--digest hash digest for each object", &_opt_action_bool["digest"], + "docbook", "--docbook process docbook output", &_opt_action_bool["docbook"], + "epub", "--epub process epub output", &_opt_action_bool["epub"], + "html", "--html process html output", &_opt_action_bool["html"], + "html_seg", "--html-seg process html output", &_opt_action_bool["html_seg"], + "html_scroll", "--html-seg process html output", &_opt_action_bool["html_scroll"], + "manifest", "--manifest process manifest output", &_opt_action_bool["manifest"], + "ocn", "--ocn object cite numbers (default)", &_opt_action_bool["ocn"], + "odf", "--odf process odf:odt output", &_opt_action_bool["odt"], + "odt", "--odt process odf:odt output", &_opt_action_bool["odt"], + "pdf", "--pdf process pdf output", &_opt_action_bool["pdf"], + "pg", "--pg process postgresql output", &_opt_action_bool["postgresql"], + "postgresql", "--postgresql process postgresql output", &_opt_action_bool["postgresql"], + "qrcode", "--qrcode with document metadata", &_opt_action_bool["qrcode"], + "sisupod", "--sisupod sisupod source content bundled", &_opt_action_bool["sisupod"], + "source", "--source markup source text content", &_opt_action_bool["source"], + "sqlite", "--sqlite process sqlite output", &_opt_action_bool["sqlite"], + "text", "--text process text output", &_opt_action_bool["text"], + "txt", "--txt process text output", &_opt_action_bool["text"], + "verbose|v", "--verbose output to terminal", &_opt_action_bool["verbose"], + "xhtml", "--xhtml process xhtml output", &_opt_action_bool["xhtml"], + "xml-dom", "--xml-dom process xml dom output", &_opt_action_bool["xml_dom"], + "xml-sax", "--xml-sax process xml sax output", &_opt_action_bool["xml_sax"], + "section-toc", "--section-toc process table of contents (default)", &_opt_action_bool["section_toc"], + "section-body", "--section-body process document body (default)", &_opt_action_bool["section_body"], + "section-endnotes", "--section-endnotes process document endnotes (default)", &_opt_action_bool["section_endnotes"], + "section-glossary", "--section-glossary process document glossary (default)", &_opt_action_bool["section_glossary"], + "section-biblio", "--section-biblio process document biblio (default)", &_opt_action_bool["section_biblio"], + "section-bookindex", "--section-bookindex process document bookindex (default)", &_opt_action_bool["section_bookindex"], + "section-blurb", "--section-blurb process document blurb (default)", &_opt_action_bool["section_blurb"], + "backmatter", "--section-backmatter process document backmatter (default)", &_opt_action_bool["backmatter"], + "skip_output", "--skip-output", &_opt_action_bool["skip_output"], + ); + if (helpInfo.helpWanted) { + defaultGetoptPrinter("Some information about the program.", helpInfo.options); + } + foreach(arg; args) { + if (arg.match(rgx.flag_action)) { + flag_action ~= " " ~ arg; // flags not taken by getopt + } else if (arg.match(rgx.src_pth)) { + fns_src ~= arg; // gather input markup source file names for processing + } else { // anything remaining, unused + arg_unrecognized ~= " " ~ arg; + } + } + 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); + foreach(fn_src; fns_src) { + if (!empty(fn_src)) { + scope(success) { + debug(checkdoc) { + writefln( + "%s\n%s", + "~ document complete, ok ~", + "------------------------------------------------------------------", + ); + } + } + scope(failure) { + debug(checkdoc) { + stderr.writefln( + "~ document run failure ~ (%s v%s)\n\t%s", + __VENDOR__, __VERSION__, + fn_src + ); + } + } + enforce( + fn_src.match(rgx.src_pth), + "not a sisu markup filename" + ); + auto t = + SiSUabstraction!()(fn_src, _opt_action_bool, env); + static assert(!isTypeTuple!(t)); + static assert(t.length==2); + auto doc_abstraction = t[dAM.abstraction]; + auto doc_matters = t[dAM.matters]; + /+ ↓ debugs +/ + if (doc_matters.opt_action_bool["verbose"]) { + SiSUabstractionSummary!()(doc_abstraction, doc_matters); + } + /+ ↓ debugs +/ + if ((doc_matters.opt_action_bool["debug"]) + || (doc_matters.opt_action_bool["verbose"]) + ) { + SiSUdebugs!()(doc_abstraction, doc_matters); + } + /+ ↓ output hub +/ + if (!(_opt_action_bool["skip_output"])) { + outputHub!()(doc_abstraction, doc_matters); + } + scope(exit) { + debug(checkdoc) { + writefln( + "processed file: %s", + fn_src + ); + } + destroy(fn_src); + } + } else { + /+ no recognized filename provided +/ + writeln("no recognized filename"); + break; // terminate, stop + } + } +} +unittest { + /++ + name "sdp" + description "A SiSU document parser writen in D." + homepage "http://sisudoc.org" + +/ +} -- cgit v1.2.3