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
2015-09-20 23:43:51 -04:00
parent 5fe27b5b3b
commit fa70c05354
1056 changed files with 8375 additions and 7095 deletions

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.parsers.amps.*;
import gplx.core.btries.*; import gplx.langs.htmls.*; import gplx.xowa.parsers.amps.*;
public class Nowiki_escape_itm {
public Nowiki_escape_itm(byte[] src, byte[] trg) {this.src = src; this.trg = trg; this.src_adj = src.length - 1;}
private int src_adj;

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.tests.*;
public class Xop_arg_itm_tkn_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Arg_itm_tkn.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_arg_itm;}

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.tests.*;
public class Xop_arg_nde_tkn_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Arg_nde_tkn.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_arg_nde;}

View File

@@ -16,11 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
public class Xop_brack_bgn_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_brack_bgn;}
public int Lxr_tid() {return Xop_lxr_.Tid_brack_bgn;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_tkn_.Lnki_bgn, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public void Term(Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
Xop_tkn_itm tkn = tkn_mkr.Brack_bgn(bgn_pos, cur_pos);
ctx.Subs_add_and_stack(root, tkn);

View File

@@ -16,11 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
public class Xop_brack_end_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_brack_end;}
public int Lxr_tid() {return Xop_lxr_.Tid_brack_end;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_tkn_.Lnki_end, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public void Term(Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
int acs_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_brack_bgn);
if (acs_pos != -1 && ctx.Cur_tkn_tid() != Xop_tkn_itm_.Tid_tmpl_curly_bgn) // NOTE: do not pop tkn if inside tmpl; EX: [[a|{{#switch:{{{1}}}|b=c]]|d=e]]|f]]}}

View File

@@ -16,11 +16,13 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*; import gplx.xowa.parsers.tblws.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
import gplx.xowa.parsers.tblws.*;
public class Xop_curly_bgn_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_curly_bgn;}
public int Lxr_tid() {return Xop_lxr_.Tid_curly_bgn;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook, this);} public static final byte[] Hook = new byte[] {Byte_ascii.Curly_bgn, Byte_ascii.Curly_bgn};
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public void Term(Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {return ctx.Curly().MakeTkn_bgn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
public static final Xop_curly_bgn_lxr _ = new Xop_curly_bgn_lxr(); Xop_curly_bgn_lxr() {}
public static Btrie_fast_mgr tmpl_bgn_trie_() { // hook sequences for adding new_line to tmpl return; "{|" "|-" ":" ";" "#" "*"; EX: "{{a}}" returns "*"; convert to "\n*"

View File

@@ -16,11 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
public class Xop_curly_end_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_curly_end;}
public int Lxr_tid() {return Xop_lxr_.Tid_curly_end;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook, this);} public static final byte[] Hook = new byte[] {Byte_ascii.Curly_end, Byte_ascii.Curly_end};
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public void Term(Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {return ctx.Curly().MakeTkn_end(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
public static final Xop_curly_end_lxr _ = new Xop_curly_end_lxr(); Xop_curly_end_lxr() {}
}

View File

@@ -23,14 +23,14 @@ public class Xop_curly_wkr implements Xop_ctx_wkr {
public void Page_end(Xop_ctx ctx, Xop_root_tkn root, byte[] src, int src_len) {}
public void AutoClose(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int lxr_bgn_pos, int lxr_cur_pos, Xop_tkn_itm tkn) {}
public int MakeTkn_bgn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int lxr_bgn_pos, int lxr_cur_pos) {
int lxr_end_pos = Bry_finder.Find_fwd_while(src, lxr_cur_pos, src_len, Byte_ascii.Curly_bgn); // NOTE: can be many consecutive {; EX: {{{{{1}}}|a}}
int lxr_end_pos = Bry_find_.Find_fwd_while(src, lxr_cur_pos, src_len, Byte_ascii.Curly_bgn); // NOTE: can be many consecutive {; EX: {{{{{1}}}|a}}
ctx.Subs_add_and_stack(root, tkn_mkr.Tmpl_curly_bgn(lxr_bgn_pos, lxr_end_pos));
return lxr_end_pos;
}
public int MakeTkn_end(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int lxr_bgn_pos, int lxr_cur_pos) {
if (ctx.Cur_tkn_tid() == Xop_tkn_itm_.Tid_brack_bgn) // WORKAROUND: ignore }} if inside lnki; EX.CM:Template:Protected; {{#switch:a|b=[[a|ja=}}]]}}
return ctx.Lxr_make_txt_(lxr_cur_pos);
int lxr_end_pos = Bry_finder.Find_fwd_while(src, lxr_cur_pos, src_len, Byte_ascii.Curly_end); // NOTE: can be many consecutive }; EX: {{a|{{{1}}}}}
int lxr_end_pos = Bry_find_.Find_fwd_while(src, lxr_cur_pos, src_len, Byte_ascii.Curly_end); // NOTE: can be many consecutive }; EX: {{a|{{{1}}}}}
int end_tkn_len = lxr_end_pos - lxr_bgn_pos;
boolean vnt_enabled = ctx.Wiki().Lang().Vnt_mgr().Enabled();
while (end_tkn_len > 0) {

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.xowa.langs.*;
public class Xot_defn_ {
public static final Xot_defn Null = Xot_defn_null._;
public static final byte

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.xowa.nss.*;
public class Xot_defn_tmpl implements Xot_defn {
public byte Defn_tid() {return Xot_defn_.Tid_tmpl;}
public boolean Defn_require_colon_arg() {return false;}
@@ -39,12 +40,12 @@ public class Xot_defn_tmpl implements Xot_defn {
int pos = 0;
int src_len = src.length;
while (true) {
int find_bgn = Bry_finder.Find_fwd(src, Bry_onlyinclude_bgn, pos, src_len);
int find_bgn = Bry_find_.Find_fwd(src, Bry_onlyinclude_bgn, pos, src_len);
if (find_bgn == Bry_.NotFound) {
break;
}
int find_bgn_lhs = find_bgn + Bry_onlyinclude_bgn_len;
int find_end = Bry_finder.Find_fwd(src, Bry_onlyinclude_end, find_bgn_lhs, src_len);
int find_end = Bry_find_.Find_fwd(src, Bry_onlyinclude_end, find_bgn_lhs, src_len);
if (find_end == Bry_.NotFound) {
break;
}
@@ -59,12 +60,12 @@ public class Xot_defn_tmpl implements Xot_defn {
if (root != null) root.Clear();
root = null;
}
public void Parse_tmpl(Xop_ctx ctx) {ctx.Wiki().Parser().Parse_text_to_defn(this, ctx, ctx.Tkn_mkr(), ns, name, data_raw);} boolean onlyinclude_parsed = false;
public void Parse_tmpl(Xop_ctx ctx) {ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn(this, ctx, ctx.Tkn_mkr(), ns, name, data_raw);} boolean onlyinclude_parsed = false;
public boolean Tmpl_evaluate(Xop_ctx ctx, Xot_invk caller, Bry_bfr bfr) {
if (root == null) Parse_tmpl(ctx);
Xoae_page page = ctx.Cur_page();
if (!page.Tmpl_stack_add(full_name)) {
bfr.Add_str_a7("<!-- template loop detected:" + gplx.html.Html_utl.Escape_html_as_str(String_.new_u8(name)) + " -->");
bfr.Add_str_a7("<!-- template loop detected:" + gplx.langs.htmls.Html_utl.Escape_html_as_str(String_.new_u8(name)) + " -->");
Xoa_app_.Usr_dlg().Warn_many("", "", "template loop detected: url=~{0} name=~{1}", ctx.Cur_page().Url().To_str(), name);
return false;
}
@@ -75,7 +76,7 @@ public class Xot_defn_tmpl implements Xot_defn {
onlyinclude_parsed = true;
byte[] new_data = Extract_onlyinclude(data_raw, wiki.Utl__bfr_mkr());
Xop_ctx new_ctx = Xop_ctx.new_sub_(wiki);
Xot_defn_tmpl tmpl = wiki.Parser().Parse_text_to_defn_obj(new_ctx, new_ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), Bry_.Empty, new_data);
Xot_defn_tmpl tmpl = wiki.Parser_mgr().Main().Parse_text_to_defn_obj(new_ctx, new_ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), Bry_.Empty, new_data);
tmpl.Root().Tmpl_compile(new_ctx, new_data, Xot_compile_data.Null);
data_raw = new_data;
root = tmpl.Root();

View File

@@ -16,7 +16,8 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.cnvs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*;
import gplx.xowa.nss.*;
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.pages.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.parsers.miscs.*;
@@ -67,7 +68,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
name_had_subst = name_key_tkn.Dat_ary_had_subst();
name_ary_orig = name_ary; // cache name_ary_orig
name_ary_len = name_ary.length;
name_bgn = Bry_finder.Find_fwd_while_not_ws(name_ary, 0, name_ary_len);
name_bgn = Bry_find_.Find_fwd_while_not_ws(name_ary, 0, name_ary_len);
if ( name_ary_len == 0 // name is blank; can occur with failed inner tmpl; EX: {{ {{does not exist}} }}
|| name_bgn == name_ary_len // name is ws; EX: {{test| }} -> {{{{{1}}}}}is whitespace String; PAGE:en.d:wear_one's_heart_on_one's_sleeve; EX:{{t+|fr|avoir le cœur sur la main| }}
) {
@@ -122,7 +123,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
break;
case Xot_defn_.Tid_func:
if (defn.Defn_require_colon_arg()) {
colon_pos = Bry_finder.Find_fwd(name_ary, Byte_ascii.Colon);
colon_pos = Bry_find_.Find_fwd(name_ary, Byte_ascii.Colon);
if (colon_pos == Bry_.NotFound)
defn = Xot_defn_.Null;
}
@@ -132,7 +133,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
break;
case Xot_defn_.Tid_raw:
case Xot_defn_.Tid_msg:
int raw_colon_pos = Bry_finder.Find_fwd(name_ary, Byte_ascii.Colon);
int raw_colon_pos = Bry_find_.Find_fwd(name_ary, Byte_ascii.Colon);
if (raw_colon_pos == Bry_.NotFound) {} // colon missing; EX: {{raw}}; noop and assume template name; DATE:2014-02-11
else { // colon present;
name_ary = Bry_.Mid(name_ary, finder.Subst_end() + 1, name_ary_len); // chop off "raw"; +1 is for ":"; note that +1 is in bounds b/c raw_colon was found
@@ -194,7 +195,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
}
if ( defn.Defn_tid() == Xot_defn_.Tid_null // name is not a known defn
&& lang.Vnt_mgr().Enabled()) { // lang has vnts
Xowd_page_itm page = lang.Vnt_mgr().Convert_ttl(wiki, wiki.Ns_mgr().Ns_template(), name_ary);
Xowd_page_itm page = lang.Vnt_mgr().Convert_mgr().Convert_ttl(wiki, wiki.Ns_mgr().Ns_template(), name_ary);
if (page != Xowd_page_itm.Null) {
name_ary = page.Ttl_page_db();
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.Add(wiki.Ns_mgr().Ns_template().Name_db_w_colon(), name_ary));
@@ -265,7 +266,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
prepend_mgr.End(ctx, bfr, rslt_bfr.Bfr(), rslt_bfr.Len(), Bool_.Y);
if (name_had_subst) { // current invk had "subst:"; parse incoming invk again to remove effects of subst; PAGE:pt.w:Argentina DATE:2014-09-24
byte[] tmp_src = rslt_bfr.Xto_bry_and_clear();
rslt_bfr.Add(wiki.Parser().Parse_text_to_wtxt(tmp_src)); // this could be cleaner / more optimized
rslt_bfr.Add(wiki.Parser_mgr().Main().Parse_text_to_wtxt(tmp_src)); // this could be cleaner / more optimized
}
if (Cache_enabled) {
byte[] rslt_val = rslt_bfr.Xto_bry_and_clear();
@@ -350,7 +351,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
}
}
if (transclude_src != null) {
Xot_defn_tmpl transclude_tmpl = ctx.Wiki().Parser().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), page_ttl.Ns(), page_ttl.Page_db(), transclude_src);
Xot_defn_tmpl transclude_tmpl = ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), page_ttl.Ns(), page_ttl.Page_db(), transclude_src);
return Eval_sub(ctx, transclude_tmpl, caller, src, bfr);
}
else {
@@ -375,7 +376,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
if (tmpl_page_bry != null) {
byte old_parse_tid = ctx.Parse_tid(); // NOTE: reusing ctxs is a bad idea; will change Parse_tid and cause strange errors; however, keeping for PERF reasons
Xow_ns ns_tmpl = wiki.Ns_mgr().Ns_template();
rv = wiki.Parser().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ns_tmpl, name_ary, tmpl_page_bry);
rv = wiki.Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ns_tmpl, name_ary, tmpl_page_bry);
byte[] frame_ttl = tmpl_page_itm.Ttl().Full_txt(); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-08-22
rv.Frame_ttl_(frame_ttl); // set defn's frame_ttl; needed for redirect_trg; PAGE:en.w:Statutory_city; DATE:2014-08-22
ctx.Parse_tid_(old_parse_tid);
@@ -406,7 +407,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
Xow_page_cache_itm cache_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
if ( cache_itm != null) {
if (!Bry_.Eq(cache_itm.Ttl().Full_db(), ctx.Cur_page().Ttl().Full_db())) { // make sure that transcluded item is not same as page_ttl; DATE:2014-01-10
transclude_tmpl = ctx.Wiki().Parser().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), page_ttl.Ns(), page_ttl.Page_db(), cache_itm.Wtxt());
transclude_tmpl = ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), page_ttl.Ns(), page_ttl.Page_db(), cache_itm.Wtxt());
page_ttl = cache_itm.Ttl();
}
}

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.tests.*;
public class Xot_invk_tkn_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Xot_invk_tkn.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tmpl_invk;}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.xowa.wikis.ttls.*;
import org.junit.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.nss.*;
public class Xot_invk_wkr_basic_tst {
private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.tests.*;
public class Xot_prm_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Xot_prm_tkn.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tmpl_prm;}