mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Fix if_exists (restore)
This commit is contained in:
22
400_xowa/src/gplx/langs/dsvs/Dsv_fld_parser.java
Normal file
22
400_xowa/src/gplx/langs/dsvs/Dsv_fld_parser.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public interface Dsv_fld_parser {
|
||||
void Init(byte fld_dlm, byte row_dlm);
|
||||
int Parse(Dsv_tbl_parser tbl_parser, Dsv_wkr_base mgr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn);
|
||||
}
|
||||
114
400_xowa/src/gplx/langs/dsvs/Dsv_fld_parser_.java
Normal file
114
400_xowa/src/gplx/langs/dsvs/Dsv_fld_parser_.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
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.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public class Dsv_fld_parser_ {
|
||||
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry.Instance;
|
||||
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int.Instance;
|
||||
public static final Dsv_fld_parser Line_parser__comment_is_pipe = new Dsv_fld_parser_line(Byte_ascii.Pipe);
|
||||
public static Err err_fld_unhandled(Dsv_fld_parser parser, Dsv_wkr_base wkr, int fld_idx, byte[] src, int bgn, int end) {
|
||||
throw Err_.new_wo_type("fld unhandled", "parser", Type_adp_.NameOf_obj(parser), "wkr", Type_adp_.NameOf_obj(wkr), "fld_idx", fld_idx, "val", String_.new_u8(src, bgn, end)).Trace_ignore_add_1_();
|
||||
}
|
||||
}
|
||||
class Dsv_fld_parser_line implements Dsv_fld_parser {
|
||||
private byte row_dlm = Byte_ascii.Nl; private final byte comment_dlm;
|
||||
public Dsv_fld_parser_line(byte comment_dlm) {this.comment_dlm = comment_dlm;}
|
||||
public void Init(byte fld_dlm, byte row_dlm) {
|
||||
this.row_dlm = row_dlm;
|
||||
}
|
||||
public int Parse(Dsv_tbl_parser parser, Dsv_wkr_base wkr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn) {
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_len;
|
||||
byte b = pos_is_last ? row_dlm : src[pos];
|
||||
if (b == comment_dlm) {
|
||||
pos = Bry_find_.Find_fwd_until(src, pos, src_len, row_dlm);
|
||||
if (pos == Bry_find_.Not_found)
|
||||
pos = src_len;
|
||||
}
|
||||
else if (b == row_dlm) {
|
||||
boolean pass = wkr.Write_bry(parser, fld_idx, src, fld_bgn, pos);
|
||||
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
|
||||
wkr.Commit_itm(parser, pos);
|
||||
int rv = pos + 1; // row_dlm is always 1 byte
|
||||
parser.Update_by_row(rv);
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
class Dsv_fld_parser_bry implements Dsv_fld_parser {
|
||||
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
|
||||
public void Init(byte fld_dlm, byte row_dlm) {
|
||||
this.fld_dlm = fld_dlm; this.row_dlm = row_dlm;
|
||||
}
|
||||
public int Parse(Dsv_tbl_parser parser, Dsv_wkr_base wkr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn) {
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_len;
|
||||
byte b = pos_is_last ? row_dlm : src[pos];
|
||||
if (b == fld_dlm) {
|
||||
boolean pass = wkr.Write_bry(parser, fld_idx, src, fld_bgn, pos);
|
||||
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
|
||||
int rv = pos + 1; // fld_dlm is always 1 byte
|
||||
parser.Update_by_fld(rv);
|
||||
return rv;
|
||||
}
|
||||
else if (b == row_dlm) {
|
||||
boolean pass = wkr.Write_bry(parser, fld_idx, src, fld_bgn, pos);
|
||||
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
|
||||
wkr.Commit_itm(parser, pos);
|
||||
int rv = pos + 1; // row_dlm is always 1 byte
|
||||
parser.Update_by_row(rv);
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
public static final Dsv_fld_parser_bry Instance = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
|
||||
}
|
||||
class Dsv_fld_parser_int implements Dsv_fld_parser {
|
||||
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
|
||||
public void Init(byte fld_dlm, byte row_dlm) {
|
||||
this.fld_dlm = fld_dlm; this.row_dlm = row_dlm;
|
||||
}
|
||||
public int Parse(Dsv_tbl_parser parser, Dsv_wkr_base wkr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn) {
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_len;
|
||||
byte b = pos_is_last ? row_dlm : src[pos];
|
||||
if (b == fld_dlm) {
|
||||
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.To_int_or(src, fld_bgn, pos, -1));
|
||||
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
|
||||
int rv = pos + 1; // fld_dlm is always 1 byte
|
||||
parser.Update_by_fld(rv);
|
||||
return rv;
|
||||
}
|
||||
else if (b == row_dlm) {
|
||||
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.To_int_or(src, fld_bgn, pos, -1));
|
||||
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
|
||||
wkr.Commit_itm(parser, pos);
|
||||
int rv = pos + 1; // row_dlm is always 1 byte
|
||||
parser.Update_by_row(rv);
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
public static final Dsv_fld_parser_int Instance = new Dsv_fld_parser_int(); Dsv_fld_parser_int() {}
|
||||
}
|
||||
83
400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser.java
Normal file
83
400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public class Dsv_tbl_parser implements Gfo_invk, Rls_able {
|
||||
private Dsv_wkr_base mgr;
|
||||
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2]; private int fld_parsers_len = 2;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Fld_bgn() {return fld_bgn;} private int fld_bgn = 0;
|
||||
public int Fld_idx() {return fld_idx;} private int fld_idx = 0;
|
||||
public int Row_bgn() {return row_bgn;} private int row_bgn = 0;
|
||||
public int Row_idx() {return row_idx;} private int row_idx = 0;
|
||||
public boolean Skip_blank_lines() {return skip_blank_lines;} public Dsv_tbl_parser Skip_blank_lines_(boolean v) {skip_blank_lines = v; return this;} private boolean skip_blank_lines = true;
|
||||
public byte Fld_dlm() {return fld_dlm;} public Dsv_tbl_parser Fld_dlm_(byte v) {fld_dlm = v; return this;} private byte fld_dlm = Byte_ascii.Pipe;
|
||||
public byte Row_dlm() {return row_dlm;} public Dsv_tbl_parser Row_dlm_(byte v) {row_dlm = v; return this;} private byte row_dlm = Byte_ascii.Nl;
|
||||
public void Init(Dsv_wkr_base mgr, Dsv_fld_parser... fld_parsers) {
|
||||
this.mgr = mgr;
|
||||
this.fld_parsers = fld_parsers;
|
||||
this.fld_parsers_len = fld_parsers.length;
|
||||
for (int i = 0; i < fld_parsers_len; i++)
|
||||
fld_parsers[i].Init(fld_dlm, row_dlm);
|
||||
}
|
||||
public void Clear() {
|
||||
fld_bgn = fld_idx = row_bgn = row_idx = 0;
|
||||
}
|
||||
public Err Err_row_bgn(String fmt, int pos) {
|
||||
return Err_.new_wo_type(fmt, "line", String_.new_u8(src, row_bgn, pos)).Trace_ignore_add_1_();
|
||||
}
|
||||
public void Update_by_fld(int pos) {
|
||||
fld_bgn = pos;
|
||||
++fld_idx;
|
||||
}
|
||||
public void Update_by_row(int pos) {
|
||||
row_bgn = fld_bgn = pos;
|
||||
++row_idx;
|
||||
fld_idx = 0;
|
||||
}
|
||||
public void Parse(byte[] src) {
|
||||
int src_len = src.length; if (src_len == 0) return; // NOTE: do not process if empty; note that loop below will process once for empty row
|
||||
this.src = src;
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
if (fld_idx == 0 && skip_blank_lines) { // row committed; skip blank lines
|
||||
while (pos < src_len) {
|
||||
if (src[pos] == row_dlm) {
|
||||
++pos;
|
||||
row_bgn = fld_bgn = pos;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fld_idx == fld_parsers_len) break;
|
||||
Dsv_fld_parser fld_parser = fld_parsers[fld_idx];
|
||||
pos = fld_parser.Parse(this, mgr, src, pos, src_len, fld_idx, fld_bgn);
|
||||
if ( pos > src_len // pos is now fully past src_len; exit
|
||||
|| pos == src_len && fld_idx == 0 // last pos but fld_idx > 0; do one more iteration which will "commit row; EX: 2 fields and src of "a|"; EOS should close out row
|
||||
) break;
|
||||
}
|
||||
}
|
||||
public void Rls() {
|
||||
src = null; fld_parsers = null; mgr = null; fld_parsers_len = 0;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_load_by_str)) Parse(m.ReadBry("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_load_by_str = "load_by_str";
|
||||
}
|
||||
64
400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_int_tst.java
Normal file
64
400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_int_tst.java
Normal 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.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Dsv_tbl_parser_int_tst {
|
||||
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt .Test_load(String_.Concat_lines_nl_skip_last
|
||||
( "a|1|3"
|
||||
, "b|2|4"
|
||||
)
|
||||
, fxt.mgr_int_()
|
||||
, fxt.itm_int_("a", 1, 3)
|
||||
, fxt.itm_int_("b", 2, 4)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Mok_int_itm implements To_str_able {
|
||||
private String fld_0;
|
||||
private int fld_1, fld_2;
|
||||
public Mok_int_itm(String fld_0, int fld_1, int fld_2) {this.fld_0 = fld_0; this.fld_1 = fld_1; this.fld_2 = fld_2;}
|
||||
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.To_str(fld_1), Int_.To_str(fld_2));}
|
||||
}
|
||||
class Mok_int_mgr extends Mok_mgr_base {
|
||||
public void Clear() {itms.Clear();}
|
||||
@Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New();
|
||||
private String fld_0;
|
||||
private int fld_1, fld_2;
|
||||
@Override public Dsv_fld_parser[] Fld_parsers() {
|
||||
return new Dsv_fld_parser[] {Dsv_fld_parser_bry.Instance, Dsv_fld_parser_int.Instance, Dsv_fld_parser_int.Instance};
|
||||
}
|
||||
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
|
||||
switch (fld_idx) {
|
||||
case 0: fld_0 = String_.new_u8(src, bgn, end); return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@Override public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {
|
||||
switch (fld_idx) {
|
||||
case 1: fld_1 = val_int; return true;
|
||||
case 2: fld_2 = val_int; return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
|
||||
Mok_int_itm itm = new Mok_int_itm(fld_0, fld_1, fld_2);
|
||||
itms.Add(itm);
|
||||
}
|
||||
}
|
||||
109
400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_str_tst.java
Normal file
109
400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_str_tst.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
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.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Dsv_tbl_parser_str_tst {
|
||||
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt .Test_load(String_.Concat_lines_nl_skip_last
|
||||
( "a|A"
|
||||
, "b|B"
|
||||
)
|
||||
, fxt.mgr_str_(2)
|
||||
, fxt.itm_str_("a", "A")
|
||||
, fxt.itm_str_("b", "B")
|
||||
);
|
||||
}
|
||||
@Test public void Blank_lines() {
|
||||
fxt .Test_load(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "a|A"
|
||||
, ""
|
||||
, "b|B"
|
||||
, ""
|
||||
)
|
||||
, fxt.mgr_str_(2)
|
||||
, fxt.itm_str_("a", "A")
|
||||
, fxt.itm_str_("b", "B")
|
||||
);
|
||||
}
|
||||
@Test public void Incomplete_row() {
|
||||
fxt .Test_load(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "b"
|
||||
, ""
|
||||
)
|
||||
, fxt.mgr_str_(2)
|
||||
, fxt.itm_str_("a")
|
||||
, fxt.itm_str_("b")
|
||||
);
|
||||
}
|
||||
@Test public void Incomplete_row_2() { // PURPOSE: handle multiple incomplete cells
|
||||
fxt .Test_load(String_.Concat_lines_nl_skip_last
|
||||
( "a|")
|
||||
, fxt.mgr_str_(3)
|
||||
, fxt.itm_str_("a", "")
|
||||
);
|
||||
}
|
||||
}
|
||||
abstract class Mok_mgr_base extends Dsv_wkr_base {
|
||||
public abstract To_str_able[] Itms();
|
||||
}
|
||||
class Dsv_mok_fxt {
|
||||
private Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser();
|
||||
public Dsv_mok_fxt Clear() {
|
||||
tbl_parser.Clear();
|
||||
return this;
|
||||
}
|
||||
public Mok_mgr_base mgr_int_() {return new Mok_int_mgr();}
|
||||
public Mok_mgr_base mgr_str_(int len) {return new Mok_str_mgr(len);}
|
||||
public Mok_str_itm itm_str_(String... flds) {return new Mok_str_itm(flds);}
|
||||
public Mok_int_itm itm_int_(String fld_0, int fld_1, int fld_2) {return new Mok_int_itm(fld_0, fld_1, fld_2);}
|
||||
public void Test_load(String src, Mok_mgr_base mgr, To_str_able... expd) {
|
||||
mgr.Load_by_bry(Bry_.new_u8(src));
|
||||
Tfds.Eq_ary_str(expd, mgr.Itms());
|
||||
}
|
||||
}
|
||||
class Mok_str_itm implements To_str_able {
|
||||
private String[] flds;
|
||||
public Mok_str_itm(String[] flds) {this.flds = flds;}
|
||||
public String To_str() {return String_.Concat_with_str("|", flds);}
|
||||
}
|
||||
class Mok_str_mgr extends Mok_mgr_base {
|
||||
private int flds_len;
|
||||
public Mok_str_mgr(int flds_len) {
|
||||
this.flds_len = flds_len;
|
||||
}
|
||||
public void Clear() {itms.Clear();}
|
||||
@Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New();
|
||||
private List_adp flds = List_adp_.New();
|
||||
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
|
||||
flds.Add(String_.new_u8(src, bgn, end));
|
||||
return true;
|
||||
}
|
||||
@Override public Dsv_fld_parser[] Fld_parsers() {
|
||||
Dsv_fld_parser[] rv = new Dsv_fld_parser[flds_len];
|
||||
for (int i = 0; i < flds_len; i++)
|
||||
rv[i] = Dsv_fld_parser_.Bry_parser;
|
||||
return rv;
|
||||
}
|
||||
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
|
||||
Mok_str_itm itm = new Mok_str_itm((String[])flds.To_ary_and_clear(String.class));
|
||||
itms.Add(itm);
|
||||
}
|
||||
}
|
||||
42
400_xowa/src/gplx/langs/dsvs/Dsv_wkr_base.java
Normal file
42
400_xowa/src/gplx/langs/dsvs/Dsv_wkr_base.java
Normal 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.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public abstract class Dsv_wkr_base implements Gfo_invk {
|
||||
public abstract Dsv_fld_parser[] Fld_parsers();
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public abstract void Commit_itm(Dsv_tbl_parser parser, int pos);
|
||||
@gplx.Virtual public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {return false;}
|
||||
@gplx.Virtual public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {return false;}
|
||||
public void Load_by_bry(byte[] src) {
|
||||
this.src = src;
|
||||
Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser(); // NOTE: this proc should only be called once, so don't bother caching tbl_parser
|
||||
tbl_parser.Init(this, this.Fld_parsers());
|
||||
Load_by_bry_bgn();
|
||||
tbl_parser.Parse(src);
|
||||
tbl_parser.Rls();
|
||||
Load_by_bry_end();
|
||||
}
|
||||
@gplx.Virtual public void Load_by_bry_bgn() {}
|
||||
@gplx.Virtual public void Load_by_bry_end() {}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_load_by_str)) Load_by_bry(m.ReadBry("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_load_by_str = "load_by_str";
|
||||
}
|
||||
214
400_xowa/src/gplx/langs/gfs/Gfs_lxr.java
Normal file
214
400_xowa/src/gplx/langs/gfs/Gfs_lxr.java
Normal file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
interface Gfs_lxr {
|
||||
int Lxr_tid();
|
||||
int Process(Gfs_parser_ctx ctx, int bgn, int end);
|
||||
}
|
||||
class Gfs_lxr_whitespace implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_whitespace;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int rv = Gfs_lxr_.Rv_eos, cur_pos;
|
||||
for (cur_pos = end; cur_pos < src_len; cur_pos++) {
|
||||
byte b = src[cur_pos];
|
||||
Object o = ctx.Trie().Match_at_w_b0(ctx.Trie_rv(), b, src, cur_pos, src_len);
|
||||
if (o == null) {
|
||||
rv = Gfs_lxr_.Rv_null;
|
||||
ctx.Process_null(cur_pos);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
Gfs_lxr lxr = (Gfs_lxr)o;
|
||||
if (lxr.Lxr_tid() == Gfs_lxr_.Tid_whitespace) {}
|
||||
else {
|
||||
rv = Gfs_lxr_.Rv_lxr;
|
||||
ctx.Process_lxr(cur_pos, lxr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final Gfs_lxr_whitespace Instance = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
|
||||
}
|
||||
class Gfs_lxr_comment_flat implements Gfs_lxr {
|
||||
public Gfs_lxr_comment_flat(byte[] bgn_bry, byte[] end_bry) {
|
||||
this.bgn_bry = bgn_bry; this.bgn_bry_len = bgn_bry.length;
|
||||
this.end_bry = end_bry; this.end_bry_len = end_bry.length;
|
||||
} byte[] bgn_bry, end_bry; int bgn_bry_len, end_bry_len;
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_comment;}
|
||||
public int Process(Gfs_parser_ctx ctx, int lxr_bgn, int lxr_end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int end_pos = Bry_find_.Find_fwd(src, end_bry, lxr_end, src_len);
|
||||
// if (end_pos == Bry_find_.Not_found) throw Err_.new_fmt_("comment is not closed: {0}", String_.new_u8(end_bry));
|
||||
return (end_pos == Bry_find_.Not_found)
|
||||
? src_len // allow eos to terminate flat comment; needed for "tidy-always-adds-nl-in-textarea" fix; NOTE: DATE:2014-06-21
|
||||
: end_pos + end_bry_len; // position after end_bry
|
||||
}
|
||||
}
|
||||
class Gfs_lxr_identifier implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_identifier;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int pos, rv = Gfs_lxr_.Rv_eos;
|
||||
for (pos = end; pos < src_len; pos++) {
|
||||
byte b = src[pos];
|
||||
Object o = ctx.Trie().Match_at_w_b0(ctx.Trie_rv(), b, src, pos, src_len);
|
||||
if (o == null) { // invalid char; stop;
|
||||
rv = Gfs_lxr_.Rv_null;
|
||||
ctx.Process_null(pos);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
Gfs_lxr lxr = (Gfs_lxr)o;
|
||||
if (lxr.Lxr_tid() == Gfs_lxr_.Tid_identifier) {} // still an identifier; continue
|
||||
else { // new lxr (EX: "." in "abc."); (a) hold word of "abc"; mark "." as new lxr;
|
||||
ctx.Hold_word(bgn, pos);
|
||||
rv = Gfs_lxr_.Rv_lxr;
|
||||
ctx.Process_lxr(pos, lxr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rv == Gfs_lxr_.Rv_eos) ctx.Process_eos(); // eos
|
||||
return rv;
|
||||
}
|
||||
public static final Gfs_lxr_identifier Instance = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
|
||||
}
|
||||
class Gfs_lxr_semic implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_semic;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); ctx.Cur_nde_from_stack(); break; // a;
|
||||
case Gfs_lxr_.Tid_quote:
|
||||
case Gfs_lxr_.Tid_paren_end: ctx.Cur_nde_from_stack(); break; // a();
|
||||
case Gfs_lxr_.Tid_semic: break; // a;; ignore;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Semic); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_semic Instance = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
|
||||
}
|
||||
class Gfs_lxr_dot implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_dot;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); break; // a.
|
||||
case Gfs_lxr_.Tid_paren_end: break; // a().
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Dot); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_dot Instance = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
|
||||
}
|
||||
class Gfs_lxr_paren_bgn implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_bgn;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); break; // a(;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Paren_bgn); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_paren_bgn Instance = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
|
||||
}
|
||||
class Gfs_lxr_paren_end implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_end;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_paren_bgn:
|
||||
case Gfs_lxr_.Tid_quote: break; // "))", "abc)", "'abc')"
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_atr_by_idf(); break; // 123)
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Paren_end); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_paren_end Instance = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
|
||||
}
|
||||
class Gfs_lxr_quote implements Gfs_lxr {
|
||||
public Gfs_lxr_quote(byte[] bgn_bry, byte[] end_bry) {
|
||||
this.bgn_bry_len = bgn_bry.length;
|
||||
this.end_bry = end_bry; this.end_bry_len = end_bry.length;
|
||||
} private byte[] end_bry; private int bgn_bry_len, end_bry_len;
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_quote;}
|
||||
public int Process(Gfs_parser_ctx ctx, int lxr_bgn, int lxr_end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int end_pos = Bry_find_.Find_fwd(src, end_bry, lxr_end, src_len);
|
||||
if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("quote is not closed", "end", String_.new_u8(end_bry));
|
||||
Bry_bfr bfr = ctx.Tmp_bfr().Clear();
|
||||
int prv_pos = lxr_end;
|
||||
int nxt_pos = end_pos + end_bry_len;
|
||||
if (Bry_.Match(src, nxt_pos, nxt_pos + end_bry_len, end_bry)) { // end_bry is doubled; EX: end_bry = ' and raw = a''
|
||||
while (true) {
|
||||
bfr.Add_mid(src, prv_pos, end_pos); // add everything up to end_bry
|
||||
bfr.Add(end_bry); // add end_bry
|
||||
prv_pos = nxt_pos + end_bry_len; // set prv_pos to after doubled end_bry
|
||||
end_pos = Bry_find_.Find_fwd(src, end_bry, prv_pos, src_len);
|
||||
if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("quote is not closed", "end", String_.new_u8(end_bry));
|
||||
nxt_pos = end_pos + end_bry_len;
|
||||
if (!Bry_.Match(src, nxt_pos, nxt_pos + end_bry_len, end_bry)) {
|
||||
bfr.Add_mid(src, prv_pos, end_pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ctx.Make_atr_by_bry(lxr_bgn + bgn_bry_len, end_pos, bfr.To_bry_and_clear());
|
||||
}
|
||||
else
|
||||
ctx.Make_atr(lxr_bgn + bgn_bry_len, end_pos);
|
||||
return end_pos + end_bry_len; // position after quote
|
||||
}
|
||||
}
|
||||
class Gfs_lxr_curly_bgn implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_bgn;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); ctx.Stack_add(); break; // a{;
|
||||
case Gfs_lxr_.Tid_paren_end: ctx.Stack_add(); break; // a(){; NOTE: node exists but needs to be pushed onto stack
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Curly_bgn); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_curly_bgn Instance = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
|
||||
}
|
||||
class Gfs_lxr_curly_end implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_end;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
ctx.Stack_pop(bgn);
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_curly_end Instance = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
|
||||
}
|
||||
class Gfs_lxr_equal implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_eq;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
ctx.Make_nde(bgn, end).Op_tid_(Gfs_nde.Op_tid_assign);
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_equal Instance = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
|
||||
}
|
||||
class Gfs_lxr_comma implements Gfs_lxr {
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_comma;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_atr_by_idf(); break; // 123,
|
||||
}
|
||||
return end;
|
||||
}
|
||||
public static final Gfs_lxr_comma Instance = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
|
||||
}
|
||||
39
400_xowa/src/gplx/langs/gfs/Gfs_lxr_.java
Normal file
39
400_xowa/src/gplx/langs/gfs/Gfs_lxr_.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
class Gfs_lxr_ {
|
||||
public static final int Rv_init = -1, Rv_null = -2, Rv_eos = -3, Rv_lxr = -4;
|
||||
public static final int Tid_identifier = 1, Tid_dot = 2, Tid_semic = 3, Tid_paren_bgn = 4, Tid_paren_end = 5, Tid_curly_bgn = 6, Tid_curly_end = 7, Tid_quote = 8, Tid_comma = 9, Tid_whitespace = 10, Tid_comment = 11, Tid_eq = 12;
|
||||
public static String Tid__name(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_identifier: return "identifier";
|
||||
case Tid_dot: return "dot";
|
||||
case Tid_semic: return "semic";
|
||||
case Tid_paren_bgn: return "paren_bgn";
|
||||
case Tid_paren_end: return "paren_end";
|
||||
case Tid_curly_bgn: return "curly_bgn";
|
||||
case Tid_curly_end: return "curly_end";
|
||||
case Tid_quote: return "quote";
|
||||
case Tid_comma: return "comma";
|
||||
case Tid_whitespace: return "whitespace";
|
||||
case Tid_comment: return "comment";
|
||||
case Tid_eq: return "eq";
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr.java
Normal file
53
400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.gfo_regys.*;
|
||||
public class Gfs_msg_bldr implements GfoMsgParser {
|
||||
private final Object thread_lock = new Object();
|
||||
private final Gfs_parser parser = new Gfs_parser();
|
||||
public GfoMsg ParseToMsg(String s) {return Bld(s);}
|
||||
public GfoMsg Bld(String src) {return Bld(Bry_.new_u8(src));}
|
||||
public GfoMsg Bld(byte[] src) {
|
||||
synchronized (thread_lock) { // LOCK:Gfs_parser called when converting messages in Xow_msg_mgr; DATE:2016-10-18
|
||||
Gfs_nde nde = parser.Parse(src);
|
||||
return Bld_msg(src, nde);
|
||||
}
|
||||
}
|
||||
private GfoMsg Bld_msg(byte[] src, Gfs_nde nde) {
|
||||
boolean op_is_assign = (nde.Op_tid() == Gfs_nde.Op_tid_assign);
|
||||
String name = String_.new_u8(nde.Name_bry(src));
|
||||
if (op_is_assign) name += Tkn_mutator;
|
||||
GfoMsg rv = GfoMsg_.new_parse_(name);
|
||||
int len = nde.Atrs_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfs_nde atr = nde.Atrs_get_at(i);
|
||||
rv.Add("", String_.new_u8(atr.Name_bry(src)));
|
||||
}
|
||||
len = nde.Subs_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfs_nde sub = nde.Subs_get_at(i);
|
||||
if (op_is_assign) // NOTE: for now (a) assignss cannot be nested; EX: "a.b = c;" is okay but "a.b = c.d;" is not
|
||||
rv.Add("", Bld_msg(src, sub).Key());
|
||||
else
|
||||
rv.Subs_add(Bld_msg(src, sub));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final Gfs_msg_bldr Instance = new Gfs_msg_bldr(); Gfs_msg_bldr() {} // TS.static
|
||||
public static final String Tkn_mutator = "_";
|
||||
}
|
||||
76
400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr_tst.java
Normal file
76
400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr_tst.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
public class Gfs_msg_bldr_tst {
|
||||
@Before public void init() {fxt.Clear();} Gfs_msg_bldr_fxt fxt = new Gfs_msg_bldr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_build("a;", fxt.msg_("a"));
|
||||
}
|
||||
@Test public void Dot() {
|
||||
fxt.Test_build("a.b.c;"
|
||||
, fxt.msg_("a").Subs_
|
||||
( fxt.msg_("b").Subs_
|
||||
( fxt.msg_("c")
|
||||
)));
|
||||
}
|
||||
@Test public void Args() {
|
||||
fxt.Test_build("a('b', 'c');", fxt.msg_("a", fxt.kv_("", "b"), fxt.kv_("", "c")));
|
||||
}
|
||||
@Test public void Args_num() {
|
||||
fxt.Test_build("a(1);", fxt.msg_("a", fxt.kv_("", "1")));
|
||||
}
|
||||
@Test public void Assign() {
|
||||
fxt.Test_build("a = 'b';", fxt.msg_("a_", fxt.kv_("", "b")));
|
||||
}
|
||||
@Test public void Assign_num() {
|
||||
fxt.Test_build("a = 1;", fxt.msg_("a_", fxt.kv_("", "1")));
|
||||
}
|
||||
}
|
||||
class Gfs_msg_bldr_fxt {
|
||||
public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr.Instance;
|
||||
public Keyval kv_(String key, String val) {return Keyval_.new_(key, val);}
|
||||
public GfoMsg msg_(String key, Keyval... args) {
|
||||
GfoMsg rv = GfoMsg_.new_parse_(key);
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval kv = args[i];
|
||||
rv.Add(kv.Key(), kv.Val());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Test_build(String raw, GfoMsg... expd) {
|
||||
GfoMsg root = msg_bldr.Bld(raw);
|
||||
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(To_ary(root)));
|
||||
}
|
||||
GfoMsg[] To_ary(GfoMsg msg) {
|
||||
int len = msg.Subs_count();
|
||||
GfoMsg[] rv = new GfoMsg[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = msg.Subs_getAt(i);
|
||||
return rv;
|
||||
}
|
||||
String Xto_str(GfoMsg[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) sb.Add_char_crlf();
|
||||
sb.Add(ary[i].To_str());
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
85
400_xowa/src/gplx/langs/gfs/Gfs_nde.java
Normal file
85
400_xowa/src/gplx/langs/gfs/Gfs_nde.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
public class Gfs_nde {
|
||||
public byte[] Name_bry(byte[] src) {return name == null ? Bry_.Mid(src, name_bgn, name_end) : name;}
|
||||
public byte[] Name() {return name;} public Gfs_nde Name_(byte[] v) {name = v; return this;} private byte[] name;
|
||||
public int Name_bgn() {return name_bgn;} private int name_bgn = -1;
|
||||
public int Name_end() {return name_end;} private int name_end = -1;
|
||||
public Gfs_nde Name_rng_(int name_bgn, int name_end) {this.name_bgn = name_bgn; this.name_end = name_end; return this;}
|
||||
public byte Op_tid() {return op_tid;} public Gfs_nde Op_tid_(byte v) {op_tid = v; return this;} private byte op_tid;
|
||||
public void Subs_clear() {
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
subs[i] = null;
|
||||
subs_len = 0;
|
||||
}
|
||||
public int Subs_len() {return subs_len;} private int subs_len;
|
||||
public Gfs_nde Subs_add_many(Gfs_nde... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
Subs_add(ary[i]);
|
||||
return this;
|
||||
}
|
||||
public Gfs_nde Subs_add(Gfs_nde nde) {
|
||||
int new_len = subs_len + 1;
|
||||
if (new_len > subs_max) { // ary too small >>> expand
|
||||
subs_max = new_len * 2;
|
||||
Gfs_nde[] new_subs = new Gfs_nde[subs_max];
|
||||
Array_.Copy_to(subs, 0, new_subs, 0, subs_len);
|
||||
subs = new_subs;
|
||||
}
|
||||
subs[subs_len] = nde;
|
||||
subs_len = new_len;
|
||||
return this;
|
||||
} Gfs_nde[] subs = Gfs_nde.Ary_empty; int subs_max; int[] subs_pos_ary = Int_.Ary_empty;
|
||||
public Gfs_nde Subs_get_at(int i) {return subs[i];}
|
||||
public Gfs_nde[] Subs_to_ary() {
|
||||
Gfs_nde[] rv = new Gfs_nde[subs_len];
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
rv[i] = subs[i];
|
||||
return rv;
|
||||
}
|
||||
public int Atrs_len() {return args_len;} private int args_len;
|
||||
public Gfs_nde Atrs_get_at(int i) {return args[i];}
|
||||
public Gfs_nde Atrs_add_many(Gfs_nde... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
Atrs_add(ary[i]);
|
||||
return this;
|
||||
}
|
||||
public Gfs_nde Atrs_add(Gfs_nde nde) {
|
||||
int new_len = args_len + 1;
|
||||
if (new_len > args_max) { // ary too small >>> expand
|
||||
args_max = new_len * 2;
|
||||
Gfs_nde[] new_args = new Gfs_nde[args_max];
|
||||
Array_.Copy_to(args, 0, new_args, 0, args_len);
|
||||
args = new_args;
|
||||
}
|
||||
args[args_len] = nde;
|
||||
args_len = new_len;
|
||||
return this;
|
||||
} Gfs_nde[] args = Gfs_nde.Ary_empty; int args_max; int[] args_pos_ary = Int_.Ary_empty;
|
||||
public Gfs_nde[] Atrs_to_ary() {
|
||||
Gfs_nde[] rv = new Gfs_nde[args_len];
|
||||
for (int i = 0; i < args_len; i++)
|
||||
rv[i] = args[i];
|
||||
return rv;
|
||||
}
|
||||
public static final Gfs_nde[] Ary_empty = new Gfs_nde[0];
|
||||
public static final byte Op_tid_null = 0, Op_tid_assign = 1;
|
||||
}
|
||||
104
400_xowa/src/gplx/langs/gfs/Gfs_parser.java
Normal file
104
400_xowa/src/gplx/langs/gfs/Gfs_parser.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Gfs_parser {
|
||||
private final Btrie_fast_mgr trie = Gfs_parser_.trie_();
|
||||
private final Gfs_parser_ctx ctx = new Gfs_parser_ctx();
|
||||
public Gfs_nde Parse(byte[] src) {
|
||||
ctx.Root().Subs_clear();
|
||||
int src_len = src.length; if (src_len == 0) return ctx.Root();
|
||||
ctx.Init(trie, src, src_len);
|
||||
int pos = 0;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_at_w_b0(ctx.Trie_rv(), b, src, pos, src_len);
|
||||
if (o == null)
|
||||
ctx.Err_mgr().Fail_unknown_char(ctx, pos, b);
|
||||
else {
|
||||
Gfs_lxr lxr = (Gfs_lxr)o;
|
||||
while (lxr != null) {
|
||||
int rslt = lxr.Process(ctx, pos, ctx.Trie_rv().Pos());
|
||||
switch (lxr.Lxr_tid()) {
|
||||
case Gfs_lxr_.Tid_whitespace: break;
|
||||
case Gfs_lxr_.Tid_comment: break;
|
||||
default: ctx.Prv_lxr_(lxr.Lxr_tid()); break;
|
||||
}
|
||||
switch (rslt) {
|
||||
case Gfs_lxr_.Rv_lxr:
|
||||
pos = ctx.Nxt_pos();
|
||||
lxr = ctx.Nxt_lxr();
|
||||
break;
|
||||
case Gfs_lxr_.Rv_eos:
|
||||
pos = src_len;
|
||||
lxr = null;
|
||||
break;
|
||||
default:
|
||||
pos = rslt;
|
||||
lxr = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_curly_end:
|
||||
case Gfs_lxr_.Tid_semic: break;
|
||||
default: ctx.Err_mgr().Fail_eos(ctx); break;
|
||||
}
|
||||
return ctx.Root();
|
||||
}
|
||||
}
|
||||
class Gfs_parser_ {
|
||||
public static Btrie_fast_mgr trie_() {
|
||||
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_a7(); // NOTE:ci.ascii:gfs;letters/symbols only;
|
||||
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier.Instance;
|
||||
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
|
||||
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
|
||||
trie_add_rng(rv, word_lxr, Byte_ascii.Num_0, Byte_ascii.Num_9);
|
||||
rv.Add(Byte_ascii.Underline, word_lxr);
|
||||
trie_add_many(rv, Gfs_lxr_whitespace.Instance, Byte_ascii.Space, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Tab);
|
||||
trie_add_quote(rv, new byte[] {Byte_ascii.Apos});
|
||||
trie_add_quote(rv, new byte[] {Byte_ascii.Quote});
|
||||
trie_add_quote(rv, Bry_.new_a7("<:[\"\n"), Bry_.new_a7("\n\"]:>"));
|
||||
trie_add_quote(rv, Bry_.new_a7("<:['\n"), Bry_.new_a7("\n']:>"));
|
||||
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Slash}, new byte[] {Byte_ascii.Nl});
|
||||
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Star}, new byte[] {Byte_ascii.Star, Byte_ascii.Slash});
|
||||
rv.Add(Byte_ascii.Semic, Gfs_lxr_semic.Instance);
|
||||
rv.Add(Byte_ascii.Paren_bgn, Gfs_lxr_paren_bgn.Instance);
|
||||
rv.Add(Byte_ascii.Paren_end, Gfs_lxr_paren_end.Instance);
|
||||
rv.Add(Byte_ascii.Curly_bgn, Gfs_lxr_curly_bgn.Instance);
|
||||
rv.Add(Byte_ascii.Curly_end, Gfs_lxr_curly_end.Instance);
|
||||
rv.Add(Byte_ascii.Dot, Gfs_lxr_dot.Instance);
|
||||
rv.Add(Byte_ascii.Comma, Gfs_lxr_comma.Instance);
|
||||
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal.Instance);
|
||||
return rv;
|
||||
}
|
||||
private static void trie_add_rng(Btrie_fast_mgr trie, Gfs_lxr lxr, byte bgn, byte end) {
|
||||
for (byte b = bgn; b <= end; b++)
|
||||
trie.Add(b, lxr);
|
||||
}
|
||||
private static void trie_add_many(Btrie_fast_mgr trie, Gfs_lxr lxr, byte... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
trie.Add(ary[i], lxr);
|
||||
}
|
||||
private static void trie_add_quote(Btrie_fast_mgr trie, byte[] bgn) {trie_add_quote(trie, bgn, bgn);}
|
||||
private static void trie_add_quote(Btrie_fast_mgr trie, byte[] bgn, byte[] end) {trie.Add(bgn, new Gfs_lxr_quote(bgn, end));}
|
||||
private static void trie_add_comment(Btrie_fast_mgr trie, byte[] bgn, byte[] end) {trie.Add(bgn, new Gfs_lxr_comment_flat(bgn, end));}
|
||||
}
|
||||
127
400_xowa/src/gplx/langs/gfs/Gfs_parser_ctx.java
Normal file
127
400_xowa/src/gplx/langs/gfs/Gfs_parser_ctx.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.btries.*;
|
||||
class Gfs_parser_ctx {
|
||||
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
|
||||
public Btrie_rv Trie_rv() {return trie_rv;} private final Btrie_rv trie_rv = new Btrie_rv();
|
||||
public Gfs_nde Root() {return root;} Gfs_nde root = new Gfs_nde();
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_len() {return src_len;} private int src_len;
|
||||
public int Prv_lxr() {return prv_lxr;} public Gfs_parser_ctx Prv_lxr_(int v) {prv_lxr = v; return this;} private int prv_lxr;
|
||||
public Gfs_nde Cur_nde() {return cur_nde;} Gfs_nde cur_nde;
|
||||
public int Nxt_pos() {return nxt_pos;} private int nxt_pos;
|
||||
public Gfs_lxr Nxt_lxr() {return nxt_lxr;} Gfs_lxr nxt_lxr;
|
||||
public Bry_bfr Tmp_bfr() {return tmp_bfr;} private Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public void Process_eos() {}
|
||||
public void Process_lxr(int nxt_pos, Gfs_lxr nxt_lxr) {this.nxt_pos = nxt_pos; this.nxt_lxr = nxt_lxr;}
|
||||
public void Process_null(int cur_pos) {this.nxt_pos = cur_pos; this.nxt_lxr = null;}
|
||||
public void Init(Btrie_fast_mgr trie, byte[] src, int src_len) {
|
||||
this.trie = trie; this.src = src; this.src_len = src_len;
|
||||
cur_nde = root;
|
||||
Stack_add();
|
||||
}
|
||||
public void Hold_word(int bgn, int end) {
|
||||
cur_idf_bgn = bgn;
|
||||
cur_idf_end = end;
|
||||
} int cur_idf_bgn = -1, cur_idf_end = -1;
|
||||
private void Held_word_clear() {cur_idf_bgn = -1; cur_idf_end = -1;}
|
||||
public Gfs_nde Make_nde(int tkn_bgn, int tkn_end) { // "abc."; "abc("; "abc;"; "abc{"
|
||||
Gfs_nde nde = new Gfs_nde().Name_rng_(cur_idf_bgn, cur_idf_end);
|
||||
this.Held_word_clear();
|
||||
cur_nde.Subs_add(nde);
|
||||
cur_nde = nde;
|
||||
return nde;
|
||||
}
|
||||
public void Make_atr_by_idf() {Make_atr(cur_idf_bgn, cur_idf_end); Held_word_clear();}
|
||||
public void Make_atr_by_bry(int bgn, int end, byte[] bry) {Make_atr(bgn, end).Name_(bry);}
|
||||
public Gfs_nde Make_atr(int bgn, int end) {
|
||||
Gfs_nde nde = new Gfs_nde().Name_rng_(bgn, end);
|
||||
cur_nde.Atrs_add(nde);
|
||||
return nde;
|
||||
}
|
||||
public void Cur_nde_from_stack() {cur_nde = (Gfs_nde)nodes.Get_at_last();}
|
||||
public void Stack_add() {nodes.Add(cur_nde);} List_adp nodes = List_adp_.New();
|
||||
public void Stack_pop(int pos) {
|
||||
if (nodes.Count() < 2) err_mgr.Fail_nde_stack_empty(this, pos); // NOTE: need at least 2 items; 1 to pop and 1 to set as current
|
||||
List_adp_.Del_at_last(nodes);
|
||||
Cur_nde_from_stack();
|
||||
}
|
||||
public Gfs_err_mgr Err_mgr() {return err_mgr;} Gfs_err_mgr err_mgr = new Gfs_err_mgr();
|
||||
}
|
||||
class Gfs_err_mgr {
|
||||
public void Fail_eos(Gfs_parser_ctx ctx) {Fail(ctx, Fail_msg_eos, ctx.Src_len());}
|
||||
public void Fail_unknown_char(Gfs_parser_ctx ctx, int pos, byte c) {Fail(ctx, Fail_msg_unknown_char, pos, Keyval_.new_("char", Char_.To_str((char)c)));}
|
||||
public void Fail_nde_stack_empty(Gfs_parser_ctx ctx, int pos) {Fail(ctx, Fail_msg_nde_stack_empty, pos);}
|
||||
public void Fail_invalid_lxr(Gfs_parser_ctx ctx, int pos, int lxr_tid, byte c) {
|
||||
Fail(ctx, Fail_msg_invalid_lxr, pos, Keyval_.new_("char", Char_.To_str((char)c)), Keyval_.new_("cur_lxr", Gfs_lxr_.Tid__name(lxr_tid)), Keyval_.new_("prv_lxr", Gfs_lxr_.Tid__name(ctx.Prv_lxr())));
|
||||
}
|
||||
private void Fail(Gfs_parser_ctx ctx, String msg, int pos, Keyval... args) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
Fail_args_standard(src, src_len, pos);
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval arg = args[i];
|
||||
tmp_fail_args.Add(arg.Key(), arg.Val_to_str_or_empty());
|
||||
}
|
||||
throw Err_.new_wo_type(Fail_msg(msg, tmp_fail_args));
|
||||
}
|
||||
private void Fail_args_standard(byte[] src, int src_len, int pos) {
|
||||
tmp_fail_args.Add("excerpt_bgn", Fail_excerpt_bgn(src, src_len, pos));
|
||||
tmp_fail_args.Add("excerpt_end", Fail_excerpt_end(src, src_len, pos));
|
||||
tmp_fail_args.Add("pos" , pos);
|
||||
}
|
||||
public static final String Fail_msg_invalid_lxr = "invalid character", Fail_msg_unknown_char = "unknown char", Fail_msg_eos = "end of stream", Fail_msg_nde_stack_empty = "node stack empty";
|
||||
String Fail_msg(String type, Keyval_list fail_args) {
|
||||
tmp_fail_bfr.Add_str_u8(type).Add_byte(Byte_ascii.Colon);
|
||||
int len = fail_args.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
tmp_fail_bfr.Add_byte(Byte_ascii.Space);
|
||||
Keyval kv = fail_args.Get_at(i);
|
||||
tmp_fail_bfr.Add_str_u8(kv.Key());
|
||||
tmp_fail_bfr.Add_byte(Byte_ascii.Eq).Add_byte(Byte_ascii.Apos);
|
||||
tmp_fail_bfr.Add_str_u8(kv.Val_to_str_or_empty()).Add_byte(Byte_ascii.Apos);
|
||||
}
|
||||
return tmp_fail_bfr.To_str_and_clear();
|
||||
}
|
||||
Bry_bfr tmp_fail_bfr = Bry_bfr_.Reset(255);
|
||||
Keyval_list tmp_fail_args = new Keyval_list();
|
||||
private static int excerpt_len = 50;
|
||||
String Fail_excerpt_bgn(byte[] src, int src_len, int pos) {
|
||||
int bgn = pos - excerpt_len; if (bgn < 0) bgn = 0;
|
||||
Fail_excerpt_rng(tmp_fail_bfr, src, bgn, pos);
|
||||
return tmp_fail_bfr.To_str_and_clear();
|
||||
}
|
||||
String Fail_excerpt_end(byte[] src, int src_len, int pos) {
|
||||
int end = pos + excerpt_len; if (end > src_len) end = src_len;
|
||||
Fail_excerpt_rng(tmp_fail_bfr, src, pos, end);
|
||||
return tmp_fail_bfr.To_str_and_clear();
|
||||
}
|
||||
private static void Fail_excerpt_rng(Bry_bfr bfr, byte[] src, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: bfr.Add(Esc_tab); break;
|
||||
case Byte_ascii.Nl: bfr.Add(Esc_nl); break;
|
||||
case Byte_ascii.Cr: bfr.Add(Esc_cr); break;
|
||||
default: bfr.Add_byte(b); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final byte[] Esc_nl = Bry_.new_a7("\\n"), Esc_cr = Bry_.new_a7("\\r"), Esc_tab = Bry_.new_a7("\\t");
|
||||
}
|
||||
196
400_xowa/src/gplx/langs/gfs/Gfs_parser_tst.java
Normal file
196
400_xowa/src/gplx/langs/gfs/Gfs_parser_tst.java
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Gfs_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt();
|
||||
@Test public void Semicolon() {
|
||||
fxt .Test_parse("a;", fxt.nde_("a"));
|
||||
fxt .Test_parse("a;b;c;", fxt.nde_("a"), fxt.nde_("b"), fxt.nde_("c"));
|
||||
fxt .Test_parse("a_0;", fxt.nde_("a_0"));
|
||||
}
|
||||
@Test public void Dot() {
|
||||
fxt .Test_parse("a.b;", fxt.nde_("a").Subs_add(fxt.nde_("b")));
|
||||
fxt .Test_parse("a.b;c.d;", fxt.nde_("a").Subs_add(fxt.nde_("b")), fxt.nde_("c").Subs_add(fxt.nde_("d")));
|
||||
}
|
||||
@Test public void Parens() {
|
||||
fxt .Test_parse("a();b();", fxt.nde_("a"), fxt.nde_("b"));
|
||||
fxt .Test_parse("a().b();c().d();", fxt.nde_("a").Subs_add(fxt.nde_("b")), fxt.nde_("c").Subs_add(fxt.nde_("d")));
|
||||
}
|
||||
@Test public void Num() {
|
||||
fxt .Test_parse("a(1,2);", fxt.nde_("a").Atrs_add_many(fxt.val_("1"), fxt.val_("2")));
|
||||
}
|
||||
@Test public void Quote() {
|
||||
fxt .Test_parse("a('b');", fxt.nde_("a").Atrs_add(fxt.val_("b")));
|
||||
}
|
||||
@Test public void Quote_escaped() {
|
||||
fxt .Test_parse("a('b''c''d');", fxt.nde_("a").Atrs_add(fxt.val_("b'c'd")));
|
||||
}
|
||||
@Test public void Quote_escaped_2() {
|
||||
fxt .Test_parse("a('a''''b');", fxt.nde_("a").Atrs_add(fxt.val_("a''b")));
|
||||
}
|
||||
@Test public void Quote_mixed() {
|
||||
fxt .Test_parse("a('b\"c');", fxt.nde_("a").Atrs_add(fxt.val_("b\"c")));
|
||||
}
|
||||
@Test public void Comma() {
|
||||
fxt .Test_parse("a('b','c','d');", fxt.nde_("a").Atrs_add_many(fxt.val_("b"), fxt.val_("c"), fxt.val_("d")));
|
||||
}
|
||||
@Test public void Ws() {
|
||||
fxt .Test_parse(" a ( 'b' , 'c' ) ; ", fxt.nde_("a").Atrs_add_many(fxt.val_("b"), fxt.val_("c")));
|
||||
}
|
||||
@Test public void Comment_slash_slash() {
|
||||
fxt .Test_parse("//z\na;//y\n", fxt.nde_("a"));
|
||||
}
|
||||
@Test public void Comment_slash_star() {
|
||||
fxt .Test_parse("/*z*/a;/*y*/", fxt.nde_("a"));
|
||||
}
|
||||
@Test public void Curly() {
|
||||
fxt .Test_parse("a{b;}", fxt.nde_("a").Subs_add(fxt.nde_("b")));
|
||||
}
|
||||
@Test public void Curly_nest() {
|
||||
fxt .Test_parse("a{b{c{d;}}}"
|
||||
, fxt.nde_("a").Subs_add
|
||||
( fxt.nde_("b").Subs_add
|
||||
( fxt.nde_("c").Subs_add
|
||||
( fxt.nde_("d")
|
||||
))));
|
||||
}
|
||||
@Test public void Curly_nest_peers() {
|
||||
fxt .Test_parse(String_.Concat_lines_nl
|
||||
( "a{"
|
||||
, " a0{"
|
||||
, " a00{"
|
||||
, " a000;"
|
||||
, " }"
|
||||
, " a01;"
|
||||
, " }"
|
||||
, " a1;"
|
||||
, "}"
|
||||
)
|
||||
, fxt.nde_("a").Subs_add_many
|
||||
( fxt.nde_("a0").Subs_add_many
|
||||
( fxt.nde_("a00").Subs_add
|
||||
( fxt.nde_("a000")
|
||||
)
|
||||
, fxt.nde_("a01")
|
||||
)
|
||||
, fxt.nde_("a1")
|
||||
));
|
||||
}
|
||||
@Test public void Curly_dot() {
|
||||
fxt .Test_parse("a{a0.a00;a1.a10;}"
|
||||
, fxt.nde_("a").Subs_add_many
|
||||
( fxt.nde_("a0").Subs_add_many(fxt.nde_("a00"))
|
||||
, fxt.nde_("a1").Subs_add_many(fxt.nde_("a10"))
|
||||
));
|
||||
}
|
||||
@Test public void Eq() {
|
||||
fxt .Test_parse("a='b';", fxt.nde_("a").Atrs_add(fxt.val_("b")));
|
||||
fxt .Test_parse("a.b.c='d';"
|
||||
, fxt.nde_("a").Subs_add
|
||||
( fxt.nde_("b").Subs_add_many
|
||||
( fxt.nde_("c").Atrs_add(fxt.val_("d"))
|
||||
)));
|
||||
fxt .Test_parse("a.b{c='d'; e='f'}"
|
||||
, fxt.nde_("a").Subs_add
|
||||
( fxt.nde_("b").Subs_add_many
|
||||
( fxt.nde_("c").Atrs_add(fxt.val_("d"))
|
||||
, fxt.nde_("e").Atrs_add(fxt.val_("f"))
|
||||
)));
|
||||
}
|
||||
@Test public void Curly_nest_peers2() {
|
||||
fxt .Test_parse(String_.Concat_lines_nl
|
||||
( "a() {"
|
||||
, " k1 = 'v1';"
|
||||
, "}"
|
||||
)
|
||||
, fxt.nde_("a").Subs_add_many
|
||||
( fxt.nde_("k1").Atrs_add(fxt.val_("v1"))
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Fail() {
|
||||
fxt .Test_parse_fail("a(.);", Gfs_err_mgr.Fail_msg_invalid_lxr); // (.)
|
||||
fxt .Test_parse_fail("a..b;", Gfs_err_mgr.Fail_msg_invalid_lxr); // ..
|
||||
fxt .Test_parse_fail("a.;", Gfs_err_mgr.Fail_msg_invalid_lxr); // .;
|
||||
fxt .Test_parse_fail("a", Gfs_err_mgr.Fail_msg_eos); // eos
|
||||
fxt .Test_parse_fail("a;~;", Gfs_err_mgr.Fail_msg_unknown_char); // ~
|
||||
}
|
||||
}
|
||||
class Gfs_parser_fxt {
|
||||
public void Clear() {}
|
||||
public Gfs_nde nde_(String v) {return new Gfs_nde().Name_(Bry_.new_a7(v));}
|
||||
public Gfs_nde val_(String v) {return new Gfs_nde().Name_(Bry_.new_a7(v));}
|
||||
public void Test_parse(String src_str, Gfs_nde... expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Gfs_nde root = parser.Parse(src_bry);
|
||||
Tfds.Eq_str_lines(To_str(null, expd), To_str(src_bry, root.Subs_to_ary()));
|
||||
} private Bry_bfr tmp_bfr = Bry_bfr_.New(), path_bfr = Bry_bfr_.New(); Gfs_parser parser = new Gfs_parser();
|
||||
public void Test_parse_fail(String src_str, String expd_err) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
try {parser.Parse(src_bry);}
|
||||
catch (Exception e) {
|
||||
String actl_err = Err_.Message_gplx_full(e);
|
||||
actl_err = String_.GetStrBefore(actl_err, ":");
|
||||
boolean match = String_.Has(actl_err, expd_err);
|
||||
if (!match) Tfds.Fail("expecting '" + expd_err + "' got '" + actl_err + "'");
|
||||
return;
|
||||
}
|
||||
Tfds.Fail("expected to fail with " + expd_err);
|
||||
}
|
||||
public String To_str(byte[] src, Gfs_nde[] expd) {
|
||||
int subs_len = expd.length;
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
path_bfr.Clear().Add_int_variable(i);
|
||||
To_str(tmp_bfr, path_bfr, src, expd[i]);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
public void To_str(Bry_bfr bfr, Bry_bfr path, byte[] src, Gfs_nde nde) {
|
||||
To_str_atr(bfr, path, src, Atr_name, nde.Name(), nde.Name_bgn(), nde.Name_end());
|
||||
int atrs_len = nde.Atrs_len();
|
||||
for (int i = 0; i < atrs_len; i++) {
|
||||
Gfs_nde atr = nde.Atrs_get_at(i);
|
||||
int path_len_old = path.Len();
|
||||
path.Add_byte(Byte_ascii.Dot).Add_byte((byte)(Byte_ascii.Ltr_a + i));
|
||||
int path_len_new = path.Len();
|
||||
To_str(bfr, path, src, atr);
|
||||
path.Del_by(path_len_new - path_len_old);
|
||||
}
|
||||
int subs_len = nde.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Gfs_nde sub = nde.Subs_get_at(i);
|
||||
int path_len_old = path.Len();
|
||||
path.Add_byte(Byte_ascii.Dot).Add_int_variable(i);
|
||||
int path_len_new = path.Len();
|
||||
To_str(bfr, path, src, sub);
|
||||
path.Del_by(path_len_new - path_len_old);
|
||||
}
|
||||
}
|
||||
private void To_str_atr(Bry_bfr bfr, Bry_bfr path_bfr, byte[] src, byte[] name, byte[] val, int val_bgn, int val_end) {
|
||||
if (val == null && val_bgn == -1 && val_end == -1) return;
|
||||
bfr.Add_bfr_and_preserve(path_bfr).Add_byte(Byte_ascii.Colon);
|
||||
bfr.Add(name);
|
||||
if (val == null)
|
||||
bfr.Add_mid(src, val_bgn, val_end);
|
||||
else
|
||||
bfr.Add(val);
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
private static final byte[] Atr_name = Bry_.new_a7("name=");
|
||||
}
|
||||
46
400_xowa/src/gplx/langs/gfs/Gfs_wtr.java
Normal file
46
400_xowa/src/gplx/langs/gfs/Gfs_wtr.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
public class Gfs_wtr {
|
||||
public byte Quote_char() {return quote_char;} public Gfs_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Apos;
|
||||
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
public void Add_grp_bgn(byte[] key) {
|
||||
bfr.Add(key); // key
|
||||
bfr.Add_byte(Byte_ascii.Curly_bgn); // {
|
||||
}
|
||||
public void Add_grp_end(byte[] key) {
|
||||
bfr.Add_byte(Byte_ascii.Curly_end); // }
|
||||
}
|
||||
public void Add_set_eq(byte[] key, byte[] val) {
|
||||
bfr.Add(key); // key
|
||||
bfr.Add_byte_eq(); // =
|
||||
bfr.Add_byte(quote_char); // '
|
||||
Write_val(val);
|
||||
bfr.Add_byte(quote_char); // '
|
||||
bfr.Add_byte(Byte_ascii.Semic); // ;
|
||||
}
|
||||
private void Write_val(byte[] bry) {
|
||||
int bry_len = bry.length;
|
||||
for (int i = 0; i < bry_len; i++) {
|
||||
byte b = bry[i];
|
||||
if (b == quote_char) // byte is quote
|
||||
bfr.Add_byte(b); // double up
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
400_xowa/src/gplx/langs/htmls/clses/Gfh_class_.java
Normal file
61
400_xowa/src/gplx/langs/htmls/clses/Gfh_class_.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_class_ {
|
||||
public static boolean Has(byte[] src, int src_bgn, int src_end, byte[] cls) {
|
||||
int cls_bgn = src_bgn;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
|
||||
if (b == Byte_ascii.Space) {
|
||||
if (cls_bgn != -1) {
|
||||
if (Bry_.Match(src, cls_bgn, pos, cls))return true;
|
||||
cls_bgn = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cls_bgn == -1) cls_bgn = pos;
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
++pos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static byte Find_1st(byte[] src, int src_bgn, int src_end, Hash_adp_bry hash) {
|
||||
int cls_bgn = src_bgn;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
|
||||
if (b == Byte_ascii.Space) {
|
||||
if (cls_bgn != -1) {
|
||||
byte rv = hash.Get_as_byte_or(src, cls_bgn, pos, Byte_.Max_value_127);
|
||||
if (rv != Byte_.Max_value_127) return rv;
|
||||
cls_bgn = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cls_bgn == -1) cls_bgn = pos;
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
++pos;
|
||||
}
|
||||
return Byte_.Max_value_127;
|
||||
}
|
||||
}
|
||||
58
400_xowa/src/gplx/langs/htmls/clses/Gfh_class__tst.java
Normal file
58
400_xowa/src/gplx/langs/htmls/clses/Gfh_class__tst.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Gfh_class__tst {
|
||||
private final Gfh_class__fxt fxt = new Gfh_class__fxt();
|
||||
@Test public void Has() {
|
||||
fxt.Test__has__y("a b c", "a", "b", "c");
|
||||
fxt.Test__has__n("a b c", "d");
|
||||
fxt.Test__has__n("ab", "a");
|
||||
}
|
||||
@Test public void Cls__has__hash() {
|
||||
Hash_adp_bry hash = fxt.Make_hash("x", "y", "z");
|
||||
fxt.Test__find_1st(hash, 0, "x");
|
||||
fxt.Test__find_1st(hash, 2, "z");
|
||||
fxt.Test__find_1st(hash, 0, "a x b");
|
||||
fxt.Test__find_1st(hash, 0, "a b x");
|
||||
fxt.Test__find_1st(hash, Byte_.Max_value_127, "a");
|
||||
fxt.Test__find_1st(hash, Byte_.Max_value_127, "xyz");
|
||||
}
|
||||
}
|
||||
class Gfh_class__fxt {
|
||||
public void Test__has__y(String src, String... ary) {Test__has(Bool_.Y, src, ary);}
|
||||
public void Test__has__n(String src, String... ary) {Test__has(Bool_.N, src, ary);}
|
||||
public void Test__has(boolean expd, String src, String... ary) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
for (String itm : ary) {
|
||||
byte[] itm_bry = Bry_.new_u8(itm);
|
||||
Tfds.Eq_bool(expd, Gfh_class_.Has(src_bry, 0, src_bry.length, itm_bry), itm);
|
||||
}
|
||||
}
|
||||
public Hash_adp_bry Make_hash(String... ary) {
|
||||
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add_bry_byte(Bry_.new_u8(ary[i]), (byte)i);
|
||||
return rv;
|
||||
}
|
||||
public void Test__find_1st(Hash_adp_bry hash, int expd, String src) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
Tfds.Eq_byte((byte)expd, Gfh_class_.Find_1st(src_bry, 0, src_bry.length, hash), src);
|
||||
}
|
||||
}
|
||||
49
400_xowa/src/gplx/langs/htmls/clses/Gfh_class_parser_.java
Normal file
49
400_xowa/src/gplx/langs/htmls/clses/Gfh_class_parser_.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
public class Gfh_class_parser_ {
|
||||
public static void Parse(Gfh_tag tag, Gfh_class_parser_wkr wkr) {
|
||||
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__class);
|
||||
if (atr.Val_dat_exists())
|
||||
Parse(tag.Src(), atr.Val_bgn(), atr.Val_end(), wkr);
|
||||
}
|
||||
public static void Parse(byte[] src, int src_bgn, int src_end, Gfh_class_parser_wkr wkr) {
|
||||
int atr_idx = 0, tmp_bgn = -1, tmp_end = -1;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
if (tmp_bgn != -1) { // ignore empty atrs
|
||||
if (!wkr.On_cls(src, atr_idx, src_bgn, src_end, tmp_bgn, tmp_end))
|
||||
pos_is_last = true;
|
||||
}
|
||||
++atr_idx; tmp_bgn = -1; tmp_end = -1;
|
||||
break;
|
||||
default:
|
||||
if (tmp_bgn == -1) tmp_bgn = pos;
|
||||
tmp_end = pos + 1;
|
||||
break;
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Gfh_class_parser__tst {
|
||||
private final Gfh_class_parser__fxt fxt = new Gfh_class_parser__fxt();
|
||||
@Test public void Basic() {fxt.Test__parse("v1" , "v1");}
|
||||
@Test public void Many() {fxt.Test__parse("v1 v2" , "v1", "v2");}
|
||||
}
|
||||
class Gfh_class_parser__fxt {
|
||||
private final Gfh_class_wkr__list wkr = new Gfh_class_wkr__list();
|
||||
public void Test__parse(String src_str, String... expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
String[] actl = wkr.Parse(src_bry, 0, src_bry.length);
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
}
|
||||
class Gfh_class_wkr__list implements Gfh_class_parser_wkr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
public boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end) {
|
||||
String s = String_.new_u8(src, val_bgn, val_end);
|
||||
list.Add(s); //
|
||||
return true;
|
||||
}
|
||||
public String[] Parse(byte[] src, int src_bgn, int src_end) {
|
||||
Gfh_class_parser_.Parse(src, src_bgn, src_end, this);
|
||||
return (String[])list.To_ary_and_clear(String.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_class_parser_wkr {
|
||||
boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end);
|
||||
}
|
||||
47
400_xowa/src/gplx/langs/htmls/docs/Gfh_atr.java
Normal file
47
400_xowa/src/gplx/langs/htmls/docs/Gfh_atr.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_atr implements gplx.core.brys.Bfr_arg {
|
||||
public Gfh_atr(int idx, int atr_bgn, int atr_end, byte[] key, byte[] val, byte[] src, int val_bgn, int val_end) {
|
||||
this.idx = idx; this.atr_bgn = atr_bgn; this.atr_end = atr_end; this.key = key; this.val = val;
|
||||
this.src = src; this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
}
|
||||
public byte[] Src() {return src;} private final byte[] src;
|
||||
public int Idx() {return idx;} private final int idx;
|
||||
public int Atr_bgn() {return atr_bgn;} private final int atr_bgn;
|
||||
public int Atr_end() {return atr_end;} private final int atr_end;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public int Val_bgn() {return val_bgn;} private final int val_bgn;
|
||||
public int Val_end() {return val_end;} private final int val_end;
|
||||
public boolean Val_dat_exists() {return val_end != -1;}
|
||||
public boolean Val_dat_missing() {return val_end == -1;}
|
||||
public byte[] Val() {
|
||||
if (val == null)
|
||||
val = Bry_.Mid(src, val_bgn, val_end);
|
||||
return val;
|
||||
} private byte[] val;
|
||||
public void Html__add(Bry_bfr bfr) {
|
||||
if (val_end > val_bgn)
|
||||
bfr.Add_mid(src, val_bgn, val_end);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (Val_dat_exists())
|
||||
bfr.Add_mid(src, val_bgn, val_end);
|
||||
}
|
||||
public static final Gfh_atr Noop = new Gfh_atr(-1, -1, -1, Bry_.Empty, Bry_.Empty, Bry_.Empty, -1, -1);
|
||||
}
|
||||
54
400_xowa/src/gplx/langs/htmls/docs/Gfh_doc_parser.java
Normal file
54
400_xowa/src/gplx/langs/htmls/docs/Gfh_doc_parser.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Gfh_doc_parser {
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
private final Gfh_txt_wkr txt_wkr;
|
||||
public Gfh_doc_parser(Gfh_txt_wkr txt_wkr, Gfh_doc_wkr... wkr_ary) {
|
||||
this.txt_wkr = txt_wkr;
|
||||
for (Gfh_doc_wkr wkr : wkr_ary)
|
||||
trie.Add_obj(wkr.Hook(), wkr);
|
||||
}
|
||||
public void Parse(byte[] page_url, byte[] src, int src_bgn, int src_end) {
|
||||
int txt_bgn = -1;
|
||||
int pos = src_bgn;
|
||||
while (pos < src_end) {
|
||||
Object o = trie.Match_at(trv, src, pos, src_end);
|
||||
if (o == null) { // not a known hook; add to txt
|
||||
if (txt_bgn == -1) txt_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else { // known hook
|
||||
if (txt_bgn != -1) { // txt pending; handle it
|
||||
txt_wkr.Parse(txt_bgn, pos);
|
||||
txt_bgn = -1;
|
||||
}
|
||||
Gfh_doc_wkr wkr = (Gfh_doc_wkr)o;
|
||||
try {pos = wkr.Parse(src, src_bgn, src_end, pos);}
|
||||
catch (Exception e) {
|
||||
Gfh_utl.Log(e, "html parse failed", page_url, src, pos);
|
||||
txt_bgn = pos; // set txt_bgn to hook_bgn which is "pos"; i.e.: txt resumes from start of failed hook
|
||||
pos = trv.Pos(); // set pos to hook_end
|
||||
}
|
||||
}
|
||||
}
|
||||
if (txt_bgn != -1) txt_wkr.Parse(txt_bgn, src_end); // handle add pending txt at EOS
|
||||
}
|
||||
}
|
||||
22
400_xowa/src/gplx/langs/htmls/docs/Gfh_doc_wkr.java
Normal file
22
400_xowa/src/gplx/langs/htmls/docs/Gfh_doc_wkr.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_doc_wkr {
|
||||
byte[] Hook();
|
||||
int Parse(byte[] src, int src_bgn, int src_end, int pos);
|
||||
}
|
||||
164
400_xowa/src/gplx/langs/htmls/docs/Gfh_tag.java
Normal file
164
400_xowa/src/gplx/langs/htmls/docs/Gfh_tag.java
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
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.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.parsers.htmls.*; import gplx.langs.htmls.styles.*; import gplx.langs.htmls.clses.*;
|
||||
public class Gfh_tag implements Mwh_atr_wkr {
|
||||
private Gfh_tag_rdr tag_rdr;
|
||||
private Ordered_hash atrs_hash; private boolean atrs_null; private int atrs_bgn, atrs_end;
|
||||
private final Gfh_style_wkr__val_as_int style_wkr = new Gfh_style_wkr__val_as_int();
|
||||
public Gfh_tag Init(Gfh_tag_rdr tag_rdr, byte[] src, boolean tag_is_tail, boolean tag_is_inline, int src_bgn, int src_end, int atrs_bgn, int atrs_end, int name_id, byte[] name_bry) {
|
||||
this.tag_rdr = tag_rdr; this.src = src; this.atrs_null = true;
|
||||
this.tag_is_tail = tag_is_tail; this.tag_is_inline = tag_is_inline;
|
||||
this.atrs_bgn = atrs_bgn; this.atrs_end = atrs_end;
|
||||
this.name_id = name_id; this.name_bry = name_bry; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
return this;
|
||||
}
|
||||
public Gfh_tag Copy() {
|
||||
Gfh_tag rv = new Gfh_tag().Init(tag_rdr, src, tag_is_tail, tag_is_inline, src_bgn, src_end, atrs_bgn, atrs_end, name_id, name_bry);
|
||||
rv.atrs_null = false;
|
||||
rv.atrs_hash = Copy(atrs_hash);
|
||||
return rv;
|
||||
}
|
||||
public int Name_id() {return name_id;} private int name_id;
|
||||
public boolean Tid_is_comment() {return name_id == Gfh_tag_.Id__comment;}
|
||||
public byte[] Name_bry() {return name_bry;} private byte[] name_bry;
|
||||
public Gfh_tag Chk_name_or_fail(int chk) {
|
||||
if (!Chk_name(chk)) tag_rdr.Err_wkr().Fail("name_id chk failed", "expecting", Gfh_tag_.To_str(chk));
|
||||
return this;
|
||||
}
|
||||
public boolean Chk_name(int chk) {
|
||||
return ( chk == name_id
|
||||
|| (name_id != Gfh_tag_.Id__eos && Int_.In(chk, Gfh_tag_.Id__any, Gfh_tag_.Id__comment)));
|
||||
}
|
||||
public boolean Chk(int chk_name, byte[] chk_cls) {return name_id == chk_name && Atrs__cls_has(chk_cls);}
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public boolean Src_exists() {return src_end > src_bgn;} // NOTE: only true if EOS where src_end == src_bgn == src_len
|
||||
public boolean Tag_is_tail() {return tag_is_tail;} private boolean tag_is_tail;
|
||||
public boolean Tag_is_inline() {return tag_is_inline;} private boolean tag_is_inline;
|
||||
public Ordered_hash Atrs__hash() {if (atrs_null) Atrs__make(); return atrs_hash;}
|
||||
public int Atrs__len() {if (atrs_null) Atrs__make(); return atrs_hash.Count();}
|
||||
public boolean Atrs__match_pair(byte[] key, byte[] val) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key);
|
||||
return rv == null ? false : Bry_.Eq(val, rv.Val());
|
||||
}
|
||||
public boolean Atrs__cls_has(byte[] val) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__class); if (rv == null) return false;
|
||||
byte[] rv_val = rv.Val();
|
||||
return Gfh_class_.Has(rv_val, 0, rv_val.length, val);
|
||||
}
|
||||
public boolean Atrs__cls_eq(byte[] val) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__class); if (rv == null) return false;
|
||||
return Bry_.Eq(val, rv.Val());
|
||||
}
|
||||
public byte Atrs__cls_find_or_fail(Hash_adp_bry hash) {
|
||||
byte rv = Atrs__cls_find_or(hash, Byte_.Max_value_127); if (rv == Byte_.Max_value_127) tag_rdr.Err_wkr().Fail("cls missing");
|
||||
return rv;
|
||||
}
|
||||
public byte Atrs__cls_find_or(Hash_adp_bry hash, byte or) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr cls_atr = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__class); if (cls_atr == null) return or;
|
||||
byte rv = Gfh_class_.Find_1st(src, cls_atr.Val_bgn(), cls_atr.Val_end(), hash); if (rv == Byte_.Max_value_127) return or;
|
||||
return rv;
|
||||
}
|
||||
public int Atrs__style_get_as_int(byte[] key) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__style); if (rv == null) return -1;
|
||||
byte[] rv_val = rv.Val();
|
||||
return style_wkr.Parse(rv_val, 0, rv_val.length, key);
|
||||
}
|
||||
public boolean Atrs__has(byte[] key) {
|
||||
if (atrs_null) Atrs__make();
|
||||
return atrs_hash.Get_by(key) != null;
|
||||
}
|
||||
public byte[] Atrs__get_as_bry(byte[] key) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key);
|
||||
return rv == null ? Bry_.Empty : rv.Val();
|
||||
}
|
||||
public int Atrs__get_as_int(byte[] key) {
|
||||
int rv = Atrs__get_as_int_or(key, Int_.Min_value); if (rv == Int_.Min_value) tag_rdr.Err_wkr().Fail("atr missing", "key", key);
|
||||
return rv;
|
||||
}
|
||||
public int Atrs__get_as_int_or(byte[] key, int or) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key); if (rv == null) return or;
|
||||
return Bry_.To_int_or(src, rv.Val_bgn(), rv.Val_end(), or);
|
||||
}
|
||||
public double Atrs__get_as_double_or(byte[] key, double or) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key); if (rv == null) return or;
|
||||
return Bry_.To_double_or(src, rv.Val_bgn(), rv.Val_end(), or);
|
||||
}
|
||||
public Gfh_atr Atrs__get_at(int i) {return (Gfh_atr)atrs_hash.Get_at(i);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.Y);}
|
||||
public Gfh_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.N);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key, boolean fail_if_null) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key);
|
||||
if (rv == null) {
|
||||
if (fail_if_null) tag_rdr.Err_wkr().Fail("atr missing", "key", key);
|
||||
else return Gfh_atr.Noop;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public String Atrs__print() {
|
||||
if (atrs_null) Atrs__make();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = atrs_hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfh_atr atr = (Gfh_atr)atrs_hash.Get_at(i);
|
||||
bfr.Add(atr.Key()).Add_byte_eq().Add(atr.Val()).Add_byte_nl();
|
||||
}
|
||||
return bfr.To_str();
|
||||
}
|
||||
private void Atrs__make() {
|
||||
atrs_null = false;
|
||||
if (atrs_hash == null) atrs_hash = Ordered_hash_.New_bry();
|
||||
else atrs_hash.Clear();
|
||||
tag_rdr.Atrs__make(this, atrs_bgn, atrs_end);
|
||||
}
|
||||
public void On_atr_each (Mwh_atr_parser mgr, byte[] src, int nde_tid, boolean valid, boolean repeated, boolean key_exists, byte[] key_bry, byte[] val_bry_manual, int[] itm_ary, int itm_idx) {
|
||||
if (!valid) return;
|
||||
byte[] val_bry = val_bry_manual;
|
||||
int val_bgn = -1, val_end = -1;
|
||||
int atr_bgn = itm_ary[itm_idx + Mwh_atr_mgr.Idx_atr_bgn];
|
||||
int atr_end = itm_ary[itm_idx + Mwh_atr_mgr.Idx_atr_end];
|
||||
if (key_exists) {
|
||||
val_bgn = itm_ary[itm_idx + Mwh_atr_mgr.Idx_val_bgn];
|
||||
val_end = itm_ary[itm_idx + Mwh_atr_mgr.Idx_val_end];
|
||||
}
|
||||
else
|
||||
val_bry = key_bry;
|
||||
Gfh_atr atr = new Gfh_atr(atrs_hash.Count(), atr_bgn, atr_end, key_bry, val_bry, src, val_bgn, val_end);
|
||||
atrs_hash.Add(key_bry, atr);
|
||||
}
|
||||
private static Ordered_hash Copy(Ordered_hash src) {
|
||||
Ordered_hash rv = Ordered_hash_.New();
|
||||
int len = src.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfh_atr atr = (Gfh_atr)src.Get_at(i);
|
||||
rv.Add(atr.Key(), atr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
360
400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr.java
Normal file
360
400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr.java
Normal file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
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.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.htmls.*;
|
||||
public class Gfh_tag_rdr {
|
||||
private final Hash_adp_bry name_hash;
|
||||
private final Mwh_atr_parser atr_parser = new Mwh_atr_parser();
|
||||
private final Gfh_tag tag__tmp__move = new Gfh_tag(), tag__tmp__peek = new Gfh_tag(), tag__eos = new Gfh_tag(), tag__comment = new Gfh_tag();
|
||||
private final Int_obj_ref tmp_depth = Int_obj_ref.New_zero();
|
||||
Gfh_tag_rdr(Hash_adp_bry name_hash) {this.name_hash = name_hash;}
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public Bry_err_wkr Err_wkr() {return err_wkr;} private final Bry_err_wkr err_wkr = new Bry_err_wkr();
|
||||
public Gfh_tag_rdr Reg(String tag_name, int tag_id) {name_hash.Add_str_int(tag_name, tag_id); return this;}
|
||||
public void Init(byte[] ctx_name, byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.pos = src_bgn; this.src_end = src_end;
|
||||
tag__eos.Init(this, src, Bool_.N, Bool_.N, src_end, src_end, src_end, src_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
err_wkr.Init_by_page(String_.new_u8(ctx_name), src);
|
||||
}
|
||||
public void Src_rng_(int src_bgn, int src_end) {
|
||||
this.pos = src_bgn; this.src_end = src_end;
|
||||
}
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public void Pos_(int v) {this.pos = v;}
|
||||
public void Atrs__make(Mwh_atr_wkr atr_wkr, int head_bgn, int head_end) {atr_parser.Parse(atr_wkr, -1, -1, src, head_bgn, head_end);}
|
||||
public Gfh_tag Tag__move_fwd_head() {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__move_fwd_head(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__move_fwd_tail(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_head() {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__peek_fwd_head(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_head() {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__find_fwd_head(int bgn, int end, int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, bgn, end, match_name_id);}
|
||||
private Gfh_tag Tag__find(boolean move, boolean bwd, boolean tail, int rng_bgn, int rng_end, int match_name_id) {
|
||||
int tmp = rng_bgn;
|
||||
int stop_pos = rng_end; int adj = 1;
|
||||
if (bwd) {
|
||||
stop_pos = -1;
|
||||
adj = -1;
|
||||
--tmp; // subtract 1 from tmp; needed when pos is at src_len, else array error below
|
||||
}
|
||||
tmp_depth.Val_zero_();
|
||||
Gfh_tag rv = null;
|
||||
while (tmp != stop_pos) {
|
||||
if (src[tmp] == Byte_ascii.Angle_bgn) {
|
||||
rv = Tag__extract(move, tail, match_name_id, tmp);
|
||||
if (rv.Name_id() == Gfh_tag_.Id__comment) { // ignore comments DATE:2016-06-25
|
||||
tmp = rv.Src_end();
|
||||
rv = null; // null rv, else rv will still be comment and may get returned to caller
|
||||
continue;
|
||||
}
|
||||
if (Tag__match(move, bwd, tail, match_name_id, tmp_depth, rv))
|
||||
break;
|
||||
else {
|
||||
tmp = bwd ? rv.Src_bgn() - 1 : rv.Src_end();
|
||||
rv = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
tmp += adj;
|
||||
}
|
||||
if (rv == null) {
|
||||
if (move && tail && !bwd)
|
||||
err_wkr.Fail("move tag fwd failed", "tag_name", Gfh_tag_.To_str(match_name_id));
|
||||
else
|
||||
return Tag__eos(rng_bgn);
|
||||
}
|
||||
if (move) pos = rv.Src_end();
|
||||
return rv;
|
||||
}
|
||||
private boolean Tag__match(boolean move, boolean bwd, boolean tail, int match_name_id, Int_obj_ref depth_obj, Gfh_tag tag) {
|
||||
int tag_name_id = tag.Name_id();
|
||||
if ( tag_name_id != match_name_id // tag doesn't match requested
|
||||
&& match_name_id != Gfh_tag_.Id__any // requested is not wildcard
|
||||
) return false;
|
||||
if (tag_name_id == Gfh_tag_.Id__comment) return true; // ignore comments
|
||||
int depth = depth_obj.Val();
|
||||
boolean tag_is_tail = tag.Tag_is_tail();
|
||||
if (tail == tag_is_tail) {
|
||||
if (depth == 0)
|
||||
return true;
|
||||
else {
|
||||
if (match_name_id == tag_name_id)
|
||||
depth_obj.Val_add(-1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!bwd && tail && !tag_is_tail && !tag.Tag_is_inline()) {
|
||||
if (match_name_id == tag_name_id)
|
||||
depth_obj.Val_add(1);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Gfh_tag Tag__move_fwd_tail(byte[] find_tag_bry) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, pos, src_end, find_tag_bry);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(byte[] find_tag_bry) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, pos, src_end, find_tag_bry);}
|
||||
private Gfh_tag Tag__find(boolean move, boolean bwd, boolean tail, int rng_bgn, int rng_end, byte[] find_tag_bry) {
|
||||
int tmp = rng_bgn;
|
||||
int stop_pos = rng_end; int adj = 1;
|
||||
if (bwd) {
|
||||
stop_pos = -1;
|
||||
adj = -1;
|
||||
--tmp; // subtract 1 from tmp; needed when pos is at src_len, else array error below
|
||||
}
|
||||
tmp_depth.Val_zero_();
|
||||
Gfh_tag rv = null;
|
||||
while (tmp != stop_pos) {
|
||||
if (src[tmp] == Byte_ascii.Angle_bgn) {
|
||||
rv = Tag__extract(move, tail, find_tag_bry, tmp);
|
||||
if (Bry_.Eq(rv.Name_bry(), Gfh_tag_.Bry__xowa_comment)) { // ignore comments DATE:2016-06-25
|
||||
tmp = rv.Src_end();
|
||||
rv = null; // null rv, else rv will still be comment and may get returned to caller
|
||||
continue;
|
||||
}
|
||||
if (Tag__match(move, bwd, tail, find_tag_bry, tmp_depth, rv))
|
||||
break;
|
||||
else {
|
||||
tmp = bwd ? rv.Src_bgn() - 1 : rv.Src_end();
|
||||
rv = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
tmp += adj;
|
||||
}
|
||||
if (rv == null) {
|
||||
if (move && tail && !bwd)
|
||||
err_wkr.Fail("move tag fwd failed", "tag_name", find_tag_bry);
|
||||
else
|
||||
return Tag__eos(rng_bgn);
|
||||
}
|
||||
if (move) pos = rv.Src_end();
|
||||
return rv;
|
||||
}
|
||||
private boolean Tag__match(boolean move, boolean bwd, boolean tail, byte[] find_tag_bry, Int_obj_ref depth_obj, Gfh_tag tag) {
|
||||
byte[] cur_tag_bry = tag.Name_bry();
|
||||
if ( !Bry_.Eq(cur_tag_bry, find_tag_bry) // tag doesn't match requested
|
||||
&& find_tag_bry != Gfh_tag_.Bry__xowa_any // requested is not wildcard
|
||||
) return false;
|
||||
if (cur_tag_bry == Gfh_tag_.Bry__xowa_comment) return true; // ignore comments
|
||||
int depth = depth_obj.Val();
|
||||
boolean tag_is_tail = tag.Tag_is_tail();
|
||||
if (tail == tag_is_tail) {
|
||||
if (depth == 0)
|
||||
return true;
|
||||
else {
|
||||
if (Bry_.Eq(cur_tag_bry, find_tag_bry))
|
||||
depth_obj.Val_add(-1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!bwd && tail && !tag_is_tail && !tag.Tag_is_inline()) {
|
||||
if (Bry_.Eq(cur_tag_bry, find_tag_bry))
|
||||
depth_obj.Val_add(1);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Gfh_tag Tag__extract(boolean move, boolean tail, byte[] find_tag_bry, int tag_bgn) {
|
||||
int name_bgn = tag_bgn + 1; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "<EOS"
|
||||
byte name_0 = src[name_bgn];
|
||||
boolean cur_is_tail = false;
|
||||
switch (name_0) {
|
||||
case Byte_ascii.Bang:
|
||||
if (Bry_.Match(src, name_bgn + 1, name_bgn + 3, Bry__comment__mid)) // skip comment; EX: "<!"
|
||||
return Tag__comment(tag_bgn);
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
++name_bgn; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "</EOS"
|
||||
name_0 = src[name_bgn];
|
||||
cur_is_tail = true;
|
||||
break;
|
||||
}
|
||||
int name_end = -1, atrs_end = -1, tag_end = -1, name_pos = name_bgn;
|
||||
byte name_byte = name_0; boolean inline = false;
|
||||
boolean loop = true;
|
||||
while (true) {
|
||||
switch (name_byte) {
|
||||
case Byte_ascii.Angle_end: // EX: "<a>"
|
||||
name_end = atrs_end = name_pos;
|
||||
tag_end = name_end + 1;
|
||||
loop = false;
|
||||
break;
|
||||
case Byte_ascii.Slash: // EX: "<a/>"
|
||||
name_end = name_pos;
|
||||
tag_end = name_pos + 1; if (tag_end == src_end) return Tag__eos(tag_bgn);// EX: "<a/EOS"
|
||||
if (src[tag_end] == Byte_ascii.Angle_end) {
|
||||
atrs_end = name_end;
|
||||
inline = true;
|
||||
loop = false;
|
||||
++tag_end; // move tag_end after >
|
||||
}
|
||||
else {
|
||||
name_end = tag_end = -1;
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
name_end = name_pos;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
if (!loop) break;
|
||||
++name_pos; if (name_pos == src_end) return Tag__eos(tag_bgn); // EX: "<abEOS"
|
||||
name_byte = src[name_pos];
|
||||
}
|
||||
if (tag_end == -1) {
|
||||
tag_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, src_end);
|
||||
if (tag_end == Bry_find_.Not_found) return Tag__eos(tag_bgn);
|
||||
int prv_pos = tag_end - 1;
|
||||
if (src[prv_pos] == Byte_ascii.Slash) {
|
||||
atrs_end = prv_pos;
|
||||
inline = true;
|
||||
}
|
||||
else
|
||||
atrs_end = tag_end;
|
||||
++tag_end; // position after ">"
|
||||
}
|
||||
Gfh_tag tmp = move ? tag__tmp__move : tag__tmp__peek;
|
||||
return tmp.Init(this, src, cur_is_tail, inline, tag_bgn, tag_end, name_end, atrs_end, Gfh_tag_.Id__unknown, Bry_.Mid(src, name_bgn, name_end));
|
||||
}
|
||||
public Gfh_tag Tag__extract(boolean move, boolean tail, int match_name_id, int tag_bgn) {
|
||||
int name_bgn = tag_bgn + 1; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "<EOS"
|
||||
byte name_0 = src[name_bgn];
|
||||
boolean cur_is_tail = false;
|
||||
switch (name_0) {
|
||||
case Byte_ascii.Bang:
|
||||
if (Bry_.Match(src, name_bgn + 1, name_bgn + 3, Bry__comment__mid)) // skip comment; EX: "<!"
|
||||
return Tag__comment(tag_bgn);
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
++name_bgn; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "</EOS"
|
||||
name_0 = src[name_bgn];
|
||||
cur_is_tail = true;
|
||||
break;
|
||||
}
|
||||
int name_end = -1, atrs_end = -1, tag_end = -1, name_pos = name_bgn;
|
||||
byte name_byte = name_0; boolean inline = false;
|
||||
boolean loop = true;
|
||||
while (true) {
|
||||
switch (name_byte) {
|
||||
case Byte_ascii.Angle_end: // EX: "<a>"
|
||||
name_end = atrs_end = name_pos;
|
||||
tag_end = name_end + 1;
|
||||
loop = false;
|
||||
break;
|
||||
case Byte_ascii.Slash: // EX: "<a/>"
|
||||
name_end = name_pos;
|
||||
tag_end = name_pos + 1; if (tag_end == src_end) return Tag__eos(tag_bgn);// EX: "<a/EOS"
|
||||
if (src[tag_end] == Byte_ascii.Angle_end) {
|
||||
atrs_end = name_end;
|
||||
inline = true;
|
||||
loop = false;
|
||||
++tag_end; // move tag_end after >
|
||||
}
|
||||
else {
|
||||
name_end = tag_end = -1;
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
name_end = name_pos;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
if (!loop) break;
|
||||
++name_pos; if (name_pos == src_end) return Tag__eos(tag_bgn); // EX: "<abEOS"
|
||||
name_byte = src[name_pos];
|
||||
}
|
||||
if (tag_end == -1) {
|
||||
tag_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, src_end);
|
||||
if (tag_end == Bry_find_.Not_found) return Tag__eos(tag_bgn);
|
||||
int prv_pos = tag_end - 1;
|
||||
if (src[prv_pos] == Byte_ascii.Slash) {
|
||||
atrs_end = prv_pos;
|
||||
inline = true;
|
||||
}
|
||||
else
|
||||
atrs_end = tag_end;
|
||||
++tag_end; // position after ">"
|
||||
}
|
||||
Gfh_tag tmp = move ? tag__tmp__move : tag__tmp__peek;
|
||||
return tmp.Init(this, src, cur_is_tail, inline, tag_bgn, tag_end, name_end, atrs_end
|
||||
, name_hash.Get_as_int_or(src, name_bgn, name_end, -1) // TODO_OLD: change from -1 to Unknown
|
||||
, Bry_.Mid(src, name_bgn, name_end));
|
||||
}
|
||||
public boolean Read_and_move(byte match) {
|
||||
byte b = src[pos];
|
||||
if (b == match) {
|
||||
++pos;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int rv = Read_int_to(to_char, Int_.Max_value); if (rv == Int_.Max_value) err_wkr.Fail("invalid int", "pos", pos);
|
||||
return rv;
|
||||
}
|
||||
public int Read_int_to(byte to_char, int or_int) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
int negative = 1;
|
||||
while (pos < src_end) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
if (negative == -1) // 2nd negative
|
||||
return or_int; // return or_int
|
||||
else // 1st negative
|
||||
negative = -1; // flag negative
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
return match ? rv * negative : or_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bgn == pos ? or_int : rv * negative;
|
||||
}
|
||||
private Gfh_tag Tag__comment(int tag_bgn) {
|
||||
int tag_end = Bry_find_.Move_fwd(src, gplx.langs.htmls.Gfh_tag_.Comm_end, tag_bgn, src_end); if (tag_end == Bry_find_.Not_found) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__comment, Bry_.Empty);
|
||||
}
|
||||
private Gfh_tag Tag__eos(int tag_bgn) {
|
||||
int tag_end = tag_bgn + 255; if (tag_end > src_end) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
}
|
||||
private static final byte[] Bry__comment__mid = Bry_.new_a7("--");
|
||||
public static Gfh_tag_rdr New__html() {return new Gfh_tag_rdr(Gfh_tag_.Hash);}
|
||||
public static Gfh_tag_rdr New__custom() {return new Gfh_tag_rdr(Hash_adp_bry.cs());}
|
||||
}
|
||||
80
400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr_tst.java
Normal file
80
400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr_tst.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
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.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Gfh_tag_rdr_tst {
|
||||
private final Gfh_tag_rdr_fxt fxt = new Gfh_tag_rdr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init("1<div id='1'>2</div>3<div id='2'>4</div>5<div id='3'>6</div>7");
|
||||
fxt.Test__move_fwd_head("<div id='1'>"); fxt.Test__pos("2");
|
||||
fxt.Test__peek_fwd_head("<div id='2'>"); fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_head("<div id='2'>"); fxt.Test__pos("4");
|
||||
fxt.Test__peek_bwd_tail("</div>3") ; fxt.Test__pos("4");
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Init("1<!--2-->3<!--4-->5<div id='1'>6</div>");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__any , "<div id='1'>") ; fxt.Test__pos("6");
|
||||
}
|
||||
@Test public void Meta() {
|
||||
fxt.Init("<!DOCTYPE html>1<div id='1'>2</div>3");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "<div id='1'>") ; fxt.Test__pos("2");
|
||||
}
|
||||
@Test public void Recursive__same_tags() {
|
||||
fxt.Init("1<a>2<a>3</a>4</a>5");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__a , "<a>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_tail(Gfh_tag_.Id__a , "</a>") ; fxt.Test__pos("5");
|
||||
}
|
||||
@Test public void Recursive__diff_tags() {
|
||||
fxt.Init("1<div>2<a>3<img/>4</a>5</div>6");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "<div>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_tail(Gfh_tag_.Id__div , "</div>") ; fxt.Test__pos("6");
|
||||
}
|
||||
@Test public void Inline() {
|
||||
fxt.Init("1<br/>2");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__br , "<br/>") ; fxt.Test__pos("2");
|
||||
}
|
||||
}
|
||||
class Gfh_tag_rdr_fxt {
|
||||
private final Gfh_tag_rdr rdr = Gfh_tag_rdr.New__html();
|
||||
public void Init(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
rdr.Init(Bry_.Empty, src_bry, 0, src_bry.length);
|
||||
}
|
||||
public void Test__move_fwd_head(String expd) {Test__move_fwd_head(Gfh_tag_.Id__any, expd);}
|
||||
public void Test__move_fwd_head(int match_name_id, String expd) {
|
||||
Gfh_tag actl_tag = rdr.Tag__move_fwd_head(match_name_id).Chk_name_or_fail(match_name_id);
|
||||
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
|
||||
}
|
||||
public void Test__move_fwd_tail(int match_name_id, String expd) {
|
||||
Gfh_tag actl_tag = rdr.Tag__move_fwd_tail(match_name_id);
|
||||
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
|
||||
}
|
||||
public void Test__peek_fwd_head(String expd) {
|
||||
Gfh_tag actl_tag = rdr.Tag__peek_fwd_head();
|
||||
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
|
||||
}
|
||||
public void Test__peek_bwd_tail(String expd_str) {
|
||||
byte[] expd_bry = Bry_.new_u8(expd_str);
|
||||
Gfh_tag actl_tag = rdr.Tag__peek_bwd_tail(-1);
|
||||
Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_bgn() + expd_bry.length));
|
||||
}
|
||||
public void Test__pos(String expd_str) {
|
||||
byte[] expd_bry = Bry_.new_u8(expd_str);
|
||||
Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), rdr.Pos(), rdr.Pos() + expd_bry.length));
|
||||
}
|
||||
}
|
||||
21
400_xowa/src/gplx/langs/htmls/docs/Gfh_txt_wkr.java
Normal file
21
400_xowa/src/gplx/langs/htmls/docs/Gfh_txt_wkr.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_txt_wkr {
|
||||
void Parse(int rng_bgn, int rng_end);
|
||||
}
|
||||
Reference in New Issue
Block a user