1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

Scribunto: Evaluate template-args when expanding template, not separately afterwards

This commit is contained in:
gnosygnu 2017-09-04 08:30:33 -04:00
parent 9f6ef68bfa
commit b101b356ad
8 changed files with 26 additions and 18 deletions

View File

@ -18,7 +18,7 @@ import gplx.xowa.wikis.nss.*;
import gplx.gflucene.indexers.*;
public class Xofulltext_indexer_args implements Gfo_invk {
public byte[] wikis;
public String idx_opt;
public String idx_opt = Gflucene_idx_opt.Docs_and_freqs.Key();
private String ns_ids_str;
public int[] ns_ids_ary;
public void Init_by_wiki(Xowe_wiki wiki) {
@ -58,8 +58,8 @@ public class Xofulltext_indexer_args implements Gfo_invk {
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, "wikis_")) this.wikis = m.ReadBryOr("v", null);
else if (ctx.Match(k, "ns_ids")) this.ns_ids_str = m.ReadStrOr("v", null);
else if (ctx.Match(k, "idx_opt")) this.idx_opt = m.ReadStrOr("v", null);
else if (ctx.Match(k, "ns_ids_")) this.ns_ids_str = m.ReadStrOr("v", null);
else if (ctx.Match(k, "idx_opt_")) this.idx_opt = m.ReadStrOr("v", null);
else return Gfo_invk_.Rv_unhandled;
return this;
}

View File

@ -28,7 +28,7 @@ public class Xoh_thm_caption_data {
public int Capt_3_bgn() {return capt_3_bgn;} private int capt_3_bgn;
public int Capt_3_end() {return capt_3_end;} private int capt_3_end;
public boolean Capt_3_exists() {return capt_3_end > capt_3_bgn;}
public Xoh_thm_magnify_data Magnify_data() {return magnify_data;} private final Xoh_thm_magnify_data magnify_data = new Xoh_thm_magnify_data();
public Xoh_thm_magnify_data Magnify_data() {return magnify_data;} private final Xoh_thm_magnify_data magnify_data = new Xoh_thm_magnify_data();
public void Clear() {
this.capt_2_is_tidy = false;
this.src_bgn = src_end = capt_1_bgn = capt_1_end = capt_2_bgn = capt_2_end = capt_3_bgn = capt_3_end = -1;
@ -69,5 +69,5 @@ public class Xoh_thm_caption_data {
}
}
public void Capt_3_(int bgn, int end) {this.capt_3_bgn = bgn; this.capt_3_end = end;}
public static final byte[] Bry__div_1_tail_bgn = Bry_.new_a7("\n</div>");
public static final byte[] Bry__div_1_tail_bgn = Bry_.new_a7("\n</div>");
}

View File

