1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-08-24 00:32:13 -04:00
parent df10db140c
commit ed911e3de5
220 changed files with 2618 additions and 1569 deletions

View File

@@ -0,0 +1,30 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
interface Mwm_lxr {
int Tid();
int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos);
}
class Mwm_lxr_ {
public static final int
Tid__ws = 0
, Tid__backslash = 1
, Tid__curly_bgn = 2
, Tid__curly_end = 3
;
}

View 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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_lxr__backslash implements Mwm_lxr {
public int Tid() {return Mwm_lxr_.Tid__backslash;}
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
boolean loop = true;
while (loop) {
if (cur_pos == src_len) break;
byte b = src[cur_pos];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
case Byte_ascii.Underline:
++cur_pos;
break;
default:
loop = false;
break;
}
}
root.Regy__add(Mwm_tkn_.Tid__func, bgn_pos, cur_pos, new Mwm_tkn__node());
return cur_pos;
}
}

View 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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_lxr__curly_bgn implements Mwm_lxr {
public int Tid() {return Mwm_lxr_.Tid__curly_bgn;}
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
int uid = root.Regy__add(Mwm_tkn_.Tid__arg, bgn_pos, cur_pos, new Mwm_tkn__node());
Mwm_tkn tkn = root.Subs__get_at(uid);
ctx.Stack().Add(tkn);
return cur_pos;
}
}
class Mwm_lxr__curly_end implements Mwm_lxr {
public int Tid() {return Mwm_lxr_.Tid__curly_end;}
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
Mwm_tkn bgn_tkn = ctx.Stack().Pop();
root.Regy__move(bgn_tkn, null);
return cur_pos;
}
}

View File

@@ -0,0 +1,31 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_lxr__ws implements Mwm_lxr {
public int Tid() {return Mwm_lxr_.Tid__ws;}
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
while (true) {
if (cur_pos == src_len) break;
if (src[cur_pos] != Byte_ascii.Space)
break;
++cur_pos;
}
root.Regy__add(Mwm_tkn_.Tid__ws, bgn_pos, cur_pos, null);
return cur_pos;
}
}

View File

@@ -0,0 +1,62 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
import gplx.core.btries.*;
class Mwm_parser {
public void Parse(Mwm_tkn__root root, byte[] src) {
int src_len = src.length;
Parse(root, new Mwm_ctx(this, Mwm_trie_bldr.new_()), src, src_len, 0, src_len);
}
private int Parse(Mwm_tkn__root root, Mwm_ctx ctx, byte[] src, int src_len, int bgn_pos, int end_pos) {
Btrie_fast_mgr trie = ctx.Trie();
int pos = bgn_pos;
int txt_bgn = pos, txt_uid = -1;
byte b = src[pos];
while (true) {
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) // no lxr found; char is txt; increment pos
pos++;
else { // lxr found
Mwm_lxr lxr = (Mwm_lxr)o;
if (txt_bgn != pos) txt_uid = Txt_calc(ctx, root, src, src_len, pos, txt_bgn, txt_uid);// chars exist between pos and txt_bgn; make txt_tkn;
pos = lxr.Make_tkn(ctx, root, src, src_len, pos, trie.Match_pos());
if (pos > 0) {txt_bgn = pos; txt_uid = -1;} // reset txt_tkn
}
if (pos == end_pos) break;
b = src[pos];
}
if (txt_bgn != pos) txt_uid = Txt_calc(ctx, root, src, src_len, src_len, txt_bgn, txt_uid);
return pos;
}
private static int Txt_calc(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int txt_bgn, int txt_uid) {
if (txt_uid == -1) // no existing txt_tkn; create new one
txt_uid = root.Regy__add(Mwm_tkn_.Tid__text, txt_bgn, bgn_pos, null);
else // existing txt_tkn; happens for false matches; EX: abc[[\nef[[a]]; see NOTE_1
root.Regy__update_end(txt_uid, bgn_pos);
return txt_uid;
}
}
class Mwm_ctx {
public Mwm_ctx(Mwm_parser parser, Btrie_fast_mgr trie) {
this.parser = parser;
this.trie = trie;
}
public Mwm_tkn_stack Stack() {return stack;} private Mwm_tkn_stack stack = new Mwm_tkn_stack();
public Btrie_fast_mgr Trie() {return trie;} private final Btrie_fast_mgr trie;
public Mwm_parser Parser() {return parser;} private final Mwm_parser parser;
}

