From 2660db249780e6ec90bf63c43bc1e85785a88cf3 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 30 Apr 2019 19:22:32 -0400 Subject: regex, meta_abstraction, naming of some regex submatches --- org/meta_abstraction.org | 106 +++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'org/meta_abstraction.org') diff --git a/org/meta_abstraction.org b/org/meta_abstraction.org index d2adf27..e2f4638 100644 --- a/org/meta_abstraction.org +++ b/org/meta_abstraction.org @@ -418,10 +418,10 @@ static auto inline_markup_faces(L)(L line) { static auto rgx = Rgx(); static auto mkup = InlineMarkup(); line = replaceAll!(m => mkup.quote_o ~ m[1] ~ mkup.quote_c)(line, rgx.within_quotes); - line = replaceAll!(m => mkup.mono ~ mkup.ff_o ~ m[2] ~ mkup.ff_c ~ mkup.mono)(line, rgx.inline_mark_mono); - line = replaceAll!(m => mkup.cite ~ mkup.ff_o ~ m[2] ~ mkup.ff_c ~ mkup.cite)(line, rgx.inline_mark_cite); + line = replaceAll!(m => mkup.mono ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.mono)(line, rgx.inline_mark_mono); + line = replaceAll!(m => mkup.cite ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.cite)(line, rgx.inline_mark_cite); foreach (regx; [rgx.inline_mark_emphasis, rgx.inline_mark_bold, rgx.inline_mark_underscore, rgx.inline_mark_italics, rgx.inline_mark_superscript, rgx.inline_mark_subscript, rgx.inline_mark_strike, rgx.inline_mark_insert]) { - line = replaceAll!(m => m[1] ~ mkup.ff_o ~ m[2] ~ mkup.ff_c ~ m[1])(line, regx); + line = replaceAll!(m => m["mark"] ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ m["mark"])(line, regx); } return line; } @@ -434,33 +434,33 @@ static auto links_and_images(L)(L obj_txt) { || obj_txt.match(rgx.smid_inline_link_endnote_url_helper_punctuated) ) { obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s%s", - mkup.lnk_o, m[1].strip, mkup.lnk_c, - mkup.url_o, m[2], mkup.url_c, + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, mkup.en_a_o, - mkup.lnk_o, m[2].strip, mkup.lnk_c, - mkup.url_o, m[2], mkup.url_c, + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, mkup.en_a_c, m[3] ))(obj_txt, rgx.smid_inline_link_endnote_url_helper_punctuated); obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s", - mkup.lnk_o, m[1].strip, mkup.lnk_c, - mkup.url_o, m[2], mkup.url_c, + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, mkup.en_a_o, - mkup.lnk_o, m[2].strip, mkup.lnk_c, - mkup.url_o, m[2], mkup.url_c, + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, mkup.en_a_c ))(obj_txt, rgx.smid_inline_link_endnote_url_helper); } else { obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", - m[1], - mkup.lnk_o, m[2].strip, mkup.lnk_c, - mkup.url_o, m[3], mkup.url_c + m["pre"], + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c ))(obj_txt, rgx.smid_inline_link_markup_regular); } obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", - m[1], - mkup.lnk_o, m[2].strip, mkup.lnk_c, - mkup.url_o, m[2], mkup.url_c + m["pre"], + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c ))(obj_txt, rgx.smid_inline_link_naked_url); // } return obj_txt; @@ -886,8 +886,8 @@ if there is a blurb section you need to: debug(paraindent) { writeln(line); } - indent["hang_position"] = (m[1]).to!int; - indent["base_position"] = (m[1]).to!int; + indent["hang_position"] = (m["indent"]).to!int; + indent["base_position"] = (m["indent"]).to!int; } else if (line.matchFirst(rgx.para_bullet)) { debug(parabullet) { writeln(line); @@ -898,16 +898,16 @@ if there is a blurb section you need to: writeln(line); } indent=[ - "hang_position" : (m[1]).to!int, - "base_position" : (m[2]).to!int, + "hang_position" : (m["hang"]).to!int, + "base_position" : (m["indent"]).to!int, ]; } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { debug(parabulletindent) { writeln(line); } indent=[ - "hang_position" : (m[1]).to!int, - "base_position" : (m[1]).to!int, + "hang_position" : (m["indent"]).to!int, + "base_position" : (m["indent"]).to!int, ]; bullet = true; } @@ -3349,7 +3349,7 @@ void _start_block_(L,T,N)( line ); } - an_object["table_head"] = m[1].to!string; + an_object["table_head"] = m["attrib"].to!string; an_object["block_type"] = "curly"; obj_type_status["blocks"] = TriState.on; obj_type_status["table"] = TriState.on; @@ -3362,7 +3362,7 @@ void _start_block_(L,T,N)( #+BEGIN_SRC d } else if (auto m = line.matchFirst(rgx.block_curly_table_special_markup)) { /+ table: special table block markup syntax! +/ - an_object["table_head"] = m[1].to!string; + an_object["table_head"] = m["attrib"].to!string; an_object["block_type"] = "special"; obj_type_status["blocks"] = TriState.on; obj_type_status["table"] = TriState.on; @@ -3472,7 +3472,7 @@ void _start_block_(L,T,N)( line ); } - an_object["table_head"] = m[1].to!string; + an_object["table_head"] = m["attrib"].to!string; an_object["block_type"] = "tic"; obj_type_status["blocks"] = TriState.on; obj_type_status["table"] = TriState.on; @@ -3754,7 +3754,7 @@ void _quote_block_(L,O,T)( debug(quote) { // quote (curly) close writeln(line); } - an_object[an_object_key] = an_object[an_object_key].stripRight; + an_object[an_object_key] = an_object[an_object_key].stripRight; obj_type_status["blocks"] = TriState.closing; obj_type_status["quote"] = TriState.closing; obj_type_status["curly_quote"] = TriState.off; @@ -3769,7 +3769,7 @@ void _quote_block_(L,O,T)( debug(quote) { // quote (tic) close writeln(line); } - an_object[an_object_key] = an_object[an_object_key].stripRight; + an_object[an_object_key] = an_object[an_object_key].stripRight; obj_type_status["blocks"] = TriState.closing; obj_type_status["quote"] = TriState.closing; obj_type_status["tic_quote"] = TriState.off; @@ -3968,7 +3968,7 @@ void _poem_block_(L,O,T,C,N,CMM,Ts)( processing.remove("verse"); ++cntr; } - object_number_poem["end"] = obj_cite_digits.object_number.to!string; + object_number_poem["end"] = obj_cite_digits.object_number.to!string; obj_type_status["blocks"] = TriState.closing; obj_type_status["poem"] = TriState.closing; obj_type_status["curly_poem"] = TriState.off; @@ -4654,7 +4654,7 @@ auto _book_index_(L,I,O,T,B)( debug(bookindexmatch) { writefln( "* [bookindex] %s\n", - m[1].to!string, + m["bookindex"].to!string, ); } an_object["bookindex_nugget"] = m.captures[1].to!string; @@ -5057,8 +5057,8 @@ void _para_match_(L,O,K,I,B,T,C)( debug(paraindent) { writeln(line); } - indent["hang_position"] = (m[1]).to!int; - indent["base_position"] = (m[1]).to!int; + indent["hang_position"] = (m["indent"]).to!int; + indent["base_position"] = (m["indent"]).to!int; } else if (line.matchFirst(rgx.para_bullet)) { debug(parabullet) { writeln(line); @@ -5069,16 +5069,16 @@ void _para_match_(L,O,K,I,B,T,C)( writeln(line); } indent=[ - "hang_position" : (m[1]).to!int, - "base_position" : (m[2]).to!int, + "hang_position" : (m["hang"]).to!int, + "base_position" : (m["indent"]).to!int, ]; } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { debug(parabulletindent) { writeln(line); } indent=[ - "hang_position" : (m[1]).to!int, - "base_position" : (m[1]).to!int, + "hang_position" : (m["indent"]).to!int, + "base_position" : (m["indent"]).to!int, ]; bullet = true; } @@ -6431,16 +6431,16 @@ struct ObjAttributes { ~ " \"indent_base\": 0,"; } else if (auto m = obj_txt_in.matchFirst(rgx.para_bullet_indent)) { _obj_attributes =" \"bullet\": \"true\"," - ~ " \"indent_hang\": " ~ m[1].to!string ~ "," - ~ " \"indent_base\": " ~ m[1].to!string ~ ","; + ~ " \"indent_hang\": " ~ m["indent"].to!string ~ "," + ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent_hang)) { _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": " ~ m[1].to!string ~ "," - ~ " \"indent_base\": " ~ m[2].to!string ~ ","; + ~ " \"indent_hang\": " ~ m["hang"].to!string ~ "," + ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent)) { _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": " ~ m[1].to!string ~ "," - ~ " \"indent_base\": " ~ m[1].to!string ~ ","; + ~ " \"indent_hang\": " ~ m["indent"].to!string ~ "," + ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; } else { _obj_attributes =" \"bullet\": \"false\"," ~ " \"indent_hang\": 0," @@ -7047,27 +7047,27 @@ struct NotesSection { ) { debug(endnotes_build) { writeln( - "{^", mkup.ff_o, m[1], ".", mkup.ff_c, "^}" + "{^", mkup.ff_o, m["num"], ".", mkup.ff_c, "^}" ~ mkup.mark_internal_site_lnk, tag_in_seg["seg_lv4"], - ".fnSuffix#noteref_\n ", m[1], " ", - m[2]); // sometimes need segment name (segmented html & epub) + ".fnSuffix#noteref_\n ", m["num"], " ", + m["note"]); // sometimes need segment name (segmented html & epub) } // you need anchor for segments at this point -> - object_notes["anchor"] ~= "note_" ~ m[1] ~ "』"; + object_notes["anchor"] ~= "note_" ~ m["num"] ~ "』"; object_notes["notes"] ~= (tag_in_seg["seg_lv4"].empty) ? (links_and_images( - "{" ~ mkup.superscript ~ mkup.ff_o ~ m[1] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}#noteref_" - ~ m[1]) ~ " " - ~ m[2] ~ "』" + "{" ~ mkup.superscript ~ mkup.ff_o ~ m["num"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}#noteref_" + ~ m["num"]) ~ " " + ~ m["note"] ~ "』" ) : (links_and_images( - "{" ~ mkup.superscript ~ mkup.ff_o ~ m[1] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}" + "{" ~ mkup.superscript ~ mkup.ff_o ~ m["num"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}" ~ mkup.mark_internal_site_lnk ~ tag_in_seg["seg_lv4"] ~ ".fnSuffix#noteref_" - ~ m[1]) ~ " " - ~ m[2] ~ "』" + ~ m["num"]) ~ " " + ~ m["note"] ~ "』" ); } return object_notes; @@ -7195,7 +7195,7 @@ struct NotesSection { comp_obj_endnote_.attrib.bullet = false; foreach (i, endnote; endnotes_["notes"]) { auto m = endnote.matchFirst(rgx.note_ref); - string notenumber = m[1].to!string; + string notenumber = m["ref"].to!string; string anchor_tag = "note_" ~ notenumber; comp_obj_endnote_.tags.anchor_tags = [ endnotes_["anchor"][i] ]; comp_obj_endnote_.has.inline_links = true; -- cgit v1.2.3