From 8ab7e935913c102fb039110e20b71f698a68c6ee Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 16 Jun 2016 01:49:06 -0400 Subject: step5 sdlang used for config files and doc headers --- org/ao_read_source_files.org | 178 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 3 deletions(-) (limited to 'org/ao_read_source_files.org') diff --git a/org/ao_read_source_files.org b/org/ao_read_source_files.org index 2d41105..05e42ec 100644 --- a/org/ao_read_source_files.org +++ b/org/ao_read_source_files.org @@ -13,6 +13,64 @@ #+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) [[./sdp.org][sdp]] [[./][org/]] +* get config file :config: + +** [#A] read config file, source string :string: +*** config file :file:config: +#+name: ao_config_file +#+BEGIN_SRC d +final private string readInConfigFile() { + // enforce( + // exists(fn_src)!=0, + // "file not found" + // ); + string[] possible_config_path_locations = [ + environment["PWD"] ~ "/.sisu", + environment["PWD"] ~ "/_sisu", + environment["HOME"] ~ "/.sisu", + "/etc/sisu" + ]; + string conf_sdl = "conf.sdl"; + string config_file_str; + foreach(pth; possible_config_path_locations) { + auto conf_file = format( + "%s/%s", + pth, + conf_sdl, + ); + // writeln(conf_file); + try { + if (exists(conf_file)) { + writeln(conf_file); + config_file_str = readText(conf_file); + break; + } + } + catch (ErrnoException ex) { + //// Handle errors + // switch(ex.errno) { + // case EPERM: + // case EACCES: + // // Permission denied + // break; + // case ENOENT: + // // File does not exist + // break; + // default: + // // Handle other errors + // break; + // } + } + // catch (UTFException ex) { + // // Handle validation errors + // } + catch (FileException ex) { + // Handle errors + } + } + return config_file_str; +} +#+END_SRC * get markup source, read file :source:markup: @@ -91,6 +149,68 @@ final private char[][] header0Content1(in string src_text) { } #+END_SRC +** header sdlang + +#+name: ao_header_extract_sdl +#+BEGIN_SRC d +final private auto headerMakeSDLang(in string src_header) { + scope(failure) { + stderr.writefln( + "%s\n%s\n%s:%s failed here:\n src_header: %s", + __MODULE__, __FUNCTION__, + __FILE__, __LINE__, + src_header, + ); + } + Tag sdl_root_header; + try { + sdl_root_header = parseSource(src_header); + } + catch(SDLangParseException e) { + stderr.writeln("SDLang problem with this document header:"); + stderr.writeln(src_header); + // Error messages of the form: + // myFile.sdl(5:28): Error: Invalid integer suffix. + stderr.writeln(e.msg); + } + debug(sdlang) { + // // Value is a std.variant.Algebraic + // Value output_dir_structure_by = sdl_root_header.tags["output_dir_structure_by"][0].values[0]; + // assert(output_dir_structure_by.type == typeid(string)); + // writeln(output_dir_structure_by); + + // Tag person = sdl_root_header.namespaces["myNamespace"].tags["person"][0]; + // writeln("Name: ", person.attributes["name"][0].value); + // + // int age = person.tags["age"][0].values[0].get!int(); + // writeln("Age: ", age); + + writeln("header SDL:"); + writeln(sdl_root_header.toSDLDocument()); + } + return sdl_root_header; +} +#+END_SRC + +** header sdlang :header: +#+name: ao_header_extract_sdl +#+BEGIN_SRC d +private auto headerSDLang(in char[] src_header) { + char[][] source_header_arr = + split(cast(char[]) src_header, rgx.line_delimiter); + char[] header_clean; + foreach(header_line; source_header_arr) { + if (!match(header_line, rgx.comments)) { + header_clean ~= header_line ~ "\n"; + // writeln(header_line); + } + } + // writeln(header_clean); // consider + auto header_sdlang=headerMakeSDLang(to!string(header_clean)); + return header_sdlang; +} +#+END_SRC + ** source line array :array: #+name: ao_markup_source_raw #+BEGIN_SRC d @@ -332,7 +452,7 @@ template SiSUmarkupRaw() { auto raw = MarkupRawUnit(); auto t = raw.markupSourceHeaderContentRawLineTupleArray(fn_src, rgx.src_pth); - auto header_content_raw = t[0]; + auto header_raw = t[0]; auto sourcefile_content = t[1]; if (match(fn_src, rgx.src_fn_master)) { auto ins = Inserts(); @@ -341,16 +461,19 @@ template SiSUmarkupRaw() { // auto ins = SiSUdocInserts.Inserts(); } t = tuple( - header_content_raw, + header_raw, sourcefile_content ); return t; } } private + struct HeaderExtractSDL { + <> + } struct MarkupRawUnit { private import std.file; - enum State { off, on } + // enum State { off, on } <> } struct Inserts { @@ -385,3 +508,52 @@ template SiSUmarkupRaw() { INSERTS? [[./ao_scan_inserts.org][ao_scan_inserts]] WORK AREA + +** config files: :ao_config_files.d: + +#+BEGIN_SRC d :tangle ../src/sdp/ao_read_config_files.d +/+ + ao_config_files.d + - read config files ++/ +template SiSUconfiguration() { + private import + std.exception, + // std.regex, + std.stdio, + std.utf, + std.conv : to; + // private import + // ao_rgx; // ao_defaults.d + // mixin RgxInit; + // auto rgx = Rgx(); + private + struct Config { + private import std.file; + <> + } +} +#+END_SRC + +* figure out +** break up file here to sisu markup content and header + +break up file here to sisu markup content and header + +*** header +take master and single sst file, read in as header until the required header 0~ +keep separate (from content) for extraction of header metadata & make detail +also now may be sdlang or old sisu markup! + +*** content +from 0~ read in as content + +** what +# #+NAME: sdp_each_file_do +# #+BEGIN_SRC d +/+ ↓ read file +/ +// auto conf = MarkupRaw(); +auto conf = Config(); +auto configfile_content = + conf.sourceConfig(fn_src); +# #+END_SRC -- cgit v1.2.3