View File

@@ -0,0 +1,105 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
import org.junit.*;
public class Mwm_parser_tst {
private final Mwm_parser_fxt fxt = new Mwm_parser_fxt();
@Test public void Text() {
fxt.Test_parse("abc"
, fxt.text(0, 3)
);
}
@Test public void Ws() {
fxt.Test_parse(" "
, fxt.ws(0, 3)
);
}
@Test public void Mix() {
fxt.Test_parse("a b c"
, fxt.text(0, 1)
, fxt.ws (1, 2)
, fxt.text(2, 3)
, fxt.ws (3, 4)
, fxt.text(4, 5)
);
}
@Test public void Func() {
fxt.Test_parse("\\abc \\def"
, fxt.func(0, 4)
, fxt.ws (4, 5)
, fxt.func(5, 9)
);
}
// @Test public void Arg() {
// fxt.Test_parse("{a}"
// , fxt.arg(0, 3
// , fxt.text(1, 2)
// )
// );
// }
}
class Mwm_parser_fxt {
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
private final Mwm_parser parser = new Mwm_parser();
private final Mwm_tkn__root expd_root, actl_root;
private final Mwm_tkn_mkr tkn_mkr = new Mwm_tkn_mkr();
public Mwm_parser_fxt() {
this.expd_root = new Mwm_tkn__root(tkn_mkr);
this.actl_root = new Mwm_tkn__root(tkn_mkr);
}
public void Test_parse(String src_str, Mwm_tkn... expd_tkns) {
byte[] src_bry = Bry_.new_u8(src_str);
int src_len = src_bry.length;
expd_root.Init_as_root(0, src_len);
actl_root.Init_as_root(0, src_len);
parser.Parse(actl_root, src_bry);
int len = actl_root.Subs__len();
for (int i = 0; i < len; ++i) {
Mwm_tkn sub = actl_root.Subs__get_at(i);
sub.To_bry(tmp_bfr, 0);
}
String expd = tmp_bfr.Xto_str_and_clear();
len = expd_tkns.length;
for (int i = 0; i < len; ++i) {
Mwm_tkn sub = expd_tkns[i];
sub.To_bry(tmp_bfr, 0);
}
String actl = tmp_bfr.Xto_str_and_clear();
Tfds.Eq_str_lines(expd, actl, src_str);
}
private Mwm_tkn leaf(int tid, int bgn, int end) {
int uid = expd_root.Regy__add(tid, bgn, end, null);
return new Mwm_tkn__leaf().Init(expd_root, tid, uid, bgn, end);
}
private Mwm_tkn node(int tid, int bgn, int end, Mwm_tkn tkn) {
int uid = expd_root.Regy__add(tid, bgn, end, tkn);
return new Mwm_tkn__node().Init(expd_root, tid, uid, bgn, end);
}
public Mwm_tkn text (int bgn, int end) {return leaf(Mwm_tkn_.Tid__text , bgn, end);}
public Mwm_tkn ws (int bgn, int end) {return leaf(Mwm_tkn_.Tid__ws , bgn, end);}
public Mwm_tkn func (int bgn, int end) {return node(Mwm_tkn_.Tid__func , bgn, end, new Mwm_tkn__node());}
public Mwm_tkn arg (int bgn, int end, Mwm_tkn... subs) {
Mwm_tkn rv = node(Mwm_tkn_.Tid__func , bgn, end, new Mwm_tkn__node());
int len = subs.length;
for (int i = 0; i < len; ++i) {
Mwm_tkn sub = subs[i];
expd_root.Regy__move(rv, sub);
}
return rv;
}
}

View File

