1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-09-06 21:31:25 -04:00
parent 5fc4eb41ec
commit 2145f6382c
89 changed files with 2250 additions and 671 deletions

View File

@@ -45,6 +45,7 @@ public class Xow_xtn_mgr implements GfoInvkAble {
Add(app, new gplx.xowa.xtns.listings.Listing_xtn_mgr());
Add(app, new gplx.xowa.xtns.titleBlacklists.Blacklist_xtn_mgr());
Add(app, new gplx.xowa.xtns.pfuncs.scribunto.Pfunc_xtn_mgr());
Add(app, new gplx.xowa.xtns.graphs.Graph_xtn());
return this;
}
public Xow_xtn_mgr Ctor_by_wiki(Xowe_wiki wiki) {

View File

@@ -0,0 +1,42 @@
/*
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.graphs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.parsers.logs.*;
import gplx.xowa.html.*;
public class Graph_xnde implements Xox_xnde, Xop_xnde_atr_parser {
private Graph_xtn xtn;
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_key_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
this.xtn = (Graph_xtn)wiki.Xtn_mgr().Get_or_fail(Graph_xtn.Xtn_key_static);
xtn.Xtn_init_assert(wiki);
ctx.Cur_page().Html_data().Head_mgr().Itm__graph().Enabled_y_();
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_graph, src, xnde);
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
}
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) {
bfr.Add(Html__div_bgn);
bfr.Add_mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
bfr.Add(Html__div_end);
}
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
private static final byte[]
Html__div_bgn = Bry_.new_a7("<div class='mw-wiki-graph'>\n")
, Html__div_end = Bry_.new_a7("</div>\n")
;
}

View File

@@ -0,0 +1,45 @@
/*
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.graphs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.*; import gplx.xowa.html.modules.*; import gplx.xowa.apps.fsys.*;
public class Graph_xtn extends Xox_mgr_base implements GfoInvkAble {
@Override public boolean Enabled_default() {return true;}
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_a7("graph");
@Override public Xox_mgr Clone_new() {return new Graph_xtn();}
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {}
private boolean xtn_init_done = false;
public void Xtn_init_assert(Xowe_wiki wiki) {
if (xtn_init_done) return;
// if (!Enabled()) return;
// Xoae_app app = wiki.Appe();
// Io_url ext_root_dir = Hiero_root_dir(app.Fsys_mgr());
// Img_src_dir = Bry_.new_u8(ext_root_dir.GenSubDir("img").To_http_file_str());
// app.Gfs_mgr().Run_url_for(this, ext_root_dir.GenSubFil_nest("data", "tables.gfs"));
// html_wtr = new Hiero_html_mgr(this);
// parser.Init();
// xtn_init_done = true;
}
public void Clear() {
// prefab_mgr.Clear();
// file_mgr.Clear();
// phoneme_mgr.Clear();
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return super.Invk(ctx, ikey, k, m);
}
}

View File

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

@@ -18,4 +18,7 @@ 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);
public void Clear() {
stack.Clear();
}
}

View File

@@ -23,10 +23,11 @@ interface Mwm_lxr {
class Mwm_lxr_ {
public static final int
Tid__ws = 0
, Tid__backslash = 1
, Tid__curly_bgn = 2
, Tid__curly_end = 3
, Tid__brack_bgn = 4
, Tid__brack_end = 5
, Tid__raw = 1
, Tid__backslash = 2
, Tid__curly_bgn = 3
, Tid__curly_end = 4
, Tid__brack_bgn = 5
, Tid__brack_end = 6
;
}

View File

@@ -44,7 +44,7 @@ class Mwm_lxr__backslash implements Mwm_lxr {
break;
}
}
root.Regy__add(Mwm_tkn_.Tid__func, bgn_pos, cur_pos, new Mwm_tkn__node());
root.Regy__add(Mwm_tkn_.Tid__fnc, bgn_pos, cur_pos, new Mwm_tkn__node());
return cur_pos;
}
}

View File

@@ -16,16 +16,11 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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());
rv.Add("}" , new Mwm_lxr__curly_end());
rv.Add("[" , new Mwm_lxr__brack_bgn());
rv.Add("]" , new Mwm_lxr__brack_end());
return rv;
class Mwm_lxr__leaf implements Mwm_lxr {
public Mwm_lxr__leaf(int tkn_tid) {this.tkn_tid = tkn_tid;} private final int tkn_tid;
public int Tid() {return Mwm_lxr_.Tid__raw;}
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
root.Regy__add(tkn_tid, bgn_pos, cur_pos, null);
return cur_pos;
}
}

View File

@@ -0,0 +1,64 @@
/*
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_lxr_trie_bldr {
public static Btrie_fast_mgr new_(Mwm_tkn_mkr tkn_mkr) {// REF.MW:/Math/textvccheck/lexer.mll
tkn_mkr.Reg_leaf(Mwm_tkn_.Tid__text, new Mwm_tkn__leaf_raw());
Btrie_fast_mgr rv = Btrie_fast_mgr.cs();
Add_lxr (rv, tkn_mkr, new Mwm_lxr__backslash() , "\\");
Add_lxr (rv, tkn_mkr, new Mwm_lxr__curly_bgn() , "{");
Add_lxr (rv, tkn_mkr, new Mwm_lxr__curly_end() , "}");
Add_lxr (rv, tkn_mkr, new Mwm_lxr__brack_bgn() , "[");
Add_lxr (rv, tkn_mkr, new Mwm_lxr__brack_end() , "]");
Add_lxr_leaf (rv, tkn_mkr, new Mwm_lxr__ws(), Mwm_tkn_.Tid__ws , " ", "\t", "\n", "\r");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__lit_basic , ">", "<", "~");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__lit_uf_lt , ",", ":", ";", "?", "!", "'");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__lit_uf_op , "+", "-", "*", "=");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__dlm_uf_lt , "(", ")", ".");
Add_lxr_leaf_repl (rv, tkn_mkr, Mwm_tkn_.Tid__lit_basic , "%", "\\%");
Add_lxr_leaf_repl (rv, tkn_mkr, Mwm_tkn_.Tid__lit_basic , "$", "\\$");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__lit_basic , "\\,", "\\ ", "\\;", "\\!");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__dlm_basic , "\\{", "\\}", "\\|");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__lit_basic , "\\_", "\\#", "\\%", "\\$", "\\&");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__next_cell , "%");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__next_row , "\\\\");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__lit_basic , "~", ">", "<");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__sup , "^");
Add_lxr_leaf (rv, tkn_mkr, Mwm_tkn_.Tid__sub , "_");
return rv;
}
private static void Add_lxr(Btrie_fast_mgr trie, Mwm_tkn_mkr tkn_mkr, Mwm_lxr lxr, String... ary) {
for (String itm : ary)
trie.Add(itm, lxr);
}
private static void Add_lxr_leaf(Btrie_fast_mgr trie, Mwm_tkn_mkr tkn_mkr, int tid, String... ary) {
Add_lxr_leaf(trie, tkn_mkr, new Mwm_lxr__leaf(tid), tid, new Mwm_tkn__leaf_raw(), ary);
}
private static void Add_lxr_leaf(Btrie_fast_mgr trie, Mwm_tkn_mkr tkn_mkr, Mwm_lxr lxr, int tkn_tid, String... ary) {
Add_lxr_leaf(trie, tkn_mkr, lxr, tkn_tid, new Mwm_tkn__leaf_raw(), ary);
}
private static void Add_lxr_leaf_repl(Btrie_fast_mgr trie, Mwm_tkn_mkr tkn_mkr, int tid, String src, String trg) {
Add_lxr_leaf(trie, tkn_mkr, new Mwm_lxr__leaf(tid), tid, new Mwm_tkn__leaf_repl(tid, Bry_.new_u8(trg)), src);
}
private static void Add_lxr_leaf(Btrie_fast_mgr trie, Mwm_tkn_mkr tkn_mkr, Mwm_lxr lxr, int tkn_tid, Mwm_tkn proto, String... ary) {
tkn_mkr.Reg_leaf(tkn_tid, proto);
for (String itm : ary)
trie.Add(itm, lxr);
}
}

View File

@@ -18,12 +18,19 @@ 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 {
private final Mwm_ctx ctx = new Mwm_ctx();
private final Btrie_fast_mgr trie;
public Mwm_tkn_mkr Tkn_mkr() {return tkn_mkr;} private final Mwm_tkn_mkr tkn_mkr = new Mwm_tkn_mkr();
public Mwm_parser() {
this.trie = Mwm_lxr_trie_bldr.new_(tkn_mkr);
}
public void Parse(Mwm_tkn__root root, byte[] src) {
int src_len = src.length;
Btrie_fast_mgr trie = Mwm_trie_bldr.new_();
Parse(trie, root, new Mwm_ctx(), src, src_len, 0, src_len);
ctx.Clear();
root.Init_as_root(tkn_mkr, 0, src.length);
Parse(root, ctx, src, src_len, 0, src_len);
}
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) {
private int Parse(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];

View File

@@ -65,14 +65,13 @@ 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);
this.expd_root = new Mwm_tkn__root();
this.actl_root = new Mwm_tkn__root();
}
public void Clear() {
expd_root.Init_as_root(0, 8);
actl_root.Init_as_root(0, 8);
expd_root.Init_as_root(parser.Tkn_mkr(), 0, 8);
actl_root.Init_as_root(parser.Tkn_mkr(), 0, 8);
}
public void Test_parse(String src_str, Mwm_tkn... expd_tkns) {
byte[] src_bry = Bry_.new_u8(src_str);
@@ -93,7 +92,7 @@ class Mwm_parser_fxt {
}
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);
return new Mwm_tkn__leaf_raw().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);
@@ -101,7 +100,7 @@ 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 func (int bgn, int end) {return node(Mwm_tkn_.Tid__fnc , 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) {

View File

@@ -21,39 +21,104 @@ class Mwm_tkn_ {
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__curly = 4
, Tid__brack = 5
Tid__root = 0
, Tid__text = 1
, Tid__ws = 2
, Tid__curly = 3
, Tid__brack = 4
, Tid__lit_basic = 5
, Tid__lit_uf_lt = 6
, Tid__lit_uf_op = 7
, Tid__dlm_basic = 8
, Tid__dlm_uf_lt = 9
, Tid__dlm_uf_op = 10
, Tid__sub = 11
, Tid__sup = 12
, Tid__next_row = 13
, Tid__next_cell = 14
, Tid__fnc = 15
, Tid__fnc_latex = 16
, Tid__fnc_mw = 17
, Tid__matrix_bgn = 18
, Tid__matrix_end = 19
, Tid__pmatrix_bgn = 20
, Tid__pmatrix_end = 21
, Tid__bmatrix_bgn = 22
, Tid__bmatrix_end = 23
, Tid__Bmatrix_bgn = 24
, Tid__Bmatrix_end = 25
, Tid__vmatrix_bgn = 26
, Tid__vmatrix_end = 27
, Tid__Vmatrix_bgn = 28
, Tid__Vmatrix_end = 29
, Tid__array_bgn = 30
, Tid__array_end = 31
, Tid__align_bgn = 32
, Tid__align_end = 33
, Tid__alignat_bgn = 34
, Tid__alignat_end = 35
, Tid__smallmatrix_bgn = 36
, Tid__smallmatrix_end = 37
, Tid__cases_bgn = 38
, Tid__cases_end = 39
;
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__curly = Bry_.new_a7("curly")
, Bry__brack = Bry_.new_a7("brack")
;
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__curly: return Bry__curly;
case Tid__brack: return Bry__brack;
default: throw Err_.new_unhandled(tid);
}
public static final int Tid_len = 40;
private static final byte[][] Bry__ary = Bry__ary__new();
private static byte[][] Bry__ary__new() {
byte[][] rv = new byte[Tid_len][];
Reg_itm(rv, Tid__root , "root");
Reg_itm(rv, Tid__text , "text");
Reg_itm(rv, Tid__ws , "ws");
Reg_itm(rv, Tid__fnc , "func");
Reg_itm(rv, Tid__curly , "curly");
Reg_itm(rv, Tid__brack , "brack");
Reg_itm(rv, Tid__lit_basic , "literal_basic");
Reg_itm(rv, Tid__lit_uf_lt , "literal_uf_lt");
Reg_itm(rv, Tid__lit_uf_op , "literal_uf_op");
Reg_itm(rv, Tid__dlm_basic , "delimiter_basic");
Reg_itm(rv, Tid__dlm_uf_lt , "delimiter_uf_lt");
Reg_itm(rv, Tid__dlm_uf_op , "delimiter_uf_op");
Reg_itm(rv, Tid__sub , "sub");
Reg_itm(rv, Tid__sup , "sup");
Reg_itm(rv, Tid__next_row , "next_row");
Reg_itm(rv, Tid__next_cell , "next_cell");
Reg_itm(rv, Tid__fnc_latex , "func_latex");
Reg_itm(rv, Tid__fnc_mw , "func_mediawiki");
Reg_itm(rv, Tid__matrix_bgn , "matrix_bgn");
Reg_itm(rv, Tid__matrix_end , "matrix_end");
Reg_itm(rv, Tid__pmatrix_bgn , "pmatrix_bgn");
Reg_itm(rv, Tid__pmatrix_end , "pmatrix_end");
Reg_itm(rv, Tid__bmatrix_bgn , "bmatrix_bgn");
Reg_itm(rv, Tid__bmatrix_end , "bmatrix_end");
Reg_itm(rv, Tid__Bmatrix_bgn , "Bmatrix_bgn");
Reg_itm(rv, Tid__Bmatrix_end , "Bmatrix_bgn");
Reg_itm(rv, Tid__vmatrix_bgn , "vmatrix_bgn");
Reg_itm(rv, Tid__vmatrix_end , "vmatrix_end");
Reg_itm(rv, Tid__Vmatrix_bgn , "Vmatrix_bgn");
Reg_itm(rv, Tid__Vmatrix_end , "Vmatrix_end");
Reg_itm(rv, Tid__array_bgn , "array_bgn");
Reg_itm(rv, Tid__array_end , "array_end");
Reg_itm(rv, Tid__align_bgn , "align_bgn");
Reg_itm(rv, Tid__align_end , "align_end");
Reg_itm(rv, Tid__alignat_bgn , "alignat_bgn");
Reg_itm(rv, Tid__alignat_end , "alignat_end");
Reg_itm(rv, Tid__smallmatrix_bgn , "smallmatrix_bgn");
Reg_itm(rv, Tid__smallmatrix_end , "smallmatrix_end");
Reg_itm(rv, Tid__cases_bgn , "cases_bgn");
Reg_itm(rv, Tid__cases_end , "cases_end");
return rv;
}
private static void Reg_itm(byte[][] ary, int id, String name) {ary[id] = Bry_.new_a7(name);}
public static byte[] Tid_to_bry(int tid) {return Bry__ary[tid];}
public static boolean Tid_is_node(int tid) {
switch (tid) {
case Mwm_tkn_.Tid__text:
case Mwm_tkn_.Tid__ws:
return false;
default:
case Mwm_tkn_.Tid__root:
case Mwm_tkn_.Tid__fnc:
case Mwm_tkn_.Tid__curly:
case Mwm_tkn_.Tid__brack:
return true;
default:
return false;
}
}
public static void Tkn_to_bry__bgn(Bry_bfr bfr, int indent, Mwm_tkn tkn) {

View File

@@ -0,0 +1,41 @@
/*
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_tkn__func {
public Mwm_tkn__func(byte[] key) {
this.key = key;
}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Manual() {return manual;} public Mwm_tkn__func Manual_(String v) {manual = Bry_.new_a7(v); return this;} private byte[] manual;
public boolean Literal() {return literal;} public Mwm_tkn__func Literal_() {this.literal = true; return this;} private boolean literal;
public boolean Big() {return big;} public Mwm_tkn__func Big_() {this.big = true; return this;} private boolean big;
public boolean Delimiter() {return delimiter;} public Mwm_tkn__func Delimiter_() {this.delimiter = true; return this;} private boolean delimiter;
public boolean Tex_only() {return tex_only;} public Mwm_tkn__func Tex_only_() {this.tex_only = true; return this;} private boolean tex_only;
public boolean Fun_ar1() {return fun_ar1;} public Mwm_tkn__func Fun_ar1_() {this.fun_ar1 = true; return this;} private boolean fun_ar1;
public boolean Fun_ar2() {return fun_ar2;} public Mwm_tkn__func Fun_ar2_() {this.fun_ar2 = true; return this;} private boolean fun_ar2;
public boolean Fun_ar2nb() {return fun_ar2nb;} public Mwm_tkn__func Fun_ar2nb_() {this.fun_ar2nb = true; return this;} private boolean fun_ar2nb;
public boolean Fun_infix() {return fun_infix;} public Mwm_tkn__func Fun_infix_() {this.fun_infix = true; return this;} private boolean fun_infix;
public boolean Declh() {return declh;} public Mwm_tkn__func Declh_() {this.declh = true; return this;} private boolean declh;
public boolean Fontforce_rm() {return fontforce_rm;} public Mwm_tkn__func Fontforce_rm_() {this.fontforce_rm = true; return this;} private boolean fontforce_rm;
public boolean Left() {return left;} public Mwm_tkn__func Left_() {this.left = true; return this;} private boolean left;
public boolean Right() {return right;} public Mwm_tkn__func Right_() {this.right = true; return this;} private boolean right;
public boolean Fail() {return fail;} public Mwm_tkn__func Fail_() {this.fail = true; return this;} private boolean fail;
public boolean Type_latex() {return type_latex;} public Mwm_tkn__func Type_latex_() {this.type_latex = true; return this;} private boolean type_latex;
public boolean Type_mw() {return type_mw;} public Mwm_tkn__func Type_mw_() {this.type_mw = true; return this;} private boolean type_mw;
}

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.*;
import gplx.core.btries.*;
class Mwm_tkn__func_ {
public static final int
Tid__space = 0
, Tid__lit_uf_lt = 1
, Tid__dlm_uf_lt = 2
, Tid__lit_uf_op = 3
, Tid__dlm_uf_op = 4
, Tid__fnc_latex = 5
, Tid__fnc_mw = 6
;
public Btrie_slim_mgr Make_trie() {
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7(); // NOTE: texvc tkns are ascii
Make_itm(rv, Tid__space , " ", "\t", "\n", "\r");
Make_itm(rv, Tid__lit_uf_lt , ",", ":", ";", "?", "!", "'");
Make_itm(rv, Tid__dlm_uf_lt , "(", ")", ".");
Make_itm(rv, Tid__lit_uf_op , "+", "-", "*", "=");
Make_itm(rv, Tid__dlm_uf_op , "/", "|");
Make_itm(rv, Tid__fnc_latex , "arccos", "arcsin", "arctan", "arg", "cos", "cosh", "cot", "coth", "csc"
, "deg", "det", "dim", "exp", "gcd", "hom", "inf", "ker", "lg", "lim", "liminf", "limsup", "ln", "log"
, "max", "min", "Pr", "sec", "sin", "sinh", "sup", "tan", "tanh");
Make_itm(rv, Tid__fnc_mw , "arccot", "arcsec", "arccsc", "sgn", "sen");
return rv;
}
private void Make_itm(Btrie_slim_mgr trie, int tid, String... ary) {
for (String itm : ary)
trie.Add_bry_int(Bry_.new_a7(itm), tid);
}
//let alpha = ['a'-'z' 'A'-'Z']
//let literal_id = ['a'-'z' 'A'-'Z']
//let literal_mn = ['0'-'9']
//let boxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ' '\128'-'\255']
//let aboxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ']
}

View File

@@ -0,0 +1,705 @@
/*
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_tkn__func_trie {
public Btrie_slim_mgr Make() {
Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7();
Add(trie, Make("\\AA").Literal_().Tex_only_());
Add(trie, Make("\\aleph").Literal_().Tex_only_());
Add(trie, Make("\\alpha").Literal_().Tex_only_());
Add(trie, Make("\\amalg").Literal_().Tex_only_());
Add(trie, Make("\\And").Literal_().Tex_only_());
Add(trie, Make("\\angle").Literal_().Tex_only_());
Add(trie, Make("\\approx").Literal_().Tex_only_());
Add(trie, Make("\\approxeq").Literal_().Tex_only_());
Add(trie, Make("\\ast").Literal_().Tex_only_());
Add(trie, Make("\\asymp").Literal_().Tex_only_());
Add(trie, Make("\\backepsilon").Literal_().Tex_only_());
Add(trie, Make("\\backprime").Literal_().Tex_only_());
Add(trie, Make("\\backsim").Literal_().Tex_only_());
Add(trie, Make("\\backsimeq").Literal_().Tex_only_());
Add(trie, Make("\\barwedge").Literal_().Tex_only_());
Add(trie, Make("\\Bbbk").Literal_().Tex_only_());
Add(trie, Make("\\because").Literal_().Tex_only_());
Add(trie, Make("\\beta").Literal_().Tex_only_());
Add(trie, Make("\\beth").Literal_().Tex_only_());
Add(trie, Make("\\between").Literal_().Tex_only_());
Add(trie, Make("\\bigcap").Literal_().Tex_only_());
Add(trie, Make("\\bigcirc").Literal_().Tex_only_());
Add(trie, Make("\\bigcup").Literal_().Tex_only_());
Add(trie, Make("\\bigodot").Literal_().Tex_only_());
Add(trie, Make("\\bigoplus").Literal_().Tex_only_());
Add(trie, Make("\\bigotimes").Literal_().Tex_only_());
Add(trie, Make("\\bigsqcup").Literal_().Tex_only_());
Add(trie, Make("\\bigstar").Literal_().Tex_only_());
Add(trie, Make("\\bigtriangledown").Literal_().Tex_only_());
Add(trie, Make("\\bigtriangleup").Literal_().Tex_only_());
Add(trie, Make("\\biguplus").Literal_().Tex_only_());
Add(trie, Make("\\bigvee").Literal_().Tex_only_());
Add(trie, Make("\\bigwedge").Literal_().Tex_only_());
Add(trie, Make("\\blacklozenge").Literal_().Tex_only_());
Add(trie, Make("\\blacksquare").Literal_().Tex_only_());
Add(trie, Make("\\blacktriangle").Literal_().Tex_only_());
Add(trie, Make("\\blacktriangledown").Literal_().Tex_only_());
Add(trie, Make("\\blacktriangleleft").Literal_().Tex_only_());
Add(trie, Make("\\blacktriangleright").Literal_().Tex_only_());
Add(trie, Make("\\bot").Literal_().Tex_only_());
Add(trie, Make("\\bowtie").Literal_().Tex_only_());
Add(trie, Make("\\Box").Literal_().Tex_only_());
Add(trie, Make("\\boxdot").Literal_().Tex_only_());
Add(trie, Make("\\boxminus").Literal_().Tex_only_());
Add(trie, Make("\\boxplus").Literal_().Tex_only_());
Add(trie, Make("\\boxtimes").Literal_().Tex_only_());
Add(trie, Make("\\bullet").Literal_().Tex_only_());
Add(trie, Make("\\bumpeq").Literal_().Tex_only_());
Add(trie, Make("\\Bumpeq").Literal_().Tex_only_());
Add(trie, Make("\\cap").Literal_().Tex_only_());
Add(trie, Make("\\Cap").Literal_().Tex_only_());
Add(trie, Make("\\cdot").Literal_().Tex_only_());
Add(trie, Make("\\cdots").Literal_().Tex_only_());
Add(trie, Make("\\centerdot").Literal_().Tex_only_());
Add(trie, Make("\\checkmark").Literal_().Tex_only_());
Add(trie, Make("\\chi").Literal_().Tex_only_());
Add(trie, Make("\\circ").Literal_().Tex_only_());
Add(trie, Make("\\circeq").Literal_().Tex_only_());
Add(trie, Make("\\circlearrowleft").Literal_().Tex_only_());
Add(trie, Make("\\circlearrowright").Literal_().Tex_only_());
Add(trie, Make("\\circledast").Literal_().Tex_only_());
Add(trie, Make("\\circledcirc").Literal_().Tex_only_());
Add(trie, Make("\\circleddash").Literal_().Tex_only_());
Add(trie, Make("\\circledS").Literal_().Tex_only_());
Add(trie, Make("\\clubsuit").Literal_().Tex_only_());
Add(trie, Make("\\colon").Literal_().Tex_only_());
Add(trie, Make("\\color").Literal_().Tex_only_());
Add(trie, Make("\\complement").Literal_().Tex_only_());
Add(trie, Make("\\cong").Literal_().Tex_only_());
Add(trie, Make("\\coprod").Literal_().Tex_only_());
Add(trie, Make("\\cup").Literal_().Tex_only_());
Add(trie, Make("\\Cup").Literal_().Tex_only_());
Add(trie, Make("\\curlyeqprec").Literal_().Tex_only_());
Add(trie, Make("\\curlyeqsucc").Literal_().Tex_only_());
Add(trie, Make("\\curlyvee").Literal_().Tex_only_());
Add(trie, Make("\\curlywedge").Literal_().Tex_only_());
Add(trie, Make("\\curvearrowleft").Literal_().Tex_only_());
Add(trie, Make("\\curvearrowright").Literal_().Tex_only_());
Add(trie, Make("\\dagger").Literal_().Tex_only_());
Add(trie, Make("\\daleth").Literal_().Tex_only_());
Add(trie, Make("\\dashv").Literal_().Tex_only_());
Add(trie, Make("\\ddagger").Literal_().Tex_only_());
Add(trie, Make("\\ddots").Literal_().Tex_only_());
Add(trie, Make("\\definecolor").Literal_().Tex_only_());
Add(trie, Make("\\delta").Literal_().Tex_only_());
Add(trie, Make("\\Delta").Literal_().Tex_only_());
Add(trie, Make("\\diagdown").Literal_().Tex_only_());
Add(trie, Make("\\diagup").Literal_().Tex_only_());
Add(trie, Make("\\diamond").Literal_().Tex_only_());
Add(trie, Make("\\Diamond").Literal_().Tex_only_());
Add(trie, Make("\\diamondsuit").Literal_().Tex_only_());
Add(trie, Make("\\digamma").Literal_().Tex_only_());
Add(trie, Make("\\displaystyle").Literal_().Tex_only_());
Add(trie, Make("\\div").Literal_().Tex_only_());
Add(trie, Make("\\divideontimes").Literal_().Tex_only_());
Add(trie, Make("\\doteq").Literal_().Tex_only_());
Add(trie, Make("\\doteqdot").Literal_().Tex_only_());
Add(trie, Make("\\dotplus").Literal_().Tex_only_());
Add(trie, Make("\\dots").Literal_().Tex_only_());
Add(trie, Make("\\dotsb").Literal_().Tex_only_());
Add(trie, Make("\\dotsc").Literal_().Tex_only_());
Add(trie, Make("\\dotsi").Literal_().Tex_only_());
Add(trie, Make("\\dotsm").Literal_().Tex_only_());
Add(trie, Make("\\dotso").Literal_().Tex_only_());
Add(trie, Make("\\doublebarwedge").Literal_().Tex_only_());
Add(trie, Make("\\downdownarrows").Literal_().Tex_only_());
Add(trie, Make("\\downharpoonleft").Literal_().Tex_only_());
Add(trie, Make("\\downharpoonright").Literal_().Tex_only_());
Add(trie, Make("\\ell").Literal_().Tex_only_());
Add(trie, Make("\\emptyset").Literal_().Tex_only_());
Add(trie, Make("\\epsilon").Literal_().Tex_only_());
Add(trie, Make("\\eqcirc").Literal_().Tex_only_());
Add(trie, Make("\\eqsim").Literal_().Tex_only_());
Add(trie, Make("\\eqslantgtr").Literal_().Tex_only_());
Add(trie, Make("\\eqslantless").Literal_().Tex_only_());
Add(trie, Make("\\equiv").Literal_().Tex_only_());
Add(trie, Make("\\eta").Literal_().Tex_only_());
Add(trie, Make("\\eth").Literal_().Tex_only_());
Add(trie, Make("\\exists").Literal_().Tex_only_());
Add(trie, Make("\\fallingdotseq").Literal_().Tex_only_());
Add(trie, Make("\\Finv").Literal_().Tex_only_());
Add(trie, Make("\\flat").Literal_().Tex_only_());
Add(trie, Make("\\forall").Literal_().Tex_only_());
Add(trie, Make("\\frown").Literal_().Tex_only_());
Add(trie, Make("\\Game").Literal_().Tex_only_());
Add(trie, Make("\\gamma").Literal_().Tex_only_());
Add(trie, Make("\\Gamma").Literal_().Tex_only_());
Add(trie, Make("\\geq").Literal_().Tex_only_());
Add(trie, Make("\\geqq").Literal_().Tex_only_());
Add(trie, Make("\\geqslant").Literal_().Tex_only_());
Add(trie, Make("\\gets").Literal_().Tex_only_());
Add(trie, Make("\\gg").Literal_().Tex_only_());
Add(trie, Make("\\ggg").Literal_().Tex_only_());
Add(trie, Make("\\gimel").Literal_().Tex_only_());
Add(trie, Make("\\gnapprox").Literal_().Tex_only_());
Add(trie, Make("\\gneq").Literal_().Tex_only_());
Add(trie, Make("\\gneqq").Literal_().Tex_only_());
Add(trie, Make("\\gnsim").Literal_().Tex_only_());
Add(trie, Make("\\gtrapprox").Literal_().Tex_only_());
Add(trie, Make("\\gtrdot").Literal_().Tex_only_());
Add(trie, Make("\\gtreqless").Literal_().Tex_only_());
Add(trie, Make("\\gtreqqless").Literal_().Tex_only_());
Add(trie, Make("\\gtrless").Literal_().Tex_only_());
Add(trie, Make("\\gtrsim").Literal_().Tex_only_());
Add(trie, Make("\\gvertneqq").Literal_().Tex_only_());
Add(trie, Make("\\hbar").Literal_().Tex_only_());
Add(trie, Make("\\heartsuit").Literal_().Tex_only_());
Add(trie, Make("\\hline").Literal_().Tex_only_());
Add(trie, Make("\\hookleftarrow").Literal_().Tex_only_());
Add(trie, Make("\\hookrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\hslash").Literal_().Tex_only_());
Add(trie, Make("\\iff").Literal_().Tex_only_());
Add(trie, Make("\\iiiint").Literal_().Tex_only_());
Add(trie, Make("\\iiint").Literal_().Tex_only_());
Add(trie, Make("\\iint").Literal_().Tex_only_());
Add(trie, Make("\\Im").Literal_().Tex_only_());
Add(trie, Make("\\imath").Literal_().Tex_only_());
Add(trie, Make("\\implies").Literal_().Tex_only_());
Add(trie, Make("\\in").Literal_().Tex_only_());
Add(trie, Make("\\infty").Literal_().Tex_only_());
Add(trie, Make("\\injlim").Literal_().Tex_only_());
Add(trie, Make("\\int").Literal_().Tex_only_());
Add(trie, Make("\\intercal").Literal_().Tex_only_());
Add(trie, Make("\\iota").Literal_().Tex_only_());
Add(trie, Make("\\jmath").Literal_().Tex_only_());
Add(trie, Make("\\kappa").Literal_().Tex_only_());
Add(trie, Make("\\lambda").Literal_().Tex_only_());
Add(trie, Make("\\Lambda").Literal_().Tex_only_());
Add(trie, Make("\\land").Literal_().Tex_only_());
Add(trie, Make("\\ldots").Literal_().Tex_only_());
Add(trie, Make("\\leftarrow").Literal_().Tex_only_());
Add(trie, Make("\\Leftarrow").Literal_().Tex_only_());
Add(trie, Make("\\leftarrowtail").Literal_().Tex_only_());
Add(trie, Make("\\leftharpoondown").Literal_().Tex_only_());
Add(trie, Make("\\leftharpoonup").Literal_().Tex_only_());
Add(trie, Make("\\leftleftarrows").Literal_().Tex_only_());
Add(trie, Make("\\leftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\Leftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\leftrightarrows").Literal_().Tex_only_());
Add(trie, Make("\\leftrightharpoons").Literal_().Tex_only_());
Add(trie, Make("\\leftrightsquigarrow").Literal_().Tex_only_());
Add(trie, Make("\\leftthreetimes").Literal_().Tex_only_());
Add(trie, Make("\\leq").Literal_().Tex_only_());
Add(trie, Make("\\leqq").Literal_().Tex_only_());
Add(trie, Make("\\leqslant").Literal_().Tex_only_());
Add(trie, Make("\\lessapprox").Literal_().Tex_only_());
Add(trie, Make("\\lessdot").Literal_().Tex_only_());
Add(trie, Make("\\lesseqgtr").Literal_().Tex_only_());
Add(trie, Make("\\lesseqqgtr").Literal_().Tex_only_());
Add(trie, Make("\\lessgtr").Literal_().Tex_only_());
Add(trie, Make("\\lesssim").Literal_().Tex_only_());
Add(trie, Make("\\limits").Literal_().Tex_only_());
Add(trie, Make("\\ll").Literal_().Tex_only_());
Add(trie, Make("\\Lleftarrow").Literal_().Tex_only_());
Add(trie, Make("\\lll").Literal_().Tex_only_());
Add(trie, Make("\\lnapprox").Literal_().Tex_only_());
Add(trie, Make("\\lneq").Literal_().Tex_only_());
Add(trie, Make("\\lneqq").Literal_().Tex_only_());
Add(trie, Make("\\lnot").Literal_().Tex_only_());
Add(trie, Make("\\lnsim").Literal_().Tex_only_());
Add(trie, Make("\\longleftarrow").Literal_().Tex_only_());
Add(trie, Make("\\Longleftarrow").Literal_().Tex_only_());
Add(trie, Make("\\longleftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\Longleftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\longmapsto").Literal_().Tex_only_());
Add(trie, Make("\\longrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\Longrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\looparrowleft").Literal_().Tex_only_());
Add(trie, Make("\\looparrowright").Literal_().Tex_only_());
Add(trie, Make("\\lor").Literal_().Tex_only_());
Add(trie, Make("\\lozenge").Literal_().Tex_only_());
Add(trie, Make("\\Lsh").Literal_().Tex_only_());
Add(trie, Make("\\ltimes").Literal_().Tex_only_());
Add(trie, Make("\\lVert").Literal_().Tex_only_());
Add(trie, Make("\\lvertneqq").Literal_().Tex_only_());
Add(trie, Make("\\mapsto").Literal_().Tex_only_());
Add(trie, Make("\\measuredangle").Literal_().Tex_only_());
Add(trie, Make("\\mho").Literal_().Tex_only_());
Add(trie, Make("\\mid").Literal_().Tex_only_());
Add(trie, Make("\\mod").Literal_().Tex_only_());
Add(trie, Make("\\models").Literal_().Tex_only_());
Add(trie, Make("\\mp").Literal_().Tex_only_());
Add(trie, Make("\\mu").Literal_().Tex_only_());
Add(trie, Make("\\multimap").Literal_().Tex_only_());
Add(trie, Make("\\nabla").Literal_().Tex_only_());
Add(trie, Make("\\natural").Literal_().Tex_only_());
Add(trie, Make("\\ncong").Literal_().Tex_only_());
Add(trie, Make("\\nearrow").Literal_().Tex_only_());
Add(trie, Make("\\neg").Literal_().Tex_only_());
Add(trie, Make("\\neq").Literal_().Tex_only_());
Add(trie, Make("\\nexists").Literal_().Tex_only_());
Add(trie, Make("\\ngeq").Literal_().Tex_only_());
Add(trie, Make("\\ngeqq").Literal_().Tex_only_());
Add(trie, Make("\\ngeqslant").Literal_().Tex_only_());
Add(trie, Make("\\ngtr").Literal_().Tex_only_());
Add(trie, Make("\\ni").Literal_().Tex_only_());
Add(trie, Make("\\nleftarrow").Literal_().Tex_only_());
Add(trie, Make("\\nLeftarrow").Literal_().Tex_only_());
Add(trie, Make("\\nleftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\nLeftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\nleq").Literal_().Tex_only_());
Add(trie, Make("\\nleqq").Literal_().Tex_only_());
Add(trie, Make("\\nleqslant").Literal_().Tex_only_());
Add(trie, Make("\\nless").Literal_().Tex_only_());
Add(trie, Make("\\nmid").Literal_().Tex_only_());
Add(trie, Make("\\nolimits").Literal_().Tex_only_());
Add(trie, Make("\\not").Literal_().Tex_only_());
Add(trie, Make("\\notin").Literal_().Tex_only_());
Add(trie, Make("\\nparallel").Literal_().Tex_only_());
Add(trie, Make("\\nprec").Literal_().Tex_only_());
Add(trie, Make("\\npreceq").Literal_().Tex_only_());
Add(trie, Make("\\nrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\nRightarrow").Literal_().Tex_only_());
Add(trie, Make("\\nshortmid").Literal_().Tex_only_());
Add(trie, Make("\\nshortparallel").Literal_().Tex_only_());
Add(trie, Make("\\nsim").Literal_().Tex_only_());
Add(trie, Make("\\nsubseteq").Literal_().Tex_only_());
Add(trie, Make("\\nsubseteqq").Literal_().Tex_only_());
Add(trie, Make("\\nsucc").Literal_().Tex_only_());
Add(trie, Make("\\nsucceq").Literal_().Tex_only_());
Add(trie, Make("\\nsupseteq").Literal_().Tex_only_());
Add(trie, Make("\\nsupseteqq").Literal_().Tex_only_());
Add(trie, Make("\\ntriangleleft").Literal_().Tex_only_());
Add(trie, Make("\\ntrianglelefteq").Literal_().Tex_only_());
Add(trie, Make("\\ntriangleright").Literal_().Tex_only_());
Add(trie, Make("\\ntrianglerighteq").Literal_().Tex_only_());
Add(trie, Make("\\nu").Literal_().Tex_only_());
Add(trie, Make("\\nvdash").Literal_().Tex_only_());
Add(trie, Make("\\nVdash").Literal_().Tex_only_());
Add(trie, Make("\\nvDash").Literal_().Tex_only_());
Add(trie, Make("\\nVDash").Literal_().Tex_only_());
Add(trie, Make("\\nwarrow").Literal_().Tex_only_());
Add(trie, Make("\\odot").Literal_().Tex_only_());
Add(trie, Make("\\oint").Literal_().Tex_only_());
Add(trie, Make("\\omega").Literal_().Tex_only_());
Add(trie, Make("\\Omega").Literal_().Tex_only_());
Add(trie, Make("\\ominus").Literal_().Tex_only_());
Add(trie, Make("\\oplus").Literal_().Tex_only_());
Add(trie, Make("\\oslash").Literal_().Tex_only_());
Add(trie, Make("\\otimes").Literal_().Tex_only_());
Add(trie, Make("\\overbrace").Literal_().Tex_only_());
Add(trie, Make("\\overleftarrow").Literal_().Tex_only_());
Add(trie, Make("\\overleftrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\overline").Literal_().Tex_only_());
Add(trie, Make("\\overrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\P").Literal_().Tex_only_());
Add(trie, Make("\\pagecolor").Literal_().Tex_only_());
Add(trie, Make("\\parallel").Literal_().Tex_only_());
Add(trie, Make("\\partial").Literal_().Tex_only_());
Add(trie, Make("\\perp").Literal_().Tex_only_());
Add(trie, Make("\\phi").Literal_().Tex_only_());
Add(trie, Make("\\Phi").Literal_().Tex_only_());
Add(trie, Make("\\pi").Literal_().Tex_only_());
Add(trie, Make("\\Pi").Literal_().Tex_only_());
Add(trie, Make("\\pitchfork").Literal_().Tex_only_());
Add(trie, Make("\\pm").Literal_().Tex_only_());
Add(trie, Make("\\prec").Literal_().Tex_only_());
Add(trie, Make("\\precapprox").Literal_().Tex_only_());
Add(trie, Make("\\preccurlyeq").Literal_().Tex_only_());
Add(trie, Make("\\preceq").Literal_().Tex_only_());
Add(trie, Make("\\precnapprox").Literal_().Tex_only_());
Add(trie, Make("\\precneqq").Literal_().Tex_only_());
Add(trie, Make("\\precnsim").Literal_().Tex_only_());
Add(trie, Make("\\precsim").Literal_().Tex_only_());
Add(trie, Make("\\prime").Literal_().Tex_only_());
Add(trie, Make("\\prod").Literal_().Tex_only_());
Add(trie, Make("\\projlim").Literal_().Tex_only_());
Add(trie, Make("\\propto").Literal_().Tex_only_());
Add(trie, Make("\\psi").Literal_().Tex_only_());
Add(trie, Make("\\Psi").Literal_().Tex_only_());
Add(trie, Make("\\qquad").Literal_().Tex_only_());
Add(trie, Make("\\quad").Literal_().Tex_only_());
Add(trie, Make("\\Re").Literal_().Tex_only_());
Add(trie, Make("\\rho").Literal_().Tex_only_());
Add(trie, Make("\\rightarrow").Literal_().Tex_only_());
Add(trie, Make("\\Rightarrow").Literal_().Tex_only_());
Add(trie, Make("\\rightarrowtail").Literal_().Tex_only_());
Add(trie, Make("\\rightharpoondown").Literal_().Tex_only_());
Add(trie, Make("\\rightharpoonup").Literal_().Tex_only_());
Add(trie, Make("\\rightleftarrows").Literal_().Tex_only_());
Add(trie, Make("\\rightrightarrows").Literal_().Tex_only_());
Add(trie, Make("\\rightsquigarrow").Literal_().Tex_only_());
Add(trie, Make("\\rightthreetimes").Literal_().Tex_only_());
Add(trie, Make("\\risingdotseq").Literal_().Tex_only_());
Add(trie, Make("\\Rrightarrow").Literal_().Tex_only_());
Add(trie, Make("\\Rsh").Literal_().Tex_only_());
Add(trie, Make("\\rtimes").Literal_().Tex_only_());
Add(trie, Make("\\rVert").Literal_().Tex_only_());
Add(trie, Make("\\S").Literal_().Tex_only_());
Add(trie, Make("\\scriptscriptstyle").Literal_().Tex_only_());
Add(trie, Make("\\scriptstyle").Literal_().Tex_only_());
Add(trie, Make("\\searrow").Literal_().Tex_only_());
Add(trie, Make("\\setminus").Literal_().Tex_only_());
Add(trie, Make("\\sharp").Literal_().Tex_only_());
Add(trie, Make("\\shortmid").Literal_().Tex_only_());
Add(trie, Make("\\shortparallel").Literal_().Tex_only_());
Add(trie, Make("\\sigma").Literal_().Tex_only_());
Add(trie, Make("\\Sigma").Literal_().Tex_only_());
Add(trie, Make("\\sim").Literal_().Tex_only_());
Add(trie, Make("\\simeq").Literal_().Tex_only_());
Add(trie, Make("\\smallfrown").Literal_().Tex_only_());
Add(trie, Make("\\smallsetminus").Literal_().Tex_only_());
Add(trie, Make("\\smallsmile").Literal_().Tex_only_());
Add(trie, Make("\\smile").Literal_().Tex_only_());
Add(trie, Make("\\spadesuit").Literal_().Tex_only_());
Add(trie, Make("\\sphericalangle").Literal_().Tex_only_());
Add(trie, Make("\\sqcap").Literal_().Tex_only_());
Add(trie, Make("\\sqcup").Literal_().Tex_only_());
Add(trie, Make("\\sqsubset").Literal_().Tex_only_());
Add(trie, Make("\\sqsubseteq").Literal_().Tex_only_());
Add(trie, Make("\\sqsupset").Literal_().Tex_only_());
Add(trie, Make("\\sqsupseteq").Literal_().Tex_only_());
Add(trie, Make("\\square").Literal_().Tex_only_());
Add(trie, Make("\\star").Literal_().Tex_only_());
Add(trie, Make("\\subset").Literal_().Tex_only_());
Add(trie, Make("\\Subset").Literal_().Tex_only_());
Add(trie, Make("\\subseteq").Literal_().Tex_only_());
Add(trie, Make("\\subseteqq").Literal_().Tex_only_());
Add(trie, Make("\\subsetneq").Literal_().Tex_only_());
Add(trie, Make("\\subsetneqq").Literal_().Tex_only_());
Add(trie, Make("\\succ").Literal_().Tex_only_());
Add(trie, Make("\\succapprox").Literal_().Tex_only_());
Add(trie, Make("\\succcurlyeq").Literal_().Tex_only_());
Add(trie, Make("\\succeq").Literal_().Tex_only_());
Add(trie, Make("\\succnapprox").Literal_().Tex_only_());
Add(trie, Make("\\succneqq").Literal_().Tex_only_());
Add(trie, Make("\\succnsim").Literal_().Tex_only_());
Add(trie, Make("\\succsim").Literal_().Tex_only_());
Add(trie, Make("\\sum").Literal_().Tex_only_());
Add(trie, Make("\\supset").Literal_().Tex_only_());
Add(trie, Make("\\Supset").Literal_().Tex_only_());
Add(trie, Make("\\supseteq").Literal_().Tex_only_());
Add(trie, Make("\\supseteqq").Literal_().Tex_only_());
Add(trie, Make("\\supsetneq").Literal_().Tex_only_());
Add(trie, Make("\\supsetneqq").Literal_().Tex_only_());
Add(trie, Make("\\surd").Literal_().Tex_only_());
Add(trie, Make("\\swarrow").Literal_().Tex_only_());
Add(trie, Make("\\tau").Literal_().Tex_only_());
Add(trie, Make("\\textstyle").Literal_().Tex_only_());
Add(trie, Make("\\textvisiblespace").Literal_().Tex_only_());
Add(trie, Make("\\therefore").Literal_().Tex_only_());
Add(trie, Make("\\theta").Literal_().Tex_only_());
Add(trie, Make("\\Theta").Literal_().Tex_only_());
Add(trie, Make("\\thickapprox").Literal_().Tex_only_());
Add(trie, Make("\\thicksim").Literal_().Tex_only_());
Add(trie, Make("\\times").Literal_().Tex_only_());
Add(trie, Make("\\to").Literal_().Tex_only_());
Add(trie, Make("\\top").Literal_().Tex_only_());
Add(trie, Make("\\triangle").Literal_().Tex_only_());
Add(trie, Make("\\triangledown").Literal_().Tex_only_());
Add(trie, Make("\\triangleleft").Literal_().Tex_only_());
Add(trie, Make("\\trianglelefteq").Literal_().Tex_only_());
Add(trie, Make("\\triangleq").Literal_().Tex_only_());
Add(trie, Make("\\triangleright").Literal_().Tex_only_());
Add(trie, Make("\\trianglerighteq").Literal_().Tex_only_());
Add(trie, Make("\\underbrace").Literal_().Tex_only_());
Add(trie, Make("\\underline").Literal_().Tex_only_());
Add(trie, Make("\\upharpoonleft").Literal_().Tex_only_());
Add(trie, Make("\\upharpoonright").Literal_().Tex_only_());
Add(trie, Make("\\uplus").Literal_().Tex_only_());
Add(trie, Make("\\upsilon").Literal_().Tex_only_());
Add(trie, Make("\\Upsilon").Literal_().Tex_only_());
Add(trie, Make("\\upuparrows").Literal_().Tex_only_());
Add(trie, Make("\\varepsilon").Literal_().Tex_only_());
Add(trie, Make("\\varinjlim").Literal_().Tex_only_());
Add(trie, Make("\\varkappa").Literal_().Tex_only_());
Add(trie, Make("\\varliminf").Literal_().Tex_only_());
Add(trie, Make("\\varlimsup").Literal_().Tex_only_());
Add(trie, Make("\\varnothing").Literal_().Tex_only_());
Add(trie, Make("\\varphi").Literal_().Tex_only_());
Add(trie, Make("\\varpi").Literal_().Tex_only_());
Add(trie, Make("\\varprojlim").Literal_().Tex_only_());
Add(trie, Make("\\varpropto").Literal_().Tex_only_());
Add(trie, Make("\\varrho").Literal_().Tex_only_());
Add(trie, Make("\\varsigma").Literal_().Tex_only_());
Add(trie, Make("\\varsubsetneq").Literal_().Tex_only_());
Add(trie, Make("\\varsubsetneqq").Literal_().Tex_only_());
Add(trie, Make("\\varsupsetneq").Literal_().Tex_only_());
Add(trie, Make("\\varsupsetneqq").Literal_().Tex_only_());
Add(trie, Make("\\vartheta").Literal_().Tex_only_());
Add(trie, Make("\\vartriangle").Literal_().Tex_only_());
Add(trie, Make("\\vartriangleleft").Literal_().Tex_only_());
Add(trie, Make("\\vartriangleright").Literal_().Tex_only_());
Add(trie, Make("\\vdash").Literal_().Tex_only_());
Add(trie, Make("\\Vdash").Literal_().Tex_only_());
Add(trie, Make("\\vDash").Literal_().Tex_only_());
Add(trie, Make("\\vdots").Literal_().Tex_only_());
Add(trie, Make("\\vee").Literal_().Tex_only_());
Add(trie, Make("\\veebar").Literal_().Tex_only_());
Add(trie, Make("\\vline").Literal_().Tex_only_());
Add(trie, Make("\\Vvdash").Literal_().Tex_only_());
Add(trie, Make("\\wedge").Literal_().Tex_only_());
Add(trie, Make("\\widehat").Literal_().Tex_only_());
Add(trie, Make("\\widetilde").Literal_().Tex_only_());
Add(trie, Make("\\wp").Literal_().Tex_only_());
Add(trie, Make("\\wr").Literal_().Tex_only_());
Add(trie, Make("\\xi").Literal_().Tex_only_());
Add(trie, Make("\\Xi").Literal_().Tex_only_());
Add(trie, Make("\\zeta").Literal_().Tex_only_());
Add(trie, Make("\\big").Big_());
Add(trie, Make("\\Big").Big_());
Add(trie, Make("\\bigg").Big_());
Add(trie, Make("\\Bigg").Big_());
Add(trie, Make("\\biggl").Big_());
Add(trie, Make("\\Biggl").Big_());
Add(trie, Make("\\biggr").Big_());
Add(trie, Make("\\Biggr").Big_());
Add(trie, Make("\\bigl").Big_());
Add(trie, Make("\\Bigl").Big_());
Add(trie, Make("\\bigr").Big_());
Add(trie, Make("\\Bigr").Big_());
Add(trie, Make("\\backslash").Delimiter_().Tex_only_());
Add(trie, Make("\\downarrow").Delimiter_().Tex_only_());
Add(trie, Make("\\Downarrow").Delimiter_().Tex_only_());
Add(trie, Make("\\langle").Delimiter_().Tex_only_());
Add(trie, Make("\\lbrace").Delimiter_().Tex_only_());
Add(trie, Make("\\lceil").Delimiter_().Tex_only_());
Add(trie, Make("\\lfloor").Delimiter_().Tex_only_());
Add(trie, Make("\\llcorner").Delimiter_().Tex_only_());
Add(trie, Make("\\lrcorner").Delimiter_().Tex_only_());
Add(trie, Make("\\rangle").Delimiter_().Tex_only_());
Add(trie, Make("\\rbrace").Delimiter_().Tex_only_());
Add(trie, Make("\\rceil").Delimiter_().Tex_only_());
Add(trie, Make("\\rfloor").Delimiter_().Tex_only_());
Add(trie, Make("\\rightleftharpoons").Delimiter_().Tex_only_());
Add(trie, Make("\\twoheadleftarrow").Delimiter_().Tex_only_());
Add(trie, Make("\\twoheadrightarrow").Delimiter_().Tex_only_());
Add(trie, Make("\\ulcorner").Delimiter_().Tex_only_());
Add(trie, Make("\\uparrow").Delimiter_().Tex_only_());
Add(trie, Make("\\Uparrow").Delimiter_().Tex_only_());
Add(trie, Make("\\updownarrow").Delimiter_().Tex_only_());
Add(trie, Make("\\Updownarrow").Delimiter_().Tex_only_());
Add(trie, Make("\\urcorner").Delimiter_().Tex_only_());
Add(trie, Make("\\Vert").Delimiter_().Tex_only_());
Add(trie, Make("\\vert").Delimiter_().Tex_only_());
Add(trie, Make("\\lbrack").Delimiter_().Tex_only_());
Add(trie, Make("\\rbrack").Delimiter_().Tex_only_());
Add(trie, Make("\\acute").Fun_ar1_());
Add(trie, Make("\\bar").Fun_ar1_());
Add(trie, Make("\\bcancel").Fun_ar1_());
Add(trie, Make("\\bmod").Fun_ar1_());
Add(trie, Make("\\boldsymbol").Fun_ar1_());
Add(trie, Make("\\breve").Fun_ar1_());
Add(trie, Make("\\cancel").Fun_ar1_());
Add(trie, Make("\\check").Fun_ar1_());
Add(trie, Make("\\ddot").Fun_ar1_());
Add(trie, Make("\\dot").Fun_ar1_());
Add(trie, Make("\\emph").Fun_ar1_());
Add(trie, Make("\\grave").Fun_ar1_());
Add(trie, Make("\\hat").Fun_ar1_());
Add(trie, Make("\\mathbb").Fun_ar1_());
Add(trie, Make("\\mathbf").Fun_ar1_());
Add(trie, Make("\\mathbin").Fun_ar1_());
Add(trie, Make("\\mathcal").Fun_ar1_());
Add(trie, Make("\\mathclose").Fun_ar1_());
Add(trie, Make("\\mathfrak").Fun_ar1_());
Add(trie, Make("\\mathit").Fun_ar1_());
Add(trie, Make("\\mathop").Fun_ar1_());
Add(trie, Make("\\mathopen").Fun_ar1_());
Add(trie, Make("\\mathord").Fun_ar1_());
Add(trie, Make("\\mathpunct").Fun_ar1_());
Add(trie, Make("\\mathrel").Fun_ar1_());
Add(trie, Make("\\mathrm").Fun_ar1_());
Add(trie, Make("\\mathsf").Fun_ar1_());
Add(trie, Make("\\mathtt").Fun_ar1_());
Add(trie, Make("\\operatorname").Fun_ar1_());
Add(trie, Make("\\pmod").Fun_ar1_());
Add(trie, Make("\\sqrt").Fun_ar1_());
Add(trie, Make("\\textbf").Fun_ar1_());
Add(trie, Make("\\textit").Fun_ar1_());
Add(trie, Make("\\textrm").Fun_ar1_());
Add(trie, Make("\\textsf").Fun_ar1_());
Add(trie, Make("\\texttt").Fun_ar1_());
Add(trie, Make("\\tilde").Fun_ar1_());
Add(trie, Make("\\vec").Fun_ar1_());
Add(trie, Make("\\xcancel").Fun_ar1_());
Add(trie, Make("\\xleftarrow").Fun_ar1_());
Add(trie, Make("\\xrightarrow").Fun_ar1_());
Add(trie, Make("\\binom").Fun_ar2_());
Add(trie, Make("\\cancelto").Fun_ar2_());
Add(trie, Make("\\cfrac").Fun_ar2_());
Add(trie, Make("\\dbinom").Fun_ar2_());
Add(trie, Make("\\dfrac").Fun_ar2_());
Add(trie, Make("\\frac").Fun_ar2_());
Add(trie, Make("\\overset").Fun_ar2_());
Add(trie, Make("\\stackrel").Fun_ar2_());
Add(trie, Make("\\tbinom").Fun_ar2_());
Add(trie, Make("\\tfrac").Fun_ar2_());
Add(trie, Make("\\underset").Fun_ar2_());
Add(trie, Make("\\atop").Fun_infix_());
Add(trie, Make("\\choose").Fun_infix_());
Add(trie, Make("\\over").Fun_infix_());
Add(trie, Make("\\Coppa").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\coppa").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\Digamma").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\euro").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\geneuro").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\geneuronarrow").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\geneurowide").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\Koppa").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\koppa").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\officialeuro").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\Sampi").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\sampi").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\Stigma").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\stigma").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\varstigma").Literal_().Tex_only_().Manual_("\\mbox{~0}"));
Add(trie, Make("\\C").Literal_().Tex_only_().Manual_("\\mathbb{C}"));
Add(trie, Make("\\H").Literal_().Tex_only_().Manual_("\\mathbb{H}"));
Add(trie, Make("\\N").Literal_().Tex_only_().Manual_("\\mathbb{N}"));
Add(trie, Make("\\Q").Literal_().Tex_only_().Manual_("\\mathbb{Q}"));
Add(trie, Make("\\R").Literal_().Tex_only_().Manual_("\\mathbb{R}"));
Add(trie, Make("\\Z").Literal_().Tex_only_().Manual_("\\mathbb{Z}"));
Add(trie, Make("\\darr").Delimiter_().Tex_only_().Manual_("\\downarrow"));
Add(trie, Make("\\dArr").Delimiter_().Tex_only_().Manual_("\\Downarrow"));
Add(trie, Make("\\Darr").Delimiter_().Tex_only_().Manual_("\\Downarrow"));
Add(trie, Make("\\lang").Delimiter_().Tex_only_().Manual_("\\langle"));
Add(trie, Make("\\rang").Delimiter_().Tex_only_().Manual_("\\rangle"));
Add(trie, Make("\\uarr").Delimiter_().Tex_only_().Manual_("\\uparrow"));
Add(trie, Make("\\uArr").Delimiter_().Tex_only_().Manual_("\\Uparrow"));
Add(trie, Make("\\Uarr").Delimiter_().Tex_only_().Manual_("\\Uparrow"));
Add(trie, Make("\\Bbb").Fun_ar1_().Manual_("\\mathbb"));
Add(trie, Make("\\bold").Fun_ar1_().Manual_("\\mathbf"));
Add(trie, Make("\\alef").Literal_().Tex_only_().Manual_("\\aleph"));
Add(trie, Make("\\alefsym").Literal_().Tex_only_().Manual_("\\aleph"));
Add(trie, Make("\\Alpha").Literal_().Tex_only_().Manual_("\\mathrm{A}"));
Add(trie, Make("\\and").Literal_().Tex_only_().Manual_("\\land"));
Add(trie, Make("\\ang").Literal_().Tex_only_().Manual_("\\angle"));
Add(trie, Make("\\Beta").Literal_().Tex_only_().Manual_("\\mathrm{B}"));
Add(trie, Make("\\bull").Literal_().Tex_only_().Manual_("\\bullet"));
Add(trie, Make("\\Chi").Literal_().Tex_only_().Manual_("\\mathrm{X}"));
Add(trie, Make("\\clubs").Literal_().Tex_only_().Manual_("\\clubsuit"));
Add(trie, Make("\\cnums").Literal_().Tex_only_().Manual_("\\mathbb{C}"));
Add(trie, Make("\\Complex").Literal_().Tex_only_().Manual_("\\mathbb{C}"));
Add(trie, Make("\\Dagger").Literal_().Tex_only_().Manual_("\\ddagger"));
Add(trie, Make("\\diamonds").Literal_().Tex_only_().Manual_("\\diamondsuit"));
Add(trie, Make("\\Doteq").Literal_().Tex_only_().Manual_("\\doteqdot"));
Add(trie, Make("\\doublecap").Literal_().Tex_only_().Manual_("\\Cap"));
Add(trie, Make("\\doublecup").Literal_().Tex_only_().Manual_("\\Cup"));
Add(trie, Make("\\empty").Literal_().Tex_only_().Manual_("\\emptyset"));
Add(trie, Make("\\Epsilon").Literal_().Tex_only_().Manual_("\\mathrm{E}"));
Add(trie, Make("\\Eta").Literal_().Tex_only_().Manual_("\\mathrm{H}"));
Add(trie, Make("\\exist").Literal_().Tex_only_().Manual_("\\exists"));
Add(trie, Make("\\ge").Literal_().Tex_only_().Manual_("\\geq"));
Add(trie, Make("\\gggtr").Literal_().Tex_only_().Manual_("\\ggg"));
Add(trie, Make("\\hAar").Literal_().Tex_only_().Manual_("\\Leftrightarrow"));
Add(trie, Make("\\harr").Literal_().Tex_only_().Manual_("\\leftrightarrow"));
Add(trie, Make("\\Harr").Literal_().Tex_only_().Manual_("\\Leftrightarrow"));
Add(trie, Make("\\hearts").Literal_().Tex_only_().Manual_("\\heartsuit"));
Add(trie, Make("\\image").Literal_().Tex_only_().Manual_("\\Im"));
Add(trie, Make("\\infin").Literal_().Tex_only_().Manual_("\\infty"));
Add(trie, Make("\\Iota").Literal_().Tex_only_().Manual_("\\mathrm{I}"));
Add(trie, Make("\\isin").Literal_().Tex_only_().Manual_("\\in"));
Add(trie, Make("\\Kappa").Literal_().Tex_only_().Manual_("\\mathrm{K}"));
Add(trie, Make("\\larr").Literal_().Tex_only_().Manual_("\\leftarrow"));
Add(trie, Make("\\Larr").Literal_().Tex_only_().Manual_("\\Leftarrow"));
Add(trie, Make("\\lArr").Literal_().Tex_only_().Manual_("\\Leftarrow"));
Add(trie, Make("\\le").Literal_().Tex_only_().Manual_("\\leq"));
Add(trie, Make("\\lrarr").Literal_().Tex_only_().Manual_("\\leftrightarrow"));
Add(trie, Make("\\Lrarr").Literal_().Tex_only_().Manual_("\\Leftrightarrow"));
Add(trie, Make("\\lrArr").Literal_().Tex_only_().Manual_("\\Leftrightarrow"));
Add(trie, Make("\\Mu").Literal_().Tex_only_().Manual_("\\mathrm{M}"));
Add(trie, Make("\\natnums").Literal_().Tex_only_().Manual_("\\mathbb{N}"));
Add(trie, Make("\\ne").Literal_().Tex_only_().Manual_("\\neq"));
Add(trie, Make("\\Nu").Literal_().Tex_only_().Manual_("\\mathrm{N}"));
Add(trie, Make("\\O").Literal_().Tex_only_().Manual_("\\emptyset"));
Add(trie, Make("\\omicron").Literal_().Tex_only_().Manual_("\\mathrm{o}"));
Add(trie, Make("\\Omicron").Literal_().Tex_only_().Manual_("\\mathrm{O}"));
Add(trie, Make("\\or").Literal_().Tex_only_().Manual_("\\lor"));
Add(trie, Make("\\part").Literal_().Tex_only_().Manual_("\\partial"));
Add(trie, Make("\\plusmn").Literal_().Tex_only_().Manual_("\\pm"));
Add(trie, Make("\\rarr").Literal_().Tex_only_().Manual_("\\rightarrow"));
Add(trie, Make("\\Rarr").Literal_().Tex_only_().Manual_("\\Rightarrow"));
Add(trie, Make("\\rArr").Literal_().Tex_only_().Manual_("\\Rightarrow"));
Add(trie, Make("\\real").Literal_().Tex_only_().Manual_("\\Re"));
Add(trie, Make("\\reals").Literal_().Tex_only_().Manual_("\\mathbb{R}"));
Add(trie, Make("\\Reals").Literal_().Tex_only_().Manual_("\\mathbb{R}"));
Add(trie, Make("\\restriction").Literal_().Tex_only_().Manual_("\\upharpoonright"));
Add(trie, Make("\\Rho").Literal_().Tex_only_().Manual_("\\mathrm{P}"));
Add(trie, Make("\\sdot").Literal_().Tex_only_().Manual_("\\cdot"));
Add(trie, Make("\\sect").Literal_().Tex_only_().Manual_("\\S"));
Add(trie, Make("\\spades").Literal_().Tex_only_().Manual_("\\spadesuit"));
Add(trie, Make("\\sub").Literal_().Tex_only_().Manual_("\\subset"));
Add(trie, Make("\\sube").Literal_().Tex_only_().Manual_("\\subseteq"));
Add(trie, Make("\\supe").Literal_().Tex_only_().Manual_("\\supseteq"));
Add(trie, Make("\\Tau").Literal_().Tex_only_().Manual_("\\mathrm{T}"));
Add(trie, Make("\\thetasym").Literal_().Tex_only_().Manual_("\\vartheta"));
Add(trie, Make("\\varcoppa").Literal_().Tex_only_().Manual_("\\mbox{coppa}"));
Add(trie, Make("\\weierp").Literal_().Tex_only_().Manual_("\\wp"));
Add(trie, Make("\\Zeta").Literal_().Tex_only_().Manual_("\\mathrm{Z}"));
Add(trie, Make("\\rm").Declh_().Fontforce_rm_());
Add(trie, Make("\\it").Declh_().Fontforce_rm_());
Add(trie, Make("\\cal").Declh_().Fontforce_rm_());
Add(trie, Make("\\bf").Declh_().Fontforce_rm_());
Add(trie, Make("\\sideset").Fun_ar2nb_().Manual_("\\sideset "));
Add(trie, Make("\\left").Left_());
Add(trie, Make("\\right").Right_());
Add(trie, Make("\\text").Fail_());
Add(trie, Make("\\mbox").Fail_());
Add(trie, Make("\\vbox").Fail_());
Add(trie, Make("\\hbox").Fail_());
Add(trie, Make("\\arccos").Type_latex_());
Add(trie, Make("\\arcsin").Type_latex_());
Add(trie, Make("\\arctan").Type_latex_());
Add(trie, Make("\\arg").Type_latex_());
Add(trie, Make("\\cos").Type_latex_());
Add(trie, Make("\\cosh").Type_latex_());
Add(trie, Make("\\cot").Type_latex_());
Add(trie, Make("\\coth").Type_latex_());
Add(trie, Make("\\csc").Type_latex_());
Add(trie, Make("\\deg").Type_latex_());
Add(trie, Make("\\det").Type_latex_());
Add(trie, Make("\\dim").Type_latex_());
Add(trie, Make("\\exp").Type_latex_());
Add(trie, Make("\\gcd").Type_latex_());
Add(trie, Make("\\hom").Type_latex_());
Add(trie, Make("\\inf").Type_latex_());
Add(trie, Make("\\ker").Type_latex_());
Add(trie, Make("\\lg").Type_latex_());
Add(trie, Make("\\lim").Type_latex_());
Add(trie, Make("\\liminf").Type_latex_());
Add(trie, Make("\\limsup").Type_latex_());
Add(trie, Make("\\ln").Type_latex_());
Add(trie, Make("\\log").Type_latex_());
Add(trie, Make("\\max").Type_latex_());
Add(trie, Make("\\min").Type_latex_());
Add(trie, Make("\\Pr").Type_latex_());
Add(trie, Make("\\sec").Type_latex_());
Add(trie, Make("\\sin").Type_latex_());
Add(trie, Make("\\sinh").Type_latex_());
Add(trie, Make("\\sup").Type_latex_());
Add(trie, Make("\\tan").Type_latex_());
Add(trie, Make("\\tanh").Type_latex_());
Add(trie, Make("\\arccot").Type_mw_());
Add(trie, Make("\\arcsec").Type_mw_());
Add(trie, Make("\\arccsc").Type_mw_());
Add(trie, Make("\\sgn").Type_mw_());
Add(trie, Make("\\sen").Type_mw_());
return trie;
}
private Mwm_tkn__func Make(String key) {return new Mwm_tkn__func(Bry_.new_a7(key));} // NOTE: TEX func names are ASCII
private void Add(Btrie_slim_mgr trie, Mwm_tkn__func tkn) {trie.Add_obj(tkn.Key(), tkn);}
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
class Mwm_tkn__leaf implements Mwm_tkn {
class Mwm_tkn__leaf_raw 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;
@@ -26,7 +26,7 @@ class Mwm_tkn__leaf implements Mwm_tkn {
return this;
}
public Mwm_tkn__root Root() {return root;} private Mwm_tkn__root root;
public int Tid() {return tid;} private int tid;
@gplx.Virtual 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;

View File

@@ -0,0 +1,44 @@
/*
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_repl implements Mwm_tkn {
private final byte[] repl;
public Mwm_tkn__leaf_repl(int tid, byte[] repl) {
this.tid = tid;
this.repl = repl;
}
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {
this.root = root;
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 final 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 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) {
Mwm_tkn_.Tkn_to_bry__bgn(bfr, indent, this);
Mwm_tkn_.Tkn_to_bry__end_head(bfr);
}
}

View File

@@ -20,19 +20,19 @@ 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;
private Mwm_tkn_mkr tkn_mkr;
public Mwm_tkn__root() {
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 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) {
public Mwm_tkn Init_as_root(Mwm_tkn_mkr tkn_mkr, int src_bgn, int src_end) {
this.tkn_mkr = tkn_mkr;
this.src_bgn = src_bgn; this.src_end = src_end;
int expd_len = (src_end - src_bgn) / 5;
root_reg.Init(expd_len);

View File

@@ -17,16 +17,17 @@ 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();
private final Mwm_tkn[] leaf_protos = new Mwm_tkn[Mwm_tkn_.Tid_len];
public void Reg_leaf(int tid, Mwm_tkn tkn) {
leaf_protos[tid] = tkn;
}
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;
}
Mwm_tkn proto = leaf_protos[tid];
return proto == null ? null : proto.Init(root, tid, uid, bgn, end);
}
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);
rv.Init(root, Mwm_tkn_.Tid__fnc, uid, bgn, end);
return rv;
}
public Mwm_tkn Make_curly(Mwm_tkn__root root, int uid, int bgn, int end) {

View File

@@ -164,6 +164,10 @@ public class Scrib_invoke_func_fxt {
KeyVal[] actl = Test_scrib_proc_rv(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return (KeyVal[])actl[0].Val();
}
public Object Test_scrib_proc_rv_as_obj(Scrib_lib lib, String proc_name, Object[] args) {
KeyVal[] actl = Test_scrib_proc_rv(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return actl[0].Val();
}
private KeyVal[] Test_scrib_proc_rv(Scrib_lib lib, String proc_name, KeyVal[] args) {
Scrib_proc proc = lib.Procs().Get_by_key(proc_name);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();

View File

@@ -21,9 +21,10 @@ public class Scrib_proc_args {
public Scrib_proc_args(KeyVal[] v) {Init(v);}
public int Len() {return ary_len;}
public KeyVal[] Ary() {return ary;}
public boolean Pull_bool(int i) {Object rv = Get_or_fail(i); return Bool_.cast(rv);}
public String Pull_str(int i) {Object rv = Get_or_fail(i); return String_.cast(rv);}
public byte[] Pull_bry(int i) {Object rv = Get_or_fail(i); return Bry_.new_u8(String_.cast(rv));}
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
public String Pull_str(int i) {return String_.cast(Get_or_fail(i));}
public byte[] Pull_bry(int i) {return Bry_.new_u8(String_.cast(Get_or_fail(i)));}
public KeyVal[] Pull_kv_ary(int i) {return (KeyVal[])Get_or_fail(i);}
public int Pull_int(int i) {Object rv = Get_or_fail(i);
try {return Int_.coerce_(rv);} // coerce to handle "1" and 1; will still fail if "abc" is passed
catch (Exception e) {
@@ -43,6 +44,7 @@ public class Scrib_proc_args {
}
}
}
public Object Pull_obj(int i) {return Get_or_fail(i);}
public String Cast_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : String_.cast (rv);}
public byte[] Cast_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(String_.cast (rv));} // NOTE: cast is deliberate; Scrib call checkType whi
public byte[] Cast_bry_or_empty(int i) {Object rv = Get_or_null(i); return rv == null ? Bry_.Empty : Bry_.new_u8(String_.cast (rv));}
@@ -54,10 +56,6 @@ public class Scrib_proc_args {
public String Xstr_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Object_.Xto_str_loose_or(rv, null);} // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
public byte[] Xstr_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(Object_.Xto_str_loose_or(rv, null));}
public KeyVal[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (KeyVal[])rv;}
public KeyVal[] Pull_kv_ary(int i) {
Object rv = Get_or_fail(i);
return (KeyVal[])rv;
}
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));
if (params_idx < 0 || params_idx >= ary_len) return Bry_.Ary_empty;
Object o = ary[params_idx].Val();

View File

@@ -59,7 +59,7 @@ class Gfo_fld_crt implements Criteria {
}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
public String To_str() {return String_.Concat(Byte_.Xto_str(fld_idx), " ", crt.To_str());}
public String To_str() {return String_.Concat(Byte_.To_str(fld_idx), " ", crt.To_str());}
public static Gfo_fld_crt new_(byte fld_idx, Criteria crt) {
Gfo_fld_crt rv = new Gfo_fld_crt();
rv.fld_idx = fld_idx; rv.crt = crt;

View File

@@ -27,8 +27,9 @@ class Kv_ary_utl {
}
public static KeyVal[] new_kvs(KeyVal... vals) {return vals;}
public static String Ary_to_str(Json_wtr wtr, KeyVal[] ary) {
wtr.Doc_nde_bgn();
Ary_to_str(wtr, 0, ary);
return wtr.To_str_and_clear();
return wtr.Doc_nde_end().To_str_and_clear();
}
private static void Ary_to_str(Json_wtr wtr, int indent, KeyVal[] ary) {
int len = ary.length;
@@ -44,7 +45,7 @@ class Kv_ary_utl {
if (Type_adp_.Eq(val_type, KeyVal[].class))
Ary_to_str__nde(wtr, indent, itm.Key(), (KeyVal[])itm.Val());
else if (Type_adp_.Is_array(val_type))
Ary_to_str__ary(wtr, indent, itm.Key(), Array_.cast(itm.Val()));
Ary_to_str__ary(wtr, indent, itm.Key(), Array_.cast(val));
else
throw Err_.new_unhandled(type_tid);
}
@@ -70,7 +71,7 @@ class Kv_ary_utl {
if (itm_type_tid == Type_adp_.Tid__obj) {
if (Type_adp_.Eq(itm_type, KeyVal.class))
Ary_to_str__itm(wtr, indent + 1, (KeyVal)itm);
if (Type_adp_.Is_array(itm_type))
else if (Type_adp_.Is_array(itm_type))
Ary_to_str__ary_itms(wtr, indent + 1, Array_.cast(itm));
else
throw Err_.new_unhandled(itm_type);

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
public class Scrib_lib_text implements Scrib_lib {
private final Scrib_lib_text__json_util json_util = new Scrib_lib_text__json_util();
private final Scrib_lib_text__reindex_data reindex_data = new Scrib_lib_text__reindex_data();
public Scrib_lib_text(Scrib_core core) {this.core = core;} private Scrib_core core;
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
@@ -27,7 +28,7 @@ public class Scrib_lib_text implements Scrib_lib {
notify_wiki_changed_fnc = mod.Fncs_get_by_key("notify_wiki_changed");
return mod;
} private Scrib_lua_proc notify_wiki_changed_fnc;
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
public Scrib_proc_mgr Procs() {return procs;} private final Scrib_proc_mgr procs = new Scrib_proc_mgr();
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
switch (key) {
case Proc_unstrip: return Unstrip(args, rslt);
@@ -51,14 +52,55 @@ public class Scrib_lib_text implements Scrib_lib {
if (Html_entity_ == null) Html_entity_ = Scrib_lib_text_html_entities.new_();
return rslt.Init_obj(Html_entity_);
} private static KeyVal[] Html_entity_;
// public boolean JsonEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
// Object itm = args.Pull_obj(0);
// Class<?> itm_type = itm.getClass();
// KeyVal[] itm_as_kvy = null;
// Object itm_as_ary = null;
// if (Type_adp_.Eq(itm_type, typeof(KeyVal[]))) itm_as_kvy = (KeyVal[])itm;
// else if (Type_adp_.Is_array(itm_type)) itm_as_ary = Array_.cast(itm);
// int flags = args.Cast_int_or(1, 0);
// if (itm_as_kvy != null && !Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))
// itm_as_kvy = json_util.Reindex_arrays(itm_as_kvy, true);
// byte[] rv = null;
// if (itm_as_kvy != null)
// rv = json_util.Encode_as_nde(itm_as_kvy, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
// else if (itm_as_ary != null)
// rv = json_util.Encode_as_ary(itm_as_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);;
// if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
// return rslt.Init_obj(rv);
// }
public boolean JsonEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
KeyVal[] kv_ary = args.Pull_kv_ary(0);
Object itm = args.Pull_obj(0);
Class<?> itm_type = itm.getClass();
KeyVal[] itm_as_kvy = null;
Object itm_as_ary = null;
if (Type_adp_.Eq(itm_type, KeyVal[].class)) itm_as_kvy = (KeyVal[])itm;
else if (Type_adp_.Is_array(itm_type)) itm_as_ary = Array_.cast(itm);
int flags = args.Cast_int_or(1, 0);
if (!Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))
kv_ary = json_util.Reindex_arrays(kv_ary, true);
byte[] rv = json_util.Encode(kv_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
return rslt.Init_obj(rv);
synchronized (reindex_data) {
if ( itm_as_kvy != null
&& itm_as_kvy.length > 0
&& !Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys)
) {
json_util.Reindex_arrays(reindex_data, itm_as_kvy, true);
if (reindex_data.Rv_is_kvy()) {
itm_as_kvy = reindex_data.Rv_as_kvy();
itm_as_ary = null;
}
else {
itm_as_ary = reindex_data.Rv_as_ary();
itm_as_kvy = null;
}
}
byte[] rv = null;
if (itm_as_kvy != null)
rv = json_util.Encode_as_nde(itm_as_kvy, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
else
rv = json_util.Encode_as_ary(itm_as_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
return rslt.Init_obj(rv);
}
}
public boolean JsonDecode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] json = args.Pull_bry(0);
@@ -66,11 +108,19 @@ public class Scrib_lib_text implements Scrib_lib {
int opts = Scrib_lib_text__json_util.Opt__force_assoc;
if (Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__try_fixing))
opts = Enm_.Add_int(opts, Scrib_lib_text__json_util.Flag__try_fixing);
KeyVal[] rv = json_util.Decode(core.App().Utl__json_parser(), json, opts);
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
if (!(Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys)))
rv = json_util.Reindex_arrays(rv, false);
return rslt.Init_obj(rv);
synchronized (procs) {
byte rv_tid = json_util.Decode(core.App().Utl__json_parser(), json, opts);
if (rv_tid == Bool_.__byte) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
if (rv_tid == Bool_.Y_byte && !(Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))) {
KeyVal[] rv_as_kvy = (KeyVal[])json_util.Decode_rslt_as_nde();
synchronized (reindex_data) {
json_util.Reindex_arrays(reindex_data, rv_as_kvy, false);
return rslt.Init_obj(reindex_data.Rv_is_kvy() ? reindex_data.Rv_as_kvy() : reindex_data.Rv_as_ary());
}
}
else
return rslt.Init_obj(json_util.Decode_rslt_as_ary());
}
}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
public boolean Init_text_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
@@ -82,7 +132,6 @@ public class Scrib_lib_text implements Scrib_lib {
rv[3] = KeyVal_.new_("nowiki_protocols", KeyVal_.Ary_empty); // NOTE: code implemented, but waiting for it to be used; DATE:2014-03-20
return rslt.Init_obj(rv);
}
public void Init_for_tests() {json_util.Init_for_tests();}
private String Init_lib_text_get_msg(Xow_msg_mgr msg_mgr, String msg_key) {
return String_.new_u8(msg_mgr.Val_by_key_obj(Bry_.new_u8(msg_key)));
}

View File

@@ -19,11 +19,10 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
import gplx.core.json.*;
class Scrib_lib_text__json_util {
private final Json_wtr wtr = new Json_wtr();
public void Init_for_tests() {wtr.Opt_quote_byte_(Byte_ascii.Apos);}
public KeyVal[] Reindex_arrays(KeyVal[] kv_ary, boolean is_encoding) {
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, KeyVal[] kv_ary, boolean is_encoding) {
int next = 0;
if (is_encoding) {
// ksort( $arr, SORT_NUMERIC );
Array_.Sort(kv_ary, KeyVal__sorter__key_is_numeric.I);
next = 1;
}
boolean is_sequence = true;
@@ -31,56 +30,91 @@ class Scrib_lib_text__json_util {
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Object kv_val = kv.Val();
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), KeyVal[].class))
kv_val = Reindex_arrays((KeyVal[])kv_val, is_encoding);
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), KeyVal[].class)) {
Reindex_arrays(rv, (KeyVal[])kv_val, is_encoding);
if (!rv.Rv_is_kvy())
kv.Val_(rv.Rv_as_ary());
}
if (is_sequence) {
if (kv.Key_tid() == Type_adp_.Tid__int) {
int kv_key_as_int = Int_.cast(kv.Key_as_obj());
is_sequence = next++ == kv_key_as_int;
// } elseif ( $isEncoding && ctype_digit( $k ) ) {
// // json_decode currently doesn't return integer keys for {}
// $isSequence = $next++ === (int)$k;
} else {
is_sequence = false;
}
else {
int kv_key_to_int = Bry_.To_int_or__strict(Bry_.new_a7(kv.Key()), -1); // NOTE: a7 b/c proc is only checking for digits; none a7 bytes will be replaced by ?
if (is_encoding && kv_key_to_int != -1) {
is_sequence = next == kv_key_to_int;
++next;
}
else
is_sequence = false;
}
}
}
if (is_sequence) {
if (is_encoding) {
// return array_values( $arr );
Object rv_as_ary = To_array_values(kv_ary);
rv.Init(Bool_.N, null, rv_as_ary);
return;
} else {
// return $arr ? array_combine( range( 1, count( $arr ) ), $arr ) : $arr;
Convert_to_base1(kv_ary); // PHP: return $arr ? array_combine( range( 1, count( $arr ) ), $arr ) : $arr;
}
}
return kv_ary;
rv.Init(Bool_.Y, kv_ary, null);
}
public KeyVal[] Decode(Json_parser parser, byte[] src, int flag) {
Json_doc jdoc = parser.Parse(src);
Json_nde root = jdoc.Root_nde();
int len = root.Len();
KeyVal[] rv = new KeyVal[len];
private static Object[] To_array_values(KeyVal[] ary) {
int len = ary.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i) {
Json_kv json_kv = root.Get_at_as_kv(i);
String kv_str = json_kv.Key_as_str();
Object kv_val = Decode_obj(json_kv.Val());
rv[i] = KeyVal_.new_(kv_str, kv_val);
KeyVal itm = ary[i];
rv[i] = itm.Val();
}
return rv;
}
private static void Convert_to_base1(KeyVal[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
KeyVal itm = ary[i];
itm.Key_(i + 1);
}
}
public KeyVal[] Decode_rslt_as_nde() {return decode_rslt_as_nde;} private KeyVal[] decode_rslt_as_nde;
public Object Decode_rslt_as_ary() {return decode_rslt_as_ary;} private Object decode_rslt_as_ary;
public byte Decode(Json_parser parser, byte[] src, int flag) {
synchronized (wtr) {
Json_doc jdoc = parser.Parse(src);
if (jdoc.Root_grp().Tid() == Json_itm_.Tid__ary) {
this.decode_rslt_as_ary = Decode_ary(jdoc.Root_ary());
return Bool_.N_byte;
}
else {
Json_nde root = (Json_nde)jdoc.Root_grp();
int len = root.Len();
this.decode_rslt_as_nde = new KeyVal[len];
for (int i = 0; i < len; ++i) {
Json_kv json_kv = root.Get_at_as_kv(i);
String kv_str = json_kv.Key_as_str();
Object kv_val = Decode_obj(json_kv.Val());
decode_rslt_as_nde[i] = KeyVal_.new_(kv_str, kv_val);
}
return Bool_.Y_byte;
}
}
}
private Object Decode_obj(Json_itm itm) {
int itm_tid = itm.Tid();
switch (itm_tid) {
case Json_itm_.Tid__ary: return Decode_ary(Json_ary.cast(itm));
case Json_itm_.Tid__nde: return Decode_nde(Json_nde.cast(itm));
case Json_itm_.Tid__nde: return Decode_nde(Json_nde.cast(itm));
default: return itm.Data();
}
}
private Object Decode_ary(Json_ary ary) {
int len = ary.Len();
Object rv = Array_.Create(int.class, len);
Object rv = Array_.Create(Object.class, len);
for (int i = 0; i < len; ++i) {
Json_itm itm = ary.Get_at(i);
Array_.Set(rv, i, Decode_obj(itm));
Array_.Set_at(rv, i, Decode_obj(itm));
}
return rv;
}
@@ -93,11 +127,18 @@ class Scrib_lib_text__json_util {
}
return rv;
}
public byte[] Encode(KeyVal[] kv_ary, int flag, int skip) {
public byte[] Encode_as_nde(KeyVal[] itm, int flag, int skip) {
synchronized (wtr ) {
wtr.Clear().Doc_bgn();
Encode_kv_ary(kv_ary);
return wtr.Doc_end().To_bry_and_clear();
wtr.Clear().Doc_nde_bgn();
Encode_kv_ary(itm);
return wtr.Doc_nde_end().To_bry_and_clear();
}
}
public byte[] Encode_as_ary(Object ary, int flag, int skip) {
synchronized (wtr ) {
wtr.Clear().Doc_ary_bgn();
Encode_ary(ary);
return wtr.Doc_ary_end().To_bry_and_clear();
}
}
private void Encode_kv_ary(KeyVal[] kv_ary) {
@@ -117,10 +158,7 @@ class Scrib_lib_text__json_util {
}
else if (Type_adp_.Is_array(type)) { // encode as array
wtr.Ary_bgn(kv.Key());
Object ary = Array_.cast(kv_val);
int ary_len = Array_.Len(ary);
for (int j = 0; j < ary_len; ++j)
wtr.Ary_itm_obj(Array_.Get_at(ary, j));
Encode_ary(kv_val);
wtr.Ary_end();
}
else if (Type_adp_.Eq(type, Int_.Cls_ref_type)) wtr.Kv_int(kv.Key(), Int_.cast(kv_val));
@@ -129,9 +167,15 @@ class Scrib_lib_text__json_util {
else if (Type_adp_.Eq(type, Double_.Cls_ref_type)) wtr.Kv_double(kv.Key(), Double_.cast(kv_val));
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.cast(kv_val));
else wtr.Kv_str(kv.Key(), Object_.Xto_str_strict_or_null(kv_val));
}
}
private void Encode_ary(Object ary) {
int ary_len = Array_.Len(ary);
for (int j = 0; j < ary_len; ++j)
wtr.Ary_itm_obj(Array_.Get_at(ary, j));
}
public static final int
Flag__preserve_keys = 1
Flag__none = 0
, Flag__preserve_keys = 1
, Flag__try_fixing = 2
, Flag__pretty = 4
;
@@ -144,3 +188,23 @@ class Scrib_lib_text__json_util {
Opt__force_assoc = 1
;
}
class KeyVal__sorter__key_is_numeric implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
KeyVal lhs_itm = (KeyVal)lhsObj;
KeyVal rhs_itm = (KeyVal)rhsObj;
int lhs_int = Int_.parse_or(lhs_itm.Key(), Int_.Min_value);
int rhs_int = Int_.parse_or(rhs_itm.Key(), Int_.Min_value);
return CompareAble_.Compare(lhs_int, rhs_int);
}
public static final KeyVal__sorter__key_is_numeric I = new KeyVal__sorter__key_is_numeric(); KeyVal__sorter__key_is_numeric() {}
}
class Scrib_lib_text__reindex_data {
public boolean Rv_is_kvy() {return rv_is_kvy;} private boolean rv_is_kvy;
public KeyVal[] Rv_as_kvy() {return rv_as_kvy;} private KeyVal[] rv_as_kvy;
public Object Rv_as_ary() {return rv_as_ary;} private Object rv_as_ary;
public void Init(boolean rv_is_kvy, KeyVal[] rv_as_kvy, Object rv_as_ary) {
this.rv_is_kvy = rv_is_kvy;
this.rv_as_kvy = rv_as_kvy;
this.rv_as_ary = rv_as_ary;
}
}

View File

@@ -0,0 +1,239 @@
/*
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.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*; import gplx.core.json.*;
public class Scrib_lib_text_json_tst {
private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib_text lib;
private Scrib_lib_json_fxt json_fxt = new Scrib_lib_json_fxt();
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_text();
lib.Init();
}
@Test public void Nde__empty() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "{"
, "}"
)
, KeyVal_.Ary_empty
);
}
@Test public void Nde__key_obj__primitives() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "{ 'int':1"
, ", 'String':'abc'"
, ", 'true':true"
, ", 'array':"
, " [ 1"
, " , 2"
, " , 3"
, " ]"
, ", 'node':"
, " { 'key':'val'"
, " }"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("int", 1)
, KeyVal_.new_("String", "abc")
, KeyVal_.new_("true", true)
, KeyVal_.new_("array", new int[] {1, 2, 3})
, KeyVal_.new_("node", KeyVal_.Ary(KeyVal_.new_("key", "val")))
));
}
@Test public void Nde__obj_in_obj() {
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "{ 'x':"
, " [ 1"
, " , 2"
, " , { 'y':'x'"
, " }"
, " ]"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x", new Object[]
{ 1, 2, KeyVal_.Ary
( KeyVal_.new_("y", "x")
)
}
)
)
);
}
@Test public void Nde__ary_in_obj() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "{ 'x':"
, " [ 1"
, " , 2"
, " , { 'y':"
, " [ 3"
, " , 4"
, " ]"
, " }"
, " ]"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x"
, new Object[] {1, 2, KeyVal_.Ary
( KeyVal_.new_("y"
, new Object[] {3, 4}
))}))
);
}
@Test public void Nde__key_int__mixed() {// NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "{ 'x':'x'"
, ", '1':1"
, ", '2':2"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x", "x")
, KeyVal_.new_("1", 1)
, KeyVal_.new_("2", 2)
));
}
@Test public void Nde__key_int__auto() {// NOTE: based on MW
json_fxt.Test_json_encode(fxt, lib
, Scrib_lib_text__json_util.Flag__preserve_keys
, Kv_ary_utl.new_(Bool_.Y, new Object[]
{ 1
, "abc"
, true
, false
})
, Json_doc.Make_str_by_apos // NOTE: numbering is done by Kv_ary_utl, not Reindex_arrays
( "{ '1':1"
, ", '2':'abc'"
, ", '3':true"
, ", '4':false"
, "}"
)
);
json_fxt.Test_json_decode(fxt, lib
, Scrib_lib_text__json_util.Flag__preserve_keys
, Json_doc.Make_str_by_apos
( "[ 1"
, ", 'abc'"
, ", true"
, ", false"
, "]"
)
, new Object[]
{ 1
, "abc"
, true
, false
}
);
}
@Test public void Ary__empty() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "["
, "]"
)
, Object_.Ary_empty
);
}
@Test public void Ary__obj() { // NOTE: based on MW
json_fxt.Test_json_encode(fxt, lib, Scrib_lib_text__json_util.Flag__none
, Kv_ary_utl.new_(Bool_.Y, 1, "abc", true)
, Json_doc.Make_str_by_apos
( "[ 1"
, ", 'abc'"
, ", true"
, "]"
)
);
}
@Test public void Ary__nested() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "[ 1"
, ", 2"
, ", 3"
, ", "
, " [ 4"
, " , 5"
, " , "
, " [ 6"
, " , 7"
, " , 8"
, " ]"
, " , 9"
, " ]"
, "]"
)
, new Object[] {1, 2, 3, new Object[] {4, 5, new Object[] {6, 7, 8}, 9}}
);
}
@Test public void Nde__smoke() {
json_fxt.Test_json_encode(fxt, lib
, Scrib_lib_text__json_util.Flag__none
, KeyVal_.Ary
( KeyVal_.new_("axes", KeyVal_.Ary
( KeyVal_.int_(1, KeyVal_.Ary
( KeyVal_.new_("type", "x")
))
, KeyVal_.int_(2, KeyVal_.Ary
( KeyVal_.new_("type", "y")
))
))
)
, Json_doc.Make_str_by_apos
( "{ 'axes':"
, " ["
, " { 'type':'x'"
, " }"
, " , { 'type':'y'"
, " }"
, " ]"
, "}"
)
);
}
}
class Scrib_lib_json_fxt {
private final Json_wtr wtr = new Json_wtr();
public void Test_json_roundtrip(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, String json, Object obj) {
Test_json_decode(fxt, lib, Scrib_lib_text__json_util.Flag__none, json, obj);
Test_json_encode(fxt, lib, Scrib_lib_text__json_util.Flag__none, obj, json);
}
public void Test_json_decode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, int flag, String raw, Object expd) {
Object actl = fxt.Test_scrib_proc_rv_as_obj(lib, Scrib_lib_text.Invk_jsonDecode, Object_.Ary(raw, flag));
Tfds.Eq_str_lines(To_str(expd), To_str(actl), raw);
}
public void Test_json_encode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, int flag, Object raw, String expd) {
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_text.Invk_jsonEncode, Object_.Ary(raw, flag), "1=" + String_.Replace(expd, "'", "\""));
}
private String To_str(Object o) {
if (o == null) return "<< NULL >>";
Class<?> type = o.getClass();
if (Type_adp_.Eq(type, KeyVal[].class)) return Kv_ary_utl.Ary_to_str(wtr, (KeyVal[])o);
else if (Type_adp_.Is_array(type)) return Array_.To_str_nested_obj(o);
else return Object_.Xto_str_strict_or_null(o);
}
}

View File

@@ -19,12 +19,10 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
import org.junit.*; import gplx.core.json.*;
public class Scrib_lib_text_tst {
private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib_text lib;
private Scrib_lib_json_fxt json_fxt = new Scrib_lib_json_fxt();
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_text();
lib.Init();
lib.Init_for_tests();
}
@Test public void Unstrip() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_text.Invk_unstrip, Object_.Ary("a"), "a");
@@ -33,106 +31,4 @@ public class Scrib_lib_text_tst {
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
Tfds.Eq(1510, actl.length); // large result; only test # of entries
}
@Test public void JsonEncode() {
json_fxt.Test_json_encode(fxt, lib, Kv_ary_utl.new_
( true
, true
, 1
, "a"
, new int[] {1, 2, 3}
, Kv_ary_utl.new_(true, "b")
), String_.Concat_lines_nl_skip_last
( "1="
+ "{ '1':true"
, ", '2':1"
, ", '3':'a'"
, ", '4':"
, " [ 1"
, " , 2"
, " , 3"
, " ]"
, ", '5':"
, " { '1':'b'"
, " }"
, "}"
));
}
@Test public void JsonDecode() {
json_fxt.Test_json_decode(fxt, lib
, String_.Concat_lines_nl_skip_last
( "{ '1':true"
, ", '2':1"
, ", '3':'a'"
, ", '4':"
, " [ 1"
, " , 2"
, " , 3"
, " ]"
, ", '5':"
, " { '1':'b'"
, " }"
, "}"
)
, Kv_ary_utl.new_
( true
, true
, 1
, "a"
, new int[] {1, 2, 3}
, Kv_ary_utl.new_(true, "b")
));
}
@Test public void JsonDecode__primitives() {
json_fxt.Test_json_decode(fxt, lib
, String_.Concat_lines_nl_skip_last
( "{ 'int':1"
, ", 'String':'abc'"
, ", 'true':true"
, "}"
)
, Kv_ary_utl.new_kvs
( KeyVal_.new_("int", 1)
, KeyVal_.new_("String", "abc")
, KeyVal_.new_("true", true)
));
}
@Test public void JsonDecode__numeric_keys() {
json_fxt.Test_json_decode(fxt, lib
, String_.Concat_lines_nl_skip_last
( "{ 'x':'x'"
, ", '1':1"
, ", '2':2"
, "}"
)
, Kv_ary_utl.new_kvs
( KeyVal_.new_("x", "x")
, KeyVal_.new_("1", 1)
, KeyVal_.new_("2", 2)
));
}
// @Test public void JsonDecode__array() {
// json_fxt.Test_json_decode(fxt, lib
// , String_.Concat_lines_nl_skip_last
// ( "[ 1"
// , ", 2"
// , ", 3"
// , "]"
// )
// , Kv_ary_utl.new_kvs
// ( KeyVal_.new_("int", 1)
// , KeyVal_.new_("String", "abc")
// , KeyVal_.new_("true", true)
// ));
// }
}
class Scrib_lib_json_fxt {
private final Json_wtr wtr = new Json_wtr().Opt_quote_byte_(Byte_ascii.Apos);
public void Test_json_decode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, String raw, KeyVal[] expd) {
raw = String_.Replace(raw, "'", "\"");
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_jsonDecode, Object_.Ary(raw));
Tfds.Eq_str_lines(Kv_ary_utl.Ary_to_str(wtr, expd), Kv_ary_utl.Ary_to_str(wtr, actl), raw);
}
public void Test_json_encode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, KeyVal[] raw, String expd) {
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_text.Invk_jsonEncode, Object_.Ary((Object)raw), expd);
}
}