From 9c14b019a6f695b54a035605e3bb3fc76bf20aa6 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 24 Apr 2016 22:35:39 -0400 Subject: step2 --- org/ao_read_source_files.org | 390 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 org/ao_read_source_files.org (limited to 'org/ao_read_source_files.org') diff --git a/org/ao_read_source_files.org b/org/ao_read_source_files.org new file mode 100644 index 0000000..c03ff94 --- /dev/null +++ b/org/ao_read_source_files.org @@ -0,0 +1,390 @@ +#+TITLE: sdp markup source raw +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:niu:ao: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +* markup source raw :markup: +[[./sdp.org][sdp]] [[./][org/]] + +** source string :string: +#+name: ao_markup_source_raw +#+BEGIN_SRC d +final private string readInMarkupSource(in string fn_src) { + enforce( + exists(fn_src)!=0, + "file not found" + ); + string source_txt_str; + try { + if (exists(fn_src)) { + source_txt_str = readText(fn_src); + } + } + 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 + } + std.utf.validate(source_txt_str); + return source_txt_str; +} +#+END_SRC + +*** notes +source_txt_str = readText(fn_src); // ok +// source_txt_str = cast(string) read(fn_src); // ok +// immutable string source_txt_str = cast(string) read(fn_src); +// auto utf8Data = readText(fn_src); +// auto utf16Data = readText!(wstring)(fn_src); +// auto utf32Data = readText!(dstring)(fn_src); + +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; +// } +} + +** source line array :array: +#+name: ao_markup_source_raw +#+BEGIN_SRC d +final private char[][] markupSourceLineArray(in string src_text) { + char[][] source_line_arr = + split(cast(char[]) src_text, rgx.line_delimiter); + return source_line_arr; +} +#+END_SRC + +** source content raw line array :array: +- used for regular .sst files; master .ssm files and; .ssi inserts +- regex is passed for relevant enforce match + +#+name: ao_markup_source_raw +#+BEGIN_SRC d +final char[][] markupSourceContentRawLineArray(in string fn_src, Regex!(char) rgx_file ) { + enforce( + match(fn_src, rgx_file), + "not a sisu markup filename" + ); + auto source_txt_str = readInMarkupSource(fn_src); + auto source_line_arr = markupSourceLineArray(source_txt_str); + return source_line_arr; +} +#+END_SRC + +* inserts :inserts: +[[./sdp.org][sdp]] [[./][org/]] + +** scan inserts (sub-document) source :scan_insert_src: +*** scan subdoc source +#+name: ao_inserts_scan +#+BEGIN_SRC d +char[][] contents_insert; +auto type1 = flags_type_init; +mixin ScreenTxtColors; +int tell_l(string color, in char[] line) { + writeln(scr_txt_marker[color], line); + return 0; +} +auto fn_pth_full = match(fn_src, rgx.src_pth); +auto markup_src_file_path = fn_pth_full.captures[1]; +#+END_SRC + +*** loop insert (sub-document) +#+name: ao_inserts_scan_loop +#+BEGIN_SRC d +if (type1["curly_code"] == 1) { + type1["header_make"] = 0; + type1["header_metadata"] = 0; + if (auto m = match(line, rgx.block_curly_code_close)) { + type1["curly_code"] = 0; + } + contents_insert ~= line; +} else if (auto m = match(line, rgx.block_curly_code_open)) { + type1["curly_code"] = 1; + type1["header_make"] = 0; + type1["header_metadata"] = 0; + contents_insert ~= line; +} else if (type1["tic_code"] == 1) { + type1["header_make"] = 0; + type1["header_metadata"] = 0; + if (auto m = match(line, rgx.block_tic_close)) { + type1["tic_code"] = 0; + } + contents_insert ~= line; +} else if (auto m = match(line, rgx.block_tic_code_open)) { + type1["tic_code"] = 1; + type1["header_make"] = 0; + type1["header_metadata"] = 0; + contents_insert ~= line; +} else if ( + (type1["header_make"] == 1) + && match(line, rgx.header_sub) +) { + type1["header_make"] = 1; + type1["header_metadata"] = 0; + // cont_dynamic_array ~= "% " ~ line; +} else if ( + (type1["header_metadata"] == 1) + && match(line, rgx.header_sub) +) { + type1["header_metadata"] = 1; + type1["header_make"] = 0; + // cont_dynamic_array ~= "% " ~ line; +} else if (auto m = match(line, rgx.insert_src_fn_ssi_or_sst)) { + type1["header_make"] = 0; + type1["header_metadata"] = 0; + auto insert_fn = m.captures[2]; + auto insert_sub_pth = m.captures[1]; + auto fn_src_insert = + to!string(markup_src_file_path ~ insert_sub_pth ~ insert_fn); + auto raw = MarkupRawUnit(); + auto markup_sourcesubfile_insert_content = + raw.markupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); + debug(insert) { // insert file + tell_l("red", line); + tell_l("red", fn_src_insert); + tell_l("fuchsia", "ERROR"); + writeln( + " length contents insert array: ", + markup_sourcesubfile_insert_content.length + ); + } + auto ins = Inserts(); + /+ + 1. load file, + 2. read lines; + 3. scan lines, + 4. if filename insert, and insert filename + 5. repeat 1 + 6. else + 7. add line to new array; + +/ +} else { + type1["header_make"] = 0; + type1["header_metadata"] = 0; + contents_insert ~= line; +} +#+END_SRC + +*** post loop +#+name: ao_inserts_scan_post +#+BEGIN_SRC d +return contents_insert; +#+END_SRC + +** scan document source :scan_src: +*** scan doc source +#+name: ao_master_doc_scan_for_insert_filenames +#+BEGIN_SRC d +char[][] contents; +auto type = flags_type_init; +mixin ScreenTxtColors; +int tell_l(string color, in char[] line) { + writeln(scr_txt_marker[color], line); + return 0; +} +auto fn_pth_full = match(fn_src, rgx.src_pth); +auto markup_src_file_path = fn_pth_full.captures[1]; +#+END_SRC +*** loop insert (document) +#+name: ao_master_doc_scan_for_insert_filenames_loop +#+BEGIN_SRC d +if (type["curly_code"] == 1) { + type["header_make"] = 0; + type["header_metadata"] = 0; + if (auto m = match(line, rgx.block_curly_code_close)) { + type["curly_code"] = 0; + } + contents ~= line; +} else if (auto m = match(line, rgx.block_curly_code_open)) { + type["curly_code"] = 1; + type["header_make"] = 0; + type["header_metadata"] = 0; + contents ~= line; +} else if (type["tic_code"] == 1) { + type["header_make"] = 0; + type["header_metadata"] = 0; + if (auto m = match(line, rgx.block_tic_close)) { + type["tic_code"] = 0; + } + contents ~= line; +} else if (auto m = match(line, rgx.block_tic_code_open)) { + type["tic_code"] = 1; + type["header_make"] = 0; + type["header_metadata"] = 0; + contents ~= line; +} else if ( + (type["header_make"] == 1) + && match(line, rgx.header_sub) +) { + contents ~= line; +} else if ( + (type["header_metadata"] == 1) + && match(line, rgx.header_sub) +) { + contents ~= line; +} else if (auto m = match(line, rgx.header_make)) { + type["header_make"] = 1; + type["header_metadata"] = 0; + contents ~= line; +} else if (auto m = match(line, rgx.header_metadata)) { + type["header_make"] = 0; + type["header_metadata"] = 1; + contents ~= line; +} else if (auto m = match(line, rgx.insert_src_fn_ssi_or_sst)) { + type["header_make"] = 0; + type["header_metadata"] = 0; + auto insert_fn = m.captures[2]; + auto insert_sub_pth = m.captures[1]; + auto fn_src_insert = + to!string(markup_src_file_path ~ insert_sub_pth ~ insert_fn); + auto raw = MarkupRawUnit(); + auto markup_sourcefile_insert_content = + raw.markupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); + debug(insert) { // insert file + tell_l("red", line); + tell_l("red", fn_src_insert); + writeln( + " length contents insert array: ", + markup_sourcefile_insert_content.length + ); + } + auto ins = Inserts(); + auto contents_insert = ins.scan_subdoc_source( + markup_sourcefile_insert_content, + to!string(fn_src_insert) + ); + contents ~= contents_insert; + /+ + 1. load file, + 2. read lines; + 3. scan lines, + 4. if filename insert, and insert filename + 5. repeat 1 + 6. else + 7. add line to new array; + +/ +} else { + type["header_make"] = 0; + type["header_metadata"] = 0; + contents ~= line; +} +#+END_SRC + +*** post loop +#+name: ao_master_doc_scan_for_insert_filenames_post +#+BEGIN_SRC d +debug(insert) { // insert file + writeln(__LINE__); + writeln(contents.length); +} +return contents; +#+END_SRC + +* tangles (code structure) :tangle: +** ao_markup_source_raw.d: :ao_markup_source_raw.d: + +#+BEGIN_SRC d :tangle ../lib/sdp/ao_read_source_files.d +/+ + ao_read_source_files.d + - open markup files + - if master file scan for addional files to import/insert ++/ +// module ao_read_source_files; +template SiSUmarkupRaw() { + 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(); + struct MarkupRaw { + final char[][] sourceContent(in string fn_src) { + auto raw = MarkupRawUnit(); + auto sourcefile_content = + raw.markupSourceContentRawLineArray(fn_src, rgx.src_pth); + if (match(fn_src, rgx.src_fn_master)) { + auto ins = Inserts(); + sourcefile_content = + ins.scan_master_doc_source_for_insert_filenames(sourcefile_content, fn_src); + // auto ins = SiSUdocInserts.Inserts(); + } + return sourcefile_content; + } + } + private + struct MarkupRawUnit { + private import std.file; + <> + } + struct Inserts { + private import ao_defaults; // ao_defaults.d + private import ao_ansi_colors; // ao_ansi_colors.d + auto scan_subdoc_source( + char[][] markup_sourcefile_insert_content, + string fn_src + ) { + mixin SiSUrgxInitFlags; + <> + foreach (line; markup_sourcefile_insert_content) { + <> + } // end src subdoc (inserts) loop + <> + } + auto scan_master_doc_source_for_insert_filenames( + char[][] sourcefile_content, + string fn_src + ) { + mixin SiSUrgxInitFlags; + <> + foreach (line; sourcefile_content) { + <> + } // end src doc loop + <> + } + } +} +#+END_SRC + +INSERTS? +[[./ao_scan_inserts.org][ao_scan_inserts]] +WORK AREA -- cgit v1.2.3