@@ -0,0 +1,43 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_root_ary {
private Mwm_tkn[] ary = Mwm_tkn_.Ary_empty; private int ary_max;
public Mwm_tkn Get_at(int i) {return i < ary_max ? ary[i] : null;}
public void Init(int expd_itms) {
if (expd_itms > ary_max) {
this.ary_max = expd_itms;
this.ary = new Mwm_tkn[ary_max];
}
else {
for (int i = 0; i < ary_max; ++i)
ary[i] = null;
}
}
public void Add(int idx, Mwm_tkn tkn) {
if (idx >= ary_max) {
int new_max = idx == 0 ? 2 : idx * 2;
Mwm_tkn[] new_ary = new Mwm_tkn[new_max];
for (int i = 0; i < ary_max; ++i)
new_ary[i] = ary[i];
this.ary = new_ary;
this.ary_max = new_max;
}
ary[idx] = tkn;
}
}

View File

@@ -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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_root_reg {
private int[] ary = Int_.Ary_empty; private int ary_len, ary_max; private int itms_len;
private final Mwm_tkn__root root;
public int Len() {return itms_len;}
public Mwm_root_reg(Mwm_tkn__root root) {
this.root = root;
}
public void Init(int expd_itms) {
int expd_max = expd_itms * Idx__slots;
if (expd_max > ary_max) {
this.ary = new int[expd_max];
this.ary_max = expd_max;
}
else {
for (int i = 0; i < ary_len; ++i)
ary[i] = 0;
}
this.ary_len = 0;
this.itms_len = 0;
}
public Mwm_tkn Get_at(Mwm_tkn_mkr tkn_mkr, int uid) {
int idx = uid * Idx__slots;
int tid = ary[idx];
switch (tid) {
case Mwm_tkn_.Tid__text:
case Mwm_tkn_.Tid__ws:
return tkn_mkr.Make_leaf(root, tid, uid, ary[idx + Idx__bgn], ary[idx + Idx__end]);
default:
return null;
}
}
public int Add(int tid, int oid, int bgn, int end) {
int new_ary_len = ary_len + Idx__slots;
if (new_ary_len >= ary_max) {
int new_max = ary_max == 0 ? Idx__slots : ary_max * 2;
int[] new_ary = new int[new_max];
for (int i = 0; i < ary_len; ++i)
new_ary[i] = ary[i];
this.ary = new_ary;
this.ary_max = new_max;
}
int idx = ary_len;
int uid = idx / Idx__slots;
ary[idx ] = tid;
ary[idx + Idx__oid] = oid;
ary[idx + Idx__bgn] = bgn;
ary[idx + Idx__end] = end;
this.ary_len = new_ary_len;
++itms_len;
return uid;
}
public void Update_end(int uid, int end) {
ary[(uid * Idx__slots) + Idx__end] = end;
}
private static final int
Idx__oid = 1
, Idx__bgn = 2
, Idx__end = 3
, Idx__slots = 4
;
}

