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-30 22:57:59 -04:00
parent ed911e3de5
commit 5fc4eb41ec
579 changed files with 2460 additions and 1564 deletions

View File

@@ -17,15 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
import gplx.xowa.parsers.logs.*;
public class Math_nde implements Xox_xnde, Xop_xnde_atr_parser {
public Xop_xnde_tkn Xnde() {throw Err_.new_unimplemented();}
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
Xof_math_mgr math_mgr = wiki.Appe().File_mgr().Math_mgr();
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_math, src, xnde);
if (math_mgr.Enabled() && math_mgr.Renderer_is_mathjax())
ctx.Cur_page().Html_data().Head_mgr().Itm__mathjax().Enabled_y_();
}
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
app.File_mgr().Math_mgr().Html_wtr().Write(html_wtr, ctx, hctx, bfr, src, xnde);
}
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
}

View File

@@ -0,0 +1,124 @@
/*
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.primitives.*;
import gplx.core.btries.*;
class Math_func_itm {
private final Ordered_hash props = Ordered_hash_.new_(); private final Int_obj_ref props_key = Int_obj_ref.neg1_();
public Math_func_itm(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Tex_bry() {return tex_bry;} public void Tex_bry_(byte[] v) {tex_bry = v;} private byte[] tex_bry;
public byte[] Html_bry() {return html_bry;} public void Html_bry_(byte[] v) {html_bry = v;} private byte[] html_bry;
public int Props__len() {return props.Count();}
public boolean Props__has(int v) {return props.Has(props_key.Val_(v));}
public void Props__add(int v) {
Int_obj_ref itm = Int_obj_ref.new_(v);
props.Add(itm, itm);
}
public int Get_at(int i) {
Int_obj_ref itm = (Int_obj_ref)props.Get_at(i);
return itm == null ? Int_.Min_value : itm.Val();
}
}
class Math_prop_itm {
public static final int
Int__LITERAL = 0
, Int__HTMLABLE = 1
, Int__HTMLABLE_BIG = 2
, Int__HTMLABLEC = 3
, Int__HTMLABLEM = 4
, Int__BIG = 5
, Int__FONT_UF = 6
, Int__FONT_UFH = 7
, Int__tex_use_ams = 8
, Int__tex_use_euro = 9
, Int__tex_use_teubner = 10
, Int__TEX_ONLY = 11
, Int__DELIMITER = 12
, Int__FUN_AR1 = 13
, Int__FUN_AR2 = 14
, Int__FUN_AR2h = 15
, Int__FUN_AR1hf = 16
, Int__FUN_AR1hl = 17
, Int__FUN_AR2nb = 18
, Int__FUN_INFIX = 19
, Int__FUN_INFIXh = 20
, Int__DECL = 21
, Int__DECLh = 22
, Int__FONTFORCE_IT = 23
, Int__FONTFORCE_RM = 24
, Int__sym_paren_bgn = 25
, Int__sym_paren_end = 26
, Int__sym_semic = 27
, Int__sym_quote = 28
;
public static final byte[]
Bry__LITERAL = Bry_.new_a7("LITERAL")
, Bry__HTMLABLE = Bry_.new_a7("HTMLABLE")
, Bry__HTMLABLE_BIG = Bry_.new_a7("HTMLABLE_BIG")
, Bry__HTMLABLEC = Bry_.new_a7("HTMLABLEC")
, Bry__HTMLABLEM = Bry_.new_a7("HTMLABLEM")
, Bry__BIG = Bry_.new_a7("BIG")
, Bry__FONT_UF = Bry_.new_a7("FONT_UF")
, Bry__FONT_UFH = Bry_.new_a7("FONT_UFH")
, Bry__tex_use_ams = Bry_.new_a7("tex_use_ams")
, Bry__tex_use_euro = Bry_.new_a7("tex_use_euro")
, Bry__tex_use_teubner = Bry_.new_a7("tex_use_teubner")
, Bry__TEX_ONLY = Bry_.new_a7("TEX_ONLY")
, Bry__DELIMITER = Bry_.new_a7("DELIMITER")
, Bry__FUN_AR1 = Bry_.new_a7("FUN_AR1")
, Bry__FUN_AR2 = Bry_.new_a7("FUN_AR2")
, Bry__FUN_AR2h = Bry_.new_a7("FUN_AR2h")
, Bry__FUN_AR1hf = Bry_.new_a7("FUN_AR1hf")
, Bry__FUN_AR1hl = Bry_.new_a7("FUN_AR1hl")
, Bry__FUN_AR2nb = Bry_.new_a7("FUN_AR2nb")
, Bry__FUN_INFIX = Bry_.new_a7("FUN_INFIX")
, Bry__FUN_INFIXh = Bry_.new_a7("FUN_INFIXh")
, Bry__DECL = Bry_.new_a7("DECL")
, Bry__DECLh = Bry_.new_a7("DECLh")
, Bry__FONTFORCE_IT = Bry_.new_a7("FONTFORCE_IT")
, Bry__FONTFORCE_RM = Bry_.new_a7("FONTFORCE_RM")
;
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
.Add_bry_int(Bry__LITERAL, Int__LITERAL)
.Add_bry_int(Bry__HTMLABLE, Int__HTMLABLE)
.Add_bry_int(Bry__HTMLABLE_BIG, Int__HTMLABLE_BIG)
.Add_bry_int(Bry__HTMLABLEC, Int__HTMLABLEC)
.Add_bry_int(Bry__HTMLABLEM, Int__HTMLABLEM)
.Add_bry_int(Bry__BIG, Int__BIG)
.Add_bry_int(Bry__FONT_UF, Int__FONT_UF)
.Add_bry_int(Bry__FONT_UFH, Int__FONT_UFH)
.Add_bry_int(Bry__tex_use_ams, Int__tex_use_ams)
.Add_bry_int(Bry__tex_use_euro, Int__tex_use_euro)
.Add_bry_int(Bry__tex_use_teubner, Int__tex_use_teubner)
.Add_bry_int(Bry__TEX_ONLY, Int__TEX_ONLY)
.Add_bry_int(Bry__DELIMITER, Int__DELIMITER)
.Add_bry_int(Bry__FUN_AR1, Int__FUN_AR1)
.Add_bry_int(Bry__FUN_AR2, Int__FUN_AR2)
.Add_bry_int(Bry__FUN_AR2h, Int__FUN_AR2h)
.Add_bry_int(Bry__FUN_AR1hf, Int__FUN_AR1hf)
.Add_bry_int(Bry__FUN_AR1hl, Int__FUN_AR1hl)
.Add_bry_int(Bry__FUN_AR2nb, Int__FUN_AR2nb)
.Add_bry_int(Bry__FUN_INFIX, Int__FUN_INFIX)
.Add_bry_int(Bry__FUN_INFIXh, Int__FUN_INFIXh)
.Add_bry_int(Bry__DECL, Int__DECL)
.Add_bry_int(Bry__DECLh, Int__DECLh)
.Add_bry_int(Bry__FONTFORCE_IT, Int__FONTFORCE_IT)
.Add_bry_int(Bry__FONTFORCE_RM, Int__FONTFORCE_RM)
;
}

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.*;
import gplx.core.btries.*; import gplx.core.primitives.*;
class Math_func_ml_parser {
private byte[] src; public int src_len;
private Btrie_slim_mgr prop_trie;
public void Parse(byte[] src) {
this.prop_trie = Math_prop_itm.Trie;
this.src = src; this.src_len = src.length;
int pos = Bry_finder.Find_fwd(src, Bry__parse_bgn, 0); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find beginning of ml file");
pos = Bry_finder.Find_fwd(src, Byte_ascii.Quote, pos, src_len); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find first func");
while (true) {
pos = Parse_itm(pos);
if (pos == Bry_finder.Not_found) break;
}
}
private int Parse_itm(int pos) { // pos should start at quote
int end_quote = Bry_finder.Find_fwd(src, Byte_ascii.Quote, pos + 1); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find end quote", "excerpt", Excerpt(pos));
byte[] key = Bry_.Mid_by_len_safe(src, pos + 1, end_quote);
Math_func_itm func_itm = new Math_func_itm(key);
pos = end_quote + 1;
pos = Bry_finder.Find_fwd(src, Bry__kv_spr, pos); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find kv spr", "excerpt", Excerpt(pos));
while (true) {
pos = Bry_finder.Find_fwd_while_ws(src, pos, src_len);
if (pos == src_len) return -1;
byte b = src[pos];
Object o = prop_trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) {
// throw error
break;
}
else {
Int_obj_val prop_obj = (Int_obj_val)o;
func_itm.Props__add(prop_obj.Val());
}
}
return pos;
}
private byte[] Excerpt(int bgn) {return Bry_.Mid_by_len_safe(src, bgn, bgn + 25);}
private static final byte[]
Bry__parse_bgn = Bry_.new_a7("let find = function")
, Bry__kv_spr = Bry_.new_a7("->")
;
}
/*
let find = function
"\\alpha" -> LITERAL (HTMLABLEC (FONT_UF, "\\alpha ", "&alpha;"))
| "\\Alpha" -> (tex_use_ams (); LITERAL (HTMLABLEC (FONT_UF,
"\\mathrm{A}", "&Alpha;")))
| "\\beta" -> LITERAL (HTMLABLEC (FONT_UF, "\\beta ", "&beta;"))
| "\\Beta" -> (tex_use_ams (); LITERAL (HTMLABLEC (FONT_UF,
"\\mathrm{B}", "&Beta;")))
| "\\gamma" -> LITERAL (HTMLABLEC (FONT_UF, "\\gamma ", "&gamma;"))
| "\\text" -> raise (Failure "malformatted \\text")
| "\\frac" -> FUN_AR2h ("\\frac ", fun num den -> Html.html_render [num], "<hr style=\"{background: black}\"/>", Html.html_render [den])
*/

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_ctx {
public Int_ary Stack() {return stack;} private final Int_ary stack = new Int_ary(4);
}