@ -217,7 +217,7 @@ public class Xow_popup_parser {
int subs_len = tmpl_root.Subs_len();
for (int i = 0; i < subs_len; i++)
tmpl_root.Subs_get(i).Tmpl_compile(tmpl_ctx, src, tmpl_props);
return Xot_tmpl_wtr.Write_all(tmpl_ctx, tmpl_root, src);
return Xot_tmpl_wtr.Write_all(tmpl_ctx, Xot_invk_temp.Null_frame, tmpl_root, src);
}
}
class Xow_popup_parser_ {

View File

@ -40,13 +40,14 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
Xop_ctx ctx = Xop_ctx.New__sub__reuse_page(wiki.Parser_mgr().Ctx()); // PERF: reuse root ctx
return Expand_tmpl(ctx, ctx.Tkn_mkr(), src);
}
private byte[] Expand_tmpl(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src) {return Expand_tmpl(tkn_mkr.Root(src), ctx, tkn_mkr, src);}
public byte[] Expand_tmpl(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src) {
private byte[] Expand_tmpl(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src) {return Expand_tmpl(tkn_mkr.Root(src), ctx, Xot_invk_temp.Null_frame, tkn_mkr, src);}
public byte[] Expand_tmpl(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src) {return Expand_tmpl(root, ctx, Xot_invk_temp.Null_frame, tkn_mkr, src);}
public byte[] Expand_tmpl(Xop_root_tkn root, Xop_ctx ctx, Xot_invk frame, Xop_tkn_mkr tkn_mkr, byte[] src) {
Parse(root, ctx, tkn_mkr, src, Xop_parser_tid_.Tid__tmpl, tmpl_trie, Xop_parser_.Doc_bgn_bos);
int len = root.Subs_len();
for (int i = 0; i < len; ++i)
root.Subs_get(i).Tmpl_compile(ctx, src, tmpl_props);
return Xot_tmpl_wtr.Write_all(ctx, root, src);
return Xot_tmpl_wtr.Write_all(ctx, frame, root, src);
}
public byte[] Parse_text_to_html(Xop_ctx ctx, byte[] src) {

View File

@ -56,6 +56,7 @@ public class Xot_invk_mock implements Xot_invk {
public Arg_nde_tkn Args_get_by_key(byte[] src, byte[] key) {return (Arg_nde_tkn)args.Get_by(key);}
public static Xot_invk_mock new_(byte defn_tid, byte[] frame_ttl, Keyval... args) {return new_(defn_tid, 1, frame_ttl, args);}
public static Xot_invk_mock new_(byte[] frame_ttl, Keyval... args) {return new_(Xot_defn_.Tid_null, 1, frame_ttl, args);}
public static Xot_invk_mock preprocess_(byte[] frame_ttl, Keyval... args) {return new_(Xot_defn_.Tid_null, 1, frame_ttl, args);}
public static Xot_invk_mock test_(byte[] frame_ttl, Keyval... args) {return new_(Xot_defn_.Tid_null, 0, frame_ttl, args);}
public static Xot_invk_mock new_(byte defn_tid, int idx_adj, byte[] frame_ttl, Keyval... args) {
Xot_invk_mock rv = new Xot_invk_mock(defn_tid, idx_adj, frame_ttl);

View File

@ -62,7 +62,9 @@ public class Xot_invk_temp implements Xot_invk {
}
arg_idx_hash.Add_if_dupe_use_nth(Int_obj_ref.New(int_key), arg); // Add_if_dupe_use_nth to keep latest version; needed for {{A|1=a|1=b}} DATE:2014-07-23
}
public static final Xot_invk_temp Page_is_caller = new Xot_invk_temp(true); // SEE NOTE_2
public static final Xot_invk Null_frame = null;
}
/*
NOTE_1:
@ -81,4 +83,6 @@ TEXT: "a {{{1}}}b c"
Note that in order to resolve mwo_concat we need to pass in an Xot_invk
This Xot_invk is the "Page_is_caller" ref
Note this has no parameters and is always empty
Does this static ref have multi-threaded issues? DATE:2017-09-01
*/

View File

@ -17,20 +17,20 @@ package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.
import gplx.core.envs.*;
import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.miscs.*;
public class Xot_tmpl_wtr {
public static byte[] Write_all(Xop_ctx ctx, Xop_root_tkn root, byte[] src) {
public static byte[] Write_all(Xop_ctx ctx, Xot_invk frame, Xop_root_tkn root, byte[] src) {
Bry_bfr bfr = ctx.Wiki().Utl__bfr_mkr().Get_m001().Reset_if_gt(Io_mgr.Len_mb);
Write_tkn(bfr, ctx, src, src.length, root);
Write_tkn(bfr, ctx, frame, src, src.length, root);
byte[] rv = bfr.To_bry_and_rls();
return ctx.Wiki().Parser_mgr().Uniq_mgr().Parse(rv); // NOTE: noops if no UNIQs; // UNIQ; DATE:2017-03-31
}
private static void Write_tkn(Bry_bfr rslt_bfr, Xop_ctx ctx, byte[] src, int src_len, Xop_tkn_itm tkn) {
private static void Write_tkn(Bry_bfr rslt_bfr, Xop_ctx ctx, Xot_invk frame, byte[] src, int src_len, Xop_tkn_itm tkn) {
switch (tkn.Tkn_tid()) {
case Xop_tkn_itm_.Tid_root: // write each sub
int subs_len = tkn.Subs_len();
for (int i = 0; i < subs_len; i++) {
Xop_tkn_itm sub_tkn = tkn.Subs_get(i);
if (!sub_tkn.Ignore())
Write_tkn(rslt_bfr, ctx, src, src_len, sub_tkn);
Write_tkn(rslt_bfr, ctx, frame, src, src_len, sub_tkn);
}
break;
case Xop_tkn_itm_.Tid_bry:
@ -91,7 +91,10 @@ public class Xot_tmpl_wtr {
break;
case Xop_tkn_itm_.Tid_tmpl_invk:
try {
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.Page_is_caller.Src_(src), rslt_bfr);
if (frame == Xot_invk_temp.Null_frame) { // NOTE: should probably remove lazy-instantiation and always force frame to be passed in; DATE:2017-09-03
frame = Xot_invk_temp.Page_is_caller.Src_(src);
}
tkn.Tmpl_evaluate(ctx, src, frame, rslt_bfr);
}
catch (Exception e) {
String err_string = String_.new_u8(src, tkn.Src_bgn(), tkn.Src_end()) + "|" + Type_adp_.NameOf_obj(e) + "|" + Err_.Cast_or_make(e).To_str__log();

View File

@ -240,11 +240,10 @@ public class Scrib_lib_mw implements Scrib_lib {
String val = tmp_bfr.To_str_and_clear();
kv_args[i] = Keyval_.new_(key, val);
}
Xot_invk_mock mock_frame = Xot_invk_mock.new_(Bry_.new_u8(frame_id), kv_args); // use frame_id for Frame_ttl; in lieu of a better candidate; DATE:2014-09-21
Xot_invk_mock mock_frame = Xot_invk_mock.preprocess_(Bry_.new_u8(frame_id), kv_args); // use frame_id for Frame_ttl; in lieu of a better candidate; DATE:2014-09-21
tmp_ctx.Parse_tid_(Xop_parser_tid_.Tid__tmpl); // default xnde names to template; needed for test, but should be in place; DATE:2014-06-27
cur_wiki.Parser_mgr().Main().Expand_tmpl(tmp_root, tmp_ctx, tmp_ctx.Tkn_mkr(), text_bry);
tmp_root.Tmpl_evaluate(tmp_ctx, text_bry, mock_frame, tmp_bfr);
return rslt.Init_obj(tmp_bfr.To_str_and_rls());
byte[] result = cur_wiki.Parser_mgr().Main().Expand_tmpl(tmp_root, tmp_ctx, mock_frame, tmp_ctx.Tkn_mkr(), text_bry);
return rslt.Init_obj(result);
}
public boolean CallParserFunction(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String frame_id = args.Pull_str(0);