1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2014-09-01 00:43:52 -04:00
parent b0a01882de
commit be63adc5af
125 changed files with 1859 additions and 952 deletions

View File

@@ -20,6 +20,7 @@ class Arg_bldr {
public boolean Bld(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_arg_wkr wkr, int wkr_typ, Xop_root_tkn root, Xop_tkn_itm tkn, int bgn_pos, int cur_pos, int loop_bgn, int loop_end, byte[] src) {
boolean ws_bgn_chk = true, colon_chk = false, itm_is_static = true, key_exists = false; int ws_bgn_idx = -1, ws_end_idx = -1, cur_itm_subs_len = 0, cur_nde_idx = -1; Arg_nde_tkn cur_nde = null; Arg_itm_tkn cur_itm = null;
int brack_count = 0;
Xop_tkn_itm eq_pending = null;
for (int i = loop_bgn; i < loop_end; i++) { // loop over subs between bookends; if lnki, all tkns between [[ and ]]; if tmpl, {{ and }}
Xop_tkn_itm sub = root.Subs_get(i);
int sub_pos_bgn = sub.Src_bgn_grp(root, i);
@@ -30,6 +31,11 @@ class Arg_bldr {
if (cur_itm == null) {
cur_itm = tkn_mkr.ArgItm(sub_pos_bgn, -1);
itm_is_static = ws_bgn_chk = true; cur_itm_subs_len = 0; ws_bgn_idx = ws_end_idx = -1;
if (eq_pending != null) { // something like "A==B" encountered; zh.w:Wikipedia:条目评选; DATE:2014-08-27
eq_pending.Src_end_(eq_pending.Src_end() -1); // remove an "=" EX:"A==B" -> "A","=","=B"
cur_itm.Subs_add_grp(eq_pending, root, i); cur_itm_subs_len++; // add the tkn to cur_itm
eq_pending = null;
}
}
switch (sub.Tkn_tid()) {
case Xop_tkn_itm_.Tid_ignore: // comment or *include* tkn; mark itm as non_static for tmpl (forces re-eval)
@@ -62,14 +68,23 @@ class Arg_bldr {
break;
case Xop_tkn_itm_.Tid_eq:
if (wkr_typ == Xop_arg_wkr_.Typ_tmpl && brack_count > 0) {}
else if (wkr_typ == Xop_arg_wkr_.Typ_prm) {} // always ignore for prm
else if (wkr_typ == Xop_arg_wkr_.Typ_prm) {} // always ignore for prm
else {
if ( cur_nde_idx != 0 // if 1st arg, treat equal_tkn as txt_tkn; i.e.: eq should not be used to separate key/val
&& cur_nde.Eq_tkn() == Xop_tkn_null.Null_tkn // only mark key if key is not set; handle multiple-keys; EX: {{name|key1=b=c}}; DATE:2014-02-09
) {
Xop_eq_tkn sub_as_eq = (Xop_eq_tkn)sub;
if (sub_as_eq.Eq_len() == 1) { // only treat as kv eq if len == 1; MW.REF:Preprocessor_DOM.php|preprocessToXml; "if ( $count == 1 && $findEquals )" PAGE:en.w:Wikipedia:Picture_of_the_day/June_2014; DATE:2014-07-21
cur_nde.Eq_tkn_(sub);
int sub_as_eq_len = sub_as_eq.Eq_len();
boolean eq_is_spr
= sub_as_eq_len == 1 // eq with len of 1 are considered separators; MW.REF:Preprocessor_DOM.php|preprocessToXml; "if ( $count == 1 && $findEquals )" PAGE:en.w:Wikipedia:Picture_of_the_day/June_2014; DATE:2014-07-21
|| ( cur_itm.Subs_len() > 0 // or eq.len > 1 that occur later in itm; EX: a==b; zh.w:Wikipedia:条目评选; DATE:2014-08-27
&& cur_itm.Subs_get(0).Tkn_tid() != Xop_tkn_itm_.Tid_eq // and 1st tkn is not ==; EX:==a==; 2nd == should not be eq b/c 1st == "deactivates" nde; DATE:2014-08-27
);
if (eq_is_spr) {
if (sub_as_eq_len == 1) // =.len == 1
cur_nde.Eq_tkn_(sub); // set as eq tkn
else // =.len > 1
eq_pending = sub; // do not set as eq tkn; note that Eq_tkn exists for bookkeeping and is not printed out,
key_exists = true;
Arg_itm_end(ctx, cur_nde, cur_itm, ws_bgn_idx, ws_end_idx, cur_itm_subs_len, sub_pos_bgn, wkr_typ, key_exists, true, itm_is_static, src, cur_nde_idx);
cur_nde.Key_tkn_(cur_itm);

View File

@@ -411,6 +411,28 @@ public class Xot_invk_wkr_basic_tst {
);
fxt.Init_defn_clear();
}
@Test public void Ignore_hdr_3() { // PURPOSE: tkn with multiple eq should have be treated as value, not header; PAGE:zh.w:Wikipedia:条目评选; DATE:2014-08-27
fxt.Init_defn_clear();
fxt.Init_defn_add("test_1", "{{{key_1|null_key_1}}}");
fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last
( "{{test_1"
, "|key_1===A==" // note that this is not "===A==", but "=","===A=="
, "}}"
), "==A=="
);
fxt.Init_defn_clear();
}
@Test public void Ignore_hdr_4() { // PURPOSE: variation of above; make sure 2nd "==" doesn't trigger another key; DATE:2014-08-27
fxt.Init_defn_clear();
fxt.Init_defn_add("test_1", "{{{key_1|null_key_1}}}");
fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last
( "{{test_1"
, "|key_1===A===B" // = should be at "==A", not "==B"
, "}}"
), "==A===B"
);
fxt.Init_defn_clear();
}
@Test public void Tmpl_case_match() { // PURPOSE: template name should match by case; EX:es.d:eclipse; DATE:2014-02-12
fxt.Init_defn_clear();
fxt.Init_defn_add("CASE_MATCH", "found", Xow_ns_case_.Id_all);