View File

@@ -26,5 +26,7 @@ class Mwm_lxr_ {
, Tid__backslash = 1
, Tid__curly_bgn = 2
, Tid__curly_end = 3
, Tid__brack_bgn = 4
, Tid__brack_end = 5
;
}

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__brack_bgn implements Mwm_lxr {
public int Tid() {return Mwm_lxr_.Tid__brack_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__brack, bgn_pos, cur_pos, new Mwm_tkn__node());
ctx.Stack().Add(uid);
return cur_pos;
}
}
class Mwm_lxr__brack_end implements Mwm_lxr {
public int Tid() {return Mwm_lxr_.Tid__brack_end;}
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
int bgn_uid = ctx.Stack().Pop_or(-1);
root.Regy__move_to_end(bgn_uid, bgn_uid);
root.Regy__update_end(bgn_uid, cur_pos);
return cur_pos;
}
}

View File

@@ -19,17 +19,17 @@ package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import g
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);
int uid = root.Regy__add(Mwm_tkn_.Tid__curly, bgn_pos, cur_pos, new Mwm_tkn__node());
ctx.Stack().Add(uid);
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);
int bgn_uid = ctx.Stack().Pop_or(-1);
root.Regy__move_to_end(bgn_uid, bgn_uid);
root.Regy__update_end(bgn_uid, cur_pos);
return cur_pos;
}
}

