mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.9.3.1
This commit is contained in:
21
400_xowa/src/gplx/xowa/parsers/Xoa_parser_mgr.java
Normal file
21
400_xowa/src/gplx/xowa/parsers/Xoa_parser_mgr.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_parser_mgr {
|
||||
public Xop_tkn_mkr Tkn_mkr() {return tkn_mkr;} private final Xop_tkn_mkr tkn_mkr = new Xop_tkn_mkr();
|
||||
}
|
||||
@@ -16,37 +16,39 @@ 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; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.lst.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.xtns.lst.*;
|
||||
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.parsers.logs.*; import gplx.xowa.html.modules.popups.keeplists.*;
|
||||
public class Xop_ctx {
|
||||
private Xop_ctx_wkr[] wkrs = new Xop_ctx_wkr[] {};
|
||||
Xop_ctx(Xowe_wiki wiki, Xoae_page page) {
|
||||
this.app = wiki.Appe(); this.msg_log = app.Msg_log();
|
||||
this.wiki = wiki; this.cur_page = page;
|
||||
this.app = wiki.Appe(); this.msg_log = app.Msg_log(); this.tkn_mkr = app.Parser_mgr().Tkn_mkr();
|
||||
this.wiki = wiki; this.cur_page = page; this.lang = wiki.Lang();
|
||||
this.wkrs = new Xop_ctx_wkr[] {para, apos, xnde, list, lnki, hdr, amp, lnke, tblw, invk};
|
||||
for (Xop_ctx_wkr wkr : wkrs) wkr.Ctor_ctx(this);
|
||||
this.xnde_tag_regy = wiki.Mw_parser_mgr().Xnde_tag_regy();
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xol_lang Lang() {return wiki.Lang();}
|
||||
public Xop_tkn_mkr Tkn_mkr() {return app.Tkn_mkr();}
|
||||
public Xoae_app App() {return app;} private final Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private final Xowe_wiki wiki;
|
||||
public Xol_lang Lang() {return lang;} private final Xol_lang lang;
|
||||
public Xop_tkn_mkr Tkn_mkr() {return tkn_mkr;} private final Xop_tkn_mkr tkn_mkr;
|
||||
public Xoae_page Cur_page() {return cur_page;} public void Cur_page_(Xoae_page v) {cur_page = v;} private Xoae_page cur_page;
|
||||
public byte Parse_tid() {return parse_tid;} public Xop_ctx Parse_tid_(byte v) {parse_tid = v; xnde_names_tid = v; return this;} private byte parse_tid = Xop_parser_.Parse_tid_null;
|
||||
public byte Xnde_names_tid() {return xnde_names_tid;} public Xop_ctx Xnde_names_tid_(byte v) {xnde_names_tid = v; return this;} private byte xnde_names_tid = Xop_parser_.Parse_tid_null;
|
||||
public Xop_amp_wkr Amp() {return amp;} private Xop_amp_wkr amp = new Xop_amp_wkr();
|
||||
public Xop_apos_wkr Apos() {return apos;} private Xop_apos_wkr apos = new Xop_apos_wkr();
|
||||
public Xop_lnke_wkr Lnke() {return lnke;} private Xop_lnke_wkr lnke = new Xop_lnke_wkr();
|
||||
public Xop_lnki_wkr Lnki() {return lnki;} private Xop_lnki_wkr lnki = new Xop_lnki_wkr();
|
||||
public Xop_hdr_wkr Hdr() {return hdr;} private Xop_hdr_wkr hdr = new Xop_hdr_wkr();
|
||||
public Xop_para_wkr Para() {return para;} private Xop_para_wkr para = new Xop_para_wkr();
|
||||
public Xop_list_wkr List() {return list;} private Xop_list_wkr list = new Xop_list_wkr();
|
||||
public Xop_tblw_wkr Tblw() {return tblw;} private Xop_tblw_wkr tblw = new Xop_tblw_wkr();
|
||||
public Xop_xnde_wkr Xnde() {return xnde;} private Xop_xnde_wkr xnde = new Xop_xnde_wkr();
|
||||
public Xot_invk_wkr Invk() {return invk;} private Xot_invk_wkr invk = new Xot_invk_wkr();
|
||||
public Xop_curly_wkr Curly() {return curly;} private Xop_curly_wkr curly = new Xop_curly_wkr();
|
||||
public Xop_amp_wkr Amp() {return amp;} private final Xop_amp_wkr amp = new Xop_amp_wkr();
|
||||
public Xop_apos_wkr Apos() {return apos;} private final Xop_apos_wkr apos = new Xop_apos_wkr();
|
||||
public Xop_lnke_wkr Lnke() {return lnke;} private final Xop_lnke_wkr lnke = new Xop_lnke_wkr();
|
||||
public Xop_lnki_wkr Lnki() {return lnki;} private final Xop_lnki_wkr lnki = new Xop_lnki_wkr();
|
||||
public Xop_hdr_wkr Hdr() {return hdr;} private final Xop_hdr_wkr hdr = new Xop_hdr_wkr();
|
||||
public Xop_para_wkr Para() {return para;} private final Xop_para_wkr para = new Xop_para_wkr();
|
||||
public Xop_list_wkr List() {return list;} private final Xop_list_wkr list = new Xop_list_wkr();
|
||||
public Xop_tblw_wkr Tblw() {return tblw;} private final Xop_tblw_wkr tblw = new Xop_tblw_wkr();
|
||||
public Xop_xnde_wkr Xnde() {return xnde;} private final Xop_xnde_wkr xnde = new Xop_xnde_wkr();
|
||||
public Xot_invk_wkr Invk() {return invk;} private final Xot_invk_wkr invk = new Xot_invk_wkr();
|
||||
public Xop_curly_wkr Curly() {return curly;} private final Xop_curly_wkr curly = new Xop_curly_wkr();
|
||||
public Xop_xnde_tag_regy Xnde_tag_regy() {return xnde_tag_regy;} private final Xop_xnde_tag_regy xnde_tag_regy; // PERF:demeter
|
||||
|
||||
public boolean Tmpl_load_enabled() {return tmpl_load_enabled;} public void Tmpl_load_enabled_(boolean v) {tmpl_load_enabled = v;} private boolean tmpl_load_enabled = true;
|
||||
@@ -264,18 +266,18 @@ public class Xop_ctx {
|
||||
int src_len = src.length;
|
||||
switch (tkn.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_newLine: break; // NOOP: just a marker
|
||||
case Xop_tkn_itm_.Tid_list: list.AutoClose(this, app.Tkn_mkr(), root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_list: list.AutoClose(this, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_xnde: xnde.AutoClose(this, root, src, src_len, bgn_pos, cur_pos, tkn, closing_tkn_tid); break;
|
||||
case Xop_tkn_itm_.Tid_apos: apos.AutoClose(this, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnke: lnke.AutoClose(this, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_hdr: hdr.AutoClose(this, app.Tkn_mkr(), root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_hdr: hdr.AutoClose(this, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tb:
|
||||
case Xop_tkn_itm_.Tid_tblw_tr:
|
||||
case Xop_tkn_itm_.Tid_tblw_td:
|
||||
case Xop_tkn_itm_.Tid_tblw_th:
|
||||
case Xop_tkn_itm_.Tid_tblw_tc: tblw.AutoClose(this, root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnki: lnki.Auto_close(this, app.Tkn_mkr(), root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_pre: para.AutoClose(this, app.Tkn_mkr(), root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnki: lnki.Auto_close(this, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
case Xop_tkn_itm_.Tid_pre: para.AutoClose(this, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, tkn); break;
|
||||
}
|
||||
}
|
||||
public void Stack_pop_idx(int tilIdx) {
|
||||
@@ -304,9 +306,9 @@ public class Xop_ctx {
|
||||
Xop_ctx rv = new Xop_ctx(wiki, Xoae_page.new_(wiki, Xoa_ttl.parse(wiki, Xoa_page_.Main_page_bry))); // HACK: use "Main_Page" to put in valid page title
|
||||
return rv;
|
||||
}
|
||||
public static Xop_ctx new_sub_(Xowe_wiki wiki) {return new_sub_(wiki, wiki.Ctx().cur_page);}
|
||||
public static Xop_ctx new_sub_(Xowe_wiki wiki) {return new_sub_(wiki, wiki.Parser_mgr().Ctx().cur_page);}
|
||||
public static Xop_ctx new_sub_(Xowe_wiki wiki, Xoae_page page) { // TODO: new_sub_ should reuse ctx's page; callers who want new_page should call new_sub_page_; DATE:2014-04-10
|
||||
Xop_ctx ctx = wiki.Ctx();
|
||||
Xop_ctx ctx = wiki.Parser_mgr().Ctx();
|
||||
Xop_ctx rv = new Xop_ctx(wiki, page);
|
||||
new_copy(ctx, rv);
|
||||
return rv;
|
||||
|
||||
@@ -16,10 +16,11 @@ 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; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public interface Xop_lxr {
|
||||
byte Lxr_tid();
|
||||
void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie);
|
||||
void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie);
|
||||
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 Lxr_tid();
|
||||
void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie);
|
||||
void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie);
|
||||
void Term(Btrie_fast_mgr core_trie);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
|
||||
public class Xop_lxr_ {
|
||||
public static final byte
|
||||
public static final int
|
||||
Tid_pipe = 0, Tid_space = 1, Tid_nbsp = 2, Tid_tab = 3, Tid_nl = 4, Tid_amp = 5, Tid_apos = 6, Tid_colon = 7, Tid_lnki_bgn = 8, Tid_lnki_end = 9
|
||||
, Tid_list = 10, Tid_hdr = 11, Tid_hr = 12, Tid_xnde = 13, Tid_lnke_bgn = 14, Tid_lnke_end = 15, Tid_tblw = 16, Tid_pre = 17, Tid_under = 18, Tid_comment = 19
|
||||
, Tid_eq = 20, Tid_curly_bgn = 21, Tid_curly_end = 22, Tid_brack_bgn = 23, Tid_brack_end = 24, Tid_poem = 25
|
||||
, Tid_tvar = 26, Tid_vnt_bgn = 27, Tid_vnt_end = 28, Tid_vnt_eqgt = 29, Tid_vnt_tmpl_bgn = 30, Tid_word = 31, Tid_nl_poem = 32, Tid_cr = 33
|
||||
, Tid_brack_end_lnki = 34, Tid_nl_tab = 35
|
||||
, Tid_brack_end_lnki = 34, Tid_nl_tab = 35, Tid_macro = 36
|
||||
;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xop_lxr_mgr {
|
||||
private Xop_lxr[] ary;
|
||||
private final Xop_lxr[] ary;
|
||||
private final List_adp page_lxr_list = List_adp_.new_();
|
||||
public Xop_lxr_mgr(Xop_lxr[] ary) {this.ary = ary;}
|
||||
public Btrie_fast_mgr Trie() {return trie;} private Btrie_fast_mgr trie = Btrie_fast_mgr.cs();
|
||||
public Btrie_fast_mgr Trie() {return trie;} private final Btrie_fast_mgr trie = Btrie_fast_mgr.cs();
|
||||
public void Page__add(Xowe_wiki wiki, Xop_lxr... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xop_lxr lxr = ary[i];
|
||||
lxr.Init_by_wiki(wiki, trie);
|
||||
page_lxr_list.Add(lxr);
|
||||
}
|
||||
}
|
||||
public void Page__del_all() {
|
||||
int len = page_lxr_list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xop_lxr lxr = (Xop_lxr)page_lxr_list.Get_at(i);
|
||||
lxr.Term(trie);
|
||||
}
|
||||
}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
@@ -64,6 +81,17 @@ public class Xop_lxr_mgr {
|
||||
, Xop_under_lxr._
|
||||
});
|
||||
}
|
||||
public static Xop_lxr_mgr new_anchor_encoder() {
|
||||
return new Xop_lxr_mgr(new Xop_lxr[]
|
||||
{ Xop_pipe_lxr._, new Xop_eq_lxr(false), Xop_space_lxr._, Xop_tab_lxr._, Xop_nl_lxr._
|
||||
, Xop_curly_bgn_lxr._, Xop_curly_end_lxr._
|
||||
, Xop_amp_lxr._, Xop_colon_lxr._
|
||||
, Xop_apos_lxr._
|
||||
, Xop_lnki_lxr_bgn._, Xop_lnki_lxr_end._
|
||||
, Xop_lnke_lxr._, Xop_lnke_end_lxr._
|
||||
, Xop_xnde_lxr._
|
||||
});
|
||||
}
|
||||
public static final Xop_lxr_mgr Popup_lxr_mgr // same as orig_page, except apos_lxr added
|
||||
= new Xop_lxr_mgr(new Xop_lxr[]
|
||||
{ Xop_pipe_lxr._, new Xop_eq_lxr(true), Xop_colon_lxr._, Xop_space_lxr._, Xop_tab_lxr._, Xop_nl_lxr._
|
||||
|
||||
@@ -17,18 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.nss.*;
|
||||
import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_parser { // NOTE: parsers are reused; do not keep any read-write state
|
||||
private Xowe_wiki wiki;
|
||||
public Xop_parser(Xowe_wiki wiki, Xop_lxr_mgr tmpl_lxr_mgr, Xop_lxr_mgr wtxt_lxr_mgr) {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Btrie_fast_mgr tmpl_trie, wtxt_trie;
|
||||
Xop_parser(Xowe_wiki wiki, Xop_lxr_mgr tmpl_lxr_mgr, Xop_lxr_mgr wtxt_lxr_mgr) {
|
||||
this.wiki = wiki;
|
||||
this.tmpl_lxr_mgr = tmpl_lxr_mgr; this.tmpl_trie = tmpl_lxr_mgr.Trie();
|
||||
this.wtxt_lxr_mgr = wtxt_lxr_mgr; this.wtxt_trie = wtxt_lxr_mgr.Trie();
|
||||
}
|
||||
public Xop_lxr_mgr Tmpl_lxr_mgr() {return tmpl_lxr_mgr;} private Xop_lxr_mgr tmpl_lxr_mgr;
|
||||
public Xop_lxr_mgr Wtxt_lxr_mgr() {return wtxt_lxr_mgr;} private Xop_lxr_mgr wtxt_lxr_mgr;
|
||||
public Btrie_fast_mgr Tmpl_trie() {return tmpl_trie;} private Btrie_fast_mgr tmpl_trie;
|
||||
public Btrie_fast_mgr Wtxt_trie() {return wtxt_trie;} private Btrie_fast_mgr wtxt_trie;
|
||||
public Xop_lxr_mgr Tmpl_lxr_mgr() {return tmpl_lxr_mgr;} private final Xop_lxr_mgr tmpl_lxr_mgr;
|
||||
public Xop_lxr_mgr Wtxt_lxr_mgr() {return wtxt_lxr_mgr;} private final Xop_lxr_mgr wtxt_lxr_mgr;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
tmpl_lxr_mgr.Init_by_wiki(wiki);
|
||||
wtxt_lxr_mgr.Init_by_wiki(wiki);
|
||||
@@ -38,7 +38,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
wtxt_lxr_mgr.Init_by_lang(lang);
|
||||
}
|
||||
public byte[] Parse_text_to_html(Xop_ctx ctx, byte[] src) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
|
||||
Parse_text_to_html(bfr, ctx.Cur_page(), false, src);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
Xop_ctx ctx = Xop_ctx.new_sub_(wiki, page);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn root = tkn_mkr.Root(src);
|
||||
Xop_parser parser = wiki.Parser();
|
||||
Xop_parser parser = wiki.Parser_mgr().Main();
|
||||
byte[] wtxt = parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, src);
|
||||
root.Reset();
|
||||
ctx.Para().Enabled_(para_enabled);
|
||||
@@ -64,7 +64,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
tmpl_props.OnlyInclude_exists = false; int subs_len = root.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
root.Subs_get(i).Tmpl_compile(ctx, src, tmpl_props);
|
||||
boolean only_include_chk = Bry_finder.Find_fwd(src, Xop_xnde_tag_.Name_onlyinclude, 0, src.length) != Bry_.NotFound;
|
||||
boolean only_include_chk = Bry_find_.Find_fwd(src, Xop_xnde_tag_.Name_onlyinclude, 0, src.length) != Bry_.NotFound;
|
||||
if (only_include_chk) tmpl_props.OnlyInclude_exists = true;
|
||||
tmpl.Init_by_new(ns, name, src, root, tmpl_props.OnlyInclude_exists);
|
||||
} private Xot_compile_data tmpl_props = new Xot_compile_data();
|
||||
@@ -94,7 +94,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
Xop_ctx ctx = Xop_ctx.new_sub_(wiki);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn root = tkn_mkr.Root(src);
|
||||
return wiki.Parser().Parse_text_to_wtxt(root, ctx, tkn_mkr, src);
|
||||
return wiki.Parser_mgr().Main().Parse_text_to_wtxt(root, ctx, tkn_mkr, src);
|
||||
}
|
||||
public byte[] Parse_text_to_wtxt(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src) {
|
||||
Parse(root, ctx, tkn_mkr, src, Xop_parser_.Parse_tid_page_tmpl, tmpl_trie, Xop_parser_.Doc_bgn_bos);
|
||||
@@ -138,7 +138,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
return pos;
|
||||
}
|
||||
public int Parse_to_stack_end(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, Btrie_fast_mgr trie, int pos, int end) {
|
||||
byte b = pos == -1 ? Byte_ascii.Nl : src[pos]; // simulate newLine at bgn of src; needed for lxrs which rely on \n (EX: "=a=")
|
||||
byte b = pos == -1 ? Byte_ascii.Nl : src[pos]; // simulate \n at bgn of src; needed for lxrs which rely on \n (EX: "=a=")
|
||||
int txt_bgn = pos == -1 ? 0 : pos; Xop_tkn_itm txt_tkn = null;
|
||||
Xop_lxr lxr = null;
|
||||
while (true) {
|
||||
@@ -191,7 +191,8 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
tkn.Src_end_(pos);
|
||||
return tkn;
|
||||
}
|
||||
public static Xop_parser new_wiki_(Xowe_wiki wiki) {
|
||||
public static Xop_parser new_(Xowe_wiki wiki, Xop_lxr_mgr tmpl_lxr_mgr, Xop_lxr_mgr wtxt_lxr_mgr) {return new Xop_parser(wiki, tmpl_lxr_mgr, wtxt_lxr_mgr);}
|
||||
public static Xop_parser new_wiki(Xowe_wiki wiki) {
|
||||
Xop_parser rv = new Xop_parser(wiki, Xop_lxr_mgr.new_tmpl_(), Xop_lxr_mgr.new_wiki_());
|
||||
rv.Init_by_wiki(wiki);
|
||||
rv.Init_by_lang(wiki.Lang());
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Xop_parser_ {
|
||||
Xop_ctx ctx = Xop_ctx.new_sub_(wiki, page);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn root = tkn_mkr.Root(src);
|
||||
Xop_parser parser = wiki.Parser();
|
||||
Xop_parser parser = wiki.Parser_mgr().Main();
|
||||
byte[] wtxt = parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, src);
|
||||
root.Reset();
|
||||
ctx.Para().Enabled_(para_enabled);
|
||||
|
||||
@@ -52,7 +52,7 @@ class Xop_parser__fxt {
|
||||
}
|
||||
public void Test_parse_to_html(String raw, boolean para_enabled, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
fxt.Wiki().Parser().Parse_text_to_html(bfr, fxt.Page(), para_enabled, raw_bry);
|
||||
fxt.Wiki().Parser_mgr().Main().Parse_text_to_html(bfr, fxt.Page(), para_enabled, raw_bry);
|
||||
Tfds.Eq(expd, bfr.Xto_str_and_clear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tkn_chkr_base implements Tst_chkr {
|
||||
@gplx.Virtual public Class<?> TypeOf() {return Xop_tkn_itm.class;}
|
||||
@gplx.Virtual public byte Tkn_tid() {return Byte_.Max_value_127;}
|
||||
|
||||
@@ -16,19 +16,17 @@ 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; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.vnts.*;
|
||||
public class Xop_tkn_mkr {
|
||||
Xop_space_tkn space_tkn_immutable = new Xop_space_tkn(true, -1, -1);
|
||||
public Xop_root_tkn Root(byte[] raw) {return new Xop_root_tkn().Root_src_(raw);}
|
||||
public Xop_txt_tkn Txt(int bgn, int end) {return new Xop_txt_tkn(bgn, end);}
|
||||
// public Xop_space_tkn Space(Xop_tkn_grp grp, int bgn, int end) {grp.Subs_src_pos_(grp.Subs_len(), bgn, end); return space_tkn_immutable;}
|
||||
public Xop_space_tkn Space(Xop_tkn_grp grp, int bgn, int end) {Xop_space_tkn rv = new Xop_space_tkn(false, bgn, end); grp.Subs_src_pos_(grp.Subs_len(), bgn, end); return rv;}
|
||||
public Xop_space_tkn Space_mutable(int bgn, int end) {return new Xop_space_tkn(false, bgn, end);}
|
||||
public Xop_apos_tkn Apos(int bgn, int end
|
||||
, int aposLen, int typ, int cmd, int lit_apos) {return new Xop_apos_tkn(bgn, end, aposLen, typ, cmd, lit_apos);}
|
||||
public Xop_tkn_itm Amp_txt(int bgn, int end, Xop_amp_trie_itm itm) {return new Xop_amp_tkn_txt(bgn, end, itm);}
|
||||
public Xop_tkn_itm Amp_num(int bgn, int end, int val_int, byte[] val_bry) {return new Xop_amp_tkn_num(bgn, end, val_int, val_bry);}
|
||||
public Xop_tkn_itm Amp_num(int bgn, int end, int val_int) {return new Xop_amp_tkn_num(bgn, end, val_int, gplx.intl.Utf16_.Encode_int_to_bry(val_int));}
|
||||
public Xop_tkn_itm Amp_num(int bgn, int end, int val_int) {return new Xop_amp_tkn_num(bgn, end, val_int, gplx.core.intls.Utf16_.Encode_int_to_bry(val_int));}
|
||||
public Xop_nl_tkn NewLine(int bgn, int end, byte nl_typ, int nl_len) {return new Xop_nl_tkn(bgn, end, nl_typ, nl_len);}
|
||||
public Xop_lnki_tkn Lnki(int bgn, int end) {return (Xop_lnki_tkn)new Xop_lnki_tkn().Tkn_ini_pos(false, bgn, end);}
|
||||
public Xop_list_tkn List_bgn(int bgn, int end, byte listType, int symLen) {return Xop_list_tkn.bgn_(bgn, end, listType, symLen);}
|
||||
@@ -91,9 +89,8 @@ public class Xop_tkn_mkr {
|
||||
public gplx.xowa.xtns.translates.Xop_languages_xnde Xnde_languages() {return new gplx.xowa.xtns.translates.Xop_languages_xnde();}
|
||||
public gplx.xowa.xtns.translates.Xop_tvar_tkn Tvar(int tkn_bgn, int tkn_end, int key_bgn, int key_end, int txt_bgn, int txt_end, byte[] wikitext)
|
||||
{return new gplx.xowa.xtns.translates.Xop_tvar_tkn(tkn_bgn, tkn_end, key_bgn, key_end, txt_bgn, txt_end, wikitext);}
|
||||
public gplx.xowa.langs.vnts.Xop_vnt_tkn Vnt(int bgn_lhs, int bgn_rhs) {return new gplx.xowa.langs.vnts.Xop_vnt_tkn(bgn_lhs, bgn_rhs);}
|
||||
public gplx.xowa.langs.vnts.Xop_vnt_eqgt_tkn Vnt_eqgt(int bgn, int end) {return new gplx.xowa.langs.vnts.Xop_vnt_eqgt_tkn(bgn, end);}
|
||||
|
||||
public Xop_vnt_tkn Vnt(int bgn_lhs, int bgn_rhs) {return new Xop_vnt_tkn(bgn_lhs, bgn_rhs);}
|
||||
public Xop_vnt_eqgt_tkn Vnt_eqgt(int bgn, int end) {return new Xop_vnt_eqgt_tkn(bgn, end);}
|
||||
// public void Clear() {
|
||||
// space_tkns_len = txt_tkns_len = 0;
|
||||
// }
|
||||
|
||||
50
400_xowa/src/gplx/xowa/parsers/Xow_parser_mgr.java
Normal file
50
400_xowa/src/gplx/xowa/parsers/Xow_parser_mgr.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Xow_parser_mgr {
|
||||
private final Xowe_wiki wiki; private final Xop_tkn_mkr tkn_mkr;
|
||||
private Xop_parser anchor_encode_parser;
|
||||
public Xow_parser_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki; this.tkn_mkr = wiki.Appe().Parser_mgr().Tkn_mkr();
|
||||
this.ctx = Xop_ctx.new_(wiki);
|
||||
this.main = Xop_parser.new_wiki(wiki);
|
||||
}
|
||||
public Xop_ctx Ctx() {return ctx;} private final Xop_ctx ctx;
|
||||
public Xop_parser Main() {return main;} private final Xop_parser main;
|
||||
public Xop_parser Anchor_encoder() {
|
||||
if (anchor_encode_parser == null) {
|
||||
anchor_encode_parser = Xop_parser.new_(wiki, wiki.Parser_mgr().Main().Tmpl_lxr_mgr(), Xop_lxr_mgr.new_anchor_encoder());
|
||||
anchor_encode_parser.Init_by_wiki(wiki);
|
||||
anchor_encode_parser.Init_by_lang(wiki.Lang());
|
||||
}
|
||||
return anchor_encode_parser;
|
||||
}
|
||||
public void Parse(Xoae_page page, boolean clear) {
|
||||
if (!Env_.Mode_testing()) wiki.Init_assert();
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
|
||||
ctx.Cur_page_(page);
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
|
||||
if (clear) {page.Clear();}
|
||||
Xoa_ttl ttl = page.Ttl();
|
||||
if (Xow_page_tid.Identify(wiki.Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
|
||||
main.Parse_text_to_wdom(root, ctx, tkn_mkr, page.Data_raw(), Xop_parser_.Doc_bgn_bos);
|
||||
page.Root_(root);
|
||||
root.Data_htm_(root.Root_src());
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xow_utl_mgr {
|
||||
public Xow_utl_mgr(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public Xop_parser Anchor_encode_parser() {
|
||||
if (anchor_encode_parser == null) {
|
||||
anchor_encode_parser = new Xop_parser(wiki, wiki.Parser().Tmpl_lxr_mgr(), Anchor_encode_lxr_mgr);
|
||||
anchor_encode_parser.Init_by_wiki(wiki);
|
||||
anchor_encode_parser.Init_by_lang(wiki.Lang());
|
||||
}
|
||||
return anchor_encode_parser;
|
||||
} private Xop_parser anchor_encode_parser;
|
||||
private static final Xop_lxr_mgr Anchor_encode_lxr_mgr
|
||||
= new Xop_lxr_mgr(new Xop_lxr[]
|
||||
{ Xop_pipe_lxr._, new Xop_eq_lxr(false), Xop_space_lxr._, Xop_tab_lxr._, Xop_nl_lxr._
|
||||
, Xop_curly_bgn_lxr._, Xop_curly_end_lxr._
|
||||
, Xop_amp_lxr._, Xop_colon_lxr._
|
||||
, Xop_apos_lxr._
|
||||
, Xop_lnki_lxr_bgn._, Xop_lnki_lxr_end._
|
||||
, Xop_lnke_lxr._, Xop_lnke_end_lxr._
|
||||
, Xop_xnde_lxr._
|
||||
});
|
||||
}
|
||||
@@ -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.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xop_amp_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_amp;}
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_amp_lxr implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_amp;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Amp, 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) {
|
||||
return ctx.Amp().Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ public class Xop_amp_mgr {
|
||||
rslt_pos = amp_pos + 1; // default to fail pos; after amp;
|
||||
rslt_val = -1; // clear any previous setting
|
||||
int cur_pos = int_bgn, int_end = -1;
|
||||
int semic_pos = Bry_finder.Find_fwd(src, Byte_ascii.Semic, cur_pos, src_len);
|
||||
if (semic_pos == Bry_finder.Not_found) return false;
|
||||
int semic_pos = Bry_find_.Find_fwd(src, Byte_ascii.Semic, cur_pos, src_len);
|
||||
if (semic_pos == Bry_find_.Not_found) return false;
|
||||
int_end = semic_pos - 1; // int_end = pos before semicolon
|
||||
int multiple = ncr_is_hex ? 16 : 10, val = 0, factor = 1, cur = 0;
|
||||
for (int i = int_end; i >= int_bgn; i--) {
|
||||
@@ -64,7 +64,7 @@ public class Xop_amp_mgr {
|
||||
if (cur < 0 || cur > 10) return false;
|
||||
}
|
||||
val += cur * factor;
|
||||
if (val > gplx.intl.Utf8_.Codepoint_max) return false; // fail if value > largest_unicode_codepoint
|
||||
if (val > gplx.core.intls.Utf8_.Codepoint_max) return false; // fail if value > largest_unicode_codepoint
|
||||
factor *= multiple;
|
||||
}
|
||||
rslt_val = val;
|
||||
|
||||
@@ -16,12 +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.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.html.*; import gplx.xowa.html.lnkis.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.html.lnkis.*;
|
||||
public class Xop_amp_trie_itm {
|
||||
public Xop_amp_trie_itm(byte tid, int char_int, byte[] xml_name_bry) {
|
||||
this.tid = tid;
|
||||
this.char_int = char_int;
|
||||
this.u8_bry = gplx.intl.Utf16_.Encode_int_to_bry(char_int);
|
||||
this.u8_bry = gplx.core.intls.Utf16_.Encode_int_to_bry(char_int);
|
||||
this.xml_name_bry = xml_name_bry;
|
||||
this.key_name_len = xml_name_bry.length - 2; // 2 for & and ;
|
||||
}
|
||||
|
||||
@@ -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.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_html_num_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_amp_tkn_num.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_html_ncr;}
|
||||
|
||||
@@ -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.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_html_txt_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_amp_tkn_txt.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_html_ref;}
|
||||
|
||||
@@ -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.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_apos_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_apos;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_apos;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Apos_ary, this);} private static final byte[] Apos_ary = new byte[] {Byte_ascii.Apos, Byte_ascii.Apos};
|
||||
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.Apos().Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
|
||||
public static final Xop_apos_lxr _ = new Xop_apos_lxr(); Xop_apos_lxr() {}
|
||||
}
|
||||
|
||||
@@ -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.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_apos_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_apos_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_apos;}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Xop_apos_wkr implements Xop_ctx_wkr {
|
||||
public void AutoClose(Xop_ctx ctx, byte[] src, int src_len, int bgn_pos, int cur_pos, Xop_tkn_itm tkn) {}
|
||||
public int Stack_len() {return stack.Count();}
|
||||
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) {
|
||||
cur_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Apos);
|
||||
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Apos);
|
||||
int apos_len = cur_pos - bgn_pos;
|
||||
dat.Ident(ctx, src, apos_len, cur_pos);
|
||||
Xop_apos_tkn apos_tkn = tkn_mkr.Apos(bgn_pos, cur_pos, apos_len, dat.Typ(), dat.Cmd(), dat.Lit_apos());
|
||||
|
||||
@@ -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.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xop_hdr_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_hdr;}
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_hdr_lxr implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_hdr;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook_bgn, this);} static final byte[] Hook_bgn = new byte[] {Byte_ascii.Nl, Byte_ascii.Eq};
|
||||
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.Hdr().Make_tkn_bgn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
|
||||
public static final Xop_hdr_lxr _ = new Xop_hdr_lxr(); Xop_hdr_lxr() {}
|
||||
public static final byte Hook = Byte_ascii.Eq;
|
||||
|
||||
@@ -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.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_hdr_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_hdr_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
|
||||
ctx.Apos().EndFrame(ctx, root, src, bgn_pos, false);
|
||||
Close_open_itms(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);
|
||||
ctx.Para().Process_block__bgn__nl_w_symbol(ctx, root, src, bgn_pos, cur_pos, Xop_xnde_tag_.Tag_h2); // pass h2; should pass h# where # is correct #, but for purpose of Para_wkr, <h2> tag does not matter
|
||||
int new_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Xop_hdr_lxr.Hook); // count all =
|
||||
int new_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Xop_hdr_lxr.Hook); // count all =
|
||||
int hdr_len = new_pos - cur_pos + 1; // +1 b/c Hook has 1 eq: "\n="
|
||||
switch (hdr_len) {
|
||||
case 1: ctx.Msg_log().Add_itm_none(Xop_hdr_log.Len_1, src, bgn_pos, new_pos); break; // <h1>; flag
|
||||
|
||||
61
400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr.java
Normal file
61
400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.strings.*;
|
||||
public class HierPosAryBldr {
|
||||
public void Init() {
|
||||
int ary_max = ary.length;
|
||||
for (int i = 0; i < ary_max; i++)
|
||||
ary[i] = 0;
|
||||
aryIdx = -1;
|
||||
root = 0;
|
||||
}
|
||||
public void MoveDown() {
|
||||
aryIdx += 1;
|
||||
if (aryIdx == 0)
|
||||
ary[aryIdx] = root;
|
||||
else
|
||||
ary[aryIdx] = 0;
|
||||
}
|
||||
public void MoveUp() {
|
||||
aryIdx -= 1;
|
||||
MoveNext();
|
||||
}
|
||||
public void MoveNext() {
|
||||
if (aryIdx == -1)
|
||||
root += 1;
|
||||
else
|
||||
ary[aryIdx] += 1;
|
||||
}
|
||||
public boolean Dirty() {return aryIdx > -1 || root > 0;}
|
||||
public int[] XtoIntAry() {
|
||||
if (aryIdx == -1) return Int_.Ary_empty;
|
||||
int[] rv = new int[aryIdx + 1];
|
||||
for (int i = 0; i < aryIdx + 1; i++)
|
||||
rv[i] = ary[i];
|
||||
return rv;
|
||||
}
|
||||
public String To_str() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < aryIdx; i++)
|
||||
sb.Add_spr_unless_first(Int_.Xto_str(ary[i]), " ", i);
|
||||
return sb.To_str();
|
||||
}
|
||||
int[] ary; int aryIdx = -1; int root = -1;
|
||||
public HierPosAryBldr(int ary_max) {ary = new int[ary_max]; this.Init();}
|
||||
}
|
||||
65
400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr_tst.java
Normal file
65
400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr_tst.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
public class HierPosAryBldr_tst {
|
||||
@Before public void init() {bldr.Init();} HierPosAryBldr bldr = new HierPosAryBldr(256);
|
||||
@Test public void Basic() {
|
||||
tst_ary(Int_.Ary_empty);
|
||||
}
|
||||
@Test public void Move_d() {
|
||||
bldr.MoveDown();
|
||||
tst_ary(0);
|
||||
}
|
||||
@Test public void Move_dd() {
|
||||
bldr.MoveDown();
|
||||
bldr.MoveDown();
|
||||
tst_ary(0, 0);
|
||||
}
|
||||
@Test public void Move_ddu() {
|
||||
bldr.MoveDown();
|
||||
bldr.MoveDown();
|
||||
bldr.MoveUp();
|
||||
tst_ary(1);
|
||||
}
|
||||
@Test public void Move_ddud() {
|
||||
bldr.MoveDown();
|
||||
bldr.MoveDown();
|
||||
bldr.MoveUp();
|
||||
bldr.MoveDown();
|
||||
tst_ary(1, 0);
|
||||
}
|
||||
@Test public void Move_dud() {
|
||||
bldr.MoveDown();
|
||||
bldr.MoveUp();
|
||||
bldr.MoveDown();
|
||||
tst_ary(1);
|
||||
}
|
||||
@Test public void Move_dn() {
|
||||
bldr.MoveDown();
|
||||
bldr.MoveNext();
|
||||
tst_ary(1);
|
||||
}
|
||||
@Test public void Move_ddn() {
|
||||
bldr.MoveDown();
|
||||
bldr.MoveDown();
|
||||
bldr.MoveNext();
|
||||
tst_ary(0, 1);
|
||||
}
|
||||
private void tst_ary(int... expd) {Tfds.Eq_ary(expd, bldr.XtoIntAry());}
|
||||
}
|
||||
@@ -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.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_colon_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_colon;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_colon;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Colon, 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_list_wkr listCtx = ctx.List();
|
||||
if (listCtx.Dd_chk()) { // handle ";a:b" construct; REF.MW: Parser.php|doBlockLevels|; title : definition text
|
||||
|
||||
@@ -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.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xop_list_lxr implements Xop_lxr {//20111222
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_list;}
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_list_lxr implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_list;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {Add_ary(core_trie, this, Xop_list_tkn_.Hook_ul, Xop_list_tkn_.Hook_ol, Xop_list_tkn_.Hook_dt, Xop_list_tkn_.Hook_dd);}
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
|
||||
public void Term(Btrie_fast_mgr core_trie) {}
|
||||
private void Add_ary(Btrie_fast_mgr core_trie, Object val, byte[]... ary) {for (byte[] itm : ary) core_trie.Add(itm, val);}
|
||||
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.List().MakeTkn_bgn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
|
||||
public static final Xop_list_lxr _ = new Xop_list_lxr(); Xop_list_lxr() {}
|
||||
|
||||
@@ -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.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_list_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_list_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_list;}
|
||||
|
||||
@@ -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.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.net.*;
|
||||
import gplx.core.net.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.hrefs.*;
|
||||
import gplx.xowa.urls.*;
|
||||
public class Xoh_lnke_wtr {
|
||||
|
||||
@@ -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.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xop_lnke_end_lxr implements Xop_lxr {//20111222
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_lnke_end;}
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_lnke_end_lxr implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_lnke_end;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Brack_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) {return ctx.Lnke().MakeTkn_end(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
|
||||
public static final Xop_lnke_end_lxr _ = new Xop_lnke_end_lxr(); Xop_lnke_end_lxr() {}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ 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.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.core.net.*;
|
||||
public class Xop_lnke_lxr implements Xop_lxr {
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.core.net.*;
|
||||
public class Xop_lnke_lxr implements Xop_lxr {
|
||||
Xop_lnke_lxr(byte lnke_typ, byte[] protocol, byte tid) {this.lnke_typ = lnke_typ; this.protocol = protocol; this.tid = tid;} private byte lnke_typ; byte[] protocol; byte tid;
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_lnke_bgn;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_lnke_bgn;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {
|
||||
Gfo_protocol_itm[] ary = Gfo_protocol_itm.Ary();
|
||||
int ary_len = ary.length;
|
||||
@@ -32,6 +33,7 @@ public class Xop_lnke_lxr implements Xop_lxr {
|
||||
Ctor_lxr_add(core_trie, Bry_.new_a7("xowa-cmd"), Gfo_protocol_itm.Tid_xowa);
|
||||
} private static final byte[] Bry_relative_1 = Bry_.new_a7("[//"), Bry_relative_2 = Bry_.new_a7("[[//");
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
|
||||
public void Term(Btrie_fast_mgr core_trie) {}
|
||||
private void Ctor_lxr_add(Btrie_fast_mgr core_trie, byte[] protocol_bry, byte tid) {
|
||||
core_trie.Add(protocol_bry , new Xop_lnke_lxr(Xop_lnke_tkn.Lnke_typ_text, protocol_bry, tid));
|
||||
core_trie.Add(Bry_.Add(Byte_ascii.Brack_bgn, protocol_bry) , new Xop_lnke_lxr(Xop_lnke_tkn.Lnke_typ_brack, protocol_bry, tid));
|
||||
|
||||
@@ -220,8 +220,8 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
|
||||
break;
|
||||
case Byte_ascii.Paren_end: // differentiate between "(http://a.org)" (trim) and "http://a.org/b(c)" (don't trim)
|
||||
if (paren_bgn_chk == Bool_.__byte) {
|
||||
int paren_bgn_pos = Bry_finder.Find_fwd(src, Byte_ascii.Paren_bgn, proto_end, lnke_end);
|
||||
paren_bgn_chk = paren_bgn_pos == Bry_finder.Not_found ? Bool_.N_byte : Bool_.Y_byte;
|
||||
int paren_bgn_pos = Bry_find_.Find_fwd(src, Byte_ascii.Paren_bgn, proto_end, lnke_end);
|
||||
paren_bgn_chk = paren_bgn_pos == Bry_find_.Not_found ? Bool_.N_byte : Bool_.Y_byte;
|
||||
}
|
||||
if (paren_bgn_chk == Bool_.Y_byte) // "(" found; do not ignore ")"
|
||||
return rv;
|
||||
@@ -274,7 +274,7 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
|
||||
return false; // alpha-numerical is invalid; EX: "titel:" should not generate a lnke for "tel:"
|
||||
}
|
||||
if (prv_byte >= Byte_ascii.Ascii_min && prv_byte <= Byte_ascii.Ascii_max) return true; // consider all other ASCII chars as true; EX: \t\n !, etc;
|
||||
prv_pos = gplx.intl.Utf8_.Get_pos0_of_char_bwd(src, prv_pos);
|
||||
prv_pos = gplx.core.intls.Utf8_.Get_pos0_of_char_bwd(src, prv_pos);
|
||||
prv_byte = src[prv_pos];
|
||||
boolean prv_char_is_letter = ctx.Lang().Case_mgr().Match_any_exists(prv_byte, src, prv_pos, bgn_pos);
|
||||
return !prv_char_is_letter;
|
||||
@@ -283,7 +283,7 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
|
||||
// NOTE: fmt is [xowa-cmd:^"app.setup_mgr.import_wiki('');"^ ]
|
||||
if (lnke_type != Xop_lnke_tkn.Lnke_typ_brack) return ctx.Lxr_make_txt_(cur_pos); // NOTE: must check for [ or else C:\xowa\ will cause it to evaluate as lnke
|
||||
int proto_end_pos = cur_pos + 1; // +1 to skip past :
|
||||
int lhs_dlm_pos = Bry_finder.Find_fwd(src, Byte_ascii.Quote, proto_end_pos, src_len); if (lhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int lhs_dlm_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, proto_end_pos, src_len); if (lhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int lnke_bgn_pos = lhs_dlm_pos + 1;
|
||||
byte[] rhs_dlm_bry = Bry_quote;
|
||||
if (lhs_dlm_pos - proto_end_pos > 0) {
|
||||
@@ -291,9 +291,9 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
|
||||
rhs_dlm_bry = bfr.Add(Bry_quote).Add_mid(src, proto_end_pos, lhs_dlm_pos).Xto_bry_and_clear();
|
||||
bfr.Mkr_rls();
|
||||
}
|
||||
int rhs_dlm_pos = Bry_finder.Find_fwd(src, rhs_dlm_bry, lnke_bgn_pos, src_len); if (rhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int txt_bgn = Bry_finder.Find_fwd_while_space_or_tab(src, rhs_dlm_pos + rhs_dlm_bry.length, src_len); if (txt_bgn == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int txt_end = Bry_finder.Find_fwd(src, Byte_ascii.Brack_end, txt_bgn, src_len); if (txt_end == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int rhs_dlm_pos = Bry_find_.Find_fwd(src, rhs_dlm_bry, lnke_bgn_pos, src_len); if (rhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int txt_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, rhs_dlm_pos + rhs_dlm_bry.length, src_len); if (txt_bgn == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
int txt_end = Bry_find_.Find_fwd(src, Byte_ascii.Brack_end, txt_bgn, src_len); if (txt_end == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
|
||||
int end_pos = txt_end + 1; // +1 to place after ]
|
||||
Xop_lnke_tkn tkn = tkn_mkr.Lnke(bgn_pos, end_pos, protocol, proto_tid, lnke_type, lnke_bgn_pos, rhs_dlm_pos); // +1 to ignore [
|
||||
|
||||
@@ -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.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tkn_chkr_lnke extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_lnke_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_lnke;}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Xop_link_parser {
|
||||
case Gfo_protocol_itm.Tid_file: // "file:///" or "File:A.png"
|
||||
int proto_len = tmp_url.Protocol_bry().length;
|
||||
if (proto_len + 1 < raw_len && raw[proto_len + 1] == Byte_ascii.Slash) { // next char is slash, assume xfer_itm refers to protocol; EX: file:///C/A.png
|
||||
int slash_pos = Bry_finder.Find_bwd(raw, Byte_ascii.Slash);
|
||||
int slash_pos = Bry_find_.Find_bwd(raw, Byte_ascii.Slash);
|
||||
if (slash_pos != Bry_.NotFound) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
|
||||
html_xowa_ttl = Bry_.Mid(raw, slash_pos + Int_.Const_dlm_len, raw.length);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.numbers.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Xop_lnki_arg_parser {
|
||||
private final Btrie_fast_mgr key_trie = Btrie_fast_mgr.cs();
|
||||
private final Bry_bfr int_bfr = Bry_bfr.reset_(16);
|
||||
@@ -94,7 +94,7 @@ public class Xop_lnki_arg_parser {
|
||||
case Key_space: break; // ignore space; EX: "100 px"
|
||||
case Key_dim_px: { // 2nd px found; EX: "40pxpx"; "40px px"
|
||||
int tmp_pos = size_trie.Match_pos();
|
||||
tmp_pos = Bry_finder.Find_fwd_while_space_or_tab(src, tmp_pos, itm_end); // look for next ws pos;
|
||||
tmp_pos = Bry_find_.Find_fwd_while_space_or_tab(src, tmp_pos, itm_end); // look for next ws pos;
|
||||
if (tmp_pos == itm_end) // no non-ws found; tmp_pos == itm_end; allow itm; EX: "40pxpx"; "40px px"; DATE:2014-03-01
|
||||
i = itm_end;
|
||||
else // non-ws found; consider as caption; EX: "20px20px"; "20pxpxpx"
|
||||
|
||||
@@ -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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_lnki_lxr_bgn implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_lnki_bgn;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_lnki_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 prv_tkn = ctx.Stack_get_last();
|
||||
if (prv_tkn != null
|
||||
|
||||
@@ -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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_lnki_lxr_end implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_lnki_end;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_lnki_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) {return ctx.Lnki().Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
|
||||
public static final Xop_lnki_lxr_end _ = new Xop_lnki_lxr_end();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
@Override public byte Tkn_tid() {return tkn_tid;} private byte tkn_tid = Xop_tkn_itm_.Tid_lnki;
|
||||
|
||||
@@ -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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.core.tests.*; import gplx.xowa.files.*;
|
||||
public class Xop_lnki_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_lnki_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_lnki;}
|
||||
|
||||
@@ -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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.xtns.relatedSites.*;
|
||||
import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
|
||||
@@ -153,7 +154,7 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
|
||||
case Xop_lnki_arg_parser.Tid_upright:
|
||||
if (arg.KeyTkn_exists()) {
|
||||
int val_tkn_bgn = arg.Val_tkn().Src_bgn(), val_tkn_end = arg.Val_tkn().Src_end();
|
||||
val_tkn_bgn = Bry_finder.Find_fwd_while_space_or_tab(src, val_tkn_bgn, val_tkn_end); // trim ws at bgn; needed for next step
|
||||
val_tkn_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, val_tkn_bgn, val_tkn_end); // trim ws at bgn; needed for next step
|
||||
if (val_tkn_end - val_tkn_bgn > 19) val_tkn_end = val_tkn_bgn + 19; // HACK: limit upright tkn to 19 digits; 20 or more will overflow long; WHEN: rewrite number_parser to handle doubles; PAGE:de.w:Feuerland DATE:2015-02-03
|
||||
number_parser.Parse(src, val_tkn_bgn, val_tkn_end);
|
||||
if (number_parser.Has_err())
|
||||
|
||||
@@ -17,6 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.xtns.relatedSites.*;
|
||||
import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
public class Xop_lnki_wkr_ {
|
||||
@@ -33,8 +35,8 @@ public class Xop_lnki_wkr_ {
|
||||
}
|
||||
public static boolean Parse_ttl(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int pipe_pos) {
|
||||
int ttl_bgn = lnki.Src_bgn() + Xop_tkn_.Lnki_bgn_len;
|
||||
ttl_bgn = Bry_finder.Find_fwd_while(src, ttl_bgn, pipe_pos, Byte_ascii.Space); // remove \s from bgn
|
||||
int ttl_end = Bry_finder.Find_bwd_while(src, pipe_pos, ttl_bgn, Byte_ascii.Space); // remove \s from end
|
||||
ttl_bgn = Bry_find_.Find_fwd_while(src, ttl_bgn, pipe_pos, Byte_ascii.Space); // remove \s from bgn
|
||||
int ttl_end = Bry_find_.Find_bwd_while(src, pipe_pos, ttl_bgn, Byte_ascii.Space); // remove \s from end
|
||||
++ttl_end; // +1 to place after non-ws; EX: [[ a ]]; ttl_end should go from 3 -> 4
|
||||
return Parse_ttl(ctx, src, lnki, ttl_bgn, ttl_end);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.cases.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.parsers.paras.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xop_lnki_wkr__basic_tst {
|
||||
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
|
||||
@@ -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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.xowa.nss.*;
|
||||
public class Xop_lnki_wkr__subpage_tst {
|
||||
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Disabled() { // PURPOSE: slash being interpreted as subpage; PAGE:en.w:[[/dev/null]]
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*;
|
||||
public class Xop_lnki_wkr__uncommon_tst {
|
||||
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Double_bracket() { // PURPOSE: handle [[[[A]]]] constructions; PAGE:ru.w:Меркатале_ин_Валь_ди_Песа; DATE:2014-02-04
|
||||
|
||||
@@ -81,12 +81,12 @@ public class Xog_redlink_mgr implements GfoInvkAble {
|
||||
if (!db_page.Exists()) {
|
||||
String lnki_id = Xopg_redlink_lnki_list.Lnki_id_prefix + Int_.Xto_str(lnki.Html_uid());
|
||||
if (variants_enabled) {
|
||||
Xowd_page_itm vnt_page = vnt_mgr.Convert_ttl(wiki, lnki.Ttl());
|
||||
Xowd_page_itm vnt_page = vnt_mgr.Convert_mgr().Convert_ttl(wiki, lnki.Ttl());
|
||||
if (vnt_page != null) {
|
||||
Xoa_ttl vnt_ttl = Xoa_ttl.parse(wiki, lnki.Ttl().Ns().Id(), vnt_page.Ttl_page_db());
|
||||
html_itm.Html_atr_set(lnki_id, "href", "/wiki/" + String_.new_u8(vnt_ttl.Full_url()));
|
||||
if (!String_.Eq(vnt_mgr.Html_style(), ""))
|
||||
html_itm.Html_atr_set(lnki_id, "style", vnt_mgr.Html_style());
|
||||
if (!String_.Eq(vnt_mgr.Html__lnki_style(), ""))
|
||||
html_itm.Html_atr_set(lnki_id, "style", vnt_mgr.Html__lnki_style());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.users.*;
|
||||
public class Xopg_redlink_lnki_list {
|
||||
private int lnki_idx = gplx.xowa.html.lnkis.Xoh_lnki_wtr.Lnki_id_min; // NOTE: default to 1, not 0, b/c 0 is ignored by wtr; DATE:2014-10-09
|
||||
|
||||
@@ -16,16 +16,18 @@ 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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.paras.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.paras.*;
|
||||
public class Xop_comm_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_comment;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_comment;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Bgn_ary, 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 lhs_end = cur_pos;
|
||||
int end_pos = Bry_finder.Find_fwd(src, End_ary, cur_pos, src_len); // search for "-->" // NOTE: do not reuse cur_pos, else cur_pos may become -1 and fatal error in ctx.Msg_log() below; DATE:2014-06-08
|
||||
int end_pos = Bry_find_.Find_fwd(src, End_ary, cur_pos, src_len); // search for "-->" // NOTE: do not reuse cur_pos, else cur_pos may become -1 and fatal error in ctx.Msg_log() below; DATE:2014-06-08
|
||||
int rhs_bgn = end_pos;
|
||||
if (end_pos == Bry_finder.Not_found) { // "-->" not found
|
||||
if (end_pos == Bry_find_.Not_found) { // "-->" not found
|
||||
ctx.Msg_log().Add_itm_none(Xop_comm_log.Eos, src, bgn_pos, cur_pos);
|
||||
cur_pos = src_len; // gobble up rest of content
|
||||
}
|
||||
|
||||
@@ -16,13 +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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_cr_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_cr;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {
|
||||
core_trie.Add(Byte_ascii.Cr, this);
|
||||
}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_cr;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Cr, 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) {
|
||||
return cur_pos; //ignore
|
||||
}
|
||||
|
||||
@@ -16,14 +16,16 @@ 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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_eq_lxr implements Xop_lxr {
|
||||
public Xop_eq_lxr(boolean tmpl_mode) {this.tmpl_mode = tmpl_mode;} boolean tmpl_mode;
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_eq;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_eq;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Eq, 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) {
|
||||
cur_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Eq); // gobble up eq; "==" should produce 1 eq_tkn with len of 2, not 2 eq_tkn with len of 1; DATE:2014-04-17
|
||||
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Eq); // gobble up eq; "==" should produce 1 eq_tkn with len of 2, not 2 eq_tkn with len of 1; DATE:2014-04-17
|
||||
int eq_len = cur_pos - bgn_pos;
|
||||
boolean hdr_like = false;
|
||||
if (tmpl_mode) {
|
||||
@@ -34,7 +36,7 @@ public class Xop_eq_lxr implements Xop_lxr {
|
||||
if (prv_pos > -1 && src[prv_pos] == Byte_ascii.Nl) // is prv char \n; EX: "\n==="
|
||||
hdr_like = true;
|
||||
else {
|
||||
int eol_pos = Bry_finder.Find_fwd_while_space_or_tab(src, cur_pos, src_len); // skip trailing ws; EX: "== \n"; PAGE:nl.q:Geert_Wilders; DATE:2014-06-05
|
||||
int eol_pos = Bry_find_.Find_fwd_while_space_or_tab(src, cur_pos, src_len); // skip trailing ws; EX: "== \n"; PAGE:nl.q:Geert_Wilders; DATE:2014-06-05
|
||||
if ( eol_pos == src_len // eos
|
||||
|| src[eol_pos] == Byte_ascii.Nl // cur_pos is \n; EX: "===\n"
|
||||
) {
|
||||
@@ -55,15 +57,15 @@ public class Xop_eq_lxr implements Xop_lxr {
|
||||
ctx.Subs_add(root, tkn_mkr.Eq(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
int ws_end = Bry_finder.Find_fwd_while_space_or_tab(src, cur_pos, src_len);
|
||||
int ws_end = Bry_find_.Find_fwd_while_space_or_tab(src, cur_pos, src_len);
|
||||
hdr_like = ws_end == src_len || src[ws_end] == Byte_ascii.Nl; // hdr_like if next char \n or eos
|
||||
if (!hdr_like) {
|
||||
int ctg_end = Xop_nl_lxr.Scan_fwd_for_ctg(ctx, src, cur_pos, src_len); // check if ==[[Category:A]]; DATE:2014-04-17
|
||||
if ( ctg_end != Bry_.NotFound) { // [[Category: found
|
||||
ctg_end = Bry_finder.Find_fwd(src, Xop_tkn_.Lnki_end, ctg_end, src_len);
|
||||
ctg_end = Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_end, ctg_end, src_len);
|
||||
if (ctg_end != Bry_.NotFound) { // ]] found; note that this should do more validation; EX: [[Category:]] should not be valid; DATE:2014-04-17
|
||||
ctg_end += Xop_tkn_.Lnki_end_len;
|
||||
ctg_end = Bry_finder.Find_fwd_while_space_or_tab(src, ctg_end, src_len);
|
||||
ctg_end = Bry_find_.Find_fwd_while_space_or_tab(src, ctg_end, src_len);
|
||||
if (ctg_end == src_len || src[ctg_end] == Byte_ascii.Nl) // hdr_like if ]]\n after [[Category:A]]
|
||||
hdr_like = true;
|
||||
}
|
||||
|
||||
@@ -16,12 +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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
public class Xop_hr_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_hr;}
|
||||
public class Xop_hr_lxr implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_hr;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr parse_trie) {parse_trie.Add(Hook_ary, this);} static final byte[] Hook_ary = new byte[] {Byte_ascii.Nl, Byte_ascii.Dash, Byte_ascii.Dash, Byte_ascii.Dash, Byte_ascii.Dash};
|
||||
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 nl_adj = -1; // -1 to ignore nl at bgn for hr_len
|
||||
boolean bos = bgn_pos == Xop_parser_.Doc_bgn_bos;
|
||||
@@ -31,7 +32,7 @@ public class Xop_hr_lxr implements Xop_lxr {
|
||||
}
|
||||
ctx.Apos().EndFrame(ctx, root, src, bgn_pos, false);
|
||||
ctx.CloseOpenItms(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos); // close open items
|
||||
cur_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Hook_byt); // gobble consecutive dashes
|
||||
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Hook_byt); // gobble consecutive dashes
|
||||
if (!bos)
|
||||
ctx.Para().Process_nl(ctx, root, src, bgn_pos, bgn_pos); // simulate \n in front of ----
|
||||
ctx.Para().Process_block__bgn_y__end_n(Xop_xnde_tag_.Tag_hr); // para=n; block=y
|
||||
|
||||
@@ -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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_ignore_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_ignore_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_ignore;}
|
||||
|
||||
35
400_xowa/src/gplx/xowa/parsers/miscs/Xop_macro_lxr.java
Normal file
35
400_xowa/src/gplx/xowa/parsers/miscs/Xop_macro_lxr.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_macro_lxr implements Xop_lxr {
|
||||
public Xop_macro_lxr() {}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_macro;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Tab, this); core_trie.Add(Xop_tab_tkn.Bry_tab_ent, 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) {
|
||||
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Tab);
|
||||
src[bgn_pos] = Byte_ascii.Tab; // HACK: SEE:NOTE_1:tabs
|
||||
for (int i = bgn_pos + 1; i < cur_pos; i++)
|
||||
src[i] = Byte_ascii.Space;
|
||||
ctx.Subs_add(root, tkn_mkr.Tab(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
public static final Xop_tab_lxr _ = new Xop_tab_lxr();
|
||||
}
|
||||
@@ -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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.vnts.*;
|
||||
public class Xop_pipe_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_pipe;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_pipe;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Pipe, 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 cur_stack_tid = ctx.Cur_tkn_tid(), rv = -1;
|
||||
switch (cur_stack_tid) {
|
||||
@@ -61,7 +63,7 @@ public class Xop_pipe_lxr implements Xop_lxr {
|
||||
return cur_pos;
|
||||
}
|
||||
case Xop_tkn_itm_.Tid_vnt:
|
||||
gplx.xowa.langs.vnts.Xop_vnt_tkn vnt_tkn = (gplx.xowa.langs.vnts.Xop_vnt_tkn)ctx.Stack_get_typ(Xop_tkn_itm_.Tid_vnt);
|
||||
Xop_vnt_tkn vnt_tkn = (Xop_vnt_tkn)ctx.Stack_get_typ(Xop_tkn_itm_.Tid_vnt);
|
||||
vnt_tkn.Vnt_pipe_tkn_count_add_();
|
||||
ctx.Subs_add(root, tkn_mkr.Pipe(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
|
||||
@@ -16,13 +16,14 @@ 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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_space_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_space;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_space;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Space, 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) {
|
||||
cur_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Space);
|
||||
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Space);
|
||||
ctx.Subs_add(root, tkn_mkr.Space(root, bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
|
||||
@@ -16,16 +16,14 @@ 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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
public class Xop_tab_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_tab;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {
|
||||
core_trie.Add(Byte_ascii.Tab, this);
|
||||
core_trie.Add(Xop_tab_tkn.Bry_tab_ent, this);
|
||||
}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_tab;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Tab, this); core_trie.Add(Xop_tab_tkn.Bry_tab_ent, 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) {
|
||||
cur_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Tab);
|
||||
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Tab);
|
||||
src[bgn_pos] = Byte_ascii.Tab; // HACK: SEE:NOTE_1:tabs
|
||||
for (int i = bgn_pos + 1; i < cur_pos; i++)
|
||||
src[i] = Byte_ascii.Space;
|
||||
|
||||
@@ -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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tkn_chkr_hr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_hr_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hr;}
|
||||
|
||||
@@ -16,11 +16,11 @@ 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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.html.tocs.*;
|
||||
public class Xop_under_lxr implements Xop_lxr {
|
||||
private Btrie_mgr words_trie_ci, words_trie_cs;
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_under;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_under;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {}
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {
|
||||
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
|
||||
@@ -64,6 +64,7 @@ public class Xop_under_lxr implements Xop_lxr {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Term(Btrie_fast_mgr core_trie) {}
|
||||
private static final int[] under_kwds = new int[] // REF.MW:MagicWord.php
|
||||
{ Xol_kwd_grp_.Id_toc, Xol_kwd_grp_.Id_notoc, Xol_kwd_grp_.Id_forcetoc
|
||||
, Xol_kwd_grp_.Id_nogallery, Xol_kwd_grp_.Id_noheader, Xol_kwd_grp_.Id_noeditsection
|
||||
@@ -114,9 +115,10 @@ public class Xop_under_lxr implements Xop_lxr {
|
||||
class Xop_word_lxr implements Xop_lxr {
|
||||
private int kwd_id;
|
||||
public Xop_word_lxr(int kwd_id) {this.kwd_id = kwd_id;}
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_word;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_word;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {}
|
||||
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_under_lxr.Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, kwd_id); // for now, all word_lxrs only call the under_lxr; DATE:2014-02-14
|
||||
return cur_pos;
|
||||
|
||||
@@ -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.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*;
|
||||
public class Xop_under_lxr_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@@ -142,13 +142,13 @@ public class Xop_under_lxr_tst {
|
||||
@Test public void Hook_alt() { // PURPOSE: ja wikis use alternate __; DATE:2014-03-04
|
||||
Xowe_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, true, "__TOC__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
wiki.Parser_mgr().Main().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__TOC__b", "ab");
|
||||
}
|
||||
@Test public void Ascii_ci() { // PURPOSE: case-insensitive ascii; DATE:2014-07-10
|
||||
Xowe_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__TOC__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
wiki.Parser_mgr().Main().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__TOC__b", "ab");
|
||||
fxt.Test_parse_page_all_str("a__toc__b", "ab");
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class Xop_under_lxr_tst {
|
||||
Xowe_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
lang.Case_mgr_u8_();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__AÉI__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
wiki.Parser_mgr().Main().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__AÉI__b", "ab");
|
||||
fxt.Test_parse_page_all_str("a__aéi__b", "ab");
|
||||
}
|
||||
@@ -164,13 +164,13 @@ public class Xop_under_lxr_tst {
|
||||
Xowe_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
lang.Case_mgr_u8_();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__İÇİNDEKİLER__"); // __TOC__ for tr.w
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
wiki.Parser_mgr().Main().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__İçindekiler__b", "ab");
|
||||
}
|
||||
@Test public void Cs() { // PURPOSE: cs (ascii / utf8 doesn't matter); DATE:2014-07-11
|
||||
Xowe_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc , Bool_.Y, "__TOC__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
wiki.Parser_mgr().Main().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__TOC__b" , "ab"); // ci.pass
|
||||
fxt.Test_parse_page_all_str("a__toc__b" , "a__toc__b"); // ci.pass
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public class Xop_under_lxr_tst {
|
||||
Xowe_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc , Bool_.N, "__TOC__");
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_notoc , Bool_.Y, "__NOTOC__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
wiki.Parser_mgr().Main().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__TOC__b" , "ab"); // ci.pass
|
||||
fxt.Test_parse_page_all_str("a__toc__b" , "ab"); // ci.pass
|
||||
fxt.Test_parse_page_all_str("a__NOTOC__b" , "ab"); // cs.pass
|
||||
|
||||
@@ -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.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xop_nl_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_nl;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_nl;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Nl, 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) {
|
||||
if (bgn_pos == Xop_parser_.Doc_bgn_bos) return ctx.Lxr_make_txt_(cur_pos); // simulated nl at beginning of every parse
|
||||
int trim_category_pos = Scan_fwd_for_ctg(ctx, src, cur_pos, src_len);
|
||||
@@ -93,13 +95,13 @@ public class Xop_nl_lxr implements Xop_lxr {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: // ignore ws
|
||||
break;
|
||||
case Byte_ascii.Brack_bgn: // [
|
||||
if ( Bry_.Eq_itm(src, src_len, i + 1, Byte_ascii.Brack_bgn) // [[
|
||||
if ( Bry_.Has_at(src, src_len, i + 1, Byte_ascii.Brack_bgn) // [[
|
||||
&& i + 2 < src_len) {
|
||||
int ttl_bgn = Bry_finder.Find_fwd_while(src, i + 2, src_len, Byte_ascii.Space);
|
||||
int ttl_bgn = Bry_find_.Find_fwd_while(src, i + 2, src_len, Byte_ascii.Space);
|
||||
Btrie_slim_mgr ctg_trie = ctx.Wiki().Ns_mgr().Category_trie();
|
||||
Object ctg_ns = ctg_trie.Match_bgn(src, ttl_bgn, src_len);
|
||||
if (ctg_ns != null // "[[Category" found
|
||||
&& Bry_.Eq_itm(src, src_len, ctg_trie.Match_pos(), Byte_ascii.Colon)) { // check that next char is :
|
||||
&& Bry_.Has_at(src, src_len, ctg_trie.Match_pos(), Byte_ascii.Colon)) { // check that next char is :
|
||||
return i;// return pos of 1st [
|
||||
}
|
||||
return Bry_.NotFound;
|
||||
|
||||
@@ -16,13 +16,15 @@ 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.paras; 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_nl_tab_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_nl_tab;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_nl_tab;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook_nl_tab, this);} private static final byte[] Hook_nl_tab = new byte[] {Byte_ascii.Nl, Byte_ascii.Tab};
|
||||
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 non_ws_pos = Bry_finder.Find_fwd_while_space_or_tab(src, cur_pos, src_len);
|
||||
int non_ws_pos = Bry_find_.Find_fwd_while_space_or_tab(src, cur_pos, src_len);
|
||||
if (non_ws_pos < src_len) { // bounds check
|
||||
Btrie_slim_mgr tblw_trie = ctx.App().Utl_trie_tblw_ws();
|
||||
Object tblw_obj = tblw_trie.Match_bgn(src, non_ws_pos, src_len);
|
||||
|
||||
@@ -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.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_nl_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_nl_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_newLine;}
|
||||
|
||||
@@ -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.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_para_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_para_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_para;}
|
||||
|
||||
@@ -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.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xop_pre_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_pre;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_pre;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook_space, this);} // NOTE: do not treat \n\t as shorthand pre; EX:pl.w:Main_Page; DATE:2014-05-06
|
||||
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) {
|
||||
if ( !ctx.Para().Enabled() // para disabled; "\n\s" should just be "\n\s"; NOTE: para disabled in <gallery>
|
||||
|| ( ctx.Stack_len() > 0 // bounds check
|
||||
@@ -32,7 +34,7 @@ public class Xop_pre_lxr implements Xop_lxr {
|
||||
ctx.Subs_add(root, tkn_mkr.Space(root, cur_pos - 1, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
int txt_pos = Bry_finder.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Space); // NOTE: was Find_fwd_while_tab_or_space, which incorrectly converted tabs to spaces; PAGE:en.w:Cascading_Style_Sheets; DATE:2014-06-23
|
||||
int txt_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Space); // NOTE: was Find_fwd_while_tab_or_space, which incorrectly converted tabs to spaces; PAGE:en.w:Cascading_Style_Sheets; DATE:2014-06-23
|
||||
if (txt_pos == src_len) return cur_pos; // "\n\s" at EOS; treat as \n only; EX: "a\n " -> ""; also bounds check
|
||||
byte b = src[txt_pos];
|
||||
if (bgn_pos == Xop_parser_.Doc_bgn_bos) { // BOS; gobble up all \s\t; EX: "BOS\s\s\sa" -> "BOSa"
|
||||
@@ -51,9 +53,9 @@ public class Xop_pre_lxr implements Xop_lxr {
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_list: // close all lists unless [[Category]]; SEE:NOTE_4; rewritten; DATE:2015-03-31
|
||||
boolean close_all_lists = true;
|
||||
if (Bry_finder.Find_fwd(src, Xop_tkn_.Lnki_bgn, txt_pos, src_len) == txt_pos) { // look for "[["
|
||||
if (Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_bgn, txt_pos, src_len) == txt_pos) { // look for "[["
|
||||
int tmp_pos = txt_pos + Xop_tkn_.Lnki_bgn.length;
|
||||
if (Bry_finder.Find_fwd(src, ctx.Wiki().Ns_mgr().Ns_category().Name_db_w_colon(), tmp_pos, src_len) == tmp_pos) // look for "Category:"
|
||||
if (Bry_find_.Find_fwd(src, ctx.Wiki().Ns_mgr().Ns_category().Name_db_w_colon(), tmp_pos, src_len) == tmp_pos) // look for "Category:"
|
||||
close_all_lists = false; // "[[Category:" found; "\n\s[[Category:" should not close list; note that [[Category]] is invisible
|
||||
}
|
||||
if (close_all_lists)
|
||||
|
||||
@@ -16,9 +16,10 @@ 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.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xop_tblw_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_tblw;}
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_tblw;}
|
||||
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 rv = Handle_bang(wlxr_type, ctx, ctx.Tkn_mkr(), root, src, src_len, bgn_pos, cur_pos);
|
||||
if (rv != Continue) return rv;
|
||||
@@ -54,11 +55,11 @@ public class Xop_tblw_lxr implements Xop_lxr {
|
||||
}
|
||||
}
|
||||
if (wlxr_type == Xop_tblw_wkr.Tblw_type_th2) { // !!; extra check to make sure \n! exists; DATE:2014-10-19
|
||||
int prv_th_pos = Bry_finder.Find_bwd(src, Byte_ascii.Nl, bgn_pos); // search for previous \n
|
||||
boolean invalid = prv_th_pos == Bry_finder.Not_found; // no \n; invalid
|
||||
int prv_th_pos = Bry_find_.Find_bwd(src, Byte_ascii.Nl, bgn_pos); // search for previous \n
|
||||
boolean invalid = prv_th_pos == Bry_find_.Not_found; // no \n; invalid
|
||||
if (!invalid) {
|
||||
++prv_th_pos; // skip \n
|
||||
prv_th_pos = Bry_finder.Find_fwd_while_space_or_tab(src, prv_th_pos, src_len); // skip \s; needed for "\n\s!" which is still a tblw
|
||||
prv_th_pos = Bry_find_.Find_fwd_while_space_or_tab(src, prv_th_pos, src_len); // skip \s; needed for "\n\s!" which is still a tblw
|
||||
if (prv_th_pos == bgn_pos) // invalid: "\n" is directly in front of "!!"
|
||||
invalid = true;
|
||||
else
|
||||
@@ -129,6 +130,7 @@ public class Xop_tblw_lxr implements Xop_lxr {
|
||||
core_trie.Add(Hook_th2, new Xop_tblw_lxr(Xop_tblw_wkr.Tblw_type_th2));
|
||||
}
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
|
||||
public void Term(Btrie_fast_mgr core_trie) {}
|
||||
public static final byte[] Hook_tb = Bry_.new_a7("\n{|"), Hook_te = Bry_.new_a7("\n|}"), Hook_tr = Bry_.new_a7("\n|-")
|
||||
, Hook_td = Bry_.new_a7("\n|"), Hook_th = Bry_.new_a7("\n!"), Hook_tc = Bry_.new_a7("\n|+")
|
||||
, Hook_td2 = Bry_.new_a7("||"), Hook_th2 = Bry_.new_a7("!!");
|
||||
|
||||
@@ -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.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tblw_tb_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_tblw_tb_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tblw_tb;}
|
||||
|
||||
@@ -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.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tblw_tc_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_tblw_tc_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tblw_tc;}
|
||||
|
||||
@@ -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.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tblw_td_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_tblw_td_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tblw_td;}
|
||||
|
||||
@@ -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.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tblw_th_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_tblw_th_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tblw_th;}
|
||||
|
||||
@@ -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.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_tblw_tr_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_tblw_tr_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tblw_tr;}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class Xop_tblw_wkr implements Xop_ctx_wkr {
|
||||
if (ignore_prv) {
|
||||
ctx.Subs_add(root, tkn_mkr.Ignore(bgn_pos, cur_pos, Xop_ignore_tkn.Ignore_tid_htmlTidy_tblw));
|
||||
++tblw_te_ignore_count;
|
||||
cur_pos = Bry_finder.Find_fwd_until(src, cur_pos, src_len, Byte_ascii.Nl); // NOTE: minor hack; this tblw tkn will be ignored, so ignore any of its attributes as well; gobble up all chars till nl. see: if two consecutive tbs, ignore attributes on 2nd; en.wikibooks.org/wiki/Wikibooks:Featured books
|
||||
cur_pos = Bry_find_.Find_fwd_until(src, cur_pos, src_len, Byte_ascii.Nl); // NOTE: minor hack; this tblw tkn will be ignored, so ignore any of its attributes as well; gobble up all chars till nl. see: if two consecutive tbs, ignore attributes on 2nd; en.wikibooks.org/wiki/Wikibooks:Featured books
|
||||
return cur_pos;
|
||||
}
|
||||
if (auto_create) {
|
||||
@@ -481,7 +481,7 @@ public class Xop_tblw_wkr implements Xop_ctx_wkr {
|
||||
root.Subs_del_between(ctx, subs_bgn, subs_pos);
|
||||
int atrs_bgn = prv_tblw.Src_end(), atrs_end = last_atr_tkn.Src_end();
|
||||
if (prv_tblw.Tkn_tid() == Xop_tkn_itm_.Tid_tblw_tr) // NOTE: if "|-" gobble all trailing dashes; REF: Parser.php!doTableStuff; $line = preg_replace( '#^\|-+#', '', $line ); DATE:2013-06-21
|
||||
atrs_bgn = Bry_finder.Find_fwd_while(src, atrs_bgn, src.length, Byte_ascii.Dash);
|
||||
atrs_bgn = Bry_find_.Find_fwd_while(src, atrs_bgn, src.length, Byte_ascii.Dash);
|
||||
prv_tblw.Atrs_rng_set(atrs_bgn, atrs_end);
|
||||
if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki && atrs_bgn != -1) {
|
||||
Xop_xatr_itm[] atrs = ctx.App().Xatr_parser().Parse(ctx.Msg_log(), src, atrs_bgn, atrs_end);
|
||||
|
||||
@@ -32,8 +32,8 @@ public class Xop_tblw_ws_itm {
|
||||
trie_itm(rv, Type_tr, Xop_tblw_lxr_ws.Hook_tr);
|
||||
trie_itm(rv, Type_th, Xop_tblw_lxr_ws.Hook_th);
|
||||
trie_itm(rv, Type_tc, Xop_tblw_lxr_ws.Hook_tc);
|
||||
trie_itm(rv, Type_td, Bry_.bytes_(Byte_ascii.Pipe));
|
||||
trie_itm(rv, Type_nl, Bry_.bytes_(Byte_ascii.Nl));
|
||||
trie_itm(rv, Type_td, Bry_.new_bytes(Byte_ascii.Pipe));
|
||||
trie_itm(rv, Type_nl, Bry_.new_bytes(Byte_ascii.Nl));
|
||||
trie_itm_xnde(rv, Xop_xnde_tag_.Tag_table);
|
||||
trie_itm_xnde(rv, Xop_xnde_tag_.Tag_tr);
|
||||
trie_itm_xnde(rv, Xop_xnde_tag_.Tag_td);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]]}}
|
||||
|
||||
@@ -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*"
|
||||
|
||||
@@ -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() {}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -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();}
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -16,7 +16,9 @@ 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.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.hrefs.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xop_redirect_mgr {
|
||||
private final Xowe_wiki wiki; private final Url_encoder url_decoder; private Hash_adp_bry redirect_hash;
|
||||
public Xop_redirect_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.url_decoder = Xoa_app_.Utl__encoder_mgr().Http_url_ttl();} // NOTE: must be Url_ttl, not Url; PAGE:en.w:Template:Positionskarte+ -> Template:Location_map+, not Template:Location_map DATE:2014-08-21
|
||||
@@ -33,7 +35,7 @@ public class Xop_redirect_mgr {
|
||||
public Xoa_ttl Extract_redirect(byte[] src) {return Extract_redirect(src, src.length);}
|
||||
public Xoa_ttl Extract_redirect(byte[] src, int src_len) { // NOTE: this proc is called by every page. be careful of changes; DATE:2014-07-05
|
||||
if (src_len == 0) return Redirect_null_ttl;
|
||||
int bgn = Bry_finder.Find_fwd_while_not_ws(src, 0, src_len);
|
||||
int bgn = Bry_find_.Find_fwd_while_not_ws(src, 0, src_len);
|
||||
if (bgn == src_len) return Redirect_null_ttl; // article is entirely whitespace
|
||||
int kwd_end = Xop_redirect_mgr_.Get_kwd_end_or_end(src, bgn, src_len);
|
||||
if (kwd_end == src_len) return Redirect_null_ttl;
|
||||
@@ -43,7 +45,7 @@ public class Xop_redirect_mgr {
|
||||
int ttl_bgn = Xop_redirect_mgr_.Get_ttl_bgn_or_neg1(src, kwd_end, src_len);
|
||||
if (ttl_bgn == Bry_.NotFound) return Redirect_null_ttl;
|
||||
ttl_bgn += Xop_tkn_.Lnki_bgn.length;
|
||||
int ttl_end = Bry_finder.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn);
|
||||
int ttl_end = Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn);
|
||||
if (ttl_end == Bry_.NotFound) return Redirect_null_ttl;
|
||||
byte[] redirect_bry = Bry_.Mid(src, ttl_bgn, ttl_end);
|
||||
redirect_bry = url_decoder.Decode(redirect_bry); // NOTE: url-decode links; PAGE: en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18
|
||||
|
||||
@@ -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.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_redirect_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xop_redirect_mgr_fxt fxt = new Xop_redirect_mgr_fxt();
|
||||
@Test public void Basic() {fxt.Test_redirect("#REDIRECT [[a]]", "A");}
|
||||
|
||||
58
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_converter_rule.java
Normal file
58
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_converter_rule.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
class Vnt_converter_rule { // REF.MW: /languages/LanguageConverter.php|ConverterRule
|
||||
private final byte[] src;
|
||||
private final int src_bgn, src_end;
|
||||
private int pipe_pos = -1;
|
||||
public Vnt_converter_rule(byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
}
|
||||
public void Parse() {
|
||||
}
|
||||
public void Parse_flags(Vnt_flag_parser parser) {
|
||||
this.pipe_pos = Bry_find_.Find_fwd(src, Byte_ascii.Pipe, src_bgn, src_end);
|
||||
if (pipe_pos != Bry_find_.Not_found) // "|" found; EX: -{A|}-
|
||||
parser.Parse(src, src_bgn, pipe_pos);
|
||||
int flag_count = parser.Count();
|
||||
if (flag_count == 0) parser.Set_y(Vnt_flag_itm_.Tid_show);
|
||||
else if (parser.Limit_if_exists(Vnt_flag_itm_.Tid_raw)) {}
|
||||
else if (parser.Limit_if_exists(Vnt_flag_itm_.Tid_name)) {}
|
||||
else if (parser.Limit_if_exists(Vnt_flag_itm_.Tid_del)) {}
|
||||
else if (flag_count == 1 && parser.Get(Vnt_flag_itm_.Tid_title)) parser.Set_y(Vnt_flag_itm_.Tid_macro);
|
||||
else if (parser.Get(Vnt_flag_itm_.Tid_macro)) {
|
||||
boolean exists_d = parser.Get(Vnt_flag_itm_.Tid_descrip);
|
||||
boolean exists_t = parser.Get(Vnt_flag_itm_.Tid_title);
|
||||
parser.Clear();
|
||||
parser.Set_y_many(Vnt_flag_itm_.Tid_all, Vnt_flag_itm_.Tid_macro);
|
||||
if (exists_d) parser.Set_y(Vnt_flag_itm_.Tid_descrip);
|
||||
if (exists_t) parser.Set_y(Vnt_flag_itm_.Tid_title);
|
||||
}
|
||||
else {
|
||||
if (parser.Get(Vnt_flag_itm_.Tid_add))
|
||||
parser.Set_y_many(Vnt_flag_itm_.Tid_all, Vnt_flag_itm_.Tid_show);
|
||||
if (parser.Get(Vnt_flag_itm_.Tid_descrip))
|
||||
parser.Set_n(Vnt_flag_itm_.Tid_show);
|
||||
parser.Limit_if_exists_vnts(); // try to find flags like "zh-hans", "zh-hant"; allow syntaxes like "-{zh-hans;zh-hant|XXXX}-"
|
||||
}
|
||||
}
|
||||
public void Parse_rules(Vnt_rule_parser parser) {
|
||||
parser.Parse(src, src_bgn, src_end);
|
||||
}
|
||||
}
|
||||
52
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_itm_.java
Normal file
52
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_itm_.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
class Vnt_flag_itm_ {
|
||||
public static final int
|
||||
Tid_unknown = 0
|
||||
, Tid_show = 1 // S: EX: -{S|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_all = 2 // +: EX: -{+|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_err = 3 // E: EX: -{E|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_add = 4 // A: add and output; EX: -{A|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_title = 5 // T: page_title; EX: -{T|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_raw = 6 // R: raw: no convert; EX: -{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
|
||||
, Tid_descrip = 7 // D: describe; EX: -{D|zh-hans:A;zh-hant:B}- -> "简体:A;繁體:B;" (简体=Simplified;繁體=Traditional)
|
||||
, Tid_del = 8 // -: remove; EX: -{-|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_macro = 9 // H: macro; EX: -{H|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_name = 10 // N: EX: -{N|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_lang = 11 // vnt: EX: -{zh-hant|B}- -> "B"
|
||||
, Tid__max = 12
|
||||
;
|
||||
private static final String[] Tid__names = new String[]
|
||||
{ "unknown", "show", "all", "err", "add", "title"
|
||||
, "raw", "descrip", "del", "macro", "name", "lang"
|
||||
};
|
||||
public static String To_name(int tid) {return Tid__names[tid];}
|
||||
public static final Hash_adp_bry Regy = Hash_adp_bry.ci_a7() // NOTE: match either lc or uc; EX: -{D}- or -{d}-;
|
||||
.Add_byte_int(Byte_ascii.Ltr_S , Tid_show)
|
||||
.Add_byte_int(Byte_ascii.Plus , Tid_all)
|
||||
.Add_byte_int(Byte_ascii.Ltr_E , Tid_err)
|
||||
.Add_byte_int(Byte_ascii.Ltr_A , Tid_add)
|
||||
.Add_byte_int(Byte_ascii.Ltr_T , Tid_title)
|
||||
.Add_byte_int(Byte_ascii.Ltr_R , Tid_raw)
|
||||
.Add_byte_int(Byte_ascii.Ltr_D , Tid_descrip)
|
||||
.Add_byte_int(Byte_ascii.Dash , Tid_del)
|
||||
.Add_byte_int(Byte_ascii.Ltr_H , Tid_macro)
|
||||
.Add_byte_int(Byte_ascii.Ltr_N , Tid_name)
|
||||
;
|
||||
}
|
||||
67
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_parser.java
Normal file
67
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_parser.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
class Vnt_flag_parser implements gplx.core.brys.Bry_split_wkr {
|
||||
private final Hash_adp_bry flag_regy = Vnt_flag_itm_.Regy;
|
||||
private final Hash_adp_bry vnt_regy = Hash_adp_bry.cs();
|
||||
private final boolean[] flag_ary = new boolean[Vnt_flag_itm_.Tid__max];
|
||||
private int count = 0;
|
||||
public int Count() {return count;}
|
||||
public boolean Get(int tid) {return flag_ary[tid];}
|
||||
public void Set_y(int tid) {flag_ary[tid] = Bool_.Y;}
|
||||
public void Set_y_many(int... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
flag_ary[ary[i]] = Bool_.Y;
|
||||
}
|
||||
public void Set_n(int tid) {flag_ary[tid] = Bool_.N;}
|
||||
public void Limit(int tid) {
|
||||
for (int i = 0; i < Vnt_flag_itm_.Tid__max; ++i) {
|
||||
if (i != tid) flag_ary[i] = false;
|
||||
}
|
||||
}
|
||||
public boolean Limit_if_exists(int tid) {
|
||||
boolean exists = flag_ary[tid]; if (!exists) return false;
|
||||
for (int i = 0; i < Vnt_flag_itm_.Tid__max; ++i) {
|
||||
if (i != tid) flag_ary[i] = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean Limit_if_exists_vnts() {
|
||||
return false;
|
||||
}
|
||||
public void Clear() {
|
||||
count = 0;
|
||||
for (int i = 0; i < Vnt_flag_itm_.Tid__max; ++i)
|
||||
flag_ary[i] = false;
|
||||
}
|
||||
public void Parse(byte[] src, int src_bgn, int src_end) {
|
||||
this.Clear();
|
||||
Bry_split_.Split(src, Byte_ascii.Semic, true, this);
|
||||
}
|
||||
public int Split(byte[] src, int itm_bgn, int itm_end) {
|
||||
int flag_tid = flag_regy.Get_as_int_or(src, itm_bgn, itm_end, -1);
|
||||
if (flag_tid == -1) {
|
||||
int vnt_tid = vnt_regy.Get_as_int_or(src, itm_bgn, itm_end, -1);
|
||||
if (vnt_tid == -1) return Bry_split_.Rv__ok; // unknown flag; ignore
|
||||
}
|
||||
flag_ary[flag_tid] = true;
|
||||
++count;
|
||||
return Bry_split_.Rv__ok;
|
||||
}
|
||||
}
|
||||
110
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_language_converter.java
Normal file
110
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_language_converter.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
public class Vnt_language_converter {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private int max_depth = 32;
|
||||
private byte[] src; private int src_len;
|
||||
private boolean convert_needed;
|
||||
private int pos;
|
||||
public byte[] Parse(byte[] vnt, byte[] src) {// REF.MW:/languages/LanguageConverter.php!recursiveConvertTopLevel
|
||||
synchronized (bfr) {
|
||||
int markup_count = 0;
|
||||
this.pos = 0;
|
||||
this.convert_needed = false; // for sr lang; SEE:LanguageSr.php !$this->guessVariant(src, vnt);
|
||||
this.src = src; this.src_len = src.length;
|
||||
while (pos < src_len) {
|
||||
int curly_bgn = Bry_find_.Find_fwd(src, Bry__curly_bgn, pos, src_len);
|
||||
if (curly_bgn == Bry_find_.Not_found) { // No more markup, append final segment
|
||||
if (markup_count == 0) return src; // no markups found; just return original
|
||||
Add_output(vnt, convert_needed, src, pos, src_len);
|
||||
return bfr.Xto_bry_and_clear();
|
||||
}
|
||||
bfr.Add_mid(src, pos, curly_bgn); // Markup found; append segment
|
||||
Add_output(vnt, convert_needed, src, pos, src_len);
|
||||
pos = curly_bgn; // Advance position
|
||||
++markup_count;
|
||||
Parse_recursive(vnt, pos, 1); // Do recursive conversion
|
||||
}
|
||||
return bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
private void Parse_recursive(byte[] vnt, int pos, int depth) {
|
||||
pos += 2; // skip "-{"
|
||||
boolean warning_done = false;
|
||||
// $inner = '';
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src,pos, src_len);
|
||||
if (o == null) { // char;
|
||||
++pos;
|
||||
continue;
|
||||
}
|
||||
int new_pos = trie.Match_pos(); // Markup found; Append initial segment
|
||||
bfr.Add_mid(src, pos, new_pos);
|
||||
pos = new_pos; // Advance position
|
||||
switch (((Byte_obj_val)o).Val()) {
|
||||
case Tid__curly_bgn:
|
||||
if (depth >= max_depth) {
|
||||
bfr.Add(Bry__curly_bgn);
|
||||
if (!warning_done) {
|
||||
bfr.Add_str("<span class=\"error\">");
|
||||
// wfMessage('language-converter-depth-warning')->numParams($this->mMaxDepth)->inContentLanguage()->text()
|
||||
bfr.Add_str("</span>");
|
||||
warning_done = true;
|
||||
}
|
||||
pos += 2; // skip "-{"
|
||||
continue;
|
||||
}
|
||||
Parse_recursive(vnt, pos, depth + 1); // Recursively parse another rule
|
||||
break;
|
||||
case Tid__curly_end:
|
||||
pos += 2;
|
||||
/*
|
||||
// Apply the rule
|
||||
$rule = new ConverterRule($inner, $this);
|
||||
$rule->parse($variant);
|
||||
$this->applyManualConv($rule);
|
||||
return $rule->getDisplay();
|
||||
*/
|
||||
return;
|
||||
default: throw Err_.new_unhandled(-1); // never happens
|
||||
}
|
||||
}
|
||||
if (pos < src_len) { // Unclosed rule
|
||||
byte[] frag = Auto_convert(vnt, src, pos, src_len);
|
||||
bfr.Add(Bry__curly_bgn).Add(frag);
|
||||
}
|
||||
pos = src_len;
|
||||
}
|
||||
private void Add_output(byte[] vnt, boolean convert_needed, byte[] src, int pos, int src_len) {
|
||||
if (convert_needed) {
|
||||
byte[] frag = Auto_convert(vnt, src, pos, src_len);
|
||||
bfr.Add(frag);
|
||||
}
|
||||
else
|
||||
bfr.Add_mid(src, pos, src_len);
|
||||
}
|
||||
private byte[] Auto_convert(byte[] vnt, byte[] src, int bgn, int end) {return src;}
|
||||
private static final byte Tid__curly_bgn = 1, Tid__curly_end = 2;
|
||||
private static final byte[] Bry__curly_bgn = Bry_.new_a7("-{"), Bry__curly_end = Bry_.new_a7("}-");
|
||||
private static final Btrie_fast_mgr trie = Btrie_fast_mgr.cs()
|
||||
.Add_bry_byte(Bry__curly_bgn, Tid__curly_bgn)
|
||||
.Add_bry_byte(Bry__curly_end, Tid__curly_end);
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser.java
Normal file
61
400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
class Vnt_rule_parser implements gplx.core.brys.Bry_split_wkr {
|
||||
// private final Btrie_slim_mgr vnt_trie = Btrie_slim_mgr.ci_a7();
|
||||
public void Parse(byte[] src, int src_bgn, int src_end) {
|
||||
Bry_split_.Split(src, Byte_ascii.Semic, false, this); // trim=false for "&#entity;" check below
|
||||
}
|
||||
public int Split(byte[] src, int itm_bgn, int itm_end) {
|
||||
int html_entity_pos = Bry_find_.Find_bwd_while_alphanum(src, itm_bgn);
|
||||
if (Bry_.Eq(src, html_entity_pos - 2, html_entity_pos, Bry__html_entity)) return Bry_split_.Rv__extend; // reject "&#entity;"; EX: " zh-hans;"
|
||||
/*
|
||||
itm_bgn = skip fwd for ws;
|
||||
itm_bgn = skip fwd for "=>"
|
||||
Object vnt_obj = vnt_trie.Match_bgn(src, itm_bgn, itm_end); if (vnt_obj == null) return Bry_split_.Rv__extend; // reject ";not_variant"; EX: ";border" in "zh-hans:<span style='color:blue;border:1px;'>;zh-hant:"
|
||||
itm_end = skip bwd for ws
|
||||
// val = trim( val[0] );
|
||||
// trg = trim( val[1] );
|
||||
// $u = explode( '=>', val, 2 );
|
||||
// // if trg is empty, strtr() could return a wrong result
|
||||
// if ( count( $u ) == 1 && trg && in_array( val, $variants ) ) {
|
||||
// bidi_ary[val] = trg;
|
||||
// } elseif ( count( $u ) == 2 ) {
|
||||
// $from = trim( $u[0] );
|
||||
// val = trim( $u[1] );
|
||||
// if ( array_key_exists( val, $unidtable )
|
||||
// && !is_array( $unidtable[val] )
|
||||
// && trg
|
||||
// && in_array( val, $variants ) ) {
|
||||
// $unidtable[val] = array( $from => trg );
|
||||
// } elseif ( trg && in_array( val, $variants ) ) {
|
||||
// $unidtable[val][$from] = trg;
|
||||
// }
|
||||
// }
|
||||
// // syntax error, pass
|
||||
// if ( !isset( $this->mConverter->mVariantNames[val] ) ) {
|
||||
// bidi_ary = array();
|
||||
// $unidtable = array();
|
||||
// break;
|
||||
// }
|
||||
*/
|
||||
return Bry_split_.Rv__ok;
|
||||
}
|
||||
private static final byte[] Bry__html_entity = Bry_.new_a7("&#");
|
||||
}
|
||||
22
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_eqgt_tkn.java
Normal file
22
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_eqgt_tkn.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
public class Xop_vnt_eqgt_tkn extends Xop_tkn_itm_base { // "=>"
|
||||
public Xop_vnt_eqgt_tkn(int bgn, int end) {this.Tkn_ini_pos(false, bgn, end);}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_vnt_eqgt;}
|
||||
}
|
||||
75
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_flag.java
Normal file
75
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_flag.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xop_vnt_flag {
|
||||
public Xop_vnt_flag(int tid) {this.tid = tid; this.mask = 0;}
|
||||
public Xop_vnt_flag(int tid, int mask) {this.tid = tid; this.mask = mask;}
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
public int Mask() {return mask;} private final int mask;
|
||||
public static Xop_vnt_flag new_lang(int mask) {return new Xop_vnt_flag(Xop_vnt_flag_.Tid_lang, mask);}
|
||||
}
|
||||
class Xop_vnt_flag_ { // REF.MW: /languages/LanguageConverter.php
|
||||
public static final Xop_vnt_flag[] Ary_empty = new Xop_vnt_flag[0];
|
||||
public static final int
|
||||
Tid_unknown = 0
|
||||
, Tid_show = 1 // EX: -{S|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_all = 2 // EX: -{+|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_err = 3 // EX: -{E|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_add = 4 // add and output; EX: -{A|zh-hans:A;zh-hant:B}- -> "A"
|
||||
, Tid_title = 5 // page_title; EX: -{T|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_raw = 6 // raw: no convert; EX: -{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
|
||||
, Tid_descrip = 7 // describe; EX: -{D|zh-hans:A;zh-hant:B}- -> "简体:A;繁體:B;" (简体=Simplified;繁體=Traditional)
|
||||
, Tid_del = 8 // remove; EX: -{-|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_macro = 9 // macro; EX: -{H|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_name = 10 // EX: -{N|zh-hans:A;zh-hant:B}- -> ""
|
||||
, Tid_lang = 11 // EX: -{zh-hant|B}- -> "B"
|
||||
, Tid_len = 12
|
||||
;
|
||||
public static final byte Tid__max = 12;
|
||||
private static final String[] Tid__names = new String[]
|
||||
{ "unknown", "show", "all", "err", "add", "title"
|
||||
, "raw", "descrip", "del", "macro", "name", "lang"
|
||||
};
|
||||
public static String To_name(int tid) {return Tid__names[tid];}
|
||||
public static final Xop_vnt_flag
|
||||
Flag_unknown = new Xop_vnt_flag(Tid_unknown)
|
||||
, Flag_show = new Xop_vnt_flag(Tid_show)
|
||||
, Flag_all = new Xop_vnt_flag(Tid_all)
|
||||
, Flag_err = new Xop_vnt_flag(Tid_err)
|
||||
, Flag_add = new Xop_vnt_flag(Tid_add)
|
||||
, Flag_title = new Xop_vnt_flag(Tid_title)
|
||||
, Flag_raw = new Xop_vnt_flag(Tid_raw)
|
||||
, Flag_descrip = new Xop_vnt_flag(Tid_descrip)
|
||||
, Flag_del = new Xop_vnt_flag(Tid_del)
|
||||
, Flag_macro = new Xop_vnt_flag(Tid_macro)
|
||||
, Flag_name = new Xop_vnt_flag(Tid_name)
|
||||
;
|
||||
public static final Btrie_fast_mgr Trie = Btrie_fast_mgr.ci_a7() // NOTE: match either lc or uc; EX: -{D}- or -{d}-; // NOTE:ci.ascii:MW_const.en; flag keys; EX: -{S|a}-
|
||||
.Add(Byte_ascii.Ltr_S , Xop_vnt_flag_.Flag_show)
|
||||
.Add(Byte_ascii.Plus , Xop_vnt_flag_.Flag_all)
|
||||
.Add(Byte_ascii.Ltr_E , Xop_vnt_flag_.Flag_err)
|
||||
.Add(Byte_ascii.Ltr_A , Xop_vnt_flag_.Flag_add)
|
||||
.Add(Byte_ascii.Ltr_T , Xop_vnt_flag_.Flag_title)
|
||||
.Add(Byte_ascii.Ltr_R , Xop_vnt_flag_.Flag_raw)
|
||||
.Add(Byte_ascii.Ltr_D , Xop_vnt_flag_.Flag_descrip)
|
||||
.Add(Byte_ascii.Dash , Xop_vnt_flag_.Flag_del)
|
||||
.Add(Byte_ascii.Ltr_H , Xop_vnt_flag_.Flag_macro)
|
||||
.Add(Byte_ascii.Ltr_N , Xop_vnt_flag_.Flag_name)
|
||||
;
|
||||
}
|
||||
92
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_flag_parser.java
Normal file
92
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_flag_parser.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
class Xop_vnt_flag_parser {
|
||||
private final Xop_vnt_lang_bldr flag_lang_bldr;
|
||||
private final Xol_vnt_regy vnt_regy;
|
||||
public Xop_vnt_flag_parser(Xol_vnt_mgr vnt_mgr) {this.flag_lang_bldr = new Xop_vnt_lang_bldr(vnt_mgr); this.vnt_regy = vnt_mgr.Regy();}
|
||||
public int Rslt_tkn_pos() {return rslt_tkn_pos;} private int rslt_tkn_pos;
|
||||
public int Rslt_pipe_last() {return rslt_pipe_last;} private int rslt_pipe_last;
|
||||
public Xop_vnt_flag[] Rslt_flags() {return rslt_flags;} private Xop_vnt_flag[] rslt_flags;
|
||||
public void Parse(Xowe_wiki wiki, Xoa_url page_url, Xop_vnt_tkn vnt_tkn, int pipe_tkn_count, byte[] src) {
|
||||
flag_lang_bldr.Clear();
|
||||
int rv_idx = 0;
|
||||
int subs_len = vnt_tkn.Subs_len();
|
||||
this.rslt_flags = new Xop_vnt_flag[pipe_tkn_count];
|
||||
this.rslt_tkn_pos = 0;
|
||||
Bry_bfr flag_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
Xop_tkn_itm sub = vnt_tkn.Subs_get(rslt_tkn_pos);
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_space: case Xop_tkn_itm_.Tid_tab: case Xop_tkn_itm_.Tid_newLine: break; // skip ws
|
||||
case Xop_tkn_itm_.Tid_txt: flag_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end()); break; // just add text
|
||||
case Xop_tkn_itm_.Tid_pipe:
|
||||
rslt_flags[rv_idx++] = Parse_flag_bry(flag_bfr.Xto_bry_and_clear());
|
||||
if (rv_idx == pipe_tkn_count) {
|
||||
loop = false;
|
||||
rslt_pipe_last = sub.Src_end();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
wiki.Appe().Usr_dlg().Log_many("", "", "unknown tkn in vnt flag; url=~{0} tid=~{1} txt=~{2}", page_url.To_str(), sub.Tkn_tid(), String_.new_u8(src, sub.Src_bgn(), sub.Src_end()));
|
||||
flag_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
break;
|
||||
}
|
||||
++rslt_tkn_pos;
|
||||
if (rslt_tkn_pos == subs_len) break;
|
||||
}
|
||||
flag_bfr.Mkr_rls();
|
||||
}
|
||||
private Xop_vnt_flag Parse_flag_bry(byte[] bry) {
|
||||
int bry_len = bry.length; if (bry_len == 0) return Xop_vnt_flag_.Flag_unknown; // EX: exit early if 0 len, else trie will fail; EX: "-{|}-"
|
||||
Object flag_obj = flag_trie.Match_exact(bry, 0, bry_len);
|
||||
return flag_obj == null
|
||||
? Parse_flag_vnts(bry, bry_len) // unknown tid sequence; either (a) "lang" cmd ("-{zh-hans;zh-hant|a}-") or (b) invalid cmd ("-{X|a}-")
|
||||
: (Xop_vnt_flag)flag_obj; // known flag; check that next non_ws is |
|
||||
}
|
||||
private Xop_vnt_flag Parse_flag_vnts(byte[] bry, int bry_len) {
|
||||
int vnt_pos = 0;
|
||||
boolean loop = true;
|
||||
Btrie_slim_mgr trie = vnt_regy.Trie();
|
||||
while (loop) {
|
||||
boolean last = false, valid = true;
|
||||
Object vnt_obj = trie.Match_bgn(bry, vnt_pos, bry_len);
|
||||
if (vnt_obj == null) break; // no more vnts found; stop
|
||||
vnt_pos = trie.Match_pos(); // update pos to end of vnt
|
||||
int semic_pos = Bry_find_.Find_fwd_while_not_ws(bry, vnt_pos, bry_len);
|
||||
if (semic_pos == bry_len) // note that Find_fwd_non_ws will return bry_len if no non-ws found;
|
||||
last = true;
|
||||
else { // char found; make sure it is semic
|
||||
if (bry[semic_pos] != Byte_ascii.Semic) // invalid vnt; ignore; EX: -{zh-hansx|}-
|
||||
valid = false;
|
||||
vnt_pos = semic_pos + 1; // update pos to after semic
|
||||
if (vnt_pos == bry_len) last = true; // EX: "a;"
|
||||
}
|
||||
if (valid)
|
||||
flag_lang_bldr.Add(((Xol_vnt_itm)vnt_obj).Key());
|
||||
else // invalid entry clears list; EX: -{zh-hans;zh-bad}-
|
||||
flag_lang_bldr.Clear();
|
||||
if (last) break;
|
||||
}
|
||||
return flag_lang_bldr.Bld();
|
||||
}
|
||||
private static final Btrie_fast_mgr flag_trie = Xop_vnt_flag_.Trie;
|
||||
}
|
||||
77
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_html_wtr.java
Normal file
77
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_html_wtr.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.langs.vnts.*;
|
||||
public class Xop_vnt_html_wtr {
|
||||
public static void Write(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page page, byte[] src, Xop_vnt_tkn vnt) {
|
||||
Xol_vnt_mgr vnt_mgr = ctx.Wiki().Lang().Vnt_mgr(); Xol_vnt_regy vnt_regy = vnt_mgr.Regy();
|
||||
byte[] cur_lang_vnt = vnt_mgr.Cur_key();
|
||||
Xop_vnt_rule_tkn[] rules = vnt.Vnt_rules(); if (rules == null) return; // shouldn't happen, but guard anyway
|
||||
int rules_len = rules.length;
|
||||
switch (vnt.Vnt_cmd()) {
|
||||
case Xop_vnt_html_wtr.Cmd_empty: break; // nothing: ""
|
||||
case Xop_vnt_html_wtr.Cmd_error: // original token; "-{A}-"
|
||||
bfr.Add_mid(src, vnt.Src_bgn(), vnt.Src_end());
|
||||
break;
|
||||
case Xop_vnt_html_wtr.Cmd_literal: { // val only; "A"
|
||||
Xop_vnt_rule_tkn rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 item
|
||||
html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule_0.Rule_subs());
|
||||
break;
|
||||
}
|
||||
case Xop_vnt_html_wtr.Cmd_bidi: { // matching rule: "A" if zh-hans; -{zh-hans:A}-
|
||||
Xop_vnt_rule_tkn rule = Get_rule_by_key(vnt_mgr, vnt_regy, rules, rules_len, cur_lang_vnt);
|
||||
if (rule != null) html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule.Rule_subs());
|
||||
break;
|
||||
}
|
||||
case Xop_vnt_html_wtr.Cmd_lang: { // matching lang: "A" if zh-hans; -{zh-hans|A}-
|
||||
Xop_vnt_rule_tkn rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 rule
|
||||
Xop_vnt_flag flag_0 = vnt.Vnt_flags()[0]; // parse guarantees there will always be 1 flag
|
||||
if (vnt_regy.Mask__match_any(flag_0.Mask(), vnt_mgr.Cur_itm().Mask__fallbacks()))
|
||||
html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule_0.Rule_subs());
|
||||
break;
|
||||
}
|
||||
case Xop_vnt_html_wtr.Cmd_raw: { // raw; everything between last flag and }-: "-{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
|
||||
bfr.Add_mid(src, vnt.Vnt_pipe_idx_last(), vnt.Src_end() - 2);
|
||||
break;
|
||||
}
|
||||
case Xop_vnt_html_wtr.Cmd_descrip: { // descrip; similar to raw, but use localized lang
|
||||
// bfr.Add_mid(src, vnt.Vnt_pipe_idx_last(), vnt.Src_end() - 2);
|
||||
break;
|
||||
}
|
||||
case Xop_vnt_html_wtr.Cmd_title: break; // title: ignore; already handled during parse; DATE:2014-08-29
|
||||
}
|
||||
}
|
||||
public static Xop_vnt_rule_tkn Get_rule_by_key(Xol_vnt_mgr vnt_mgr, Xol_vnt_regy vnt_regy, Xop_vnt_rule_tkn[] rules, int rules_len, byte[] cur_lang_vnt) {
|
||||
vnt_regy.Mask__sort(rules); // sort to put more specific in front; EX: -{zh-hans:A;zh-cn:B}- should be "B", not "A"
|
||||
for (int i = 0; i < rules_len; i++) {
|
||||
Xop_vnt_rule_tkn rule = rules[i];
|
||||
if (vnt_regy.Mask__match_any(vnt_regy.Mask__calc(rule.Rule_lang()), vnt_mgr.Cur_itm().Mask__fallbacks())) return rule;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static final byte
|
||||
Cmd_error = 0 // eror -> output literal; EX: "-{some_unknown_error}-" -> "-{some_unknown_error}-"
|
||||
, Cmd_empty = 1 // empty -> output nothing; EX: "-{}-" -> ""
|
||||
, Cmd_literal = 2 // literal EX: "-{A}-" -> "A"
|
||||
, Cmd_bidi = 3 // bidi EX: "-{zh-hans:A;zh-hant:B}-" -> "A" if zh-hans; "B" if zh-hant
|
||||
, Cmd_lang = 4 // lang EX: "-{zh-hans|A}-" -> "A" if zh-hans; "" if zh-hant
|
||||
, Cmd_raw = 5 // raw; text in -{}- EX: "-{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
|
||||
, Cmd_descrip = 6 // describe; output rules EX: "-{D|zh-hans:A;zh-hant:B}- -> "简体:A;繁體:B;"
|
||||
, Cmd_title = 7 // title; change title EX: "-{T|zh-hans:A;zh-hant:B}- -> "A" as display title
|
||||
;
|
||||
}
|
||||
33
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_lang_bldr.java
Normal file
33
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_lang_bldr.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
class Xop_vnt_lang_bldr { // performant way of building langs; EX: -{zh;zh-hans;zh-cn|B}-
|
||||
private final Xol_vnt_regy vnt_regy;
|
||||
private int rslt_mask;
|
||||
public Xop_vnt_lang_bldr(Xol_vnt_mgr vnt_mgr) {this.vnt_regy = vnt_mgr.Regy();}
|
||||
public void Clear() {rslt_mask = 0;}
|
||||
public void Add(byte[] key) {
|
||||
Xol_vnt_itm vnt = vnt_regy.Get_by(key); if (vnt == null) return; // ignore invalid vnts; EX: -{zh;zhx}-
|
||||
int vnt_mask = vnt.Mask__vnt();
|
||||
this.rslt_mask = (rslt_mask == 0) ? vnt_mask : Enm_.Flip_int(true, rslt_mask, vnt_mask);
|
||||
}
|
||||
public Xop_vnt_flag Bld() {
|
||||
return (rslt_mask == 0) ? Xop_vnt_flag_.Flag_unknown : Xop_vnt_flag.new_lang(rslt_mask);
|
||||
}
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_lxr.java
Normal file
73
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_lxr.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
class Xop_vnt_lxr_bgn implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_vnt_bgn;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_vnt_lxr_.Hook_bgn, this);}
|
||||
public void Init_by_lang(Xol_lang lang, 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) {
|
||||
ctx.Subs_add_and_stack(root, tkn_mkr.Vnt(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
public void Term(Btrie_fast_mgr core_trie) {}
|
||||
public static final Xop_vnt_lxr_bgn _ = new Xop_vnt_lxr_bgn(); Xop_vnt_lxr_bgn() {}
|
||||
}
|
||||
class Xop_vnt_lxr_end implements Xop_lxr {
|
||||
private Xop_vnt_flag_parser flag_parser;
|
||||
private Xop_vnt_rules_parser rule_parser;
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_vnt_end;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {
|
||||
core_trie.Add(Xop_vnt_lxr_.Hook_end, this);
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
flag_parser = new Xop_vnt_flag_parser(vnt_mgr);
|
||||
rule_parser = new Xop_vnt_rules_parser(vnt_mgr);
|
||||
}
|
||||
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 stack_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_vnt);
|
||||
if (stack_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "}-" found but no "-{" in stack;
|
||||
Xop_vnt_tkn vnt_tkn = (Xop_vnt_tkn)ctx.Stack_pop_til(root, src, stack_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_vnt);
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
try {
|
||||
vnt_tkn.Src_end_(cur_pos);
|
||||
vnt_tkn.Subs_move(root);
|
||||
Xop_vnt_flag[] vnt_flag_ary = Xop_vnt_flag_.Ary_empty;
|
||||
int rule_subs_bgn = 0;
|
||||
int pipe_tkn_count = vnt_tkn.Vnt_pipe_tkn_count();
|
||||
if (pipe_tkn_count > 0) {
|
||||
flag_parser.Parse(wiki, ctx.Cur_page().Url(), vnt_tkn, pipe_tkn_count, src);
|
||||
vnt_flag_ary = flag_parser.Rslt_flags();
|
||||
rule_subs_bgn = flag_parser.Rslt_tkn_pos();
|
||||
vnt_tkn.Vnt_pipe_idx_last_(flag_parser.Rslt_pipe_last());
|
||||
}
|
||||
vnt_tkn.Vnt_flags_(vnt_flag_ary);
|
||||
Xop_vnt_rule_tkn[] rules = rule_parser.Parse(ctx, vnt_tkn, src, rule_subs_bgn);
|
||||
vnt_tkn.Vnt_rules_(rules);
|
||||
vnt_tkn.Vnt_cmd_calc(wiki, ctx.Cur_page(), ctx, src);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "vnt.parse failed: page=~{0} src=~{1} err=~{2}", ctx.Cur_page().Ttl().Raw(), String_.new_u8(src, bgn_pos, cur_pos), Err_.Message_gplx_full(e));
|
||||
if (vnt_tkn != null)
|
||||
root.Subs_add(tkn_mkr.Bry_mid(src, vnt_tkn.Src_bgn(), cur_pos));
|
||||
}
|
||||
return cur_pos;
|
||||
}
|
||||
}
|
||||
46
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_lxr_.java
Normal file
46
400_xowa/src/gplx/xowa/parsers/vnts/Xop_vnt_lxr_.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
public class Xop_vnt_lxr_ {
|
||||
public static void Init(Xowe_wiki wiki) {
|
||||
Btrie_fast_mgr wiki_trie = wiki.Parser_mgr().Main().Wtxt_lxr_mgr().Trie();
|
||||
Object exists = wiki_trie.Match_bgn(Xop_vnt_lxr_.Hook_bgn, 0, Xop_vnt_lxr_.Hook_bgn.length);
|
||||
if (exists == null) {
|
||||
Xop_vnt_lxr_eqgt._.Init_by_wiki(wiki, wiki_trie);
|
||||
Xop_vnt_lxr_bgn._.Init_by_wiki(wiki, wiki_trie);
|
||||
new Xop_vnt_lxr_end().Init_by_wiki(wiki, wiki_trie);
|
||||
// Btrie_fast_mgr tmpl_trie = wiki.Parser_mgr().Main().Tmpl_trie(); // do not add to tmpl trie
|
||||
// Xop_vnt_lxr_bgn._.Init_by_wiki(wiki, tmpl_trie);
|
||||
}
|
||||
}
|
||||
public static final byte[] Hook_bgn = new byte[] {Byte_ascii.Dash, Byte_ascii.Curly_bgn}, Hook_end = new byte[] {Byte_ascii.Curly_end, Byte_ascii.Dash};
|
||||
}
|
||||
class Xop_vnt_lxr_eqgt implements Xop_lxr {
|
||||
public int Lxr_tid() {return Xop_lxr_.Tid_vnt_eqgt;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook, this);}
|
||||
public void Init_by_lang(Xol_lang lang, 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) {
|
||||
ctx.Subs_add_and_stack(root, tkn_mkr.Vnt_eqgt(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
public void Term(Btrie_fast_mgr core_trie) {}
|
||||
public static final byte[] Hook = new byte[] {Byte_ascii.Eq, Byte_ascii.Gt};
|
||||
public static final Xop_vnt_lxr_eqgt _ = new Xop_vnt_lxr_eqgt(); Xop_vnt_lxr_eqgt() {}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
public class Xop_vnt_parser__html__tst { // NOTE: cur_vnt is zh-cn
|
||||
private final Xop_vnt_parser_fxt fxt = new Xop_vnt_parser_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Literal() {fxt.Test_parse("-{A}-", "A");}
|
||||
@Test public void Bidi_fwd() {fxt.Test_parse("-{zh-cn:B;zh-hans:A}-", "B");}
|
||||
@Test public void Bidi_bwd() {fxt.Test_parse("-{zh-hans:A;zh-cn:B}-", "B");}
|
||||
@Test public void Empty() {fxt.Test_parse("a-{}-b", "ab");}
|
||||
@Test public void Unknown_empty() {fxt.Test_parse("a-{|}-c", "ac");}
|
||||
@Test public void Unknown_text() {fxt.Test_parse("a-{|b}-c", "abc");}
|
||||
@Test public void Unknown_flag() {fxt.Test_parse("a-{x|b}-c", "abc");}
|
||||
@Test public void Lang_y() {fxt.Test_parse("-{zh-hant|A}-", "A");}
|
||||
@Test public void Lang_n() {fxt.Test_parse("-{zh-sg|A}-", "");}
|
||||
@Test public void Raw() {fxt.Test_parse("-{R|zh-hans:A;}-", "zh-hans:A;");}
|
||||
// @Test public void Descrip() {fxt.Test_parse("-{D|zh-hans:A;}-", "zh-hans:A");}
|
||||
@Test public void Tmpl() {
|
||||
fxt.Parser_fxt().Init_page_create("Template:A", "B");
|
||||
fxt.Test_parse("-{{{A}}}-", "B");
|
||||
}
|
||||
@Test public void Tmpl_arg_4() { // PURPOSE: handle "-{" + "{{{"
|
||||
fxt.Parser_fxt().Init_page_create("Template:A", "-{{{{1}}}}-");
|
||||
fxt.Test_parse("{{A|B}}", "B"); // -{ {{{1}}} }- -> -{B}- -> B
|
||||
}
|
||||
@Test public void Tmpl_arg_3() { // PURPOSE: handle "-" + "{{{"; PAGE:sr.w:ДНК; EX:<span id="interwiki-{{{1}}}-fa"></span> DATE:2014-07-03
|
||||
fxt.Parser_fxt().Init_page_create("Template:A", "-{{{1}}}-");
|
||||
fxt.Test_parse("{{A|B}}", "-B-");
|
||||
}
|
||||
@Test public void Parser_function() {
|
||||
fxt.Test_parse("-{{{#expr:1}}}-", "1");
|
||||
}
|
||||
@Test public void Ignore() {
|
||||
fxt.Test_parse("-{{#expr:1}}-", "-1-");
|
||||
}
|
||||
@Test public void Expr() {
|
||||
fxt.Parser_fxt().Init_page_create("Template:A", "{{#expr: 0-{{{1|2}}}}}");
|
||||
fxt.Test_parse("{{A}}", "-2");
|
||||
}
|
||||
@Test public void Invalid() { // PURPOSE: invalid flags should cause vnt to render text only; DATE:2014-04-10
|
||||
fxt.Test_parse("-{:a|b}-", "b");
|
||||
}
|
||||
@Test public void Macro_ignore() { // PURPOSE: ignore macro (implement later); EX:zh.v:西安; Template:pagebanner; DATE:2014-05-03
|
||||
fxt.Test_parse("-{H|zh-cn:亚琛; zh-tw:阿亨;}-", "");
|
||||
}
|
||||
@Test public void Title() { // PURPOSE: implement title; PAGE:zh.w:Help:進階字詞轉換處理 DATE:2014-08-29
|
||||
fxt.Test_parse("-{T|zh-hant:A;zh-hans:B}-", "");
|
||||
Tfds.Eq("A", String_.new_u8(fxt.Parser_fxt().Page().Html_data().Display_ttl_vnt()));
|
||||
}
|
||||
// @Test public void Disabled() {
|
||||
// Xop_fxt fxt = new Xop_fxt();
|
||||
// fxt.Wiki().Vnt_mgr().Set(null, null);
|
||||
// fxt.Test_parse_page_all_str("a-{b}-c", "a-{b}-c");
|
||||
// }
|
||||
// @Test public void Enabled() {
|
||||
// Xoae_app app = Xoa_app_fxt.app_();
|
||||
// Xol_lang lang = new Xol_lang(app, Bry_.new_a7("zh"));
|
||||
// Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "zh.wikipedia.org", lang);
|
||||
// Xop_fxt fxt = new Xop_fxt(app, wiki);
|
||||
// fxt.Test_parse_page_all_str("a-{b}-c", "ac");
|
||||
// fxt.Wiki().Vnt_mgr().Set(null, null); // set it back to null for other tests
|
||||
// }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user