View 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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_root_sub {
private Int_ary[] ary = new Int_ary[0]; private int ary_max;
public Int_ary Get_at(int i) {return i < ary_max ? ary[i] : null;}
public int Get_subs_len(int uid) {
Int_ary subs_ary = uid < ary_max ? ary[uid] : null;
return subs_ary == null ? 0 : subs_ary.Len();
}
public void Init(int expd_itms) {
if (expd_itms > ary_max) {
this.ary_max = expd_itms;
this.ary = new Int_ary[ary_max];
}
else {
for (int i = 0; i < ary_max; ++i)
ary[i] = null;
}
}
public void Add(int owner_uid, int sub_uid) {
if (owner_uid >= ary_max) {
int new_max = owner_uid == 0 ? 2 : owner_uid * 2;
Int_ary[] new_ary = new Int_ary[new_max];
for (int i = 0; i < ary_max; ++i)
new_ary[i] = ary[i];
this.ary = new_ary;
this.ary_max = new_max;
}
Int_ary subs_ary = ary[owner_uid];
if (subs_ary == null) {
subs_ary = new Int_ary(2);
ary[owner_uid] = subs_ary;
}
subs_ary.Add(sub_uid);
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
interface Mwm_tkn {
int Tid();
Mwm_tkn__root Root();
int Uid();
int Src_bgn();
int Src_end();
Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end);
int Subs__len();
Mwm_tkn Subs__get_at(int i);
void To_bry(Bry_bfr bfr, int indent);
}

View 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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn_ {
public static final Mwm_tkn Owner__null = null;
public static final Mwm_tkn[] Ary_empty = new Mwm_tkn[0];
public static final int Uid__root = 0;
public static final int
Tid__root = 0
, Tid__text = 1
, Tid__ws = 2
, Tid__func = 3
, Tid__arg = 4
;
public static byte[]
Bry__root = Bry_.new_a7("root")
, Bry__text = Bry_.new_a7("text")
, Bry__ws = Bry_.new_a7("ws")
, Bry__func = Bry_.new_a7("func")
, Bry__arg = Bry_.new_a7("arg")
;
public static byte[] Tid_to_bry(int tid) {
switch (tid) {
case Tid__root: return Bry__root;
case Tid__text: return Bry__text;
case Tid__ws: return Bry__ws;
case Tid__func: return Bry__func;
case Tid__arg: return Bry__arg;
default: throw Err_.new_unhandled(tid);
}
}
public static void Tkn_to_bry__bgn(Bry_bfr bfr, int indent, Mwm_tkn tkn) {
if (indent > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent);
bfr.Add(Mwm_tkn_.Tid_to_bry(tkn.Tid()));
bfr.Add_byte(Byte_ascii.Paren_bgn);
bfr.Add_int_variable(tkn.Src_bgn());
bfr.Add_byte_comma().Add_int_variable(tkn.Src_end());
}
public static void Tkn_to_bry__end_head(Bry_bfr bfr) {
bfr.Add_byte(Byte_ascii.Paren_end);
bfr.Add_byte_nl();
}
}

View File

@@ -0,0 +1,39 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn__leaf implements Mwm_tkn {
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {
this.root = root;
this.tid = tid;
this.uid = uid;
this.src_bgn = src_bgn;
this.src_end = src_end;
return this;
}
public Mwm_tkn__root Root() {return root;} private Mwm_tkn__root root;
public int Tid() {return tid;} private int tid;
public int Uid() {return uid;} private int uid;
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Subs__len() {return 0;}
public Mwm_tkn Subs__get_at(int i) {throw Err_.new_unsupported();}
public void To_bry(Bry_bfr bfr, int indent) {
Mwm_tkn_.Tkn_to_bry__bgn(bfr, indent, this);
Mwm_tkn_.Tkn_to_bry__end_head(bfr);
}
}

View File

@@ -0,0 +1,39 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn__node implements Mwm_tkn {
public Mwm_tkn__root Root() {return root;} private Mwm_tkn__root root;
public int Tid() {return tid;} private int tid;
public int Uid() {return uid;} private int uid;
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {
this.root = root;
this.tid = tid;
this.uid = uid;
this.src_bgn = src_bgn;
this.src_end = src_end;
return this;
}
public int Subs__len() {return root.Regy__get_subs_len(uid);}
public Mwm_tkn Subs__get_at(int i) {return root.Regy__get_subs_tkn(uid, i);}
public void To_bry(Bry_bfr bfr, int indent) {
Mwm_tkn_.Tkn_to_bry__bgn(bfr, indent, this);
Mwm_tkn_.Tkn_to_bry__end_head(bfr);
}
}

View 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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn__root implements Mwm_tkn {
private final Mwm_root_reg root_reg;
private final Mwm_root_ary root_ary = new Mwm_root_ary();
private final Mwm_root_sub root_sub = new Mwm_root_sub();
public Mwm_tkn__root(Mwm_tkn_mkr tkn_mkr) {
this.tkn_mkr = tkn_mkr;
this.root_reg = new Mwm_root_reg(this);
}
public Mwm_tkn__root Root() {return this;}
public Mwm_tkn_mkr Tkn_mkr() {return tkn_mkr;} private final Mwm_tkn_mkr tkn_mkr;
public int Tid() {return Mwm_tkn_.Tid__root;}
public int Uid() {return Mwm_tkn_.Uid__root;}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {throw Err_.new_unsupported();}
public Mwm_tkn Init_as_root(int src_bgn, int src_end) {
this.src_bgn = src_bgn; this.src_end = src_end;
int expd_len = (src_end - src_bgn) / 5;
root_reg.Init(expd_len);
root_ary.Init(expd_len);
root_sub.Init(expd_len);
root_reg.Add(Mwm_tkn_.Tid__root, Mwm_tkn_.Uid__root, src_bgn, src_end);
// this.Regy__add(Mwm_tkn_.Tid__root, src_bgn, src_end, this);
return this;
}
public int Subs__len() {return Regy__get_subs_len(Mwm_tkn_.Uid__root);}
public Mwm_tkn Subs__get_at(int i) {return Regy__get_subs_tkn(Mwm_tkn_.Uid__root, i);}
public void To_bry(Bry_bfr bfr, int indent) {
Mwm_tkn_.Tkn_to_bry__bgn(bfr, indent, this);
Mwm_tkn_.Tkn_to_bry__end_head(bfr);
}
public int Regy__add(int tid, int bgn, int end, Mwm_tkn tkn) {
int uid = root_reg.Add(tid, Mwm_tkn_.Uid__root, bgn, end);
if (tkn != null) {
tkn.Init(this, tid, uid, bgn, end);
root_ary.Add(uid, tkn);
}
root_sub.Add(Mwm_tkn_.Uid__root, uid);
return uid;
}
public int Regy__get_subs_len(int uid) {return root_sub.Get_subs_len(uid);}
public Mwm_tkn Regy__get_subs_tkn(int owner_uid, int sub_idx) {
return Regy__get_tkn(root_sub.Get_at(owner_uid).Get_at(sub_idx));
}
public Mwm_tkn Regy__get_tkn(int uid) {
Mwm_tkn rv = root_reg.Get_at(tkn_mkr, uid);
return rv == null ? root_ary.Get_at(uid) : rv;
}
public void Regy__move(Mwm_tkn new_owner, Mwm_tkn sub) {
// int cur_owner_id = root_reg.Get_owner_id(sub.Uid());
// Mwm_tkn cur_owner = Regy__get_tkn(cur_owner_id);
// root_reg.Change_owner(cur_owner, new_owner);
}
public void Regy__update_end(int uid, int end) {}
}

View File

@@ -0,0 +1,37 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn_mkr {
private final Mwm_tkn__leaf tmp_leaf = new Mwm_tkn__leaf();
public Mwm_tkn Make_leaf(Mwm_tkn__root root, int tid, int uid, int bgn, int end) {
synchronized (tmp_leaf) {
tmp_leaf.Init(root, tid, uid, bgn, end);
return tmp_leaf;
}
}
public Mwm_tkn Make_func(Mwm_tkn__root root, int uid, int bgn, int end) {
Mwm_tkn__node rv = new Mwm_tkn__node();
rv.Init(root, Mwm_tkn_.Tid__func, uid, bgn, end);
return rv;
}
public Mwm_tkn Make_arg(Mwm_tkn__root root, int uid, int bgn, int end) {
Mwm_tkn__node rv = new Mwm_tkn__node();
rv.Init(root, Mwm_tkn_.Tid__arg, uid, bgn, end);
return rv;
}
}

View File

@@ -0,0 +1,47 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn_stack {
private Mwm_tkn[] ary; private int ary_len, ary_max;
public Mwm_tkn_stack() {this.Clear();}
public int Len() {return ary_len;}
public void Clear() {
this.ary = Mwm_tkn_.Ary_empty;
this.ary_len = 0;
this.ary_max = 0;
}
public void Add(Mwm_tkn tkn) {
int new_ary_len = ary_len + 1;
if (new_ary_len >= ary_max) {
int new_max = ary_max == 0 ? 2 : ary_max * 2;
Mwm_tkn[] new_ary = new Mwm_tkn[new_max];
for (int i = 0; i < ary_len; ++i)
new_ary[i] = ary[i];
this.ary = new_ary;
this.ary_max = new_max;
}
ary[ary_len] = tkn;
this.ary_len = new_ary_len;
}
public Mwm_tkn Pop() {
int new_ary_len = ary_len - 1;
Mwm_tkn rv = ary[new_ary_len];
this.ary_len = new_ary_len;
return rv;
}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
import gplx.core.btries.*;
class Mwm_trie_bldr {
public static Btrie_fast_mgr new_() {
Btrie_fast_mgr rv = Btrie_fast_mgr.cs();
rv.Add(" " , new Mwm_lxr__ws());
rv.Add("\\" , new Mwm_lxr__backslash());
rv.Add("{" , new Mwm_lxr__curly_bgn());
return rv;
}
}