View File

@@ -20,10 +20,10 @@ 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);
Btrie_fast_mgr trie = Mwm_trie_bldr.new_();
Parse(trie, root, new Mwm_ctx(), 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();
private int Parse(Btrie_fast_mgr trie, Mwm_tkn__root root, Mwm_ctx ctx, byte[] src, int src_len, int bgn_pos, int end_pos) {
int pos = bgn_pos;
int txt_bgn = pos, txt_uid = -1;
byte b = src[pos];
@@ -51,12 +51,3 @@ class Mwm_parser {
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

@@ -19,6 +19,7 @@ package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import g
import org.junit.*;
public class Mwm_parser_tst {
private final Mwm_parser_fxt fxt = new Mwm_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Text() {
fxt.Test_parse("abc"
, fxt.text(0, 3)
@@ -45,13 +46,20 @@ public class Mwm_parser_tst {
, fxt.func(5, 9)
);
}
// @Test public void Arg() {
// fxt.Test_parse("{a}"
// , fxt.arg(0, 3
// , fxt.text(1, 2)
// )
// );
// }
@Test public void Curly() {
fxt.Test_parse("{a}"
, fxt.curly(0, 3
, fxt.text(1, 2)
)
);
}
@Test public void Brack() {
fxt.Test_parse("[a]"
, fxt.brack(0, 3
, fxt.text(1, 2)
)
);
}
}
class Mwm_parser_fxt {
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
@@ -62,24 +70,25 @@ class Mwm_parser_fxt {
this.expd_root = new Mwm_tkn__root(tkn_mkr);
this.actl_root = new Mwm_tkn__root(tkn_mkr);
}
public void Clear() {
expd_root.Init_as_root(0, 8);
actl_root.Init_as_root(0, 8);
}
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();
String actl = 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();
String expd = tmp_bfr.Xto_str_and_clear();
Tfds.Eq_str_lines(expd, actl, src_str);
}
private Mwm_tkn leaf(int tid, int bgn, int end) {
@@ -93,12 +102,14 @@ class Mwm_parser_fxt {
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());
public Mwm_tkn brack(int bgn, int end, Mwm_tkn... subs) {return node_w_subs(Mwm_tkn_.Tid__brack, bgn, end, subs);}
public Mwm_tkn curly(int bgn, int end, Mwm_tkn... subs) {return node_w_subs(Mwm_tkn_.Tid__curly, bgn, end, subs);}
private Mwm_tkn node_w_subs(int tid, int bgn, int end, Mwm_tkn... subs) {
Mwm_tkn rv = node(tid, 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);
expd_root.Regy__move(rv.Uid(), sub.Uid());
}
return rv;
}

View File

@@ -40,4 +40,7 @@ class Mwm_root_ary {
}
ary[idx] = tkn;
}
public void Update_end(int uid, int end) {
Get_at(uid).Src_end_(end);
}
}

View File

@@ -39,13 +39,11 @@ class Mwm_root_reg {
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;
}
return Mwm_tkn_.Tid_is_node(tid) ? null: tkn_mkr.Make_leaf(root, tid, uid, ary[idx + Idx__bgn], ary[idx + Idx__end]);
}
public int Get_owner_id(int uid) {
int idx = uid * Idx__slots;
return ary[idx + Idx__oid];
}
public int Add(int tid, int oid, int bgn, int end) {
int new_ary_len = ary_len + Idx__slots;
@@ -67,8 +65,19 @@ class Mwm_root_reg {
++itms_len;
return uid;
}
public void Update_end(int uid, int end) {
ary[(uid * Idx__slots) + Idx__end] = end;
public boolean Update_end(int uid, int end) {
int idx = uid * Idx__slots;
ary[idx + Idx__end] = end;
return Mwm_tkn_.Tid_is_node(ary[idx]);
}
public int Update_owner_id(int cur_uid, int new_owner_uid) { // return old owner_id
int cur_idx = cur_uid * Idx__slots;
int cur_owner_uid_idx = cur_idx + Idx__oid;
int old_owner_uid = ary[cur_owner_uid_idx];
ary[cur_owner_uid_idx] = new_owner_uid;
return old_owner_uid;
}
public void Change_owner(Mwm_tkn cur_owner, Mwm_tkn new_owner) {
}
private static final int
Idx__oid = 1

View File

@@ -49,4 +49,8 @@ class Mwm_root_sub {
}
subs_ary.Add(sub_uid);
}
public boolean Del_by_key_from_end(int owner_uid, int sub_uid) {
Int_ary subs_ary = Get_at(owner_uid);
return subs_ary.Del_by_key_from_end(sub_uid);
}
}

View File

@@ -22,6 +22,7 @@ interface Mwm_tkn {
int Uid();
int Src_bgn();
int Src_end();
void Src_end_(int v);
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);

View File

@@ -25,14 +25,16 @@ class Mwm_tkn_ {
, Tid__text = 1
, Tid__ws = 2
, Tid__func = 3
, Tid__arg = 4
, Tid__curly = 4
, Tid__brack = 5
;
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")
, Bry__curly = Bry_.new_a7("curly")
, Bry__brack = Bry_.new_a7("brack")
;
public static byte[] Tid_to_bry(int tid) {
switch (tid) {
@@ -40,10 +42,20 @@ class Mwm_tkn_ {
case Tid__text: return Bry__text;
case Tid__ws: return Bry__ws;
case Tid__func: return Bry__func;
case Tid__arg: return Bry__arg;
case Tid__curly: return Bry__curly;
case Tid__brack: return Bry__brack;
default: throw Err_.new_unhandled(tid);
}
}
public static boolean Tid_is_node(int tid) {
switch (tid) {
case Mwm_tkn_.Tid__text:
case Mwm_tkn_.Tid__ws:
return false;
default:
return true;
}
}
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()));

View File

@@ -30,6 +30,7 @@ class Mwm_tkn__leaf implements Mwm_tkn {
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 void Src_end_(int v) {this.src_end = v;}
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) {

View File

@@ -22,6 +22,7 @@ class Mwm_tkn__node implements Mwm_tkn {
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 void Src_end_(int v) {this.src_end = v;}
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {
this.root = root;
this.tid = tid;
@@ -35,5 +36,10 @@ class Mwm_tkn__node implements Mwm_tkn {
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);
int subs_len = this.Subs__len();
for (int i = 0; i < subs_len; ++i) {
Mwm_tkn sub_tkn = Subs__get_at(i);
sub_tkn.To_bry(bfr, indent + 1);
}
}
}

View File

@@ -30,6 +30,7 @@ class Mwm_tkn__root implements Mwm_tkn {
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 void Src_end_(int v) {this.src_end = v;}
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;
@@ -64,10 +65,22 @@ class Mwm_tkn__root implements Mwm_tkn {
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__move(int new_owner_uid, int cur_uid) {
int old_owner_uid = root_reg.Update_owner_id(cur_uid, new_owner_uid);
if (!root_sub.Del_by_key_from_end(old_owner_uid, cur_uid)) throw Err_.new_("mwm.parse", "unable to find sub in owner", "old_owner_uid", old_owner_uid, "new_owner_uid", new_owner_uid, "cur_uid", cur_uid);
root_sub.Add(new_owner_uid, cur_uid);
}
public void Regy__move_to_end(int src_uid, int trg_uid) {
Int_ary subs_ary = root_sub.Get_at(Mwm_tkn_.Uid__root);
int bgn_idx = subs_ary.Idx_of(src_uid);
int subs_len = subs_ary.Len();
for (int i = bgn_idx + 1; i < subs_len; ++i) {
int sub_uid = subs_ary.Get_at(i);
Regy__move(trg_uid, sub_uid);
}
}
public void Regy__update_end(int uid, int end) {
if (root_reg.Update_end(uid, end))
root_ary.Update_end(uid, end);
}
public void Regy__update_end(int uid, int end) {}
}

View File

@@ -29,9 +29,9 @@ class Mwm_tkn_mkr {
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) {
public Mwm_tkn Make_curly(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);
rv.Init(root, Mwm_tkn_.Tid__curly, uid, bgn, end);
return rv;
}
}

View File

@@ -23,6 +23,9 @@ class Mwm_trie_bldr {
rv.Add(" " , new Mwm_lxr__ws());
rv.Add("\\" , new Mwm_lxr__backslash());
rv.Add("{" , new Mwm_lxr__curly_bgn());
rv.Add("}" , new Mwm_lxr__curly_end());
rv.Add("[" , new Mwm_lxr__brack_bgn());
rv.Add("]" , new Mwm_lxr__brack_end());
return rv;
}
}