mirror of https://github.com/gnosygnu/xowa
Xomw.Preprocessor: Start integrating Preprocessor_Hash [#508]
parent
b65fda764f
commit
7f76d8128d
@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
public class Char_bfr {
|
||||
private char[] ary;
|
||||
private int ary_len;
|
||||
private int ary_max, ary_max_reset;
|
||||
public Char_bfr(int ary_max) {
|
||||
this.ary_max = ary_max;
|
||||
ary = new char[ary_max];
|
||||
ary_max_reset = ary_max;
|
||||
}
|
||||
public Char_bfr Add_char(char val) {
|
||||
int new_len = ary_len + 1;
|
||||
if (new_len > ary_len) Resize(ary_len * 2);
|
||||
ary[ary_len] = val;
|
||||
ary_len = new_len;
|
||||
return this;
|
||||
}
|
||||
public Char_bfr Add_chry(char[] val) {
|
||||
int val_len = val.length;
|
||||
if (ary_len + val_len > ary_max) Resize((ary_max + val_len) * 2);
|
||||
Copy_to(val, 0, val_len, ary, ary_len);
|
||||
ary_len += val_len;
|
||||
return this;
|
||||
}
|
||||
public Char_bfr Add_bry(byte[] val) {return Add_str(String_.new_u8(val));}
|
||||
public Char_bfr Add_str(String val) {
|
||||
int val_len = String_.Len(val);
|
||||
if (ary_len + val_len > ary_max) Resize((ary_max + val_len) * 2);
|
||||
Copy_to(val, 0, val_len, ary, ary_len);
|
||||
ary_len += val_len;
|
||||
return this;
|
||||
}
|
||||
private void Resize(int new_max) {
|
||||
ary_max = new_max;
|
||||
ary = Resize(ary, 0, new_max);
|
||||
}
|
||||
public String To_str_and_clear() {
|
||||
String rv = String_.new_charAry_(ary, 0, ary_len);
|
||||
ary_len = 0;
|
||||
ary_max = ary_max_reset;
|
||||
return rv;
|
||||
}
|
||||
public byte[] To_bry_and_clear() {
|
||||
return Bry_.new_u8(To_str_and_clear());
|
||||
}
|
||||
private static char[] Resize(char[] src, int src_bgn, int trg_len) {
|
||||
char[] trg = new char[trg_len];
|
||||
int src_len = src.length; if (src_len > trg_len) src_len = trg_len; // trg_len can be less than src_len
|
||||
Copy_to(src, src_bgn, src_len, trg, 0);
|
||||
return trg;
|
||||
}
|
||||
private static void Copy_to(char[] src, int src_bgn, int src_end, char[] trg, int trg_bgn) {
|
||||
int trg_adj = trg_bgn - src_bgn;
|
||||
for (int i = src_bgn; i < src_end; i++)
|
||||
trg[i + trg_adj] = src[i];
|
||||
}
|
||||
private static void Copy_to(String src, int src_bgn, int src_end, char[] trg, int trg_bgn) {
|
||||
int trg_adj = trg_bgn - src_bgn;
|
||||
for (int i = src_bgn; i < src_end; i++)
|
||||
trg[i + trg_adj] = String_.CharAt(src, i);
|
||||
}
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class XophpArrayUtl_tst { // REF:https://www.php.net/manual/en/function.array-merge.php
|
||||
private final XophpArrayUtl_fxt fxt = new XophpArrayUtl_fxt();
|
||||
@Test public void array_merge__basic() {
|
||||
XophpArray ary1 = fxt.Make().Add("key1", "val1").Add("a");
|
||||
XophpArray ary2 = fxt.Make().Add("key2", "val2").Add("b");
|
||||
fxt.Test__array_merge
|
||||
( fxt.Make().Add("key1", "val1").Add("a").Add("key2", "val2").Add("b")
|
||||
, ary1, ary2);
|
||||
}
|
||||
@Test public void array_merge__same_key() {
|
||||
XophpArray ary1 = fxt.Make().Add("key", "val1");
|
||||
XophpArray ary2 = fxt.Make().Add("key", "val2");
|
||||
fxt.Test__array_merge
|
||||
( fxt.Make().Add("key", "val2")
|
||||
, ary1, ary2);
|
||||
}
|
||||
@Test public void array_merge__same_idx() {
|
||||
XophpArray ary1 = fxt.Make().Add(0, "a");
|
||||
XophpArray ary2 = fxt.Make().Add(0, "b");
|
||||
fxt.Test__array_merge
|
||||
( fxt.Make().Add(0, "a").Add(1, "b")
|
||||
, ary1, ary2);
|
||||
}
|
||||
@Test public void array_merge__renumber() {
|
||||
XophpArray ary1 = fxt.Make().Add(3, "a");
|
||||
XophpArray ary2 = fxt.Make().Add(2, "b");
|
||||
fxt.Test__array_merge
|
||||
( fxt.Make().Add(0, "a").Add(1, "b")
|
||||
, ary1, ary2);
|
||||
}
|
||||
@Test public void array_merge__example_1() {
|
||||
XophpArray ary1 = fxt.Make().Add("color", "red").Add_many(2, 4);
|
||||
XophpArray ary2 = fxt.Make().Add_many("a", "b").Add("color", "green").Add("shape", "trapezoid").Add(4);
|
||||
fxt.Test__array_merge
|
||||
( fxt.Make().Add("color", "green").Add_many(2, 4, "a", "b").Add("shape", "trapezoid").Add(4)
|
||||
, ary1, ary2);
|
||||
}
|
||||
@Test public void array_merge__example_2() {
|
||||
XophpArray ary1 = fxt.Make();
|
||||
XophpArray ary2 = fxt.Make().Add(1, "data");
|
||||
fxt.Test__array_merge
|
||||
( fxt.Make().Add(0, "data")
|
||||
, ary1, ary2);
|
||||
}
|
||||
@Test public void array_splice__bgn_is_positive() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("b", "c", "d")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__bgn_is_positive_large() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 99);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a", "b", "c", "d")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many()
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__bgn_is_negative() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, -3);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("b", "c", "d")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__bgn_is_negative_large() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, -99);
|
||||
fxt.Test__eq
|
||||
( fxt.Make()
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a", "b", "c", "d")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__len_is_positive() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, 2);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a", "d")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("b", "c")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__len_is_positive_large() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, 99);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("b", "c", "d")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__len_is_negative() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, -2);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a", "c", "d")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("b")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__len_is_negative_large() {
|
||||
XophpArray src = fxt.Make().Add_many("a", "b", "c", "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, -99);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("a", "b", "c", "d")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make()
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__repl() {
|
||||
XophpArray src = fxt.Make().Add(0, "a").Add(1, "b").Add(2, "c").Add(3, "d");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, 2, fxt.Make().Add(0, "x"));
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add(0, "a").Add(1, "x").Add(2, "d")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add(0, "b").Add(1, "c")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__example_1a() {
|
||||
XophpArray src = fxt.Make().Add_many("red", "green", "blue", "yellow");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 2);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("red", "green")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("blue", "yellow")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__example_1b() {
|
||||
XophpArray src = fxt.Make().Add_many("red", "green", "blue", "yellow");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, -1);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("red", "yellow")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("green", "blue")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__example_1c() {
|
||||
XophpArray src = fxt.Make().Add_many("red", "green", "blue", "yellow");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, 1, 4, XophpArray.New("orange"));
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("red", "orange")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("green", "blue", "yellow")
|
||||
, del
|
||||
);
|
||||
}
|
||||
@Test public void array_splice__example_1d() {
|
||||
XophpArray src = fxt.Make().Add_many("red", "green", "blue", "yellow");
|
||||
XophpArray del = XophpArrayUtl.array_splice(src, -1, 1, XophpArray.New("black", "maroon"));
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("red", "green", "blue", "black", "maroon")
|
||||
, src
|
||||
);
|
||||
fxt.Test__eq
|
||||
( fxt.Make().Add_many("yellow")
|
||||
, del
|
||||
);
|
||||
}
|
||||
}
|
||||
class XophpArrayUtl_fxt {
|
||||
public XophpArray Make() {return new XophpArray();}
|
||||
public void Test__array_merge(XophpArray expd, XophpArray... vals) {
|
||||
XophpArray actl = XophpArrayUtl.array_merge(vals);
|
||||
Gftest.Eq__str(expd.To_str(), actl.To_str());
|
||||
}
|
||||
public void Test__eq(XophpArray expd, XophpArray actl) {
|
||||
Gftest.Eq__str(expd.To_str(), actl.To_str());
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Xophp_ary implements Bry_bfr_able {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private int nxt_idx;
|
||||
public Xophp_ary Add(Object val) {
|
||||
int key = nxt_idx++;
|
||||
Xophp_ary_itm itm = Xophp_ary_itm.New(key, val);
|
||||
hash.Add_if_dupe_use_nth(key, itm);
|
||||
return this;
|
||||
}
|
||||
public Xophp_ary Add(int key, Object val) {
|
||||
nxt_idx = key + 1;
|
||||
Xophp_ary_itm itm = Xophp_ary_itm.New(key, val);
|
||||
hash.Add_if_dupe_use_nth(key, itm);
|
||||
return this;
|
||||
}
|
||||
public Xophp_ary Add(double key, Object val) {
|
||||
int key_as_int = (int)key;
|
||||
nxt_idx = key_as_int + 1;
|
||||
Xophp_ary_itm itm = Xophp_ary_itm.New(key_as_int, val);
|
||||
hash.Add_if_dupe_use_nth(key_as_int, itm);
|
||||
return this;
|
||||
}
|
||||
public Xophp_ary Add(boolean key, Object val) {
|
||||
int key_as_int = key ? 1 : 0;
|
||||
nxt_idx = key_as_int + 1;
|
||||
Xophp_ary_itm itm = Xophp_ary_itm.New(key_as_int, val);
|
||||
hash.Add_if_dupe_use_nth(key_as_int, itm);
|
||||
return this;
|
||||
}
|
||||
public Xophp_ary Add(String key, Object val) {
|
||||
Xophp_ary_itm itm = null;
|
||||
int key_as_int = Int_.Parse_or(key, Int_.Min_value);
|
||||
if (key_as_int != Int_.Min_value) {
|
||||
itm = Xophp_ary_itm.New(key_as_int, val);
|
||||
nxt_idx = key_as_int + 1;
|
||||
hash.Add_if_dupe_use_nth(key_as_int, itm);
|
||||
}
|
||||
else {
|
||||
itm = Xophp_ary_itm.New(key, val);
|
||||
hash.Add_if_dupe_use_nth(key, itm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Object Get(Object key) {
|
||||
Xophp_ary_itm itm = (Xophp_ary_itm)hash.Get_by(key);
|
||||
return itm.Val();
|
||||
}
|
||||
public void Unset(Object key) {
|
||||
hash.Del(key);
|
||||
}
|
||||
public boolean Has(Object key) {
|
||||
return hash.Has(key);
|
||||
}
|
||||
public Xophp_ary Values() {
|
||||
Xophp_ary rv = new Xophp_ary();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xophp_ary_itm old_itm = (Xophp_ary_itm)hash.Get_at(i);
|
||||
rv.Add(i, old_itm.Val());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xophp_ary_itm[] To_ary() {
|
||||
return (Xophp_ary_itm[])hash.To_ary(Xophp_ary_itm.class);
|
||||
}
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
Xophp_ary_itm[] itms = To_ary();
|
||||
for (Xophp_ary_itm itm : itms) {
|
||||
itm.To_bfr(bfr);
|
||||
}
|
||||
}
|
||||
public static Xophp_ary New() {return new Xophp_ary();}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.mediawiki.includes.parsers.preprocessors.*;
|
||||
// THREAD.UNSAFE: caching for repeated calls
|
||||
class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private Xomw_prepro_accum__dom accum_dom = new Xomw_prepro_accum__dom("");
|
||||
|
||||
@Override protected Xomw_prepro_accum Factory__accum() {return Xomw_prepro_accum__dom.Instance;}
|
||||
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_DOM("");}
|
||||
|
||||
@Override public XomwPPNode preprocessToObj(String text, int flags) {
|
||||
return null;
|
||||
}
|
||||
@Override public XomwPPFrame newFrame() {
|
||||
return null;
|
||||
}
|
||||
@Override public XomwPPFrame newCustomFrame(XomwPPFrame args) {
|
||||
return null;
|
||||
}
|
||||
@Override protected Xomw_prepro_accum Accum__set(Xomw_prepro_accum accum) {
|
||||
this.accum_dom = (Xomw_prepro_accum__dom)accum;
|
||||
return accum;
|
||||
}
|
||||
|
||||
@Override protected void preprocessToObj_root() {
|
||||
accum_dom.Clear();
|
||||
accum_dom.Add_str_literal("<root>");
|
||||
}
|
||||
@Override protected void preprocessToObj_ignore(byte[] src, int bgn, int end) {
|
||||
accum_dom.Add_str_literal("<ignore>").Add_str_escaped(src, bgn, end).Add_str_literal("</ignore>");
|
||||
}
|
||||
@Override protected void preprocessToObj_comment(byte[] src, int bgn, int end) {
|
||||
accum_dom.Add_str_literal("<comment>").Add_str_escaped(src, bgn, end).Add_str_literal("</comment>");
|
||||
}
|
||||
@Override protected void preprocessToObj_literal(byte[] src, int bgn, int end) {
|
||||
accum_dom.Add_str_escaped(src, bgn, end);
|
||||
}
|
||||
@Override protected void preprocessToObj_removeLeadingWhitespaceFromEnd(int ws_len) {
|
||||
int accum_dom_len = accum_dom.Len();
|
||||
if ( ws_len > 0
|
||||
&& XophpString.strspn_fwd__space_or_tab(accum_dom.Bfr_bry(), accum_dom_len - ws_len, -1, accum_dom_len) == ws_len) {
|
||||
accum_dom.Del_at_end(ws_len);
|
||||
}
|
||||
}
|
||||
@Override protected byte[] preprocessToObj_close_init() {return Bry_.Empty;}
|
||||
@Override protected byte[] preprocessToObj_close_make(byte[] src, int bgn, int end) {
|
||||
return tmp_bfr.Add_str_a7("<close>").Add_bry_escape_html(src, bgn, end).Add_str_a7("</close>").To_bry_and_clear();
|
||||
}
|
||||
@Override protected void preprocessToObj_ext(byte[] src, byte[] name, int atr_bgn, int atr_end, byte[] inner, byte[] close) {
|
||||
accum_dom.Add_str_literal("<ext>");
|
||||
// PORTED:
|
||||
// if ( $attrEnd <= $attrStart ) {
|
||||
// $attr = '';
|
||||
// } else {
|
||||
// $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
|
||||
// }
|
||||
accum_dom.Add_str_literal("<name>").Add_bry(name).Add_str_literal("</name>");
|
||||
// Note that the attr element contains the whitespace between name and attribute,
|
||||
// this is necessary for precise reconstruction during pre-save transform.
|
||||
accum_dom.Add_str_literal("<attr>");
|
||||
if (atr_end > atr_bgn)
|
||||
accum_dom.Add_str_escaped(src, atr_bgn, atr_end);
|
||||
accum_dom.Add_str_literal("</attr>");
|
||||
if (inner != null) {
|
||||
accum_dom.Add_str_literal("<inner>").Add_str_escaped(inner, 0, inner.length).Add_str_literal("</inner>");
|
||||
}
|
||||
accum_dom.Add_bry(close).Add_str_literal("</ext>");
|
||||
}
|
||||
@Override protected Xomw_prepro_accum preprocessToObj_heading_init(int count, int heading_index) {
|
||||
byte[] rv = tmp_bfr.Add_str_a7("<h level=\"").Add_int_variable(count).Add_str_a7("\" i=\"").Add_int_variable(heading_index).Add_str_a7("\">").Add_str_u8(accum_dom.To_str()).Add_str_a7("</h>").To_bry_and_clear();
|
||||
return new Xomw_prepro_accum__dom(String_.new_u8(rv));
|
||||
}
|
||||
@Override protected void preprocessToObj_heading_end(Xomw_prepro_accum element) {
|
||||
accum_dom.Add_bry(((Xomw_prepro_accum__dom)element).To_bry());
|
||||
}
|
||||
@Override protected Xomw_prepro_accum preprocessToObj_text(Xomw_prepro_accum element_obj, Xomw_prepro_piece piece, byte[] rule_end, int matching_count) {
|
||||
Xomw_prepro_accum__dom element = (Xomw_prepro_accum__dom)element_obj;
|
||||
tmp_bfr.Add(piece.Break_syntax(tmp_bfr, matching_count));
|
||||
if (element != null)
|
||||
tmp_bfr.Add(element.To_bry());
|
||||
tmp_bfr.Add(Bry_.Repeat_bry(rule_end, matching_count));
|
||||
byte[] rv = tmp_bfr.To_bry_and_clear();
|
||||
return new Xomw_prepro_accum__dom(String_.new_u8(rv));
|
||||
}
|
||||
@Override protected Xomw_prepro_accum preprocessToObj_xml(Xomw_prepro_piece piece, byte[] name_bry, int max_count, int matching_count) {
|
||||
// Note: $parts is already XML, does not need to be encoded further
|
||||
List_adp parts = piece.parts;
|
||||
byte[] title = ((XomwPPDPart_DOM)parts.Get_at(0)).To_bry();
|
||||
parts.Del_at(0);
|
||||
|
||||
// The invocation is at the start of the line if lineStart is set in
|
||||
// the stack, and all opening brackets are used up.
|
||||
byte[] attr = null;
|
||||
if (max_count == matching_count && piece.line_start) { // RELIC:!empty( $piece->lineStart )
|
||||
attr = Bry_.new_a7(" lineStart=\"1\"");
|
||||
}
|
||||
else {
|
||||
attr = Bry_.Empty;
|
||||
}
|
||||
|
||||
tmp_bfr.Add_str_a7("<").Add(name_bry).Add(attr).Add_str_a7(">");
|
||||
tmp_bfr.Add_str_a7("<title>").Add(title).Add_str_a7("</title>");
|
||||
|
||||
int arg_idx = 1;
|
||||
int parts_len = parts.Len();
|
||||
for (int j = 0; j < parts_len; j++) {
|
||||
XomwPPDPart_DOM part = (XomwPPDPart_DOM)parts.Get_at(j);
|
||||
if (part.eqpos != -1) {
|
||||
byte[] part_bfr_bry = part.To_bry();
|
||||
tmp_bfr.Add_str_a7("<part><name>").Add_mid(part_bfr_bry, 0, part.eqpos);
|
||||
tmp_bfr.Add_str_a7("</name>=<value>").Add_mid(part_bfr_bry, part.eqpos + 1, part.Len());
|
||||
tmp_bfr.Add_str_a7("</value></part>");
|
||||
}
|
||||
else {
|
||||
tmp_bfr.Add_str_a7("<part><name index=\"").Add_int_variable(arg_idx).Add_str_a7("\" /><value>").Add(part.To_bry()).Add_str_a7("</value></part>");
|
||||
arg_idx++;
|
||||
}
|
||||
}
|
||||
byte[] element = tmp_bfr.Add_str_a7("</").Add(name_bry).Add_str_a7(">").To_bry_and_clear();
|
||||
return new Xomw_prepro_accum__dom(String_.new_u8(element));
|
||||
}
|
||||
@Override protected void preprocessToObj_add_element(Xomw_prepro_accum element) {
|
||||
accum_dom.Add_bry(((Xomw_prepro_accum__dom)element).To_bry());
|
||||
}
|
||||
@Override protected void preprocessToObj_equals(XomwPPDStack stack) {
|
||||
stack.Get_current_part().eqpos = accum_dom.Len();
|
||||
accum_dom.Add_bry(Byte_ascii.Eq_bry);
|
||||
}
|
||||
@Override protected Object preprocessToObj_term(XomwPPDStack stack) {
|
||||
Bry_bfr root_accum = Bry_bfr_.New().Add_str_u8(((Xomw_prepro_accum__dom)stack.Get_root_accum()).To_str());
|
||||
int stack_len = stack.stack.Len();
|
||||
for (int j = 0; j < stack_len; j++) {
|
||||
Xomw_prepro_piece piece = (Xomw_prepro_piece)stack.stack.Get_at(j);
|
||||
root_accum.Add(piece.Break_syntax(tmp_bfr, -1));
|
||||
}
|
||||
root_accum.Add_str_a7("</root>");
|
||||
return root_accum.To_bry_and_clear();
|
||||
}
|
||||
|
||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_DOM();}
|
||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_DOM();
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.xowa.mediawiki.includes.parsers.preprocessors.*;
|
||||
class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum = new XophpArray();
|
||||
@Override public XomwPPNode preprocessToObj(String text, int flags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public XomwPPFrame newFrame() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public XomwPPFrame newCustomFrame(XomwPPFrame args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override protected Xomw_prepro_accum Factory__accum() {return Xomw_prepro_accum__hash.Instance;}
|
||||
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_Hash("");}
|
||||
@Override protected Xomw_prepro_accum Accum__set(Xomw_prepro_accum accum) {return accum;}
|
||||
|
||||
@Override protected void preprocessToObj_root() {} // NOTE: deliberately empty;
|
||||
|
||||
@Override protected void preprocessToObj_ignore(byte[] src, int bgn, int end) {
|
||||
accum.Add(XophpArray.New("ignore", XophpString.substr(src, bgn, end)));
|
||||
}
|
||||
@Override protected void preprocessToObj_literal(byte[] src, int bgn, int end) {
|
||||
addLiteral(accum, XophpString.substr(src, bgn, end));
|
||||
}
|
||||
@Override protected void preprocessToObj_comment(byte[] src, int bgn, int end) {
|
||||
accum.Add(XophpArray.New("comment", XophpString.substr(src, bgn, end)));
|
||||
}
|
||||
@Override protected void preprocessToObj_removeLeadingWhitespaceFromEnd(int ws_len) {
|
||||
int endIndex = accum.Len() - 1;
|
||||
if ( ws_len > 0
|
||||
&& endIndex >= 0) {
|
||||
Object itm_obj = accum.Get(endIndex);
|
||||
if (Type_.Eq_by_obj(itm_obj, Bry_.Cls_ref_type)) {
|
||||
byte[] itm = (byte[])itm_obj;
|
||||
if (XophpString.strspn_fwd__space_or_tab(itm, 0, itm.length, itm.length) == ws_len) {
|
||||
accum.Set(endIndex, XophpString.substr(itm, 0, -ws_len));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override protected byte[] preprocessToObj_close_init() {return null;}
|
||||
@Override protected byte[] preprocessToObj_close_make(byte[] src, int bgn, int end) {
|
||||
return Bry_.Mid(src, bgn, end);
|
||||
}
|
||||
@Override protected void preprocessToObj_ext(byte[] src, byte[] name, int atr_bgn, int atr_end, byte[] inner, byte[] close) {
|
||||
XophpArray children = XophpArray.New();
|
||||
children.Add(XophpArray.New("name", name));
|
||||
children.Add(XophpArray.New("attr", Bry_.Mid(src, atr_bgn, atr_end)));
|
||||
if (inner != null)
|
||||
children.Add(XophpArray.New("inner", inner));
|
||||
if (close != null)
|
||||
children.Add(XophpArray.New("close", close));
|
||||
accum.Add(XophpArray.New("ext", children));
|
||||
}
|
||||
@Override protected Xomw_prepro_accum preprocessToObj_heading_init(int count, int heading_index) {
|
||||
Xomw_prepro_accum__hash rv = new Xomw_prepro_accum__hash();
|
||||
rv.Ary().Add
|
||||
( XophpArray.New
|
||||
( "possible-h",
|
||||
XophpArrayUtl.array_merge
|
||||
( XophpArray.New
|
||||
( XophpArray.New("@level", XophpArray.New(count))
|
||||
, XophpArray.New("@i" , XophpArray.New(heading_index))
|
||||
)
|
||||
, accum
|
||||
)
|
||||
)
|
||||
);
|
||||
return rv;
|
||||
}
|
||||
@Override protected void preprocessToObj_heading_end(Xomw_prepro_accum element) {
|
||||
XophpArrayUtl.array_splice(accum, accum.Len(), 0, ((Xomw_prepro_accum__hash)element).Ary());
|
||||
}
|
||||
|
||||
@Override protected Xomw_prepro_accum preprocessToObj_text(Xomw_prepro_accum element_obj, Xomw_prepro_piece piece, byte[] rule_end, int matching_count) {
|
||||
Xomw_prepro_accum__hash element = (Xomw_prepro_accum__hash)element_obj;
|
||||
// element = piece.breakSyntax(matchingCount);
|
||||
addLiteral(element.Ary(), String_.new_u8(Bry_.Repeat_bry(rule_end, matching_count)));
|
||||
return element;
|
||||
}
|
||||
@Override protected Xomw_prepro_accum preprocessToObj_xml(Xomw_prepro_piece piece, byte[] name_bry, int max_count, int matching_count) {
|
||||
List_adp parts = piece.parts;
|
||||
byte[] title = ((XomwPPDPart_DOM)parts.Get_at(0)).To_bry();
|
||||
parts.Del_at(0);
|
||||
|
||||
XophpArray children = XophpArray.New();
|
||||
|
||||
// The invocation is at the start of the line if lineStart is set in
|
||||
// the stack, and all opening brackets are used up.
|
||||
if (max_count == matching_count && piece.line_start) { // RELIC:!empty( $piece->lineStart )
|
||||
children.Add(XophpArray.New("@lineStart", XophpArray.New(1)));
|
||||
}
|
||||
XophpArray titleNode = XophpArray.New("title", title);
|
||||
children.Add(titleNode);
|
||||
|
||||
// int argIndex = 1;
|
||||
int parts_len = parts.Len();
|
||||
for (int j = 0; j < parts_len; j++) {
|
||||
XomwPPDPart part = (XomwPPDPart)parts.Get_at(j);
|
||||
if (part.eqpos != -1) {
|
||||
/*
|
||||
Object equalsNode = part.Out()[part.eqpos];
|
||||
XophpArray nameNode = XophpArray.New("name" , XophpArrayUtl.array_splice(part.Out(), 0, part.eqpos));
|
||||
XophpArray valueNode = XophpArray.New("value", XophpArrayUtl.array_splice(part.Out(), part.eqpos + 1));
|
||||
XophpArray partNode = XophpArray.New("part", XophpArray.New(nameNode, equalsNode, valueNode));
|
||||
children.Add(partNode);
|
||||
*/
|
||||
}
|
||||
else {
|
||||
/*
|
||||
XophpArray nameNode = XophpArray.New("name" , XophpArray.New(XophpArray.New("@index", XophpArray.New(argIndex++))));
|
||||
XophpArray valueNode = XophpArray.New("value", part.Out());
|
||||
XophpArray partNode = XophpArray.New("part", XophpArray.New(nameNode, valueNode));
|
||||
children.Add(partNode);
|
||||
*/
|
||||
}
|
||||
}
|
||||
// XophpArray element = XophpArray.New(XophpArray.New(name, children));
|
||||
// return new Xomw_prepro_piece__hash(element);
|
||||
return null;
|
||||
}
|
||||
@Override protected void preprocessToObj_add_element(Xomw_prepro_accum element) {
|
||||
XophpArrayUtl.array_splice(accum, accum.Len(), 0, ((Xomw_prepro_accum__hash)element).Ary());
|
||||
}
|
||||
@Override protected void preprocessToObj_equals(XomwPPDStack stack) {
|
||||
accum.Add(XophpArray.New("equals", XophpArray.New("=")));
|
||||
stack.Get_current_part().eqpos = accum.Len() - 1;
|
||||
}
|
||||
@Override protected Object preprocessToObj_term(XomwPPDStack stack) {
|
||||
// for ( $stack->stack as $piece ) {
|
||||
// array_splice( $stack->rootAccum, count( $stack->rootAccum ), 0, $piece->breakSyntax() );
|
||||
// }
|
||||
//
|
||||
// # Enable top-level headings
|
||||
// for ( $stack->rootAccum as &$node ) {
|
||||
// if ( is_array( $node ) && $node[PPNode_Hash_Tree::NAME] === 'possible-h' ) {
|
||||
// $node[PPNode_Hash_Tree::NAME] = 'h';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $rootStore = [ [ 'root', $stack->rootAccum ] ];
|
||||
// $rootNode = new PPNode_Hash_Tree( $rootStore, 0 );
|
||||
//
|
||||
// // Cache
|
||||
// $tree = json_encode( $rootStore, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
|
||||
// if ( $tree !== false ) {
|
||||
// $this->cacheSetTree( $text, $flags, $tree );
|
||||
// }
|
||||
//
|
||||
// return $rootNode;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void addLiteral(XophpArray accum, byte[] text) {addLiteral(accum, String_.new_u8(text));}
|
||||
private static void addLiteral(XophpArray accum, String text) {
|
||||
int n = accum.Len();
|
||||
if (n > 0) {
|
||||
Object itm = accum.Get(n - 1);
|
||||
if (itm != null) {
|
||||
accum.Set(n - 1, ((String)itm) + text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
accum.Add(text);
|
||||
}
|
||||
|
||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_Hash();}
|
||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_Hash();
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
// MW.FILE:Preprocessor_DOM
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*/
|
||||
public abstract class XomwPPDPart {
|
||||
/**
|
||||
* @var String Output accumulator String
|
||||
*/
|
||||
// private final byte[] output;
|
||||
|
||||
// Optional member variables:
|
||||
// eqpos Position of equals sign in output accumulator
|
||||
// commentEnd Past-the-end input pointer for the last comment encountered
|
||||
// visualEnd Past-the-end input pointer for the end of the accumulator minus comments
|
||||
public int eqpos = -1;
|
||||
public int commentEnd = -1;
|
||||
public int visualEnd = -1;
|
||||
|
||||
public XomwPPDPart(String output) {
|
||||
// accum.Add_bry(Bry_.new_u8(output));
|
||||
// bfr = ((Xomw_prepro_accum__dom)accum).Bfr();
|
||||
}
|
||||
// private final Xomw_prepro_accum__dom accum = new Xomw_prepro_accum__dom("");
|
||||
// private final Bry_bfr bfr;
|
||||
public abstract Xomw_prepro_accum Accum();
|
||||
//
|
||||
// public Bry_bfr Bfr() {return bfr;}
|
||||
// public int Len() {return bfr.Len();}
|
||||
// public byte[] To_bry() {return bfr.To_bry();}
|
||||
|
||||
public abstract XomwPPDPart Make_new(String val);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
// MW.FILE:NONE
|
||||
public class XomwPPDPart_DOM extends XomwPPDPart { // @codingStandardsIgnoreEnd
|
||||
private final Bry_bfr bfr;
|
||||
private final Xomw_prepro_accum__dom accum = new Xomw_prepro_accum__dom("");
|
||||
public XomwPPDPart_DOM(String output) {super(output);
|
||||
bfr = accum.Bfr();
|
||||
if (output != String_.Empty) {
|
||||
bfr.Add_str_u8(output);
|
||||
}
|
||||
}
|
||||
@Override public Xomw_prepro_accum Accum() {return accum;}
|
||||
public Bry_bfr Bfr() {return bfr;}
|
||||
public int Len() {return bfr.Len();}
|
||||
public byte[] To_bry() {return bfr.To_bry();}
|
||||
|
||||
@Override public XomwPPDPart Make_new(String val) {
|
||||
return new XomwPPDPart_DOM(val);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
// MW.FILE:Preprocessor_Hash
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*/
|
||||
// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
public class XomwPPDPart_Hash extends XomwPPDPart { // @codingStandardsIgnoreEnd
|
||||
private final Xomw_prepro_accum__hash accum = new Xomw_prepro_accum__hash();
|
||||
public XomwPPDPart_Hash(String output) {super(output);
|
||||
if (output != String_.Empty) {
|
||||
accum.Ary().Add(output);
|
||||
}
|
||||
}
|
||||
@Override public Xomw_prepro_accum Accum() {return accum;}
|
||||
@Override public XomwPPDPart Make_new(String val) {
|
||||
return new XomwPPDPart_Hash(val);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
// MW.FILE:Preprocessor_DOM
|
||||
/**
|
||||
* Stack class to help Preprocessor::preprocessToObj()
|
||||
* @ingroup Parser
|
||||
*/
|
||||
public class XomwPPDStack {
|
||||
public final List_adp stack = List_adp_.New();
|
||||
public Xomw_prepro_piece top;
|
||||
private final Xomw_prepro_flags flags = new Xomw_prepro_flags();
|
||||
private Xomw_prepro_accum root_accum, accum;
|
||||
|
||||
public XomwPPDStack(Xomw_prepro_accum prototype) {
|
||||
root_accum = prototype.Make_new();
|
||||
accum = root_accum;
|
||||
}
|
||||
public void Clear() {
|
||||
stack.Clear();
|
||||
accum.Clear();
|
||||
top = null;
|
||||
}
|
||||
public int Count() {return stack.Len();}
|
||||
|
||||
public Xomw_prepro_accum Get_accum() {return accum;}
|
||||
public Xomw_prepro_accum Get_root_accum() {return root_accum;}
|
||||
|
||||
public XomwPPDPart Get_current_part() {
|
||||
if (top == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return top.Get_current_part();
|
||||
}
|
||||
}
|
||||
|
||||
public void Push(Xomw_prepro_piece item) {
|
||||
stack.Add(item);
|
||||
this.top = (Xomw_prepro_piece)stack.Get_at(stack.Len() - 1);
|
||||
accum = top.Get_accum();
|
||||
}
|
||||
|
||||
public Xomw_prepro_piece Pop() {
|
||||
int len = stack.Count();
|
||||
if (len == 0) {
|
||||
throw Err_.new_wo_type("XomwPPDStack: no elements remaining");
|
||||
}
|
||||
|
||||
Xomw_prepro_piece rv = (Xomw_prepro_piece)stack.Get_at(len - 1);
|
||||
stack.Del_at(len - 1);
|
||||
len--;
|
||||
|
||||
if (len > 0) {
|
||||
this.top = (Xomw_prepro_piece)stack.Get_at(stack.Len() - 1);
|
||||
this.accum = top.Get_accum();
|
||||
} else {
|
||||
this.top = null;
|
||||
this.accum = root_accum;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public void Add_part(byte[] bry) {
|
||||
top.Add_part(bry);
|
||||
accum = top.Get_accum();
|
||||
}
|
||||
|
||||
public Xomw_prepro_flags Get_flags() {
|
||||
if (stack.Count() == 0) {
|
||||
flags.findEquals = false;
|
||||
flags.findPipe = false;
|
||||
flags.inHeading = false;
|
||||
return flags;
|
||||
}
|
||||
else {
|
||||
top.Set_flags(flags);
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
// MW.FILE:Preprocessor
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*/
|
||||
public abstract class XomwPPFrame {
|
||||
public static final int NO_ARGS = 1;
|
||||
public static final int NO_TEMPLATES = 2;
|
||||
public static final int STRIP_COMMENTS = 4;
|
||||
public static final int NO_IGNORE = 8;
|
||||
public static final int RECOVER_COMMENTS = 16;
|
||||
public static final int NO_TAGS = 32;
|
||||
|
||||
public static final int RECOVER_ORIG = 59; // = 1|2|8|16|32 no constant expression support in PHP yet
|
||||
|
||||
/** This constant exists when $indexOffset is supported in newChild() */
|
||||
public static final int SUPPORTS_INDEX_OFFSET = 1;
|
||||
|
||||
/**
|
||||
* Create a child frame
|
||||
*
|
||||
* @param array|boolean $args
|
||||
* @param boolean|Title $title
|
||||
* @param int $indexOffset A number subtracted from the index attributes of the arguments
|
||||
*
|
||||
* @return PPFrame
|
||||
*/
|
||||
public abstract XomwPPFrame newChild(Object args, XomwTitle title, int indexOffset);
|
||||
|
||||
/**
|
||||
* Expand a document tree node, caching the result on its parent with the given key
|
||||
* @param String|int $key
|
||||
* @param String|PPNode $root
|
||||
* @param int $flags
|
||||
* @return String
|
||||
*/
|
||||
public abstract String cachedExpand(String key, XomwPPNode root, int flags);
|
||||
|
||||
/**
|
||||
* Expand a document tree node
|
||||
* @param String|PPNode $root
|
||||
* @param int $flags
|
||||
* @return String
|
||||
*/
|
||||
public abstract String expand(XomwPPNode root, int flags);
|
||||
|
||||
/**
|
||||
* Implode with flags for expand()
|
||||
* @param String $sep
|
||||
* @param int $flags
|
||||
* @param String|PPNode $args,...
|
||||
* @return String
|
||||
*/
|
||||
public abstract String implodeWithFlags(String sep, int flags, Object... args);
|
||||
|
||||
/**
|
||||
* Implode with no flags specified
|
||||
* @param String $sep
|
||||
* @param String|PPNode $args,...
|
||||
* @return String
|
||||
*/
|
||||
public abstract String implode(String sep, Object... args);
|
||||
|
||||
/**
|
||||
* Makes an Object that, when expand()ed, will be the same as one obtained
|
||||
* with implode()
|
||||
* @param String $sep
|
||||
* @param String|PPNode $args,...
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode virtualImplode(String sep, Object... args);
|
||||
|
||||
/**
|
||||
* Virtual implode with brackets
|
||||
* @param String $start
|
||||
* @param String $sep
|
||||
* @param String $end
|
||||
* @param String|PPNode $args,...
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode virtualBracketedImplode(String start, String sep, String end, Object... args);
|
||||
|
||||
/**
|
||||
* Returns true if there are no arguments in this frame
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Returns all arguments of this frame
|
||||
* @return array
|
||||
*/
|
||||
public abstract Object[] getArguments();
|
||||
|
||||
/**
|
||||
* Returns all numbered arguments of this frame
|
||||
* @return array
|
||||
*/
|
||||
public abstract Object[] getNumberedArguments();
|
||||
|
||||
/**
|
||||
* Returns all named arguments of this frame
|
||||
* @return array
|
||||
*/
|
||||
public abstract Object[] getNamedArguments();
|
||||
|
||||
/**
|
||||
* Get an argument to this frame by name
|
||||
* @param int|String $name
|
||||
* @return String|boolean
|
||||
*/
|
||||
public abstract String getArgument(String name);
|
||||
|
||||
/**
|
||||
* Returns true if the infinite loop check is OK, false if a loop is detected
|
||||
*
|
||||
* @param Title $title
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean loopCheck(XomwTitle title);
|
||||
|
||||
/**
|
||||
* Return true if the frame is a template frame
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isTemplate();
|
||||
|
||||
/**
|
||||
* Set the "volatile" flag.
|
||||
*
|
||||
* Note that this is somewhat of a "hack" in order to make extensions
|
||||
* with side effects (such as Cite) work with the PHP parser. New
|
||||
* extensions should be written in a way that they do not need this
|
||||
* function, because other parsers (such as Parsoid) are not guaranteed
|
||||
* to respect it, and it may be removed in the future.
|
||||
*
|
||||
* @param boolean $flag
|
||||
*/
|
||||
public abstract void setVolatile(boolean flag);
|
||||
|
||||
/**
|
||||
* Get the "volatile" flag.
|
||||
*
|
||||
* Callers should avoid caching the result of an expansion if it has the
|
||||
* volatile flag set.
|
||||
*
|
||||
* @see self::setVolatile()
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isVolatile();
|
||||
|
||||
/**
|
||||
* Get the TTL of the frame's output.
|
||||
*
|
||||
* This is the maximum amount of time, in seconds, that this frame's
|
||||
* output should be cached for. A value of null indicates that no
|
||||
* maximum has been specified.
|
||||
*
|
||||
* Note that this TTL only applies to caching frames as parts of pages.
|
||||
* It is not relevant to caching the entire rendered output of a page.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public abstract int getTTL();
|
||||
|
||||
/**
|
||||
* Set the TTL of the output of this frame and all of its ancestors.
|
||||
* Has no effect if the new TTL is greater than the one already set.
|
||||
* Note that it is the caller's responsibility to change the cache
|
||||
* expiry of the page as a whole, if such behavior is desired.
|
||||
*
|
||||
* @see self::getTTL()
|
||||
* @param int $ttl
|
||||
*/
|
||||
public abstract void setTTL(int ttl);
|
||||
|
||||
/**
|
||||
* Get a title of frame
|
||||
*
|
||||
* @return Title
|
||||
*/
|
||||
public abstract XomwTitle getTitle();
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
// MW.FILE:Preprocessor
|
||||
/**
|
||||
* There are three types of nodes:
|
||||
* * Tree nodes, which have a name and contain other nodes as children
|
||||
* * Array nodes, which also contain other nodes but aren't considered part of a tree
|
||||
* * Leaf nodes, which contain the actual data
|
||||
*
|
||||
* This interface provides access to the tree structure and to the contents of array nodes,
|
||||
* but it does not provide access to the @gplx.Internal protected structure of leaf nodes. Access to leaf
|
||||
* data is provided via two means:
|
||||
* * PPFrame::expand(), which provides expanded text
|
||||
* * The PPNode::split*() functions, which provide metadata about certain types of tree node
|
||||
* @ingroup Parser
|
||||
*/
|
||||
public abstract class XomwPPNode {
|
||||
/**
|
||||
* Get an array-type node containing the children of this node.
|
||||
* Returns false if this is not a tree node.
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode[] getChildren();
|
||||
|
||||
/**
|
||||
* Get the first child of a tree node. False if there isn't one.
|
||||
*
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode getFirstChild();
|
||||
|
||||
/**
|
||||
* Get the next sibling of any node. False if there isn't one
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode getNextSibling();
|
||||
|
||||
/**
|
||||
* Get all children of this tree node which have a given name.
|
||||
* Returns an array-type node, or false if this is not a tree node.
|
||||
* @param String $type
|
||||
* @return boolean|PPNode
|
||||
*/
|
||||
public abstract XomwPPNode getChildrenOfType(String type);
|
||||
|
||||
/**
|
||||
* Returns the length of the array, or false if this is not an array-type node
|
||||
*/
|
||||
public abstract int getLength();
|
||||
|
||||
/**
|
||||
* Returns an item of an array-type node
|
||||
* @param int $i
|
||||
* @return boolean|PPNode
|
||||
*/
|
||||
public abstract XomwPPNode item(int i);
|
||||
|
||||
/**
|
||||
* Get the name of this node. The following names are defined here:
|
||||
*
|
||||
* h A heading node.
|
||||
* template A double-brace node.
|
||||
* tplarg A triple-brace node.
|
||||
* title The first argument to a template or tplarg node.
|
||||
* part Subsequent arguments to a template or tplarg node.
|
||||
* #nodelist An array-type node
|
||||
*
|
||||
* The subclass may define various other names for tree and leaf nodes.
|
||||
* @return String
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Split a "<part>" node into an associative array containing:
|
||||
* name PPNode name
|
||||
* index String index
|
||||
* value PPNode value
|
||||
* @return array
|
||||
*/
|
||||
public abstract Hash_adp splitArg();
|
||||
|
||||
/**
|
||||
* Split an "<ext>" node into an associative array containing name, attr, inner and close
|
||||
* All values in the resulting array are PPNodes. Inner and close are optional.
|
||||
* @return array
|
||||
*/
|
||||
public abstract Hash_adp splitExt();
|
||||
|
||||
/**
|
||||
* Split an "<h>" node
|
||||
* @return array
|
||||
*/
|
||||
public abstract Hash_adp splitHeading();
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public interface Xomw_prepro_accum {
|
||||
void Clear();
|
||||
Xomw_prepro_accum Make_new();
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_prepro_accum__dom implements Xomw_prepro_accum {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public Xomw_prepro_accum__dom(String val) {
|
||||
this.Add_str_literal(val);
|
||||
}
|
||||
public Xomw_prepro_accum__dom Add_str_literal(String val) {
|
||||
bfr.Add_str_u8(val);
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Bfr() {return bfr;}
|
||||
public byte[] Bfr_bry() {return bfr.Bfr();}
|
||||
public int Len() {return bfr.Len();}
|
||||
public void Clear() {bfr.Clear();}
|
||||
public Xomw_prepro_accum__dom Add_str_escaped(byte[] src, int bgn, int end) {
|
||||
bfr.Add_bry_escape_html(src, bgn, end);
|
||||
return this;
|
||||
}
|
||||
public Xomw_prepro_accum__dom Add_bry(byte[] val) {
|
||||
bfr.Add(val);
|
||||
return this;
|
||||
}
|
||||
public Xomw_prepro_accum__dom Add_bry(byte[] val, int bgn, int end) {
|
||||
bfr.Add_mid(val, bgn, end);
|
||||
return this;
|
||||
}
|
||||
public void Del_at_end(int count) {
|
||||
bfr.Del_by(count);
|
||||
}
|
||||
public String To_str() {
|
||||
return bfr.To_str();
|
||||
}
|
||||
public byte[] To_bry() {
|
||||
return bfr.To_bry();
|
||||
}
|
||||
|
||||
public static final Xomw_prepro_accum__dom Instance = new Xomw_prepro_accum__dom("");
|
||||
public Xomw_prepro_accum Make_new() {return new Xomw_prepro_accum__dom("");}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_prepro_accum__hash implements Xomw_prepro_accum {
|
||||
public Xomw_prepro_accum__hash() {
|
||||
}
|
||||
public XophpArray Ary() {return ary;} private final XophpArray ary = new XophpArray();
|
||||
public void Clear() {ary.Clear();}
|
||||
|
||||
public static final Xomw_prepro_accum__hash Instance = new Xomw_prepro_accum__hash();
|
||||
public Xomw_prepro_accum Make_new() {return new Xomw_prepro_accum__hash();}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_prepro_curchar_itm {
|
||||
public Xomw_prepro_curchar_itm(byte[] bry, byte type) {
|
||||
this.bry = bry;
|
||||
this.type = type;
|
||||
}
|
||||
public byte[] bry;
|
||||
public byte type;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_prepro_elem {
|
||||
private static final byte[] Bry__tag_end = Bry_.new_a7("</");
|
||||
public Xomw_prepro_elem(int type, byte[] name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.tag_end_lhs = Bry_.Add(Bry__tag_end, name);
|
||||
}
|
||||
public final int type;
|
||||
public final byte[] name;
|
||||
public final byte[] tag_end_lhs;
|
||||
public static final int Type__comment = 0, Type__other = 1;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_prepro_flags {
|
||||
public boolean findPipe;
|
||||
public boolean findEquals;
|
||||
public boolean inHeading;
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_prepro_piece {
|
||||
public final byte[] open; // Opening character (\n for heading)
|
||||
public final byte[] close; // Matching closing char;
|
||||
public int count; // Number of opening characters found (number of "=" for heading)
|
||||
public final boolean line_start; // True if the open char appeared at the start of the input line; Not set for headings.
|
||||
public final int start_pos;
|
||||
public List_adp parts = List_adp_.New();
|
||||
private final XomwPPDPart part_factory;
|
||||
public Xomw_prepro_piece(XomwPPDPart part_factory, byte[] open, byte[] close, int count, int start_pos, boolean line_start) {
|
||||
this.part_factory = part_factory;
|
||||
this.open = open;
|
||||
this.close = close;
|
||||
this.count = count;
|
||||
this.start_pos = start_pos;
|
||||
this.line_start = line_start;
|
||||
parts.Add(part_factory.Make_new(""));
|
||||
}
|
||||
public void Parts__renew() {
|
||||
parts.Clear();
|
||||
this.Add_part(Bry_.Empty);
|
||||
}
|
||||
public XomwPPDPart Get_current_part() {
|
||||
return (XomwPPDPart)parts.Get_at(parts.Len() - 1);
|
||||
}
|
||||
public Xomw_prepro_accum Get_accum() {
|
||||
return Get_current_part().Accum();
|
||||
}
|
||||
public void Add_part(byte[] bry) {
|
||||
parts.Add(part_factory.Make_new(String_.new_u8(bry)));
|
||||
}
|
||||
public static final byte[] Brack_bgn_bry = Bry_.new_a7("[");
|
||||
public void Set_flags(Xomw_prepro_flags flags) {
|
||||
int parts_len = parts.Len();
|
||||
boolean open_is_nl = Bry_.Eq(open, Byte_ascii.Nl_bry);
|
||||
boolean findPipe = !open_is_nl && !Bry_.Eq(open, Brack_bgn_bry);
|
||||
flags.findPipe = findPipe;
|
||||
flags.findEquals = findPipe && parts_len > 1 && ((XomwPPDPart)parts.Get_at(parts_len - 1)).eqpos != -1;
|
||||
flags.inHeading = open_is_nl;
|
||||
}
|
||||
// Get the output String that would result if the close is not found.
|
||||
public byte[] Break_syntax(Bry_bfr tmp_bfr, int opening_count) {
|
||||
byte[] rv = Bry_.Empty;
|
||||
if (Bry_.Eq(open, Byte_ascii.Nl_bry)) {
|
||||
rv = ((XomwPPDPart_DOM)parts.Get_at(0)).To_bry();
|
||||
}
|
||||
else {
|
||||
if (opening_count == -1) {
|
||||
opening_count = count;
|
||||
}
|
||||
tmp_bfr.Add(Bry_.Repeat_bry(open, opening_count));
|
||||
|
||||
// concat parts with "|"
|
||||
boolean first = true;
|
||||
int len = parts.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
XomwPPDPart part = (XomwPPDPart)parts.Get_at(i);
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
tmp_bfr.Add_byte_pipe();
|
||||
}
|
||||
tmp_bfr.Add(((XomwPPDPart_DOM)part).To_bry());
|
||||
}
|
||||
rv = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers.prepros; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
class Xomw_prepro_stack {
|
||||
public List_adp stack = List_adp_.New();
|
||||
public Xomw_prepro_piece top;
|
||||
private Bry_bfr root_accum = Bry_bfr_.New(), accum;
|
||||
private final Xomw_prepro_flags flags = new Xomw_prepro_flags();
|
||||
|
||||
public Xomw_prepro_stack() {
|
||||
accum = root_accum;
|
||||
}
|
||||
public void Clear() {
|
||||
stack.Clear();
|
||||
accum.Clear();
|
||||
top = null;
|
||||
}
|
||||
public int Count() {return stack.Len();}
|
||||
public Bry_bfr Get_accum() {return accum;}
|
||||
public Bry_bfr Get_root_accum() {return root_accum;}
|
||||
|
||||
public Xomw_prepro_part Get_current_part() {
|
||||
if (top == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return top.Get_current_part();
|
||||
}
|
||||
}
|
||||
|
||||
public void Push(Xomw_prepro_piece item) {
|
||||
stack.Add(item);
|
||||
this.top = (Xomw_prepro_piece)stack.Get_at(stack.Len() - 1);
|
||||
accum = top.Get_accum();
|
||||
}
|
||||
|
||||
public Xomw_prepro_piece Pop() {
|
||||
int len = stack.Count();
|
||||
if (len == 0) {
|
||||
throw Err_.new_wo_type("Xomw_prepro_stack: no elements remaining");
|
||||
}
|
||||
|
||||
Xomw_prepro_piece rv = (Xomw_prepro_piece)stack.Get_at(len - 1);
|
||||
stack.Del_at(len - 1);
|
||||
len--;
|
||||
|
||||
if (len > 0) {
|
||||
this.top = (Xomw_prepro_piece)stack.Get_at(stack.Len() - 1);
|
||||
accum = top.Get_accum();
|
||||
} else {
|
||||
this.top = null;
|
||||
this.accum = root_accum;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public void Add_part(byte[] bry) {
|
||||
top.Add_part(bry);
|
||||
accum = top.Get_accum();
|
||||
}
|
||||
|
||||
public Xomw_prepro_flags Get_flags() {
|
||||
if (stack.Count() == 0) {
|
||||
flags.Find_eq = false;
|
||||
flags.Find_pipe = false;
|
||||
flags.In_heading = false;
|
||||
return flags;
|
||||
}
|
||||
else {
|
||||
top.Set_flags(flags);
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xomw_prepro_flags {
|
||||
public boolean Find_pipe;
|
||||
public boolean Find_eq;
|
||||
public boolean In_heading;
|
||||
}
|
||||
class Xomw_prepro_piece {
|
||||
public final byte[] open; // Opening character (\n for heading)
|
||||
public final byte[] close; // Matching closing char;
|
||||
public int count; // Number of opening characters found (number of "=" for heading)
|
||||
public final boolean line_start; // True if the open char appeared at the start of the input line; Not set for headings.
|
||||
public final int start_pos;
|
||||
public List_adp parts = List_adp_.New();
|
||||
public Xomw_prepro_piece(byte[] open, byte[] close, int count, int start_pos, boolean line_start) {
|
||||
this.open = open;
|
||||
this.close = close;
|
||||
this.count = count;
|
||||
this.start_pos = start_pos;
|
||||
this.line_start = line_start;
|
||||
parts.Add(new Xomw_prepro_part(Bry_.Empty));
|
||||
}
|
||||
public void Parts__renew() {
|
||||
parts.Clear();
|
||||
this.Add_part(Bry_.Empty);
|
||||
}
|
||||
public Xomw_prepro_part Get_current_part() {
|
||||
return (Xomw_prepro_part)parts.Get_at(parts.Len() - 1);
|
||||
}
|
||||
public Bry_bfr Get_accum() {
|
||||
return Get_current_part().bfr;
|
||||
}
|
||||
public void Add_part(byte[] bry) {
|
||||
parts.Add(new Xomw_prepro_part(bry));
|
||||
}
|
||||
public static final byte[] Brack_bgn_bry = Bry_.new_a7("[");
|
||||
public void Set_flags(Xomw_prepro_flags flags) {
|
||||
int parts_len = parts.Len();
|
||||
boolean open_is_nl = Bry_.Eq(open, Byte_ascii.Nl_bry);
|
||||
boolean find_pipe = !open_is_nl && !Bry_.Eq(open, Brack_bgn_bry);
|
||||
flags.Find_pipe = find_pipe;
|
||||
flags.Find_eq = find_pipe && parts_len > 1 && ((Xomw_prepro_part)parts.Get_at(parts_len - 1)).Eqpos != -1;
|
||||
flags.In_heading = open_is_nl;
|
||||
}
|
||||
// Get the output String that would result if the close is not found.
|
||||
public byte[] Break_syntax(Bry_bfr tmp_bfr, int opening_count) {
|
||||
byte[] rv = Bry_.Empty;
|
||||
if (Bry_.Eq(open, Byte_ascii.Nl_bry)) {
|
||||
rv = ((Xomw_prepro_part)parts.Get_at(0)).bfr.To_bry();
|
||||
}
|
||||
else {
|
||||
if (opening_count == -1) {
|
||||
opening_count = count;
|
||||
}
|
||||
tmp_bfr.Add(Bry_.Repeat_bry(open, opening_count));
|
||||
|
||||
// concat parts with "|"
|
||||
boolean first = true;
|
||||
int len = parts.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xomw_prepro_part part = (Xomw_prepro_part)parts.Get_at(i);
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
tmp_bfr.Add_byte_pipe();
|
||||
}
|
||||
tmp_bfr.Add(part.bfr.To_bry());
|
||||
}
|
||||
rv = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xomw_prepro_part {
|
||||
public Xomw_prepro_part(byte[] bry) {
|
||||
bfr.Add(bry);
|
||||
}
|
||||
public final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public int Eqpos = -1;
|
||||
public int comment_end = -1;
|
||||
public int visual_end = -1;
|
||||
}
|
Loading…
Reference in new issue