1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,34 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.texts.*; /*CharStream*/
public interface GfmlLxr extends Gfo_evt_itm {
String Key();
String[] Hooks();
GfmlTkn CmdTkn();
void CmdTkn_set(GfmlTkn val); // needed for lxr pragma
GfmlTkn MakeTkn(CharStream stream, int hookLength);
GfmlLxr SubLxr();
void SubLxr_Add(GfmlLxr... lexer);
}
class GfmlLxrRegy {
public int Count() {return hash.Count();}
public void Add(GfmlLxr lxr) {hash.Add(lxr.Key(), lxr);}
public GfmlLxr Get_by(String key) {return (GfmlLxr)hash.Get_by(key);}
Hash_adp hash = Hash_adp_.New();
}

View File

@@ -1,217 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
import gplx.core.texts.*; /*CharStream*/
public class GfmlLxr_ {
public static GfmlLxr general_(String key, GfmlTkn protoTkn) {return GfmlLxr_general.new_(key, protoTkn);}
public static GfmlLxr solo_(String key, GfmlTkn singletonTkn) {return GfmlLxr_singleton.new_(key, singletonTkn.Raw(), singletonTkn);}
public static GfmlLxr range_(String key, String[] ary, GfmlTkn protoTkn, boolean ignoreOutput) {return GfmlLxr_group.new_(key, ary, protoTkn, ignoreOutput);}
@gplx.Internal protected static GfmlLxr symbol_(String key, String raw, String val, GfmlBldrCmd cmd) {
GfmlTkn tkn = GfmlTkn_.singleton_(key, raw, val, cmd);
return GfmlLxr_.solo_(key, tkn);
}
@gplx.Internal protected static GfmlLxr frame_(String key, GfmlFrame frame, String bgn, String end) {return GfmlLxr_frame.new_(key, frame, bgn, end, GfmlBldrCmd_pendingTkns_add.Instance, GfmlBldrCmd_frameEnd.data_());}
public static final GfmlLxr Null = new GfmlLxr_null();
public static final String CmdTknChanged_evt = "Changed";
public static GfmlLxr as_(Object obj) {return obj instanceof GfmlLxr ? (GfmlLxr)obj : null;}
public static GfmlLxr cast(Object obj) {try {return (GfmlLxr)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfmlLxr.class, obj);}}
}
class GfmlLxr_null implements GfmlLxr {
public String Key() {return "gfml.nullLxr";}
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;}
public GfmlTkn CmdTkn() {return GfmlTkn_.Null;} public void CmdTkn_set(GfmlTkn val) {}
public String[] Hooks() {return String_.Ary_empty;}
public GfmlTkn MakeTkn(CharStream stream, int hookLength) {return GfmlTkn_.Null;}
public void SubLxr_Add(GfmlLxr... lexer) {}
public GfmlLxr SubLxr() {return this;}
}
class GfmlLxr_singleton implements GfmlLxr, Gfo_evt_itm {
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;}
public String Key() {return key;} private String key;
public GfmlTkn CmdTkn() {return singletonTkn;} GfmlTkn singletonTkn;
public void CmdTkn_set(GfmlTkn val) {
String oldRaw = singletonTkn.Raw();
singletonTkn = val;
hooks = String_.Ary(val.Raw());
Gfo_evt_mgr_.Pub_vals(this, GfmlLxr_.CmdTknChanged_evt, Keyval_.new_("old", oldRaw), Keyval_.new_("new", val.Raw()), Keyval_.new_("lxr", this));
}
public String[] Hooks() {return hooks;} private String[] hooks;
public GfmlTkn MakeTkn(CharStream stream, int hookLength) {
stream.MoveNextBy(hookLength);
return singletonTkn;
}
public GfmlLxr SubLxr() {return subLxr;} GfmlLxr subLxr;
public void SubLxr_Add(GfmlLxr... lexer) {subLxr.SubLxr_Add(lexer);}
public static GfmlLxr_singleton new_(String key, String hook, GfmlTkn singletonTkn) {
GfmlLxr_singleton rv = new GfmlLxr_singleton();
rv.ctor_(key, hook, singletonTkn, GfmlLxr_.Null);
return rv;
} protected GfmlLxr_singleton() {}
@gplx.Internal protected void ctor_(String key, String hook, GfmlTkn singletonTkn, GfmlLxr subLxr) {
this.key = key;
this.hooks = String_.Ary(hook);
this.subLxr = subLxr;
this.singletonTkn = singletonTkn;
}
}
class GfmlLxr_group implements GfmlLxr {
public String Key() {return key;} private String key;
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;}
public GfmlTkn CmdTkn() {return outputTkn;} public void CmdTkn_set(GfmlTkn val) {} GfmlTkn outputTkn;
public String[] Hooks() {return trie.Symbols();}
public GfmlTkn MakeTkn(CharStream stream, int hookLength) {
while (stream.AtMid()) {
if (!ignoreOutput)
sb.Add_mid(stream.Ary(), stream.Pos(), hookLength);
stream.MoveNextBy(hookLength);
String found = String_.cast(trie.FindMatch(stream));
if (found == null) break;
hookLength = trie.LastMatchCount;
}
if (ignoreOutput) return GfmlTkn_.IgnoreOutput;
String raw = sb.To_str_and_clear();
return outputTkn.MakeNew(raw, raw);
}
public GfmlLxr SubLxr() {throw Err_sublxr();}
public void SubLxr_Add(GfmlLxr... lexer) {throw Err_sublxr();}
Err Err_sublxr() {return Err_.new_unimplemented_w_msg("group lxr does not have subLxrs", "key", key, "output_tkn", outputTkn.Raw()).Trace_ignore_add_1_();}
GfmlTrie trie = GfmlTrie.new_(); String_bldr sb = String_bldr_.new_(); boolean ignoreOutput;
public static GfmlLxr_group new_(String key, String[] hooks, GfmlTkn outputTkn, boolean ignoreOutput) {
GfmlLxr_group rv = new GfmlLxr_group();
rv.key = key;
for (String hook : hooks)
rv.trie.Add(hook, hook);
rv.outputTkn = outputTkn; rv.ignoreOutput = ignoreOutput;
return rv;
} GfmlLxr_group() {}
}
class GfmlLxr_general implements GfmlLxr, Gfo_invk {
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public String Key() {return key;} private String key;
public GfmlTkn CmdTkn() {return txtTkn;} public void CmdTkn_set(GfmlTkn val) {} GfmlTkn txtTkn;
public String[] Hooks() {return symTrie.Symbols();}
public GfmlTkn MakeTkn(CharStream stream, int firstTknLength) {
GfmlTkn rv = null;
if (symLxr != null) { // symLxr has something; produce
rv = MakeTkn_symLxr(stream);
if (rv != GfmlTkn_.IgnoreOutput) return rv;
}
while (stream.AtMid()) { // keep moving til (a) symChar or (b) endOfStream
Object result = symTrie.FindMatch(stream);
symTknLen = symTrie.LastMatchCount;
if (result == null) { // no match; must be txtChar;
txtBfr.Add(stream);
stream.MoveNext();
}
else { // symChar
symLxr = (GfmlLxr)result; // set symLxr for next pass
if (txtBfr.Has()) // txtBfr has something: gen txtTkn
rv = txtBfr.MakeTkn(stream, txtTkn);
else { // txtBfr empty: gen symbol
rv = MakeTkn_symLxr(stream);
if (rv == GfmlTkn_.IgnoreOutput) continue;
}
return rv;
}
}
if (txtBfr.Has()) // endOfStream, but txtBfr has chars
return txtBfr.MakeTkn(stream, txtTkn);
return GfmlTkn_.EndOfStream;
}
public void SubLxr_Add(GfmlLxr... lxrs) {
for (GfmlLxr lxr : lxrs) {
for (String hook : lxr.Hooks())
symTrie.Add(hook, lxr);
Gfo_evt_mgr_.Sub_same(lxr, GfmlLxr_.CmdTknChanged_evt, this);
}
}
public GfmlLxr SubLxr() {return this;}
GfmlTkn MakeTkn_symLxr(CharStream stream) {
GfmlLxr lexer = symLxr; symLxr = null;
int length = symTknLen; symTknLen = 0;
return lexer.MakeTkn(stream, length);
}
GfmlLxr_general_txtBfr txtBfr = new GfmlLxr_general_txtBfr(); GfmlTrie symTrie = GfmlTrie.new_(); GfmlLxr symLxr; int symTknLen;
@gplx.Internal protected static GfmlLxr_general new_(String key, GfmlTkn txtTkn) {
GfmlLxr_general rv = new GfmlLxr_general();
rv.key = key; rv.txtTkn = txtTkn;
return rv;
} protected GfmlLxr_general() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, GfmlLxr_.CmdTknChanged_evt)) {
symTrie.Del(m.ReadStr("old"));
symTrie.Add(m.ReadStr("new"), m.CastObj("lxr"));
}
else return Gfo_invk_.Rv_unhandled;
return this;
}
}
class GfmlLxr_general_txtBfr {
public int Bgn = NullPos;
public int Len;
public boolean Has() {return Bgn != NullPos;}
public void Add(CharStream stream) {
if (Bgn == NullPos) Bgn = stream.Pos();
Len++;
} static final int NullPos = -1;
public GfmlTkn MakeTkn(CharStream stream, GfmlTkn textTkn) {
String raw = String_.new_charAry_(stream.Ary(), Bgn, Len);
Bgn = -1; Len = 0;
return textTkn.MakeNew(raw, raw);
}
}
class GfmlLxr_frame extends GfmlLxr_singleton { GfmlFrame frame; GfmlLxr endLxr, txtLxr;
public void BgnRaw_set(String val) {// needed for lxr pragma
GfmlBldrCmd_frameBgn bgnCmd = GfmlBldrCmd_frameBgn.new_(frame, txtLxr);
GfmlTkn bgnTkn = GfmlTkn_.singleton_(this.Key() + "_bgn", val, GfmlTkn_.NullVal, bgnCmd);
this.CmdTkn_set(bgnTkn);
}
public void EndRaw_set(String val) {// needed for lxr pragma
GfmlBldrCmd_frameEnd endCmd = GfmlBldrCmd_frameEnd.data_();
GfmlTkn endTkn = GfmlTkn_.singleton_(this.Key() + "_end", val, GfmlTkn_.NullVal, endCmd);
endLxr.CmdTkn_set(endTkn);
}
public static GfmlLxr new_(String key, GfmlFrame frame, String bgn, String end, GfmlBldrCmd txtCmd, GfmlBldrCmd endCmd) {
GfmlLxr_frame rv = new GfmlLxr_frame();
GfmlTkn txtTkn = frame.FrameType() == GfmlFrame_.Type_comment
? GfmlTkn_.valConst_(key + "_txt", GfmlTkn_.NullVal, txtCmd)
: GfmlTkn_.cmd_(key + "_txt", txtCmd)
;
GfmlLxr txtLxr = GfmlLxr_.general_(key + "_txt", txtTkn);
GfmlTkn bgnTkn = GfmlTkn_.singleton_(key + "_bgn", bgn, GfmlTkn_.NullVal, GfmlBldrCmd_frameBgn.new_(frame, txtLxr));
rv.ctor_(key, bgn, bgnTkn, txtLxr);
GfmlTkn endTkn = GfmlTkn_.singleton_(key + "_end", end, GfmlTkn_.NullVal, endCmd);
GfmlLxr endLxr = GfmlLxr_.solo_(key + "_end", endTkn);
rv.SubLxr_Add(endLxr);
rv.frame = frame;
rv.endLxr = endLxr;
rv.txtLxr = txtLxr;
return rv;
} GfmlLxr_frame() {}
public static GfmlLxr_frame as_(Object obj) {return obj instanceof GfmlLxr_frame ? (GfmlLxr_frame)obj : null;}
public static GfmlLxr_frame cast(Object obj) {try {return (GfmlLxr_frame)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfmlLxr_frame.class, obj);}}
}

View File

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

View File

@@ -1,25 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlObjList extends List_adp_base {
@gplx.New public GfmlObj Get_at(int idx) {return (GfmlObj)Get_at_base(idx);}
public void Add(GfmlObj tkn) {Add_base(tkn);}
public void Add_at(GfmlObj tkn, int idx) {super.AddAt_base(idx, tkn);}
public void Del(GfmlObj tkn) {Del_base(tkn);}
public static GfmlObjList new_() {return new GfmlObjList();} GfmlObjList() {}
}

View File

@@ -1,46 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
public interface GfmlTkn extends GfmlObj {
String TknType();
String Raw();
String Val();
GfmlTkn[] SubTkns();
GfmlBldrCmd Cmd_of_Tkn();
GfmlTkn MakeNew(String raw, String val);
}
class GfmlTknAry_ {
public static final GfmlTkn[] Empty = new GfmlTkn[0];
public static GfmlTkn[] ary_(GfmlTkn... ary) {return ary;}
@gplx.Internal protected static String XtoRaw(GfmlTkn[] ary) {
String_bldr sb = String_bldr_.new_();
for (GfmlTkn tkn : ary)
sb.Add(tkn.Raw());
return sb.To_str();
}
@gplx.Internal protected static String XtoVal(GfmlTkn[] ary) {return XtoVal(ary, 0, ary.length);}
static String XtoVal(GfmlTkn[] ary, int bgn, int end) {
String_bldr sb = String_bldr_.new_();
for (int i = bgn; i < end; i++) {
GfmlTkn tkn = ary[i];
sb.Add(tkn.Val());
}
return sb.To_str();
}
}

View File

@@ -1,65 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlTkn_ {
@gplx.Internal protected static final String NullRaw = "", NullVal = ""; static final String Type_base = "gfml.baseTkn";
@gplx.Internal protected static final GfmlTkn
Null = new GfmlTkn_base().ctor_GfmlTkn_base("gfml.nullTkn", NullRaw, NullVal, GfmlBldrCmd_.Null)
, EndOfStream = GfmlTkn_.raw_("<<End Of Stream>>")
, IgnoreOutput = GfmlTkn_.raw_("<<Ignore Output>>");
public static GfmlTkn as_(Object obj) {return obj instanceof GfmlTkn ? (GfmlTkn)obj : null;}
@gplx.Internal protected static GfmlTkn new_(String raw, String val) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, raw, val, GfmlBldrCmd_.Null);}
public static GfmlTkn raw_(String raw) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, raw, raw, GfmlBldrCmd_.Null);}
@gplx.Internal protected static GfmlTkn val_(String val) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, NullRaw, val, GfmlBldrCmd_.Null);}
@gplx.Internal protected static GfmlTkn cmd_(String tknType, GfmlBldrCmd cmd) {return new GfmlTkn_base().ctor_GfmlTkn_base(tknType, NullRaw, NullVal, cmd);}
@gplx.Internal protected static GfmlTkn valConst_(String tknType, String val, GfmlBldrCmd cmd) {return new GfmlTkn_valConst().ctor_GfmlTkn_base(tknType, GfmlTkn_.NullRaw, val, cmd);}
@gplx.Internal protected static GfmlTkn singleton_(String tknType, String raw, String val, GfmlBldrCmd cmd) {return new GfmlTkn_singleton().ctor_GfmlTkn_base(tknType, raw, val, cmd);}
@gplx.Internal protected static GfmlTkn composite_(String tknType, GfmlTkn[] ary) {return new GfmlTkn_composite(tknType, ary);}
@gplx.Internal protected static GfmlTkn composite_list_(String tknType, GfmlObjList list) {
GfmlTkn[] ary = new GfmlTkn[list.Count()];
for (int i = 0; i < list.Count(); i++)
ary[i] = (GfmlTkn)list.Get_at(i);
return GfmlTkn_.composite_(tknType, ary);
}
}
class GfmlTkn_base implements GfmlTkn {
public int ObjType() {return GfmlObj_.Type_tkn;}
public String TknType() {return tknType;} private String tknType;
public String Raw() {return raw;} private String raw;
public String Val() {return val;} private String val;
public GfmlBldrCmd Cmd_of_Tkn() {return cmd;} GfmlBldrCmd cmd;
public GfmlTkn[] SubTkns() {return GfmlTknAry_.Empty;}
@gplx.Virtual public GfmlTkn MakeNew(String rawNew, String valNew) {return new GfmlTkn_base().ctor_GfmlTkn_base(tknType, rawNew, valNew, cmd);}
@gplx.Internal protected GfmlTkn_base ctor_GfmlTkn_base(String tknType, String raw, String val, GfmlBldrCmd cmd) {this.tknType = tknType; this.raw = raw; this.val = val; this.cmd = cmd; return this;}
}
class GfmlTkn_valConst extends GfmlTkn_base {
@Override public GfmlTkn MakeNew(String rawNew, String valNew) {return new GfmlTkn_base().ctor_GfmlTkn_base(this.TknType(), rawNew, this.Val(), this.Cmd_of_Tkn());}
}
class GfmlTkn_singleton extends GfmlTkn_base {
@Override public GfmlTkn MakeNew(String rawNew, String valNew) {return this;}
}
class GfmlTkn_composite implements GfmlTkn {
public int ObjType() {return GfmlObj_.Type_tkn;}
public String TknType() {return tknType;} private String tknType;
public String Raw() {return GfmlTknAry_.XtoRaw(ary);}
public String Val() {return GfmlTknAry_.XtoVal(ary);}
public GfmlBldrCmd Cmd_of_Tkn() {return GfmlBldrCmd_.Null;}
public GfmlTkn[] SubTkns() {return ary;} GfmlTkn[] ary;
public GfmlTkn MakeNew(String rawNew, String valNew) {throw Err_.new_unimplemented_w_msg(".MakeNew cannot be invoked on GfmlTkn_composite (raw is available, but not val)", "tknType", tknType, "rawNew", rawNew, "valNew", valNew);}
@gplx.Internal protected GfmlTkn_composite(String tknType, GfmlTkn[] ary) {this.tknType = tknType; this.ary = ary;}
}

View File

@@ -1,114 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.texts.*; /*CharStream*/
public class GfmlTrie {
public String[] Symbols() {
String[] rv = new String[symbols.Count()];
for (int i = 0; i < rv.length; i++)
rv[i] = String_.cast(symbols.Get_at(i));
return rv;
} Ordered_hash symbols = Ordered_hash_.New();
public int LastMatchCount; // PERF: prop is faster than method
public Object FindMatch(CharStream stream) {
Object result = null; int moveCount = 0; LastMatchCount = 0;
IntObjHash_base link = rootLink;
while (stream.AtMid()) {
Object found = link.Get_by(stream.Cur());
if (found == null) break; // found is null; can happen for false matches; ex: <!-- reg, and <!-* is cur; goes to <!- before exit
LastMatchCount++;
IntObjHash_base foundAsLink = IntObjHash_base_.as_(found);
if (foundAsLink != null) { // if (found is link) (ie: another link exists)
result = foundAsLink.Bay(); // set .Bay as possible result; needed for short-long pairs; ex: < and <!-- exist; < found, but need to check next symbol for !
link = foundAsLink; // make foundAsLink the current one
moveCount++;
stream.MoveNext();
}
else { // not a link; must be last
result = found;
break;
}
}
if (moveCount > 0) stream.MoveBackBy(moveCount); // restore stream to original position; imitate idempotency
return result;
}
public void Add(String symbol, Object data) {
if (data == null) throw Err_.new_wo_type("null objects cannot be registered", "symbol", symbol);
char[] ary = String_.XtoCharAry(symbol); int lastIndex = ary.length - 1;
IntObjHash_base curLink = rootLink;
for (int i = 0; i < ary.length; i++) {
char c = ary[i];
Object found = curLink.Get_by(c);
IntObjHash_base foundAsLink = IntObjHash_base_.as_(found);
if (i == lastIndex) { // lastChar
if (found != null) { // slot is occupied
if (foundAsLink != null) // found is link; occurs when symbol is shorter than existing: ex: adding '<' when '<!--' exists)
foundAsLink.Bay_set(data); // place found in link's bay
else // found is makr; occurs when symbol is the same as existing; ex: adding '<!' when '<!' exists
curLink.Set(c, data); // place found in slot (replaces slot)
}
else // slot is unoccupied
curLink.Add(c, data); // place found in slot
}
else { // not lastChar
if (foundAsLink == null) { // next link does not exist (NOTE: next link is necessary, since char is not lastChar)
foundAsLink = IntObjHash_base_.new_(); // create next link
if (found != null) { // slot is occupied; occurs when symbol is longer than existing: ex: adding '<!--' when '<' exists
foundAsLink.Bay_set(found); // transplant occupied found to link's Bay
curLink.Set(c, foundAsLink); // place new link in slot
}
else // slot is unoccupied
curLink.Add(c, foundAsLink); // place found in slot
}
curLink = foundAsLink;
}
}
symbols.Add_if_dupe_use_nth(symbol, symbol);
}
public void Del(String symbol) {
char[] ary = String_.XtoCharAry(symbol); int lastIndex = ary.length - 1;
IntObjHash_base[] linkAry = new IntObjHash_base[ary.length]; // first, get linkAry -- one link for each symbol
IntObjHash_base link = rootLink;
for (int i = 0; i < ary.length; i++) {
char c = ary[i];
linkAry[i] = link;
link = IntObjHash_base_.as_(link.Get_by(c));
if (link == null) break; // c does not have nextHash; break
}
IntObjHash_base nextHash = null;
for (int i = lastIndex; i >= 0; i--) { // remove each char from hashes; must move backwards
char c = ary[i];
IntObjHash_base curLink = linkAry[i];
Object found = curLink.Get_by(c);
IntObjHash_base foundAsLink = IntObjHash_base_.as_(found);
if (nextHash != null && nextHash.Bay() != null) // occurs when long is dropped; ex: '<-' and '<'; '<-' dropped; <'s .Bay in '<-' chain must be transplanted to '<' .Bay
curLink.Set(c, nextHash.Bay());
else if (foundAsLink != null && foundAsLink.Bay() != null) // occurs when short is dropped; ex: '<-' and '<'; '<' dropped; <'s .Bay must be transplanted to '<' .Bay in '<-' chain
foundAsLink.Bay_set(found);
else // no long/short overlap; simply remove
curLink.Del(c);
nextHash = curLink;
}
symbols.Del(symbol);
}
public void Clear() {rootLink.Clear();}
IntObjHash_base rootLink = IntObjHash_base_.new_();
public static GfmlTrie new_() {return new GfmlTrie();}
}

View File

@@ -1,77 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class IntObjHash_base {
public int Count() {return count;} int count;
public boolean Has(int key) {return Get_by(key) != null;}
public Object Get_by(int key) {
if (key < 0) throw Err_.new_wo_type("key must be >= 0", "key", key);
if (key > maxKey) return null;
Object[] subAry = FetchSubAry(key);
return subAry == null ? null : subAry[subIdx];
}
public void Add(int key, Object obj) {PutObjAtKey(key, obj, true);}
public void Set(int key, Object obj) {PutObjAtKey(key, obj, false);}
public void Del(int key) {
if (key > maxKey) return; // key does not exist; exit
Object[] subAry = FetchSubAry(key);
if (subAry == null) return;
subAry[subIdx] = null;
count--;
}
public void Clear() {
rootAry = new Object[0];
count = 0;
maxKey = -1;
}
void PutObjAtKey(int key, Object obj, boolean isAdd) {
if (key < 0) throw Err_.new_wo_type("key must be >= 0", "key", key);
if (obj == null) throw Err_.new_wo_type("Object cannot be null; call .Del on key instead", "key", key);
if (key > maxKey) ExpandRootAry(key);
Object[] subAry = FetchSubAry(key);
if (subAry == null) {
subAry = new Object[subAryLength];
rootAry[rootIdx] = subAry;
}
Object curVal = subAry[subIdx];
if ( isAdd && curVal != null) throw Err_.new_wo_type(".Add cannot be called on non-null vals; call .Set instead", "key", key, "val", curVal);
if (!isAdd && curVal == null) throw Err_.new_wo_type(".Set cannot be called on null vals; call .Add instead", "key", key);
subAry[subIdx] = obj;
if (isAdd) count++;
}
void ExpandRootAry(int key) {
int newRootAryBound = (key / subAryLength) + 1;
Object[] newRootAry = new Object[newRootAryBound];
Array_.Copy(rootAry, newRootAry);
rootAry = newRootAry;
maxKey = (rootAry.length * subAryLength) - 1;
}
Object[] FetchSubAry(int key) {
rootIdx = key / subAryLength;
subIdx = key % subAryLength;
return (Object[])rootAry[rootIdx];
}
Object[] rootAry = new Object[0]; int maxKey = -1;
int rootIdx, subIdx; // NOTE: these are temp values that are cached at class level for PERF (originally out)
public Object Bay() {return bay;} public void Bay_set(Object v) {bay = v;} Object bay = null;
static final int subAryLength = 16;
}
class IntObjHash_base_ {
public static IntObjHash_base new_() {return new IntObjHash_base();}
public static IntObjHash_base as_(Object obj) {return obj instanceof IntObjHash_base ? (IntObjHash_base)obj : null;}
}

View File

@@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
public class GfmlFld {
public String Name() {return name;} private String name;
public boolean Name_isKey() {return name_isKey;} private boolean name_isKey;
public String TypeKey() {return typeKey;} private String typeKey;
public GfmlObj DefaultTkn() {return defaultTkn;} public GfmlFld DefaultTkn_(GfmlObj val) {defaultTkn = val; return this;} GfmlObj defaultTkn = GfmlTkn_.Null;
public GfmlFld Clone() {
GfmlFld rv = new GfmlFld();
rv.name = name; rv.name_isKey = name_isKey; rv.typeKey = typeKey;
rv.defaultTkn = defaultTkn; // FIXME: defaultTkn.clone_()
return rv;
}
public String To_str() {String_bldr sb = String_bldr_.new_(); this.To_str(sb); return sb.To_str_and_clear();}
public void To_str(String_bldr sb) {sb.Add_fmt("name={0} typeKey={1}", name, typeKey);}
public static final GfmlFld Null = new_(false, GfmlItmKeys.NullKey, GfmlType_.AnyKey);
public static GfmlFld new_(boolean name_isKey, String name, String typeKey) {
GfmlFld rv = new GfmlFld();
rv.name_isKey = name_isKey; rv.name = name; rv.typeKey = typeKey;
return rv;
} GfmlFld() {}
}

View File

@@ -1,34 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlFldList {
public int Count() {return hash.Count();}
public GfmlFld Get_at(int index) {return (GfmlFld)hash.Get_at(index);}
public GfmlFld Get_by(String id) {return (GfmlFld)hash.Get_by(id);}
public void Add(GfmlFld fld) {
if (String_.Len_eq_0(fld.Name())) throw Err_.new_wo_type("fld name cannot be null");
if (hash.Has(fld.Name())) throw Err_.new_wo_type("key already exists", "key", fld.Name()); // FIXME: commented out to allow multiple types with same name; need "_type:invk"
hash.Add_if_dupe_use_nth(fld.Name(), fld);
}
public void Del(GfmlFld fld) {
hash.Del(fld);
hash.Del(fld.Name());
}
Ordered_hash hash = Ordered_hash_.New();
public static GfmlFldList new_() {return new GfmlFldList();} GfmlFldList() {}
}

View File

@@ -1,53 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlType implements GfmlScopeItm {
public String Key() {return key;} private String key; // key for typeRegy; EX: itm/rect
public String NdeName() {return ndeName;} private String ndeName; // name for typeResolver; EX: rect
public GfmlDocPos DocPos() {return docPos;} public GfmlType DocPos_(GfmlDocPos val) {docPos = val; return this;} GfmlDocPos docPos = GfmlDocPos_.Null;
public GfmlFldList SubFlds() {return subFlds;} GfmlFldList subFlds = GfmlFldList.new_();
public GfmlType Clone() {
GfmlType rv = new GfmlType().ctor_GfmlType_(key, ndeName).DocPos_(docPos.NewClone());
for (int i = 0; i < subFlds.Count(); i++) {
GfmlFld subFld = (GfmlFld)subFlds.Get_at(i);
rv.subFlds.Add(subFld.Clone());
}
return rv;
}
public boolean IsTypeAny() {return String_.Eq(key, GfmlType_.AnyKey);}
public boolean IsTypeNull() {return String_.Eq(key, GfmlType_.NullKey);}
@gplx.Internal protected GfmlType ctor_GfmlType_(String key, String ndeName) {
this.key = key;
this.ndeName = ndeName;
return this;
}
}
class GfmlType_ {
public static final String
AnyKey = "gfml.any"
, StringKey = "gfml.String"
, NullKey = "gfml.null"
;
public static final GfmlType Root = null;
public static final GfmlType String = new_(StringKey, StringKey);
public static final GfmlType Null = new_(NullKey, NullKey);
@gplx.Internal protected static GfmlType new_(String key, String ndeName) {return new GfmlType().ctor_GfmlType_(key, ndeName);}
@gplx.Internal protected static GfmlType new_any_() {return new_(AnyKey, AnyKey);}
@gplx.Internal protected static String MakeKey(String ownerKey, String ndeName) {return String_.Concat(ownerKey, "/", ndeName);}
}

View File

@@ -1,105 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlTypeCompiler {
@gplx.Internal protected static GfmlType Compile(GfmlNde nde, GfmlType owner, GfmlTypRegy typeRegy, Ordered_hash results) {return Compile(nde, owner, true, typeRegy, results);}
static GfmlType Compile(GfmlNde nde, GfmlType owner, boolean isTopLevel, GfmlTypRegy typeRegy, Ordered_hash results) {
String name = nde.SubKeys().FetchDataOrFail("name");
String typeKey = FetchTypeKey(nde, owner, isTopLevel, name);
GfmlType rv = FetchTypeOrNew(name, typeKey, typeRegy, results);
for (int i = 0; i < nde.SubHnds().Count(); i++) {
GfmlNde subNde = (GfmlNde)nde.SubHnds().Get_at(i);
GfmlFld fld = CompileFld(subNde, rv, typeRegy, results);
rv.SubFlds().Add(fld);
}
return rv;
}
static GfmlFld CompileFld(GfmlNde nde, GfmlType ownerType, GfmlTypRegy typeRegy, Ordered_hash results) {
String name = nde.SubKeys().FetchDataOrFail("name");
String typeKey = nde.SubKeys().FetchDataOrNull("type");
GfmlObj defaultTkn = FetchDefaultTkn(nde, name); boolean isDefaultTknNde = defaultTkn.ObjType() == GfmlObj_.Type_nde;
boolean isKeyed = false;
if (nde.SubHnds().Count() == 0) { // is either (a) simple (ex: String) or (b) reference (ex: gfml.point); in either case, TypeFld is same
if (isDefaultTknNde) {
typeKey = GfmlType_.AnyKey;
isKeyed = true; // implicit: default to isKeyed if is nde token
}
if (typeKey == null) { // implicit: no typeKey defined; assume String
typeKey = GfmlType_.String.Key();
isKeyed = true;
}
}
else { // is inlineType
GfmlType type = Compile(nde, ownerType, false, typeRegy, results);
name = type.NdeName();
typeKey = type.Key();
}
return GfmlFld.new_(isKeyed, name, typeKey).DefaultTkn_(defaultTkn);
}
static String FetchTypeKey(GfmlNde nde, GfmlType owner, boolean isTopLevel, String name) {
String atrKey = isTopLevel ? "key" : "type";
String typeKey = nde.SubKeys().FetchDataOrNull(atrKey);
if (typeKey == null) { // implicit
typeKey = (owner == GfmlType_.Root)
? name // root type; assume typeKey is same as name; ex: point {x; y;} -> point is name; use as typeKey
: GfmlType_.MakeKey(owner.Key(), name); // nested type; build typeKey based on owner; ex: rect {pos {x; y;}} -> rect.pos is typeKey
}
return typeKey;
}
static GfmlType FetchTypeOrNew(String name, String typeKey, GfmlTypRegy typeRegy, Ordered_hash results) {
GfmlType rv = typeRegy.FetchOrNull(typeKey); // look for type in regy to see if it was declared earlier
if (rv == GfmlType_.Null) {
rv = (GfmlType)results.Get_by(rv.Key()); // look for type in current pragma's results
if (rv == null) { // nothing found; create and add
rv = GfmlType_.new_(typeKey, name);
results.Add(typeKey, rv);
}
}
return rv;
}
static GfmlObj FetchDefaultTkn(GfmlNde nde, String name) {
GfmlItm defaultTkn = nde.SubKeys().Get_by("default"); if (defaultTkn == null) return GfmlTkn_.Null;
GfmlItm itm = GfmlItm_.as_(defaultTkn); if (itm.ObjType() == GfmlObj_.Type_atr) return GfmlAtr.as_(itm).DatTkn();
GfmlNde rv = GfmlNde.new_(GfmlTkn_.val_(name), GfmlType_.new_any_(), true);
for (int i = 0; i < itm.SubObjs_Count(); i++) {
GfmlObj sub = (GfmlObj)itm.SubObjs_GetAt(i);
rv.SubObjs_Add(sub);
}
return rv;
}
@gplx.Internal protected static void AddDefaultAtrs(GfmlNde nde, GfmlType type, GfmlTypRegy regy) {
if (type.IsTypeAny()) return;
for (int i = 0; i < type.SubFlds().Count(); i++) {
GfmlFld subFld = (GfmlFld)type.SubFlds().Get_at(i);
if (subFld.DefaultTkn() == GfmlTkn_.Null) continue;
if (nde.SubKeys().Has(subFld.Name())) continue;
GfmlNde defaultNde = GfmlNde.as_(subFld.DefaultTkn());
if (defaultNde != null) {
nde.SubObjs_Add(defaultNde);
continue;
}
GfmlType atrType = regy.FetchOrNull(subFld.TypeKey());
GfmlTkn nameTkn = GfmlTkn_.new_(GfmlTkn_.NullRaw, subFld.Name());
GfmlTkn subFldDefault = (GfmlTkn)subFld.DefaultTkn();
GfmlTkn valTkn = GfmlTkn_.new_(GfmlTkn_.NullRaw, subFldDefault.Val());
GfmlAtr atr = GfmlAtr.new_(nameTkn, valTkn, atrType);
nde.SubObjs_Add(atr);
}
}
}

View File

@@ -1,49 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlTypeHash {
public GfmlType Get_by(String key) {return (GfmlType)hash.Get_by(key);}
public void Add(GfmlType type) {
if (type.IsTypeNull()) throw Err_.new_wo_type("cannot add null type to GfmlTypeHash");
if (hash.Has(type.Key())) throw Err_.new_wo_type("type key already exists", "key", type.Key());
hash.Add(type.Key(), type);
}
Hash_adp hash = Hash_adp_.New();
public static GfmlTypeHash new_() {return new GfmlTypeHash();} GfmlTypeHash() {}
}
class GfmlTypRegy {
public boolean Has(String typeKey) {return hash.Has(typeKey);}
public GfmlType FetchOrNull(String typeKey) {return FetchOrNull(typeKey, GfmlDocPos_.Root);}
public GfmlType FetchOrNull(String typeKey, GfmlDocPos pos) {
if (typeKey == null) throw Err_.new_wo_type("typeKey cannot be null when added to typRegy");
GfmlType rv = (GfmlType)hash.Get_by(typeKey, pos);
return rv == null ? GfmlType_.Null : rv;
}
public GfmlTypRegy Add(GfmlType type) {
hash.Del(type); // always replace existing with most recent
hash.Add(type);
return this;
}
public void Add_ary(GfmlType... ary) {
for (GfmlType type : ary)
this.Add(type);
}
public void Del(GfmlType type) {hash.Del(type);}
GfmlScopeRegy hash = GfmlScopeRegy.new_();
public static GfmlTypRegy new_() {return new GfmlTypRegy();}
}

View File

@@ -1,67 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlTypeMakr {
public GfmlType Owner() {return owner;}
public GfmlType MakeRootType(String key, String name, String... flds) {
GfmlType rv = MakeType(key, name);
for (String fld : flds)
AddSubFld_imp(rv, GfmlFld.new_(true, fld, GfmlType_.String.Key()));
owner = rv;
return rv;
}
public GfmlType MakeSubType(String name, String... flds) {
String key = Key_make(name);
GfmlType rv = MakeType(key, name);
for (String fld : flds)
AddSubFld_imp(rv, GfmlFld.new_(true, fld, GfmlType_.StringKey));
return rv;
}
public GfmlType MakeSubTypeAsOwner(String name, String... flds) {
GfmlType rv = MakeSubType(name, flds);
owner = rv;
return rv;
}
public void AddSubFld(GfmlFld subFld) {AddSubFld_imp(owner, subFld);}
public GfmlType[] Xto_bry() {
GfmlType[] rv = (GfmlType[])list.To_ary(GfmlType.class);
list.Clear();
owner = null;
return rv;
}
String Key_make(String name) {
return (owner == null)
? name
: GfmlType_.MakeKey(owner.Key(), name);
}
GfmlType MakeType(String key, String name) {
GfmlType rv = GfmlType_.new_(key, name);
if (owner != null) {
GfmlFld fld = GfmlFld.new_(false, name, key);
AddSubFld_imp(owner, fld);
}
list.Add(rv);
return rv;
}
void AddSubFld_imp(GfmlType ownerType, GfmlFld subFld) {ownerType.SubFlds().Add(subFld);}
GfmlType owner;
List_adp list = List_adp_.New();
public static GfmlTypeMakr new_() {return new GfmlTypeMakr();}
}

View File

@@ -1,140 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.lists.*;/*StackAdp*/
class GfmlTypeMgr {
public GfmlTypRegy TypeRegy() {return typeRegy;} GfmlTypRegy typeRegy = GfmlTypRegy.new_();
public GfmlFldPool FldPool() {return fldPool;} GfmlFldPool fldPool = GfmlFldPool.new_(GfmlType_.new_any_());
public void NdeBgn(GfmlNde nde, String ownerTypeKey) {
Resolve(nde, ownerTypeKey);
stack.Push(fldPool);
fldPool = GfmlFldPool.new_(nde.Type());
ownerNdeStack.Push(ownerNde);
ownerNde = nde;
} GfmlNde ownerNde;
public void NdeEnd() {
if (stack.Count() == 0) return;
fldPool = (GfmlFldPool)stack.Pop();
ownerNde = (GfmlNde)ownerNdeStack.Pop();
}
public void NdeResolve(GfmlNde nde, String ownerTypeKey) {
Resolve(nde, ownerTypeKey);
fldPool = GfmlFldPool.new_(nde.Type());
}
public void AtrExec(GfmlNde nde, GfmlAtr atr) {
String atrKey = atr.Key();
boolean isNull = String_.Eq(atrKey, GfmlTkn_.NullRaw);
GfmlFld atrFld = isNull
? fldPool.Keyed_PopNext()
: fldPool.Keyed_PopByKey(atrKey);
if (isNull) {
atr.Key_set(atrFld.Name());
nde.SubKeys().RegisterKey(atrFld.Name(), atr);
}
}
void Resolve(GfmlNde nde, String ownerTypeKey) {
GfmlType type = GfmlType_.Null;
if (!String_.Eq(ownerTypeKey, GfmlType_.AnyKey)) { // ownerType is specificType (!AnyType); lookup nde by ownerTypeKey + nde.Hnd
String ndeHndOrKey = String_.Len_eq_0(nde.Hnd()) ? nde.Key() : nde.Hnd();
if (String_.Len_eq_0(ndeHndOrKey)) ndeHndOrKey = nde.Hnd();
String typeKey = GfmlType_.MakeKey(ownerTypeKey, ndeHndOrKey);
type = typeRegy.FetchOrNull(typeKey, nde.DocPos());
}
if (type == GfmlType_.Null) { // typeKey not found; try nde.Hnd only
type = FetchByNde(nde);
}
if (!type.IsTypeAny()) // add defaults (skip AnyKey for perf)
GfmlTypeCompiler.AddDefaultAtrs(nde, type, typeRegy);
nde.Type_set(type);
}
GfmlType FetchByNde(GfmlNde nde) {
GfmlType rv = GfmlType_.Null;
String ndeKey = nde.Key(), ndeHnd = nde.Hnd();
String typKey = nde.Type().Key(); GfmlFld fld;
if (nde.KeyedSubObj()) {
if (String_.Len_eq_0(ndeKey)) {
fld = fldPool.Keyed_PopNext();
typKey = (fld == GfmlFld.Null) ? GfmlType_.AnyKey : fld.TypeKey();
if (ownerNde != null && !String_.Len_eq_0(fld.Name())) // HACK: String_.Len_eq_0(fld.Name()) needed for DoesNotUsurpDatTknForName
ownerNde.SubKeys().RegisterKey(fld.Name(), nde);
}
else {
fldPool.Keyed_PopByKey(ndeKey);
typKey = ndeKey;
}
}
else {
if (String_.Len_eq_0(ndeHnd)) {
fld = fldPool.DefaultMember();
typKey = (fld == GfmlFld.Null) ? GfmlType_.AnyKey : fld.TypeKey();
if (String_.Len_eq_0(nde.Hnd())) // type found, and curNde.Id is null; generate Id (DataRdr depends on this)
nde.Hnd_set(fld.Name());
}
else
typKey = ndeHnd;
}
if (typKey == null) throw Err_.new_wo_type("could not identity type for node", "ndeKey", ndeKey, "ndeHnd", ndeHnd, "typKey", nde.Type().Key());
rv = typeRegy.FetchOrNull(typKey, nde.DocPos());
return (rv == GfmlType_.Null)
? GfmlType_.new_any_() // unknown typeKey; name is not known (see EX:2) -> create new anyType
: rv;
}
public void OverridePool(GfmlType type) {
GfmlType owner = GfmlType_.new_any_();
owner.SubFlds().Add(GfmlFld.new_(false, type.NdeName(), type.Key()));
fldPool = GfmlFldPool.new_(owner);
}
StackAdp stack = StackAdp_.new_(), ownerNdeStack = StackAdp_.new_();
public static GfmlTypeMgr new_() {return new GfmlTypeMgr();} GfmlTypeMgr() {}
}
class GfmlFldPool {
public GfmlTkn Keyed_PopNextAsTkn() {return GfmlTkn_.val_(Keyed_PopNext().Name());} // helper method for GfmlFrame_nde
public GfmlFld Keyed_PopNext() {
if (keyedRegy.Count() == 0) return GfmlFld.Null;
GfmlFld rv = (GfmlFld)keyedRegy.Get_at(0);
keyedRegy.Del(rv.Name());
return rv;
}
public GfmlFld Keyed_PopByKey(String key) {
GfmlFld rv = (GfmlFld)keyedRegy.Get_by(key); if (rv == null) return GfmlFld.Null;
keyedRegy.Del(rv.Name());
return rv;
}
@gplx.Internal protected int Keyd_Count() {return keyedRegy.Count();}
@gplx.Internal protected GfmlFld Keyd_FetchAt(int i) {return (GfmlFld)keyedRegy.Get_at(i);}
public GfmlFld DefaultMember() {return defaultMember;} GfmlFld defaultMember = GfmlFld.Null;
@gplx.Internal protected GfmlType Type() {return type;} GfmlType type = GfmlType_.Null;
void InitByType(GfmlType type) {
this.type = type;
for (int i = 0; i < type.SubFlds().Count(); i++) {
GfmlFld fld = (GfmlFld)type.SubFlds().Get_at(i);
if (fld.Name_isKey())
keyedRegy.Add(fld.Name(), fld);
else {
defaultMember = fld;
}
}
}
Ordered_hash keyedRegy = Ordered_hash_.New();
public static GfmlFldPool new_(GfmlType type) {
GfmlFldPool rv = new GfmlFldPool();
rv.InitByType(type);
return rv;
} GfmlFldPool() {}
}

View File

@@ -1,76 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlAtr implements GfmlItm {
public int ObjType() {return GfmlObj_.Type_atr;}
public GfmlTkn KeyTkn() {return keyTkn;} GfmlTkn keyTkn; public String Key() {return keyTkn.Val();}
public GfmlTkn DatTkn() {return datTkn;} GfmlTkn datTkn;
public GfmlType Type() {return type;} GfmlType type;
public boolean KeyedSubObj() {return true;}
public int SubObjs_Count() {return subObjs.Count();}
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.Get_at(i);} GfmlObjList subObjs = GfmlObjList.new_(); // PERF?: make capacity 3 instead of 8
public void SubObjs_Add(GfmlObj o) {subObjs.Add(o);}
public String To_str() {return String_.Concat(this.Key(), "=", this.DatTkn().Val());}
@gplx.Internal protected void Key_set(String v) {keyTkn = GfmlTkn_.val_(v);} // used for 1 test
public static GfmlAtr as_(Object obj) {return obj instanceof GfmlAtr ? (GfmlAtr)obj : null;}
public static GfmlAtr string_(GfmlTkn keyTkn, GfmlTkn datTkn) {return new_(keyTkn, datTkn, GfmlType_.String);}
public static GfmlAtr new_(GfmlTkn keyTkn, GfmlTkn datTkn, GfmlType type) {
GfmlAtr rv = new GfmlAtr();
rv.keyTkn = keyTkn; rv.datTkn = datTkn; rv.type = type;
return rv;
} GfmlAtr() {}
public void UpdateAtr(String key, String dat) {
keyTkn = MakeTknAndReplace(keyTkn, key);
datTkn = MakeTknAndReplace(datTkn, dat);
}
GfmlTkn MakeTknAndReplace(GfmlTkn oldTkn, String s) {
int idx = GetTknIdx(oldTkn);
GfmlTkn tkn = MakeTkn(oldTkn, s);
if (idx != -1)
subObjs.Del_at(idx);
if (idx == -1) idx = 0;
subObjs.Add_at(tkn, idx);
return tkn;
}
int GetTknIdx(GfmlTkn t) {
for (int i = 0; i < subObjs.Count(); i++) {
GfmlObj obj = (GfmlObj)subObjs.Get_at(i);
if (obj == t) return i;
}
return -1;
}
GfmlTkn MakeTkn(GfmlTkn oldTkn, String newStr) {
if (newStr == null) return oldTkn;
if (oldTkn.SubTkns().length > 0) {
GfmlTkn bgn = oldTkn.SubTkns()[0];
GfmlTkn end = oldTkn.SubTkns()[oldTkn.SubTkns().length - 1];
newStr = String_.Replace(newStr, bgn.Raw(), bgn.Raw() + bgn.Raw());
if (bgn.Raw() != end.Raw())
newStr = String_.Replace(newStr, end.Raw(), end.Raw() + end.Raw());
return GfmlTkn_.composite_(oldTkn.TknType(), GfmlTknAry_.ary_(bgn, GfmlTkn_.raw_(newStr), end));
}
else {
boolean hasQuote = String_.Has(newStr, "'");
if (hasQuote)
return GfmlTkn_.composite_("composite", GfmlTknAry_.ary_(GfmlTkn_.new_("'", ""), GfmlTkn_.raw_(String_.Replace(newStr, "'", "''")), GfmlTkn_.new_("'", "")));
else
return GfmlTkn_.raw_(newStr);
}
}
}

View File

@@ -1,45 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlDoc {
public GfmlNde RootNde() {return rootNde;} GfmlNde rootNde;
@gplx.Internal protected List_adp UsrMsgs() {return usrMsgs;} List_adp usrMsgs = List_adp_.New();
@gplx.Internal protected GfmlLxrRegy LxrRegy() {return lxrRegy;} GfmlLxrRegy lxrRegy = new GfmlLxrRegy();
@gplx.Internal protected GfmlBldrCmdRegy CmdRegy() {return cmdRegy;} GfmlBldrCmdRegy cmdRegy = GfmlBldrCmdRegy.new_();
@gplx.Internal protected GfmlPragmaMgr PragmaMgr() {return pragmaMgr;} GfmlPragmaMgr pragmaMgr = GfmlPragmaMgr.new_();
@gplx.Internal protected GfmlLxr RootLxr() {return rootLxr;} GfmlLxr rootLxr;
@gplx.Internal protected void RootLxr_set(GfmlLxr v) {rootLxr = v;}
@gplx.Internal protected void Clear() {
usrMsgs.Clear();
rootNde = GfmlNde.named_(GfmlTkn_.cmd_("tkn.gfml.root_tkn", GfmlBldrCmd_pendingTkns_add.Instance), GfmlType_.Null);
rootNde.DocPos_(GfmlDocPos_.Root);
}
@gplx.Internal protected static GfmlDoc new_() {
GfmlDoc rv = new GfmlDoc();
rv.Clear();
return rv;
} GfmlDoc() {}
}
// class GfmlDocEditor {
// public GfmlTkn BgnParen() {return bgnParen;} public GfmlDocEditor BgnParen_(GfmlTkn v) {bgnParen = v; return this;} GfmlTkn bgnParen = GfmlTkn_.new_("(", "");
// public GfmlTkn EndParen() {return endParen;} public GfmlDocEditor EndParen_(GfmlTkn v) {endParen = v; return this;} GfmlTkn endParen = GfmlTkn_.new_(")", "");
// public GfmlTkn BgnBrace() {return bgnBrace;} public GfmlDocEditor BgnBrace_(GfmlTkn v) {bgnBrace = v; return this;} GfmlTkn bgnBrace = GfmlTkn_.new_("{", "");
// public GfmlTkn EndBrace() {return endBrace;} public GfmlDocEditor EndBrace_(GfmlTkn v) {endBrace = v; return this;} GfmlTkn endBrace = GfmlTkn_.new_("}", "");
// public GfmlTkn Hnd() {return hnd;} public GfmlDocEditor Hnd_(GfmlTkn v) {hnd = v; return this;} GfmlTkn hnd = GfmlTkn_.new_(":", "");
// public static final GfmlDocEditor Instance = new GfmlDocEditor(); GfmlDocEditor() {}
// }

View File

@@ -1,130 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlDocLxrs {
@gplx.Internal protected static void Default_lxr(GfmlLxrRegy regy, GfmlLxr rootLxr) {
GfmlLxr[] ary = new GfmlLxr[] { GfmlDocLxrs.Whitespace_lxr()
, GfmlDocLxrs.Quote0_Eval0_lxr()
, GfmlDocLxrs.Quote1_lxr()
, GfmlDocLxrs.QuoteBlock_lxr()
, GfmlDocLxrs.QuoteBlock1_lxr()
, GfmlDocLxrs.QuoteBlock2_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
, GfmlDocLxrs.NdeHeader_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.ElmKey_lxr()
, GfmlDocLxrs.Comment0_lxr()
, GfmlDocLxrs.Comment1_lxr()
, GfmlDocLxrs.NdePropBgn_lxr()
, GfmlDocLxrs.NdePropEnd_lxr()
};
// if (Op_sys.Cur().Tid_is_wnt())
// regy.Add(Comment0a_lxr());
for (GfmlLxr lxr : ary)
regy.Add(lxr);
rootLxr.SubLxr_Add(ary);
}
public static GfmlLxr Root_lxr() {
GfmlTkn txtTkn = GfmlTkn_.cmd_("tkn:text", GfmlBldrCmd_dataTkn_set.Instance);
return GfmlLxr_.general_("lxr:root", txtTkn);
}
public static GfmlLxr Whitespace_lxr() {
GfmlTkn tkn = GfmlTkn_.cmd_("key:gfml.whitespace_0", GfmlBldrCmd_whitespace.Instance);
GfmlLxr rv = GfmlLxr_.range_("lxr:gfml.whitespace_0", String_.Ary(" ", String_.Tab, String_.CrLf, String_.Lf), tkn, false);
return rv;
}
public static GfmlLxr Comment0_lxr() {return GfmlLxr_.frame_("gfml.comment_0", GfmlFrame_.comment_(), "//", String_.Lf);}
// public static GfmlLxr Comment0a_lxr() {return GfmlLxr_.frame_("gfml.comment_0b", GfmlFrame_.comment_(), "//", "\n");}
public static GfmlLxr Comment1_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.comment_1", GfmlFrame_.comment_(), "/*", "*/");
GfmlLxr escapeBgn = lxr_escape_("gfml.comment_1_escape_bgn", "/*/*", "/*");
GfmlLxr escapeEnd = lxr_escape_("gfml.comment_1_escape_end", "*/*/", "*/");
rv.SubLxr_Add(escapeBgn, escapeEnd, rv);
return rv;
}
public static GfmlLxr Eval0_lxr() {return GfmlLxr_.frame_("gfml.eval_0", GfmlFrame_.eval_(), "<~", ">");}
public static GfmlLxr Quote0_Eval0_lxr() {
GfmlLxr rv = Quote0_lxr();
GfmlLxr eval0 = Eval0_lxr();
rv.SubLxr_Add(eval0);
eval0.SubLxr_Add(rv); // recursive!
return rv;
}
public static GfmlLxr Quote0_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_0", GfmlFrame_.quote_(), "'", "'");
GfmlLxr escape = lxr_escape_("gfml.quote_0_escape", "''", "'");
rv.SubLxr_Add(escape);
return rv;
}
public static GfmlLxr Quote1_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_1", GfmlFrame_.quote_(), "\"", "\"");
GfmlLxr escape = lxr_escape_("gfml.quote_1_escape", "\"\"", "\"");
rv.SubLxr_Add(escape);
return rv;
}
public static GfmlLxr QuoteBlock_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_block_0", GfmlFrame_.quote_(), "|'", "'|");
GfmlLxr escapeBgn = lxr_escape_("gfml.quote_block_0_escape_bgn", "|'|'", "|'");
GfmlLxr escapeEnd = lxr_escape_("gfml.quote_block_0_escape_end", "'|'|", "'|");
rv.SubLxr_Add(escapeBgn, escapeEnd, rv); // NOTE: adding rv makes it recursive
return rv;
}
public static GfmlLxr QuoteBlock1_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_block_1", GfmlFrame_.quote_(), "<:['\n", "\n']:>");
// GfmlLxr escapeBgn = lxr_escape_("gfml.quote_block_1_escape_bgn", "<~{'\n<~{'\n", "<~{'\n"); // doesn't work; causes dangling errors; need to debug later
// GfmlLxr escapeEnd = lxr_escape_("gfml.quote_block_1_escape_end", "\n'}~>\n'}~>", "\n'}~>");
// rv.SubLxr_Add(rv);
return rv;
}
public static GfmlLxr QuoteBlock2_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_block_2", GfmlFrame_.quote_(), "<:[\"\n", "\n\"]:>");
return rv;
}
public static GfmlLxr QuoteFold_lxr() {
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_fold_0", GfmlFrame_.quote_(), "^'", "'^");
GfmlTkn tkn = GfmlTkn_.valConst_("key:gfml.quote_fold_0_whitespace", GfmlTkn_.NullVal, GfmlBldrCmd_whitespace.Instance);
GfmlLxr whitespace = GfmlLxr_.range_("lxr:gfml.quote_fold_0_whitespace", String_.Ary(String_.Tab, String_.CrLf, String_.Lf), tkn, false);
GfmlLxr escapeBgn = lxr_escape_("gfml.quote_fold_0_escape_bgn", "^'^'", "^'");
GfmlLxr escapeEnd = lxr_escape_("gfml.quote_fold_0_escape_end", "'^'^", "'^");
rv.SubLxr_Add(whitespace, escapeBgn, escapeEnd, rv); // NOTE: adding rv makes it recursive
rv.SubLxr_Add(Eval0_lxr(),
Comment0_lxr(),
Comment1_lxr());
return rv;
}
public static GfmlLxr ElmKey_lxr() {return lxr_symbol_("gfml.elm_key_0", "=", GfmlBldrCmd_elemKey_set.Instance);}
public static GfmlLxr NdeHeader_lxr() {return lxr_symbol_("gfml.node_name_0", ":", GfmlBldrCmd_ndeName_set.Instance);}
public static GfmlLxr NdeInline_lxr() {return lxr_symbol_("gfml.node_inline_0", ";", GfmlBldrCmd_ndeInline.Instance);}
public static GfmlLxr NdeBodyBgn_lxr() {return lxr_symbol_("gfml.node_body_0_begin", "{", GfmlBldrCmd_ndeBody_bgn.Instance);}
public static GfmlLxr NdeBodyEnd_lxr() {return lxr_symbol_("gfml.node_body_0_end", "}", GfmlBldrCmd_frameEnd.nde_(GfmlNdeSymType.BodyEnd));}
public static GfmlLxr NdePropBgn_lxr() {return lxr_symbol_("lxr.gfml.node_prop_0_bgn", "[", GfmlBldrCmd_ndeProp_bgn.Instance);}
public static GfmlLxr NdePropEnd_lxr() {return lxr_symbol_("lxr.gfml.node_prop_0_end", "]", GfmlBldrCmd_frameEnd.nde_(GfmlNdeSymType.PrpEnd));}
public static GfmlLxr NdeDot_lxr() {return lxr_symbol_("gfml.node_drill_0", ".", GfmlBldrCmd_ndeDot.Instance);}
public static GfmlLxr NdeHdrBgn_lxr() {return lxr_symbol_("lxr.gfml.node_hdr_0_bgn", "(", GfmlBldrCmd_ndeHdr_bgn.Instance);}
public static GfmlLxr NdeHdrEnd_lxr() {return lxr_symbol_("lxr.gfml.node_hdr_0_end", ")", GfmlBldrCmd_ndeHdr_end.Instance);}
public static GfmlLxr AtrSpr_lxr() {return lxr_symbol_("lxr.gfml.atrSpr", ",", GfmlBldrCmd_atrSpr.Instance);}
static GfmlLxr lxr_escape_(String key, String raw, String escape) {return GfmlLxr_.symbol_(key, raw, escape, GfmlBldrCmd_pendingTkns_add.Instance);}
static GfmlLxr lxr_symbol_(String key, String raw, GfmlBldrCmd cmd) {return GfmlLxr_.symbol_(key, raw, raw, cmd);}
}

View File

@@ -1,71 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
public class GfmlDocPos implements CompareAble {
public String Path() {if (path == null) MakePath(); return path;} private String path;
public int compareTo(Object obj) {
/* Same: same coord (ex: 0_1 = 0_1)
More: higher level (ex: 0_1 > 0_1_0) or higher idx (ex: 0_1 > 0_2)
Less: lower level (ex: 0_1 < 0) or lower idx (ex: 0_1 < 0_0) */
GfmlDocPos comp = (GfmlDocPos)obj;
for (int i = 0; i < ary.length; i++) {
if (i >= comp.ary.length) return CompareAble_.More; // more ary than comp and whatever ary they share are equal; must be more;
int origVal = ary[i];
int compVal = comp.ary[i];
if (origVal == compVal) continue; // indexes are equal; continue to next
else if (origVal < compVal) return CompareAble_.Less;
else if (origVal > compVal) return CompareAble_.More;
}
if (ary.length < comp.ary.length) return CompareAble_.Less; // less ary than comp, and whatever ary they share are equal; must be less
return Int_.Compare(idx, comp.idx); // compare idx
}
public GfmlDocPos NewClone() {return new GfmlDocPos(ary, idx);}
public GfmlDocPos NewDown(int newIdx) {
int oldLen = ary.length;
int[] newAry = new int[oldLen + 1];
for (int i = 0; i < oldLen; i++)
newAry[i] = ary[i];
newAry[oldLen] = idx;
return new GfmlDocPos(newAry, newIdx);
}
public GfmlDocPos NewUp() {
int oldLen = ary.length; if (oldLen == 0) return GfmlDocPos_.Null;
int[] newAry = new int[oldLen - 1];
for (int i = 0; i < oldLen - 1; i++)
newAry[i] = ary[i];
int newIdx = ary[oldLen - 1];
return new GfmlDocPos(newAry, newIdx);
}
@Override public String toString() {return path;} public String To_str() {return path;}
void MakePath() {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < ary.length; i++) {
sb.Add(ary[i]);
sb.Add("_");
}
sb.Add(idx);
path = sb.To_str();
}
int[] ary; int idx;
@gplx.Internal protected GfmlDocPos(int[] ary, int idx) {this.ary = ary; this.idx = idx;}
}
class GfmlDocPos_ {
public static final GfmlDocPos Null = new GfmlDocPos(new int[0], -1);
public static final GfmlDocPos Root = new GfmlDocPos(new int[0], 0);
}

View File

@@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
public class GfmlDocWtr_ {
public String To_str_and_clear() {return sb.To_str_and_clear();}
public void BuildAttrib(GfmlAtr atr) {Build(atr);}
public void BuildNode(GfmlNde nde) {Build(nde);}
void Build(GfmlItm owner) {
for (int i = 0; i < owner.SubObjs_Count(); i++) {
GfmlObj subObj = owner.SubObjs_GetAt(i);
GfmlItm subItm = GfmlItm_.as_(subObj);
if (subItm == null)
sb.Add(GfmlTkn_.as_(subObj).Raw());
else
Build(subItm);
}
}
String_bldr sb = String_bldr_.new_();
public static String xtoStr_(GfmlNde nde) {
GfmlDocWtr_ wtr = new GfmlDocWtr_();
wtr.BuildNode(nde);
return wtr.To_str_and_clear();
}
}

View File

@@ -1,46 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlDoc_ {
public static GfmlDoc parse_any_eol_(String raw) {return parse(String_.Replace(raw, String_.CrLf, String_.Lf));}
public static GfmlDoc parse(String raw) {
GfmlBldr bldr = GfmlBldr_.default_();
return bldr.XtoGfmlDoc(raw);
}
}
class GfmlUsrMsgs {
public static UsrMsg fail_HndTkn_alreadyExists() {return UsrMsg.new_("hndTkn already exists");}
public static UsrMsg fail_KeyTkn_alreadyExists() {return UsrMsg.new_("keyTkn already exists");}
public static UsrMsg fail_DatTkn_notFound() {return UsrMsg.new_("datTkn not found");}
public static UsrMsg fail_Frame_danglingBgn() {return UsrMsg.new_("dangling frame");}
public static void MakeErr(GfmlBldr bldr, UsrMsg um, String raw) {
bldr.Doc().UsrMsgs().Add(um);
GfmlStringHighlighter sh = GfmlStringHighlighter.new_();
sh.Raw_(raw).Mark_(bldr.StreamPos(), '*', "failed");
um.Add("errorPos", bldr.StreamPos());
um.Add("errorHighlight", String_.CrLf + String_.Concat_lines_crlf(sh.Gen()));
}
public static Err gfmlParseError(GfmlBldr bldr) {
Err rv = Err_.new_wo_type("gfml parse error");
for (int i = 0; i < bldr.Doc().UsrMsgs().Count(); i++) {
UsrMsg um = (UsrMsg)bldr.Doc().UsrMsgs().Get_at(i);
rv.Args_add("err" + Int_.To_str(i), um.To_str());
}
return rv;
}
}

View File

@@ -1,29 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public interface GfmlItm extends GfmlObj, To_str_able {
GfmlTkn KeyTkn(); String Key(); // Key() is alternative to Key().Val()
GfmlType Type();
boolean KeyedSubObj();
int SubObjs_Count();
GfmlObj SubObjs_GetAt(int i);
void SubObjs_Add(GfmlObj obj);
}
class GfmlItm_ {
public static GfmlItm as_(Object obj) {return obj instanceof GfmlItm ? (GfmlItm)obj : null;}
}

View File

@@ -1,24 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlItmHnds {
public int Count() {return list.Count();} List_adp list = List_adp_.New();
public GfmlNde Get_at(int idx) {return (GfmlNde)list.Get_at(idx);}
public void Add(GfmlNde nde) {list.Add(nde);}
public static GfmlItmHnds new_() {return new GfmlItmHnds();} GfmlItmHnds() {}
}

View File

@@ -1,61 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlItmKeys {
public int Count() {return list.Count();}
public boolean Has(String key) {return hash.Has(key);}
public GfmlItm Get_at(int i) {return (GfmlItm)list.Get_at(i);}
public GfmlItm Get_by(String key) {return (GfmlItm)hash.Get_by(key);}
public String FetchDataOr(String key, String or) {
GfmlAtr atr = FetchAtr(key);
return (atr == null) ? or : atr.DatTkn().Val();
}
public String FetchDataOrNull(String key) {return FetchDataOr(key, null);}
public String FetchDataOrFail(String key) {
GfmlAtr atr = FetchAtr(key); if (atr == null) throw Err_.new_missing_key(key);
return atr.DatTkn().Val();
}
public GfmlTkn FetchDataTknOrNull(String key) {
GfmlAtr atr = FetchAtr(key); if (atr == null) return GfmlTkn_.Null;
return atr.DatTkn();
}
public void Add(GfmlItm itm) {
String key = itm.Key();
if (hash.Has(key)) DelDefault(itm); // default attribs are added automatically; drop default when adding newElm
list.Add(itm);
if (!String_.Eq(key, GfmlItmKeys.NullKey))
RegisterKey(key, itm);
}
@gplx.Internal protected void RegisterKey(String key, GfmlItm itm) {
if (hash.Has(key)) hash.Del(key); // replace default
hash.Add(key, itm);
}
void DelDefault(GfmlItm elm) {
GfmlItm toDel = null;
for (Object subObj : list) {
GfmlItm sub = (GfmlItm)subObj;
if (String_.Eq(sub.Key(), elm.Key()))
toDel = sub;
}
if (toDel != null) list.Del(toDel);
}
GfmlAtr FetchAtr(String key) {return GfmlAtr.as_(hash.Get_by(key));}
List_adp list = List_adp_.New(); Hash_adp hash = Hash_adp_.New();
public static GfmlItmKeys new_() {return new GfmlItmKeys();} GfmlItmKeys() {}
@gplx.Internal protected static final String NullKey = "";
}

View File

@@ -1,113 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlNde implements GfmlItm {
public static final int OBJ_TYPE = GfmlObj_.Type_nde;
public int ObjType() {return objType;} int objType = GfmlObj_.Type_nde;
public GfmlTkn KeyTkn() {return keyTkn;} public String Key() {return keyTkn.Val();} GfmlTkn keyTkn = GfmlTkn_.Null;
public GfmlType Type() {return type;} GfmlType type;
public boolean KeyedSubObj() {return keyedSubObj;} public GfmlNde KeyedSubObj_(boolean v) {keyedSubObj = v; return this;} private boolean keyedSubObj;
public int ChainId() {return chainId;} public GfmlNde ChainId_(int v) {chainId = v; return this;} int chainId; // can use boolean chainHead, but this is easier for debugging
public int SubObjs_Count() {return subObjs.Count();} GfmlObjList subObjs = GfmlObjList.new_();
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.Get_at(i);}
public void SubObjs_Add(GfmlObj gobj) {
subObjs.Add(gobj);
GfmlItm subItm = GfmlItm_.as_(gobj);
if ( subItm == null // gobj is tkn: symbol, whitespace, comment
|| subItm.ObjType() == GfmlObj_.Type_prg) // gobj is pragma
return;
if (subItm.KeyedSubObj())
subKeys.Add(subItm);
else
subHnds.Add(GfmlNde.as_(subItm));
}
public String Hnd() {return hndTkn.Val();} GfmlTkn hndTkn = GfmlTkn_.Null;
public GfmlDocPos DocPos() {return docPos;} GfmlDocPos docPos = GfmlDocPos_.Null;
public GfmlItmKeys SubKeys() {return subKeys;} GfmlItmKeys subKeys = GfmlItmKeys.new_();
public GfmlItmHnds SubHnds() {return subHnds;} GfmlItmHnds subHnds = GfmlItmHnds.new_();
public String To_str() {return GfmlDocWtr_.xtoStr_(this);}
public void UpdateNde(String hnd) {
for (int i = 0; i < subHnds.Count(); i++) {
GfmlNde nde = (GfmlNde)subHnds.Get_at(i);
if (String_.Eq(nde.hndTkn.Raw(), hnd)) return;
}
int endAtrPos = PosOf(false, ";", "}");
GfmlTkn bgnParen = GfmlTkn_.new_("(", "");
GfmlTkn endParen = GfmlTkn_.new_(")", "");
GfmlTkn bgnBrace = GfmlTkn_.new_("{", "");
GfmlTkn endBrace = GfmlTkn_.new_("}", "");
GfmlTkn hndTkn = GfmlTkn_.new_(hnd, hnd);
GfmlNde subNde = GfmlNde.new_(hndTkn, GfmlType_.new_any_(), false);
subNde.SubObjs_Add(hndTkn);
subNde.SubObjs_Add(bgnParen);
subNde.SubObjs_Add(endParen);
subNde.SubObjs_Add(bgnBrace);
subNde.SubObjs_Add(endBrace);
subObjs.Add_at(subNde, endAtrPos);
// a(){b(){}}
// a:{} -> a:{b:{}}
}
int PosOf(boolean fwd, String... find) {
int bgn = fwd ? 0 : subObjs.Count() - 1;
int end = fwd ? subObjs.Count() : 0;
int dif = fwd ? 1 : -1;
for (int i = bgn; i != end; i+=dif) {
GfmlObj subObj = (GfmlObj)subObjs.Get_at(i);
GfmlTkn subTkn = GfmlTkn_.as_(subObj);
if (subTkn == null) continue;
if (String_.In(subTkn.Raw(), find)) {
return i;
}
}
return -1;
}
public void UpdateAtr(String key, String val) {
GfmlAtr atr = (GfmlAtr)subKeys.Get_by(key);
if (atr != null) {atr.UpdateAtr(key, val); return;}
val = String_.Replace(val, "'", "''");
GfmlTkn quote = GfmlTkn_.new_("'", "");
GfmlTkn keyTkn = GfmlTkn_.raw_(key);
GfmlTkn valTkn = GfmlTkn_.composite_("composite", GfmlTknAry_.ary_(quote, GfmlTkn_.raw_(val), quote));
GfmlTkn eqTkn = GfmlTkn_.new_("=", "");
atr = GfmlAtr.string_(keyTkn, valTkn);
atr.SubObjs_Add(keyTkn);
atr.SubObjs_Add(eqTkn);
atr.SubObjs_Add(valTkn);
int endAtrPos = PosOf(true, ";", "{");
if (subKeys.Count() != 0) {
subObjs.Add_at(GfmlTkn_.new_(" ", ""), endAtrPos);
endAtrPos++;
}
subObjs.Add_at(atr, endAtrPos);
}
@gplx.Internal protected void ObjType_set_pragma() {objType = GfmlObj_.Type_prg;}
@gplx.Internal protected void KeyTkn_set(GfmlTkn gobj) {keyTkn = gobj;}
@gplx.Internal protected void Type_set(GfmlType val) {type = val;}
@gplx.Internal protected void SubObjs_Clear() {subObjs.Clear();}
@gplx.Internal protected GfmlTkn HndTkn() {return hndTkn;}
@gplx.Internal protected void HndTkn_set(GfmlTkn tkn) {hndTkn = tkn;}
@gplx.Internal protected void Hnd_set(String v) {hndTkn = String_.Len_eq_0(v) ? GfmlTkn_.Null : GfmlTkn_.val_(v);} // NOTE: v is empty for types with empty fldNames
@gplx.Internal protected GfmlNde DocPos_(GfmlDocPos val) {docPos = val; return this;}
public static GfmlNde as_(Object obj) {return obj instanceof GfmlNde ? (GfmlNde)obj : null;}
@gplx.Internal protected static GfmlNde named_(GfmlTkn hndTkn, GfmlType type) {return new GfmlNde(hndTkn, type, false);}
@gplx.Internal protected static GfmlNde new_(GfmlTkn hndTkn, GfmlType type, boolean keyedSubObj) {return new GfmlNde(hndTkn, type, keyedSubObj);}
GfmlNde(GfmlTkn hndTkn, GfmlType type, boolean keyedSubObj) {
this.hndTkn = hndTkn; this.type = type; this.keyedSubObj = keyedSubObj;}
}

View File

@@ -1,73 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
interface GfmlScopeItm {
String Key();
GfmlDocPos DocPos();
}
class GfmlScopeRegy {
public boolean Has(String key) {
GfmlScopeList list = (GfmlScopeList)hash.Get_by(key); if (list == null) return false;
return list.Count() > 0;
}
public void Add(GfmlScopeItm itm) {
GfmlScopeList list = ItmOrNew(itm.Key());
list.Add(itm);
}
public void Del(GfmlScopeItm itm) {
GfmlScopeList list = (GfmlScopeList)hash.Get_by(itm.Key()); if (list == null) return;
list.Del(itm);
if (list.Count() == 0) hash.Del(itm.Key());
}
public GfmlScopeItm Get_by(String key, GfmlDocPos pos) {
GfmlScopeList list = (GfmlScopeList)hash.Get_by(key); if (list == null) return null;
return list.Get_by(pos);
}
GfmlScopeList ItmOrNew(String key) {
GfmlScopeList rv = (GfmlScopeList)hash.Get_by(key);
if (rv == null) {
rv = GfmlScopeList.new_(key);
hash.Add(key, rv);
}
return rv;
}
Hash_adp hash = Hash_adp_.New();
public static GfmlScopeRegy new_() {return new GfmlScopeRegy();}
}
class GfmlScopeList {
public String Key() {return key;} private String key;
public int Count() {return list.Count();}
public void Add(GfmlScopeItm itm) {list.Add(itm);}
public void Del(GfmlScopeItm itm) {list.Del(itm);}
public GfmlScopeItm Get_by(GfmlDocPos pos) {
if (list.Count() == 0) return null;
GfmlScopeItm rv = null;
for (Object itemObj : list) {
GfmlScopeItm itm = (GfmlScopeItm)itemObj;
if (CompareAble_.Is(CompareAble_.More_or_same, pos, itm.DocPos()))
rv = itm;
else
break; // ASSUME: insertion is done in order; first lessThan means rest will also be lessThan
}
return rv;
}
List_adp list = List_adp_.New();
public static GfmlScopeList new_(String key) {
GfmlScopeList rv = new GfmlScopeList(); rv.key = key; return rv;
} GfmlScopeList() {}
}

View File

@@ -1,50 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.lists.*;/*Hash_adp_list*/
interface GfmlPragma {
String KeyOfPragma();
void Exec(GfmlBldr bldr, GfmlNde pragmaNde);
GfmlType[] MakePragmaTypes(GfmlTypeMakr typeMakr);
}
class GfmlPragmaMgr {
public void Pragmas_add(GfmlPragma cmd) {pragmas.Add(cmd.KeyOfPragma(), cmd);}
public boolean Pragmas_compile(String ndeName, GfmlBldr bldr) {
if (pragmas.Count() == 0) return false;
GfmlPragma cmd = (GfmlPragma)pragmas.Get_by(ndeName); if (cmd == null) return false;
GfmlNde pragmaNde = bldr.CurNde();
pragmaNde.ObjType_set_pragma();
cmd.Exec(bldr, pragmaNde);
return true;
}
public void BgnCmds_add(GfmlDocPos pos, GfmlBldrCmd cmd) {bgnCmds.AddInList(pos.Path(), cmd);}
public void BgnCmds_del(GfmlDocPos pos, GfmlBldrCmd cmd) {bgnCmds.DelInList(pos.Path(), cmd);}
public void BgnCmds_exec(GfmlDocPos pos, GfmlBldr bldr) {Exec(pos, bldr, bgnCmds);}
public void EndCmds_add(GfmlDocPos pos, GfmlBldrCmd cmd) {endCmds.AddInList(pos.Path(), cmd);}
public void EndCmds_del(GfmlDocPos pos, GfmlBldrCmd cmd) {endCmds.DelInList(pos.Path(), cmd);}
public void EndCmds_exec(GfmlDocPos pos, GfmlBldr bldr) {Exec(pos, bldr, endCmds);}
static void Exec(GfmlDocPos pos, GfmlBldr bldr, Hash_adp_list cmds) {
List_adp list = cmds.Get_by(pos.Path()); if (list == null) return;
for (int i = 0; i < list.Count(); i++) {
GfmlBldrCmd cmd = (GfmlBldrCmd)list.Get_at(i);
cmd.Exec(bldr, GfmlTkn_.Null);
}
}
Hash_adp pragmas = Hash_adp_.New(); Hash_adp_list bgnCmds = Hash_adp_list.new_(), endCmds = Hash_adp_list.new_();
public static GfmlPragmaMgr new_() {return new GfmlPragmaMgr();} GfmlPragmaMgr() {}
}

View File

@@ -1,133 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlPragmaDefault implements GfmlPragma {
public String KeyOfPragma() {return "_default";}
public void Exec(GfmlBldr bldr, GfmlNde pragmaNde) {
List_adp list = Compile(pragmaNde);
GfmlDefaultPragma_bgnCmd.ExecList(bldr.TypeMgr().TypeRegy(), bldr.CurNdeFrame().CurDocPos(), list);
// bldr.PragmaMgr.EndCmds_add(GfmlDocPos_.up_(bldr.CurNdeFrame.DocPos), GfmlDefaultPragma_endCmd.new_(list));
}
@gplx.Internal protected List_adp Compile(GfmlNde pragmaNde) {
List_adp list = List_adp_.New();
for (int i = 0; i < pragmaNde.SubHnds().Count(); i++) {
GfmlNde subNde = (GfmlNde)pragmaNde.SubHnds().Get_at(i);
CompileSubNde(subNde, list);
}
return list;
}
@gplx.Internal protected void CompileSubNde(GfmlNde nde, List_adp list) {
String typeKey = nde.SubKeys().FetchDataOrNull("typeKey"); if (typeKey == null) throw Err_.new_missing_key("typeKey");
for (int i = 0; i < nde.SubHnds().Count(); i++) {
GfmlNde subNde = (GfmlNde)nde.SubHnds().Get_at(i);
GfmlDefaultItem item = CompileItem(subNde, typeKey);
list.Add(item);
}
}
@gplx.Internal protected GfmlDefaultItem CompileItem(GfmlNde nde, String typeKey) {
String key = nde.SubKeys().FetchDataOrFail("key");
GfmlTkn valTkn = nde.SubKeys().FetchDataTknOrNull("val");
return GfmlDefaultItem.new_(typeKey, key, valTkn);
}
public GfmlType[] MakePragmaTypes(GfmlTypeMakr makr) {
makr.MakeSubTypeAsOwner( "_default");
makr.MakeSubTypeAsOwner( "type", "typeKey");
makr.MakeSubTypeAsOwner( "atr", "key", "val");
return makr.Xto_bry();
}
public static GfmlPragmaDefault new_() {return new GfmlPragmaDefault();} GfmlPragmaDefault() {}
public static final GfmlTkn Default_none = GfmlTkn_.raw_("DEFAULT NONE");
}
class GfmlDefaultItem {
public String TypeKey() {return typeKey;} private String typeKey;
public String Key() {return key;} private String key;
public GfmlObj Val() {return val;} GfmlObj val;
public GfmlObj ValPrev() {return valPrev;} @gplx.Internal protected GfmlDefaultItem ValPrev_(GfmlObj tkn) {valPrev = tkn; return this;} GfmlObj valPrev;
public void Exec_bgn(GfmlType type) {
GfmlFld fld = type.SubFlds().Get_by(key);
if (fld == null) { // no default defined; create
valPrev = GfmlPragmaDefault.Default_none;
fld = GfmlFld.new_(true, key, GfmlType_.StringKey).DefaultTkn_(val);
type.SubFlds().Add(fld);
}
else { // default exists; overwrite
valPrev = fld.DefaultTkn();
fld.DefaultTkn_(val);
}
}
public void Exec_end(GfmlType type) {
GfmlFld fld = type.SubFlds().Get_by(key); if (fld == null) return;
// if (fld == null) throw Err_.arg_range_msg_("fatal: could not find fld; typeKey={0} fld={1}", typeKey, key);
if (valPrev == GfmlPragmaDefault.Default_none) // drop default; (had been created by pragma)
type.SubFlds().Del(fld);
else // restore default
fld.DefaultTkn_(valPrev);
}
public static GfmlDefaultItem new_(String typeKey, String key, GfmlTkn val) {
GfmlDefaultItem rv = new GfmlDefaultItem();
rv.typeKey = typeKey;
rv.key = key;
rv.val = val;
return rv;
} GfmlDefaultItem() {}
}
class GfmlDefaultPragma_bgnCmd implements GfmlBldrCmd {
public String Key() {return "pragma:gfml.default.bgnCmd";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {ExecList(bldr.TypeMgr().TypeRegy(), bldr.CurNdeFrame().CurDocPos(), list);}
@gplx.Internal protected static void ExecList(GfmlTypRegy regy, GfmlDocPos pos, List_adp list) {
GfmlType type = GfmlType_.Null;
for (Object itemObj : list) {
GfmlDefaultItem item = (GfmlDefaultItem)itemObj;
if (!String_.Eq(item.TypeKey(), type.Key())) {
type = regy.FetchOrNull(item.TypeKey(), pos);
if (type == GfmlType_.Null) throw Err_.new_wo_type("default type must exist", "typeKey", item.TypeKey());
}
type = type.Clone().DocPos_(pos);
regy.Add(type);
item.Exec_bgn(type);
}
}
List_adp list;
public static GfmlDefaultPragma_bgnCmd new_(List_adp list) {
GfmlDefaultPragma_bgnCmd rv = new GfmlDefaultPragma_bgnCmd();
rv.list = list;
return rv;
} GfmlDefaultPragma_bgnCmd() {}
}
class GfmlDefaultPragma_endCmd implements GfmlBldrCmd {
public String Key() {return "pragma:gfml.default.endCmd";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {ExecList(bldr.TypeMgr().TypeRegy(), list);}
public static void ExecList(GfmlTypRegy regy, List_adp list) {
GfmlType type = GfmlType_.Null;
for (Object itemObj : list) {
GfmlDefaultItem item = (GfmlDefaultItem)itemObj;
if (!String_.Eq(item.TypeKey(), type.Key())) {
type = regy.FetchOrNull(item.TypeKey());
if (type == GfmlType_.Null) throw Err_.new_wo_type("fatal: default type must exist", "typeKey", item.TypeKey());
}
item.Exec_end(type);
}
}
List_adp list;
public static GfmlDefaultPragma_endCmd new_(List_adp list) {
GfmlDefaultPragma_endCmd rv = new GfmlDefaultPragma_endCmd();
rv.list = list;
return rv;
} GfmlDefaultPragma_endCmd() {}
}

View File

@@ -1,64 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlPragmaLxrFrm implements GfmlPragma {
public String KeyOfPragma() {return "_lxr_frame";}
public void Exec(GfmlBldr bldr, GfmlNde pragmaNde) {
Compile(bldr, pragmaNde);
}
@gplx.Internal protected static GfmlLxr Compile(GfmlBldr bldr, GfmlNde ownerNde) {
String key = ownerNde.SubKeys().FetchDataOrFail("key");
String type = ownerNde.SubKeys().FetchDataOrNull("type");
String bgn = ownerNde.SubKeys().FetchDataOrFail("bgn");
String end = ownerNde.SubKeys().FetchDataOrFail("end");
GfmlFrame frame = String_.Eq(type, "comment") ? GfmlFrame_.comment_() : GfmlFrame_.quote_();
GfmlLxr lxr = bldr.Doc().LxrRegy().Get_by(key);
if (lxr == null) {
lxr = GfmlLxr_.frame_(key, frame, bgn, end);
bldr.Doc().LxrRegy().Add(lxr);
bldr.Doc().RootLxr().SubLxr_Add(lxr); // FIXME: always add to cur lxr; should be outside if block; also, auto_add=n to skip adding to rootLxr
}
else {
GfmlLxr_frame frameLxr = GfmlLxr_frame.as_(lxr); if (frameLxr == null) throw Err_.new_wo_type("lxr is not GfmlLxr_frame", "key", key, "type", Type_adp_.NameOf_obj(lxr));
if (type != null) {
// frame = frameLxr.Frame.MakeNew(frameLxr);
}
if (bgn != null) {
frameLxr.BgnRaw_set(bgn);
}
if (end != null) {
frameLxr.EndRaw_set(end);
// end = frameLxr.EndLxr.CmdTkn.Raw;
}
}
for (int i = 0; i < ownerNde.SubHnds().Count(); i++) {
GfmlNde subNde = (GfmlNde)ownerNde.SubHnds().Get_at(i);
GfmlLxr subLxr = null;
if (String_.Eq(subNde.Hnd(), "sym"))
subLxr = GfmlPragmaLxrSym.Compile(bldr, subNde);
lxr.SubLxr_Add(subLxr);
}
return lxr;
}
public GfmlType[] MakePragmaTypes(GfmlTypeMakr makr) {
makr.MakeRootType("_lxr_frame", "_lxr_frame", "key", "type", "bgn", "end");
return makr.Xto_bry();
}
public static GfmlPragmaLxrFrm new_() {return new GfmlPragmaLxrFrm();} GfmlPragmaLxrFrm() {}
}

View File

@@ -1,56 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlPragmaLxrSym implements GfmlPragma {
public String KeyOfPragma() {return "_lxr_sym";}
public void Exec(GfmlBldr bldr, GfmlNde pragmaNde) {
Compile(bldr, pragmaNde);
}
@gplx.Internal protected static GfmlLxr Compile(GfmlBldr bldr, GfmlNde ownerNde) {
String key = ownerNde.SubKeys().FetchDataOrFail("key");
String raw = ownerNde.SubKeys().FetchDataOrFail("raw");
String val = ownerNde.SubKeys().FetchDataOr("val", raw);
GfmlTkn cmdTkn = ownerNde.SubKeys().FetchDataTknOrNull("cmd");
GfmlBldrCmd cmd = bldr.Doc().CmdRegy().GetOrFail(cmdTkn.Val());
GfmlLxr lxr = bldr.Doc().LxrRegy().Get_by(key);
if (lxr == null) {
lxr = GfmlLxr_.symbol_(key, raw, val, cmd);
bldr.Doc().LxrRegy().Add(lxr);
bldr.Doc().RootLxr().SubLxr_Add(lxr); // FIXME: always add to cur lxr; should be outside if block; also, auto_add=n to skip adding to rootLxr
}
else {
GfmlTkn curTkn = lxr.CmdTkn();
if (raw == null) raw = curTkn.Raw();
if (val == null) val = curTkn.Val();
if (String_.Eq(cmdTkn.Raw(), GfmlTkn_.NullRaw)) cmd = bldr.Doc().CmdRegy().GetOrFail(curTkn.Cmd_of_Tkn().Key());
GfmlTkn tkn = GfmlTkn_.singleton_(key, raw, val, cmd);
lxr.CmdTkn_set(tkn);
}
return lxr;
}
public GfmlType[] MakePragmaTypes(GfmlTypeMakr makr) {
makr.MakeRootType("_lxr_sym", "_lxr_sym", "key", "raw");
GfmlFld fld = GfmlFld.new_(true, "cmd", GfmlType_.StringKey).DefaultTkn_(GfmlTkn_.val_("gfml.elm_data"));
makr.AddSubFld(fld);
return makr.Xto_bry();
}
public static GfmlPragmaLxrSym new_() {return new GfmlPragmaLxrSym();} GfmlPragmaLxrSym() {}
public static final String CacheLog_key = "log:var";
}

View File

@@ -1,79 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.lists.*;
class GfmlPragmaType implements GfmlPragma {
public String KeyOfPragma() {return pragmaKey;} private String pragmaKey = "_type";
public void Exec(GfmlBldr bldr, GfmlNde pragmaNde) {
Ordered_hash list = Ordered_hash_.New(); List_adp replaced = List_adp_.New();
for (int i = 0 ; i < pragmaNde.SubHnds().Count(); i++) {
GfmlNde typNde = pragmaNde.SubHnds().Get_at(i);
GfmlType type = GfmlTypeCompiler.Compile(typNde, GfmlType_.Root, bldr.TypeMgr().TypeRegy(), list);
if (i == 0) {
GfmlFrame_nde topFrame = GfmlFrame_nde_.as_(bldr.CurFrame());
AssignDefaultType(type, topFrame.CurNde(), bldr);
}
}
ExecList(bldr.TypeMgr().TypeRegy(), list, replaced);
// bldr.PragmaMgr().EndCmds_add(bldr.CurNdeFrame().DocPos().NewUp(), GfmlPragmaType_endCmd.new_(list, replaced)); // expireCmd commented out?
}
void AssignDefaultType(GfmlType type, GfmlNde nde, GfmlBldr bldr) {
if (nde.Type().IsTypeNull())
nde.Type_set(GfmlType_.new_any_());
GfmlFld subFld = GfmlFld.new_(false, type.NdeName(), type.Key());
nde.Type().SubFlds().Add(subFld);
bldr.TypeMgr().OverridePool(type);
}
public static GfmlPragmaType new_() {return new GfmlPragmaType();} GfmlPragmaType() {}
public GfmlType[] MakePragmaTypes(GfmlTypeMakr makr) {
makr.MakeSubTypeAsOwner( "_type");
makr.MakeSubTypeAsOwner( "type", "name", "key");
makr.MakeSubTypeAsOwner( "fld", "name", "default", "type");
makr.AddSubFld(GfmlFld.new_(false, "fld", "_type/type/fld"));
return makr.Xto_bry();
}
public static final String CacheLog_key = "log:type";
@gplx.Internal protected static void ExecList(GfmlTypRegy regy, Ordered_hash list, List_adp replaced) {
for (Object typeObj : list) {
GfmlType type = (GfmlType)typeObj;
if (regy.Has(type.Key()))
replaced.Add(type);
regy.Add(type);
}
}
}
class GfmlPragmaType_endCmd implements GfmlBldrCmd {
public String Key() {return "cmd.gfml.type.end";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {ExecList(bldr.TypeMgr().TypeRegy(), list, replaced);}
@gplx.Internal protected static void ExecList(GfmlTypRegy regy, Ordered_hash list, List_adp replaced) {
for (Object typeObj : list) {
GfmlType type = (GfmlType)typeObj;
regy.Del(type);
}
for (Object typeObj : replaced) {
GfmlType type = (GfmlType)typeObj;
regy.Add(type);
}
}
Ordered_hash list; List_adp replaced;
public static GfmlPragmaType_endCmd new_(Ordered_hash list, List_adp replaced) {
GfmlPragmaType_endCmd rv = new GfmlPragmaType_endCmd();
rv.list = list; rv.replaced = replaced;
return rv;
} GfmlPragmaType_endCmd() {}
}

View File

@@ -1,78 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlPragmaVar implements GfmlPragma {
public String KeyOfPragma() {return pragmaKey;} public void PragmaKey_set(String v) {pragmaKey = v;} private String pragmaKey = "_var";
public void Exec(GfmlBldr bldr, GfmlNde pragmaNde) {
List_adp list = Compile(pragmaNde);
ExecList(bldr.Vars(), list);
bldr.Doc().PragmaMgr().EndCmds_add(bldr.CurNdeFrame().CurDocPos().NewUp(), GfmlPragmaVar_scopeEndCmd.new_(list));
}
@gplx.Internal protected List_adp Compile(GfmlNde pragmaNde) {
List_adp list = List_adp_.New();
for (int i = 0; i < pragmaNde.SubHnds().Count(); i++) {
GfmlNde subNde = (GfmlNde)pragmaNde.SubHnds().Get_at(i);
GfmlVarItm itm = CompileItmNde(subNde);
list.Add(itm);
}
return list;
}
@gplx.Internal protected GfmlVarItm CompileItmNde(GfmlNde subNde) {
String key = subNde.SubKeys().FetchDataOrFail("key");
GfmlAtr valAtr = (GfmlAtr)subNde.SubKeys().Get_by("val");
String ctx = subNde.SubKeys().FetchDataOrNull("ctx"); if (ctx == null) ctx = GfmlVarCtx_.DefaultKey;
return GfmlVarItm.new_(key, valAtr.DatTkn(), ctx);
}
public GfmlType[] MakePragmaTypes(GfmlTypeMakr makr) {
makr.MakeSubTypeAsOwner (pragmaKey);
makr.MakeSubType ( "text", "key", "val", "ctx");
return makr.Xto_bry();
}
void ExecList(Hash_adp cache, List_adp list) {
GfmlVarCtx ctx = null;
for (Object varObj : list) {
GfmlVarItm var = (GfmlVarItm)varObj;
ctx = FetchIfNew(ctx, var, cache);
var.Scope_bgn(ctx);
}
}
public static GfmlPragmaVar new_() {return new GfmlPragmaVar();} GfmlPragmaVar() {}
public static GfmlVarCtx FetchIfNew(GfmlVarCtx ctx, GfmlVarItm var, Hash_adp cache) {// reused in two procs
if (ctx == null || !String_.Eq(ctx.Key(), var.CtxKey()))
ctx = GfmlVarCtx_.FetchFromCacheOrNew(cache, var.CtxKey());
return ctx;
}
}
class GfmlPragmaVar_scopeEndCmd implements GfmlBldrCmd {
public String Key() {return "cmd:gfml.var.expire";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
Hash_adp cache = bldr.Vars();
GfmlVarCtx ctx = null;
for (Object varObj : list) {
GfmlVarItm var = (GfmlVarItm)varObj;
ctx = GfmlPragmaVar.FetchIfNew(ctx, var, cache);
var.Scope_end(ctx);
}
}
List_adp list;
public static GfmlPragmaVar_scopeEndCmd new_(List_adp list) {
GfmlPragmaVar_scopeEndCmd rv = new GfmlPragmaVar_scopeEndCmd();
rv.list = list;
return rv;
} GfmlPragmaVar_scopeEndCmd() {}
}

View File

@@ -1,62 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlVarCtx {
public String Key() {return key;} private String key;
public void Add_if_dupe_use_nth(GfmlVarItm itm) {hash.Add_if_dupe_use_nth(itm.Key(), itm);}
public void Del(String key) {hash.Del(key);}
public String Fetch_Val(String key) {
GfmlVarItm itm = (GfmlVarItm)hash.Get_by(key); if (itm == null) return null;
return itm.TknVal();
}
Hash_adp hash = Hash_adp_.New();
public static GfmlVarCtx new_(String key) {
GfmlVarCtx rv = new GfmlVarCtx();
rv.key = key;
return rv;
}
}
class GfmlVarCtx_ {
public static GfmlVarCtx FetchFromCacheOrNew(Hash_adp cache, String ctxKey) {
Hash_adp ctxRegy = FetchRegyOrNew(cache);
GfmlVarCtx rv = (GfmlVarCtx)ctxRegy.Get_by(ctxKey);
if (rv == null) {
rv = (String_.Eq(ctxKey, DefaultKey))
? default_(ctxKey)
: GfmlVarCtx.new_(ctxKey);
ctxRegy.Add(rv.Key(), rv);
}
return rv;
}
static GfmlVarCtx default_(String ctxKey) {
GfmlVarCtx rv = GfmlVarCtx.new_(ctxKey);
rv.Add_if_dupe_use_nth(GfmlVarItm.new_("t", GfmlTkn_.raw_("\t"), GfmlVarCtx_.DefaultKey));
rv.Add_if_dupe_use_nth(GfmlVarItm.new_("n", GfmlTkn_.raw_(String_.CrLf), GfmlVarCtx_.DefaultKey));
return rv;
}
static Hash_adp FetchRegyOrNew(Hash_adp cache) {
String key = "gfml.cacheKeys.ctxRegy";
Hash_adp rv = (Hash_adp)cache.Get_by(key);
if (rv == null) {
rv = Hash_adp_.New();
cache.Add(key, rv);
}
return rv;
}
public static final String DefaultKey = "gfml.varKeys.default";
}

View File

@@ -1,32 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlVarItm implements GfmlScopeItm {
public String Key() {return key;} private String key;
public GfmlDocPos DocPos() {return docPos;} public GfmlVarItm DocPos_(GfmlDocPos v) {docPos = v; return this;} GfmlDocPos docPos = GfmlDocPos_.Null;
public GfmlTkn Tkn() {return tkn;} public void Tkn_set(GfmlTkn v) {tkn = v;} GfmlTkn tkn;
public String TknVal() {return tkn.Val();}
public String CtxKey() {return ctxKey;} private String ctxKey;
@gplx.Internal protected void Scope_bgn(GfmlVarCtx ctx) {ctx.Add_if_dupe_use_nth(this);}
@gplx.Internal protected void Scope_end(GfmlVarCtx ctx) {ctx.Del(key);}
public static GfmlVarItm new_(String key, GfmlTkn tkn, String ctxKey) {
GfmlVarItm rv = new GfmlVarItm();
rv.key = key; rv.tkn = tkn; rv.ctxKey = ctxKey;
return rv;
} GfmlVarItm() {}
}

View File

@@ -1,39 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlVarTkn implements GfmlTkn {
public int ObjType() {return GfmlObj_.Type_tkn;}
public String Key() {return key;} private String key;
public String Raw() {return GfmlTknAry_.XtoRaw(ary);}
public String Val() {
String s = ctx.Fetch_Val(varKey); if (s == null) return val;
val = s;
return val;
} String val;
public GfmlBldrCmd Cmd_of_Tkn() {return GfmlBldrCmd_.Null;}
public GfmlTkn[] SubTkns() {return ary;} GfmlTkn[] ary;
public GfmlTkn MakeNew(String rawNew, String valNew) {throw Err_.new_invalid_op("makeNew cannot make copy of token with only raw").Args_add("key", key, "rawNew", rawNew, "valNew", valNew);}
public String TknType() {return "evalTkn";}
GfmlVarCtx ctx; String varKey;
@gplx.Internal protected GfmlVarTkn(String key, GfmlTkn[] ary, GfmlVarCtx ctx, String varKey) {
this.key = key; this.ary = ary;
this.ctx = ctx; this.varKey = varKey;
this.val = ctx.Fetch_Val(varKey);
}
}

View File

@@ -1,74 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.texts.*; /*CharStream*/
public class GfmlBldr {
@gplx.Internal protected GfmlDoc Doc() {return gdoc;} GfmlDoc gdoc = GfmlDoc.new_();
@gplx.Internal protected GfmlFrame CurFrame() {return curFrame;} GfmlFrame curFrame;
@gplx.Internal protected GfmlFrame_nde CurNdeFrame() {return curNdeFrame;} GfmlFrame_nde curNdeFrame;
@gplx.Internal protected GfmlNde CurNde() {return curNdeFrame.CurNde();}
@gplx.Internal protected GfmlTypeMgr TypeMgr() {return typeMgr;} GfmlTypeMgr typeMgr = GfmlTypeMgr.new_();
@gplx.Internal protected Hash_adp Vars() {return vars;} Hash_adp vars = Hash_adp_.New();
@gplx.Internal protected int StreamPos() {return streamPos;} int streamPos;
@gplx.Internal protected void ThrowErrors_set(boolean v) {throwErrors = v;} private boolean throwErrors = true;
@gplx.Internal protected int PrvSymType() {return prvSymType;} @gplx.Internal protected void PrvSymType_set(int v) {prvSymType = v;} int prvSymType = GfmlNdeSymType.Null;
@gplx.Internal protected int ChainIdNext() {return chainIdNext++;} int chainIdNext = 1;
public GfmlDoc XtoGfmlDoc(String raw) {
Init(raw);
CharStream stream = CharStream.pos0_(raw);
while (stream.AtMid()) {
streamPos = stream.Pos(); // NOTE: streamPos is defined as just before curTkn
GfmlTkn curTkn = curFrame.Lxr().MakeTkn(stream, 0);
curTkn.Cmd_of_Tkn().Exec(this, curTkn);
if (stopBldr) break;
}
if (!stopBldr) {
curNdeFrame.Build_end(this, GfmlFrame_nde_.OwnerRoot_);
if (frameStack.Count() > 0) UsrMsgs_fail(GfmlUsrMsgs.fail_Frame_danglingBgn());
}
if (throwErrors && gdoc.UsrMsgs().Count() > 0) throw GfmlUsrMsgs.gfmlParseError(this);
raw = "";
return gdoc;
}
void Init(String raw) {
this.raw = raw; stopBldr = false; gdoc.Clear(); vars.Clear(); frameStack.Clear(); chainIdNext = 1;
curNdeFrame = GfmlFrame_nde_.root_(this, gdoc.RootNde(), gdoc.RootLxr());
curNdeFrame.NullArea_set(true);
curFrame = curNdeFrame;
}
@gplx.Internal protected void Frames_push(GfmlFrame newFrame) {
frameStack.Push(curFrame);
curFrame = newFrame;
if (curFrame.FrameType() == GfmlFrame_.Type_nde) curNdeFrame = GfmlFrame_nde_.as_(curFrame);
}
@gplx.Internal protected void Frames_end() {
if (frameStack.Count() == 0) {
UsrMsgs_fail(GfmlUsrMsgs.fail_Frame_danglingBgn());
return;
}
GfmlFrame oldFrame = curFrame;
curFrame = frameStack.Pop();
oldFrame.Build_end(this, curFrame);
if (curFrame.FrameType() == GfmlFrame_.Type_nde) curNdeFrame = GfmlFrame_nde_.as_(curFrame);
}
@gplx.Internal protected void UsrMsgs_fail(UsrMsg um) {
GfmlUsrMsgs.MakeErr(this, um, raw);
stopBldr = true;
}
GfmlFrameStack frameStack = GfmlFrameStack.new_(); boolean stopBldr = false; String raw = "";
}

View File

@@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public interface GfmlBldrCmd {
String Key();
void Exec(GfmlBldr bldr, GfmlTkn tkn);
}
class GfmlBldrCmd_ {
public static final GfmlBldrCmd Null = new GfmlBldrCmd_null();
}
class GfmlBldrCmd_null implements GfmlBldrCmd {
public String Key() {return "gfml.nullCmd";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {}
}
class GfmlBldrCmdRegy {
public void Add(GfmlBldrCmd cmd) {hash.Add(cmd.Key(), cmd);}
public GfmlBldrCmd GetOrFail(String key) {return (GfmlBldrCmd)hash.Get_by_or_fail(key);}
Hash_adp hash = Hash_adp_.New();
public static GfmlBldrCmdRegy new_() {
GfmlBldrCmdRegy rv = new GfmlBldrCmdRegy();
rv.Add(GfmlBldrCmd_elemKey_set.Instance);
rv.Add(GfmlBldrCmd_dataTkn_set.Instance);
return rv;
} GfmlBldrCmdRegy() {}
}

View File

@@ -1,128 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlBldrCmd_pendingTkns_add implements GfmlBldrCmd {
public String Key() {return "gfml.pendingTkns_add";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurFrame().WaitingTkns().Add(tkn);}
public static final GfmlBldrCmd_pendingTkns_add Instance = new GfmlBldrCmd_pendingTkns_add(); GfmlBldrCmd_pendingTkns_add() {}
}
class GfmlBldrCmd_dataTkn_set implements GfmlBldrCmd {
public String Key() {return "gfml.elm_data";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().DatTkn_set(tkn);}
public static final GfmlBldrCmd_dataTkn_set Instance = new GfmlBldrCmd_dataTkn_set(); GfmlBldrCmd_dataTkn_set() {}
}
class GfmlBldrCmd_elemKey_set implements GfmlBldrCmd {
public String Key() {return "gfml.elm_key";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().KeyTkn_set(tkn);}
public static final GfmlBldrCmd_elemKey_set Instance = new GfmlBldrCmd_elemKey_set(); GfmlBldrCmd_elemKey_set() {}
}
class GfmlBldrCmd_ndeName_set implements GfmlBldrCmd {
public String Key() {return "gfml.ndeName_set";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().NdeHeader_set(tkn);}
public static final GfmlBldrCmd_ndeName_set Instance = new GfmlBldrCmd_ndeName_set(); GfmlBldrCmd_ndeName_set() {}
}
class GfmlBldrCmd_ndeBody_bgn implements GfmlBldrCmd {
public String Key() {return "gfml.nodeBody_bgn";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
bldr.CurNdeFrame().NdeBody_bgn(tkn);
bldr.CurNdeFrame().BgnPos_set(bldr.StreamPos() - String_.Len(tkn.Raw()));// stream has already advanced tkn.len so subtract
}
public static final GfmlBldrCmd_ndeBody_bgn Instance = new GfmlBldrCmd_ndeBody_bgn(); GfmlBldrCmd_ndeBody_bgn() {}
}
class GfmlBldrCmd_ndeProp_bgn implements GfmlBldrCmd {
public String Key() {return "cmd.gfml.ndeProp_bgn";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().NdeProp_bgn(tkn);}
public static final GfmlBldrCmd_ndeProp_bgn Instance = new GfmlBldrCmd_ndeProp_bgn(); GfmlBldrCmd_ndeProp_bgn() {}
}
class GfmlBldrCmd_ndeHdr_bgn implements GfmlBldrCmd {
public String Key() {return "cmd.gfml.ndeHdr_bgn";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().NdeParen_bgn(tkn);}
public static final GfmlBldrCmd_ndeHdr_bgn Instance = new GfmlBldrCmd_ndeHdr_bgn(); GfmlBldrCmd_ndeHdr_bgn() {}
}
class GfmlBldrCmd_ndeHdr_end implements GfmlBldrCmd {
public String Key() {return "cmd.gfml.ndeHdr_end";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().NdeParen_end(tkn);}
public static final GfmlBldrCmd_ndeHdr_end Instance = new GfmlBldrCmd_ndeHdr_end(); GfmlBldrCmd_ndeHdr_end() {}
}
class GfmlBldrCmd_ndeInline implements GfmlBldrCmd {
public String Key() {return "gfml.nodeInline_exec_end";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().NdeInline(tkn);}
public static final GfmlBldrCmd_ndeInline Instance = new GfmlBldrCmd_ndeInline(); GfmlBldrCmd_ndeInline() {}
}
class GfmlBldrCmd_ndeDot implements GfmlBldrCmd {
public String Key() {return "gfml.ndeDot";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().NdeDot(tkn);}
public static final GfmlBldrCmd_ndeDot Instance = new GfmlBldrCmd_ndeDot(); GfmlBldrCmd_ndeDot() {}
}
class GfmlBldrCmd_atrSpr implements GfmlBldrCmd {
public String Key() {return "gfml.nodeInline_atrSpr";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {bldr.CurNdeFrame().AtrSpr(tkn);}
public static final GfmlBldrCmd_atrSpr Instance = new GfmlBldrCmd_atrSpr(); GfmlBldrCmd_atrSpr() {}
}
class GfmlBldrCmd_frameBgn implements GfmlBldrCmd {
public String Key() {return "gfml.frame_bgn";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
GfmlFrame newFrame = frame.MakeNew(lxr.SubLxr());
bldr.Frames_push(newFrame);
bldr.CurFrame().WaitingTkns().Add(tkn);
bldr.CurNdeFrame().BgnPos_set(bldr.StreamPos() - String_.Len(tkn.Raw()));// stream has already advanced tkn.len so subtract
}
GfmlLxr lxr; GfmlFrame frame;
public static GfmlBldrCmd_frameBgn new_(GfmlFrame frame, GfmlLxr lxr) {
GfmlBldrCmd_frameBgn rv = new GfmlBldrCmd_frameBgn();
rv.frame = frame; rv.lxr = lxr;
return rv;
} GfmlBldrCmd_frameBgn() {}
}
class GfmlBldrCmd_frameEnd implements GfmlBldrCmd {
public String Key() {return "gfml.frame_end";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
if (bldr.CurFrame().FrameType() == GfmlFrame_.Type_nde) {
GfmlFrame_nde ndeFrm = (GfmlFrame_nde)bldr.CurFrame();
ndeFrm.WaitingTkns_AddSym(tkn, ndeSymType);
}
else
bldr.CurFrame().WaitingTkns().Add(tkn);
if (bldr.CurNdeFrame().CurNdeStartType() == GfmlNdeStartType.Prop
&& String_.Eq(tkn.Raw(), "}")) return;
bldr.Frames_end();
}
int ndeSymType;
public static GfmlBldrCmd_frameEnd data_() {return nde_(GfmlNdeSymType.Null);}
public static GfmlBldrCmd_frameEnd nde_(int ndeSymType) {
GfmlBldrCmd_frameEnd rv = new GfmlBldrCmd_frameEnd();
rv.ndeSymType = ndeSymType;
return rv;
} GfmlBldrCmd_frameEnd() {}
}
class GfmlBldrCmd_whitespace implements GfmlBldrCmd {
public String Key() {return "gfml.whitespace_exec";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
if (bldr.CurNdeFrame().waitingTkns.Count() > 0) {
GfmlObj t = (GfmlObj)bldr.CurNdeFrame().waitingTkns.Get_at(bldr.CurNdeFrame().waitingTkns.Count() - 1);
if (t.ObjType() == GfmlObj_.Type_nde)
bldr.CurNdeFrame().IdxNdeBgn_set(bldr.CurNdeFrame().WaitingTkns().Count() + 1);
}
if (bldr.CurFrame().WaitingTkns().Count() == 0) {
bldr.CurNde().SubObjs_Add(tkn); // if curFrame begins with whitespace, add directly to node (whitespace should not belong to atr)
}
else
bldr.CurFrame().WaitingTkns().Add(tkn);
}
public static final GfmlBldrCmd_whitespace Instance = new GfmlBldrCmd_whitespace(); GfmlBldrCmd_whitespace() {}
}

View File

@@ -1,44 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlBldr_ {
@gplx.Internal protected static GfmlBldr new_() {return new GfmlBldr();}
@gplx.Internal protected static GfmlBldr default_() {
GfmlBldr rv = new GfmlBldr();
GfmlLxr rootLxr = GfmlDocLxrs.Root_lxr();
GfmlDocLxrs.Default_lxr(rv.Doc().LxrRegy(), rootLxr);
rv.Doc().RootLxr_set(rootLxr);
InitDocBldr(rv
, GfmlPragmaVar.new_()
, GfmlPragmaType.new_()
, GfmlPragmaDefault.new_()
, GfmlPragmaLxrSym.new_()
, GfmlPragmaLxrFrm.new_()
);
return rv;
}
static void InitDocBldr(GfmlBldr bldr, GfmlPragma... ary) {
GfmlTypeMakr makr = GfmlTypeMakr.new_();
GfmlTypRegy regy = bldr.TypeMgr().TypeRegy(); GfmlPragmaMgr cmdMgr = bldr.Doc().PragmaMgr();
for (GfmlPragma pragma : ary) {
regy.Add_ary(pragma.MakePragmaTypes(makr));
cmdMgr.Pragmas_add(pragma);
}
}
}

View File

@@ -1,35 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.lists.*; /*StackAdp*/
public interface GfmlFrame {
GfmlLxr Lxr(); // each frame has only one lxr
int FrameType();
GfmlObjList WaitingTkns();
void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame);
GfmlFrame MakeNew(GfmlLxr newLxr);
}
class GfmlFrameStack {
public int Count() {return stack.Count();}
public void Push(GfmlFrame frame) {stack.Push(frame);}
public GfmlFrame Pop() {return (GfmlFrame)stack.Pop();}
public GfmlFrame Peek() {return (GfmlFrame)stack.Peek();}
public void Clear() {stack.Clear();}
StackAdp stack = StackAdp_.new_();
public static GfmlFrameStack new_() {return new GfmlFrameStack();} GfmlFrameStack() {}
}

View File

@@ -1,87 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlFrame_ {
public static GfmlFrame comment_() {return new GfmlFrame_comment();}
public static GfmlFrame quote_() {return new GfmlFrame_quote();}
public static GfmlFrame eval_() {return new GfmlFrame_eval();}
public static final int
Type_nde = 1
, Type_data = 2
, Type_comment = 3
;
}
abstract class GfmlFrame_base implements GfmlFrame {
public GfmlLxr Lxr() {return lxr;} GfmlLxr lxr;
public abstract int FrameType();
public int BgnPos() {return bgnPos;} public void BgnPos_set(int v) {bgnPos = v;} int bgnPos;
public GfmlObjList WaitingTkns() {return waitingTkns;} @gplx.Internal protected final GfmlObjList waitingTkns = GfmlObjList.new_();
public GfmlFrame MakeNew(GfmlLxr newLxr) {GfmlFrame_base rv = MakeNew_hook(); rv.ctor_(newLxr); return rv;}
public abstract void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame);
protected abstract GfmlFrame_base MakeNew_hook();
protected void ctor_(GfmlLxr lxr) {this.lxr = lxr;}
}
class GfmlFrame_comment extends GfmlFrame_base {
@Override public int FrameType() {return GfmlFrame_.Type_comment;}
@Override public void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame) {
GfmlTkn commentTkn = GfmlTkn_.composite_list_("tkn:comment", waitingTkns);
ownerFrame.WaitingTkns().Add(commentTkn); // always add commentTkn to WaitingTkns
}
@Override protected GfmlFrame_base MakeNew_hook() {return new GfmlFrame_comment();}
}
class GfmlFrame_quote extends GfmlFrame_base {
@Override public int FrameType() {return GfmlFrame_.Type_data;}
@Override public void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame) {
GfmlTkn quoteTkn = GfmlTkn_.composite_list_("tkn:quote", waitingTkns);
GfmlFrameUtl.AddFrameTkn(ownerFrame, quoteTkn);
}
@Override protected GfmlFrame_base MakeNew_hook() {return new GfmlFrame_quote();}
}
class GfmlFrame_eval extends GfmlFrame_base {
@Override public int FrameType() {return GfmlFrame_.Type_data;}
@Override public void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame) {
GfmlTkn evalTkn = MakeEvalTkn(bldr, waitingTkns);
GfmlFrameUtl.AddFrameTkn(ownerFrame, evalTkn);
}
@Override protected GfmlFrame_base MakeNew_hook() {return new GfmlFrame_eval();}
static GfmlTkn MakeEvalTkn(GfmlBldr bldr, GfmlObjList waitingTkns) {
GfmlTkn composite = GfmlTkn_.composite_list_("tkn:eval_temp", waitingTkns);
String[] ary = ExtractContextKey(composite.Val());
String varContext = ary[0], varKey = ary[1];
GfmlVarCtx evalContext = GfmlVarCtx_.FetchFromCacheOrNew(bldr.Vars(), varContext);
return new GfmlVarTkn("tkn:eval", composite.SubTkns(), evalContext, varKey);
}
static String[] ExtractContextKey(String raw) {
String[] ary = String_.Split(raw, ".");
if (ary.length == 2) return ary; // NOOP: elems already assigned; context = ary[0]; key = ary[1];
if (ary.length > 2) throw Err_.new_wo_type("invalid context key for eval frame; should have 0 or 1 dlms", "key", raw);
String[] rv = new String[2];
rv[0] = GfmlVarCtx_.DefaultKey;
rv[1] = ary[0];
return rv;
}
}
class GfmlFrameUtl {
@gplx.Internal protected static void AddFrameTkn(GfmlFrame ownerFrame, GfmlTkn frameTkn) {
GfmlFrame_nde nodeFrame = GfmlFrame_nde_.as_(ownerFrame);
if (nodeFrame != null) // ownerFrame is node: set frameTkn as dataTkn
nodeFrame.DatTkn_set(frameTkn);
else // ownerFrame is likely quoteFrame; add to waitingTkns (allows multiple nestings)
ownerFrame.WaitingTkns().Add(frameTkn);
}
}

View File

@@ -1,250 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlFrame_nde extends GfmlFrame_base {
@Override public int FrameType() {return GfmlFrame_.Type_nde;}
public GfmlNde CurNde() {return nde;} GfmlNde nde;
public int CurNdeStartType() {return ndeStartType;} int ndeStartType;
public GfmlDocPos CurDocPos() {return docPos;} GfmlDocPos docPos = GfmlDocPos_.Root;
public void NullArea_set(boolean v) {nullArea = v;} private boolean nullArea = false;
public void DatTkn_set(GfmlTkn datTkn) { // < data >
if (nullArea) { // tkn is unnamed atrVal for new nde; EX: < a:; data >
nullArea = false;
GfmlFrame_nde frame = NewFrame(GfmlNdeStartType.DatTkn);
frame.tknMgr.DatTkn_set(datTkn);
}
else {
GfmlTkn itmKeyTkn = tknMgr.KeyTkn_pop();
if (itmKeyTkn != GfmlTkn_.Null) // elemKey is pending: tkn is atrVal; EX: < a=data >
tknMgr.ExecMakeAtr(itmKeyTkn, datTkn);
else // tkn is unnamed atrVal; EX: < a datTkn >
tknMgr.DatTkn_set(datTkn);
}
}
public void NdeBody_bgn(GfmlTkn symTkn) { // EX: < { >
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.BodyBgn);
GfmlFrame_nde frame = this;
if (nullArea) // EX: {{ NOTE: else nde is in header; don't begin nde; EX: a:{
frame = NewFrame(GfmlNdeStartType.Brace);
tknMgr.ExecXferTkns_ndeBgn(this.CurNde());
frame.nullArea = true;
}
public void NdeInline(GfmlTkn symTkn) { // ;
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.Inline);
if (nullArea) // empty node; EX: < ;; > NOTE: this will not be called if dataTkn is present, since dataTkn starts node; EX: < a; >
NewFrame(GfmlNdeStartType.Inline);
bldr.Frames_end(); // NOTE: no need for frame.nullArea = true b/c frame is ended
}
public void KeyTkn_set(GfmlTkn symTkn) { // EX: < = >
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.Key);
tknMgr.KeyTkn_setFromDataTknOrFail();
}
public void NdeHeader_set(GfmlTkn symTkn) { // EX: < : >
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.Hnd);
tknMgr.IdxNdeBgn_setToAtrBgn();
tknMgr.HndTkn_setByDatTknOrFail();
GfmlTkn hnd = tknMgr.HndTkn_pop();
GfmlFrame_nde frame = this;
if (bldr.CurNdeFrame().CurNdeStartType() == GfmlNdeStartType.Prop) // EX: < [a: > - must start new sub node;
frame = NewFrame(GfmlNdeStartType.Hnd);
frame.CurNde().HndTkn_set(hnd);
bldr.TypeMgr().NdeResolve(frame.CurNde(), ownerTypeKey);
}
public void NdeDot(GfmlTkn symTkn) { // EX: < . >
GfmlFrame_nde frm = this, oldFrm = this;
GfmlTkn hndTkn = HndTkn_GetForDotOp(frm); // get hndTkn; needed for (a) newFrm if prpNde; or (b) curFrm
boolean createPrpNde = dotSymCreatesPrpNde; // get createPrpNde b/c it will be reused later in this proc
if (createPrpNde) { // inside parens; . will create a prpNde EX: a:(b.c); vs a.b
frm = NewFrame(GfmlNdeStartType.Dot);
frm.nde.KeyedSubObj_(true); // NOTE: must set prpNdes to keyed
frm.nde.ChainId_(bldr.ChainIdNext());
}
if (hndTkn != GfmlTkn_.Null) { // NOTE: need to check for Null to handle ")."; EX: a.b().c(); 2nd . would return Null and overwrite b
if (frm.nde.HndTkn() == GfmlTkn_.Null)
frm.nde.HndTkn_set(hndTkn);
else
tknMgr.ExecMakeAtr(GfmlTkn_.Null, hndTkn);
}
frm.WaitingTkns_AddSym(symTkn, GfmlNdeSymType.Dot); // REVIEW: may want to dump into differnt nde...
frm.tknMgr.ExecXferTkns_ndeBgn(frm.CurNde());
oldFrm = frm; // get oldFrm
frm = frm.NewFrame(GfmlNdeStartType.Dot);
NdeDot_SetChainId(createPrpNde, oldFrm, frm);
}
public void NdeParen_bgn(GfmlTkn symTkn) { // EX: < ( >
HndTkn_SetFromDatTkn();
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.HdrBgn); // REVIEW: may want to dump into differnt nde...
dotSymCreatesPrpNde = true;
frmHasParens = true;
}
public void NdeParen_end(GfmlTkn symTkn) { // EX: < ) >
tknMgr.ConsumeWaitingDatTkn(bldr.CurNde());
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.HdrEnd);
dotSymCreatesPrpNde = false;
if (!frmHasParens) {
bldr.Frames_end();
bldr.CurNdeFrame().frmHasParens = false; // does this assume that auto-closing stops at paren node?
}
}
public void AtrSpr(GfmlTkn symTkn) { // EX: < , > NOTE: proc resembles NdeParen_end
tknMgr.ConsumeWaitingDatTkn(bldr.CurNde());
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.AtrSpr);
if (!frmHasParens) {
bldr.Frames_end();
GfmlFrame_nde frm = bldr.CurNdeFrame(); // get the current frm after all popped
int idx = frm.waitingTkns.Count(); // NOTE: reset idxs b/c endFrame will automatically set to 0, and should be objCount
frm.tknMgr.IdxAtrBgn_setHack(idx);
frm.tknMgr.IdxNdeBgn_set(idx);
frm.nullArea = false; // NOTE: endFrame automatically sets nullArea to true; set to false
}
}
public void NdeProp_bgn(GfmlTkn symTkn) { // EX: < [ >
int oldNdeBgn = tknMgr.IdxNdeBgn(); // get oldNdeBgn; needed for header atrs; EX: < a:b [d] > ndeBgn = 0 (a pos), but will start keyNde at 5 ([ pos)
GfmlTkn keyTkn = tknMgr.KeyTkn_pop(); boolean keyTknExists = keyTkn != GfmlTkn_.Null;
int newNdeBgn = keyTknExists ? tknMgr.IdxAtrBgn() : waitingTkns.Count(); // if there is a key, set ndeBgn end atrBgn (EX: a=[); else set end curIdx
tknMgr.IdxNdeBgn_set(newNdeBgn);
WaitingTkns_AddSym(symTkn, GfmlNdeSymType.PrpBgn);
tknMgr.ConsumeWaitingDatTkn(nde);// NEEDED for KeydDefault
GfmlFrame_nde frame = NewFrame(GfmlNdeStartType.Prop);
tknMgr.IdxNdeBgn_set(oldNdeBgn); // restore oldNdeBgn
if (!keyTknExists) {
keyTkn = bldr.TypeMgr().FldPool().Keyed_PopNextAsTkn();
}
frame.CurNde().KeyTkn_set(keyTkn);
bldr.TypeMgr().NdeResolve(frame.CurNde(), ownerTypeKey);
frame.nullArea = false;
}
GfmlFrame_nde NewFrame(int newNdeFrameType) {
GfmlDocPos newPos = docPos.NewDown(subNdeCount++);
GfmlNde newNde = GfmlNde.new_(tknMgr.HndTkn_pop(), GfmlType_.Null, newNdeFrameType == GfmlNdeStartType.Prop).DocPos_(newPos);
GfmlFrame_nde newFrm = GfmlFrame_nde_.node_(bldr, newNde);
newFrm.ndeStartType = newNdeFrameType;
newFrm.ownerTypeKey = this.CurNde().Type().Key();
tknMgr.ExecXferTkns_ndeBgn(newNde);
bldr.Frames_push(newFrm);
bldr.TypeMgr().NdeBgn(newNde, newFrm.ownerTypeKey);
bldr.Doc().PragmaMgr().BgnCmds_exec(newPos, bldr);
return newFrm;
}
@Override public void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame) {
GfmlFrame_nde ownerNdeFrame = (GfmlFrame_nde)ownerFrame;
tknMgr.ExecXferTkns_ndeAll(nde);
bldr.TypeMgr().NdeEnd();
bldr.Doc().PragmaMgr().EndCmds_exec(docPos, bldr);
bldr.Doc().PragmaMgr().Pragmas_compile(this.CurNde().Hnd(), bldr);
if (ownerFrame == null) return; // rootFrame; ignore below
ownerNdeFrame.waitingTkns.Add(this.CurNde());
int ndeType = this.CurNdeStartType();
if (ndeType == GfmlNdeStartType.Dot){ // if i was created by dot, close owner;
if (ownerNdeFrame.nde.ChainId() != this.nde.ChainId()) { // can also be if (nde.ChainHead())
}
else
bldr.Frames_end(); // auto-close dot ndes
}
else if (ndeType == GfmlNdeStartType.Prop) {}
else {
ownerNdeFrame.tknMgr.IdxNdeBgn_set(ownerNdeFrame.waitingTkns.Count());
ownerNdeFrame.nullArea = true; // reset
}
}
@Override protected GfmlFrame_base MakeNew_hook() {return new GfmlFrame_nde();}
public void IdxNdeBgn_set(int v) {tknMgr.IdxNdeBgn_set(v);}
@gplx.Internal protected void WaitingTkns_AddSym(GfmlTkn tkn, int type) {waitingTkns.Add(tkn); bldr.PrvSymType_set(type);}
@gplx.Internal protected void HndTkn_SetFromDatTkn() {
GfmlTkn hndTkn = tknMgr.DatTkn_pop();
if (hndTkn != GfmlTkn_.Null)
nde.HndTkn_set(hndTkn);
}
GfmlTkn HndTkn_GetForDotOp(GfmlFrame_nde frm) {
if (bldr.PrvSymType() == GfmlNdeSymType.HdrEnd) return GfmlTkn_.Null; // if prev was ), ignore; EX: a(). does not have hndTkn
GfmlTkn hndTkn = frm.tknMgr.DatTkn_pop();
// if (hndTkn == GfmlTkn_.Null) bldr.UsrMsgs_fail(GfmlUsrMsgs.fail_DatTkn_notFound());
return hndTkn;
}
void NdeDot_SetChainId(boolean createPrpNde, GfmlFrame_nde oldFrm, GfmlFrame_nde frm) {
if (createPrpNde) // prpNde; make sure new dotNde gets same chainId
frm.nde.ChainId_(oldFrm.nde.ChainId());
else { // oldNde is dotNde
if (oldFrm.ndeStartType == GfmlNdeStartType.Dot) // oldNde is dotNde; just take oldNde's chainId; ex: a.b.c
frm.nde.ChainId_(oldFrm.nde.ChainId());
else { // oldNde is something else
int chainId = bldr.ChainIdNext();
oldFrm.nde.ChainId_(chainId); // NOTE: needed for auto-closing; EX: {a.b;} a is a DatTkn nde, but needs to be closed when b is closed
frm.nde.ChainId_(chainId);
}
}
}
GfmlBldr bldr; GfmlFrame_ndeTknMgr tknMgr; int subNdeCount = 0; String ownerTypeKey; boolean frmHasParens = false; boolean dotSymCreatesPrpNde = false;
public static GfmlFrame_nde new_(GfmlBldr bldr, GfmlNde newNde, GfmlLxr newLxr) {
GfmlFrame_nde rv = new GfmlFrame_nde();
rv.bldr = bldr;
rv.ctor_(newLxr);
rv.tknMgr = GfmlFrame_ndeTknMgr.new_(rv, bldr);
rv.nde = newNde;
rv.docPos = newNde.DocPos();
return rv;
}
}
class GfmlFrame_nde_ {
public static GfmlFrame_nde as_(Object obj) {return obj instanceof GfmlFrame_nde ? (GfmlFrame_nde)obj : null;}
public static GfmlFrame_nde node_(GfmlBldr bldr, GfmlNde newNde) {return GfmlFrame_nde.new_(bldr, newNde, bldr.CurFrame().Lxr());}
@gplx.Internal protected static GfmlFrame_nde root_(GfmlBldr bldr, GfmlNde newNde, GfmlLxr newLxr) {return GfmlFrame_nde.new_(bldr, newNde, newLxr);}
@gplx.Internal protected static final GfmlFrame_nde OwnerRoot_ = null;
@gplx.Internal protected static void TransferToNde(GfmlObjList waitingTkns, GfmlNde nde, int bgn) {
int end = waitingTkns.Count();
for (int i = bgn; i < end; i++) {
GfmlObj tkn = waitingTkns.Get_at(i);
nde.SubObjs_Add(tkn);
}
if (bgn != end) // ignore if bgn == end
waitingTkns.Del_range(bgn, end - 1);
}
@gplx.Internal protected static void TransferToAtr(GfmlObjList src, GfmlAtr trg, int bgn, int end) {
int len = end - bgn;
if (len <= 0 || end == -1) return; // -1 b/c calling proc passes end - 1, and end may be 0
for (int i = 0; i < len; i++)
trg.SubObjs_Add(src.Get_at(i + bgn));
src.Del_range(bgn, end - 1);
}
}
class GfmlNdeStartType {
public static final int
Hnd = 1 // a:
, Brace = 2 // { // has no header (since header would have created node first)
, DatTkn = 3 // c; // has no hnd
, Inline = 4 // ; // is empty (since something would have created node first)
, Dot = 5 // a.b;
, Prop = 6 // a=[b c];
;
}
class GfmlNdeSymType {
public static final int
Null = 0
, BodyBgn = 1 // {
, BodyEnd = 2 // }
, Inline = 3 // ;
, Key = 4 // =
, Hnd = 5 // :
, Dot = 6 // .
, HdrBgn = 7 // (
, HdrEnd = 8 // )
, PrpBgn = 9 // [
, PrpEnd = 10 // ]
, AtrSpr = 11 // ,
;
}

View File

@@ -1,90 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlFrame_ndeTknMgr {
public int IdxAtrBgn() {return idxAtrBgn;} int idxAtrBgn, idxAtrEnd;
public int IdxNdeBgn() {return idxNdeBgn;} public void IdxNdeBgn_set(int v) {idxNdeBgn = v;} int idxNdeBgn = 0;
void IdxAtr_clear() {idxAtrBgn = 0; idxAtrEnd = -1;}
@gplx.Internal protected void IdxAtrBgn_setHack(int v) {idxAtrBgn = v; idxAtrEnd = v + 1;}
@gplx.Internal protected void IdxNdeBgn_setToAtrBgn() {
if (idxAtrEnd == -1) return;
idxNdeBgn = idxAtrBgn;
this.IdxAtr_clear(); // newNode starting; old atr range no longer valid
}
public GfmlTkn HndTkn_pop() {GfmlTkn rv = hndTkn; hndTkn = GfmlTkn_.Null; return rv;} GfmlTkn hndTkn = GfmlTkn_.Null;
public void HndTkn_setByDatTkn() {
if (datTkn == GfmlTkn_.Null) return;
hndTkn = DatTkn_pop();
}
@gplx.Internal protected void HndTkn_setByDatTknOrFail() {
if (datTkn == GfmlTkn_.Null) {bldr.UsrMsgs_fail(GfmlUsrMsgs.fail_DatTkn_notFound()); return;} // ex: < : >
if (hndTkn != GfmlTkn_.Null) {bldr.UsrMsgs_fail(GfmlUsrMsgs.fail_HndTkn_alreadyExists()); return;} // ex: < a:b: >
hndTkn = DatTkn_pop();
}
public GfmlTkn KeyTkn_pop() {GfmlTkn rv = keyTkn; keyTkn = GfmlTkn_.Null; return rv;} GfmlTkn keyTkn = GfmlTkn_.Null;
public void KeyTkn_setByDatTkn() {
if (datTkn == GfmlTkn_.Null) return;
keyTkn = DatTkn_pop();
}
public void KeyTkn_setFromDataTknOrFail() {
if (datTkn == GfmlTkn_.Null) {bldr.UsrMsgs_fail(GfmlUsrMsgs.fail_DatTkn_notFound()); return;} // ex: < = >
if (keyTkn != GfmlTkn_.Null) {bldr.UsrMsgs_fail(GfmlUsrMsgs.fail_KeyTkn_alreadyExists()); return;} // ex: < a=[b=] >
keyTkn = DatTkn_pop();
}
@gplx.Internal protected GfmlTkn DatTkn_pop() {GfmlTkn rv = datTkn; datTkn = GfmlTkn_.Null; return rv;} GfmlTkn datTkn = GfmlTkn_.Null;
@gplx.Internal protected void DatTkn_set(GfmlTkn tkn) {
this.ConsumeWaitingDatTkn(frame.CurNde());
idxAtrBgn = frame.waitingTkns.Count();
idxAtrEnd = idxAtrBgn + 1;
frame.waitingTkns.Add(tkn);
datTkn = tkn;
}
@gplx.Internal protected void ExecMakeAtr(GfmlTkn itmKeyTkn, GfmlTkn valTkn) {
frame.waitingTkns.Add(valTkn);
idxAtrEnd = frame.waitingTkns.Count();
this.MakeAtr(itmKeyTkn, valTkn);
}
@gplx.Internal protected void ExecXferTkns_ndeAll(GfmlNde nde) {ExecXferTkns(nde, 0);}
@gplx.Internal protected void ExecXferTkns_ndeBgn(GfmlNde nde) {ExecXferTkns(nde, this.IdxNdeBgn());}
void ExecXferTkns(GfmlNde nde, int from) {
this.ConsumeWaitingDatTkn(nde);
GfmlFrame_nde_.TransferToNde(frame.waitingTkns, nde, from);
}
@gplx.Internal protected void ConsumeWaitingDatTkn(GfmlNde nde) {
if (datTkn == GfmlTkn_.Null) return; // no datTkn; return;
if ( bldr.CurNdeFrame().CurNdeStartType() == GfmlNdeStartType.Dot
&& String_.Len_eq_0(nde.Hnd())) // if cur hnd is empty, use datTkn for hndTkn
frame.HndTkn_SetFromDatTkn();
else
this.MakeAtr(GfmlTkn_.Null, this.DatTkn_pop());
}
void MakeAtr(GfmlTkn k, GfmlTkn v) {
if (k == GfmlTkn_.Null)
k = bldr.TypeMgr().FldPool().Keyed_PopNextAsTkn();
GfmlAtr atr = GfmlAtr.string_(k, v);
GfmlFrame_nde_.TransferToAtr(frame.waitingTkns, atr, idxAtrBgn, idxAtrEnd);
frame.waitingTkns.Add_at(atr, idxAtrBgn);
this.IdxAtr_clear();
}
GfmlFrame_nde frame; GfmlBldr bldr;
public static GfmlFrame_ndeTknMgr new_(GfmlFrame_nde frame, GfmlBldr bldr) {
GfmlFrame_ndeTknMgr rv = new GfmlFrame_ndeTknMgr();
rv.frame = frame; rv.bldr = bldr;
return rv;
} GfmlFrame_ndeTknMgr() {}
}

View File

@@ -1,103 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
class GfmlStringHighlighter {
public String Raw() {return raw;} public GfmlStringHighlighter Raw_(String v) {raw = v; return this;} private String raw;
public int ExcerptLen() {return excerptLen;} public GfmlStringHighlighter ExcerptLen_(int v) {excerptLen = v; return this;} int excerptLen = 40;
public GfmlStringHighlighter Mark_(int pos, char c, String msg) {
marks.Add(new GfmlStringHighlighterMarker().Pos_(pos).Sym_(c).Msg_(msg));
return this;
}
int XtoBgnPos(int pos, int prvEndPos) {
int rv = pos - excerptLen;
if (rv < prvEndPos) rv = prvEndPos; // ensure bgnPos is not < prev end pos; ex: marks of 5,12; at 12, bgnPos = 2 which is less than 5; make 5
return rv;
}
public String[] Gen() {
String_bldr posBfr = String_bldr_.new_(), rawBfr = String_bldr_.new_(), symBfr = String_bldr_.new_();
List_adp symList = List_adp_.New();
int bgnPos = 0, endPos = 0;
int rawLen = String_.Len(raw); int rawLenDigits = Int_.DigitCount(rawLen);
int rawBfrBgn = -1, marksLastIdx = marks.Idx_last();
for (int i = 0; i < marks.Count(); i++) {
GfmlStringHighlighterMarker curMark = (GfmlStringHighlighterMarker)marks.Get_at(i);
GfmlStringHighlighterMarker nxtMark = i == marksLastIdx ? GfmlStringHighlighterMarker.Null : (GfmlStringHighlighterMarker)marks.Get_at(i + 1);
// bgnPos
bgnPos = XtoBgnPos(curMark.Pos(), endPos);
if (i == 0) rawBfrBgn = bgnPos;
// endPos
int nxtMarkPos = nxtMark == GfmlStringHighlighterMarker.Null ? Int_.Max_value : nxtMark.Pos();
endPos = curMark.Pos() + excerptLen;
if (endPos >= nxtMarkPos) endPos = nxtMarkPos;
if (endPos > rawLen ) endPos = rawLen + 1;
// build bfrs
for (int j = bgnPos; j < endPos; j++) {
char rawChar = j == rawLen ? ' ' : String_.CharAt(raw, j);
if (rawChar == '\t') {posBfr.Add("t"); rawBfr.Add(" ");}
else if (rawChar == '\n') {posBfr.Add("n"); rawBfr.Add(" ");}
else {
char posChar = j == rawLen ? '>' : ' ';
posBfr.Add(posChar);
rawBfr.Add(rawChar);
}
char symChar = j == curMark.Pos() ? curMark.Sym() : ' ';
symBfr.Add(symChar);
}
// gap
int nxtMarkBgn = XtoBgnPos(nxtMark.Pos(), endPos);
int gap = nxtMarkBgn - endPos;
if (gap > 0) {
int gapDigits = Int_.DigitCount(gap);
posBfr.Add_fmt("[{0}]", Int_.To_str_pad_bgn_zero(gap, gapDigits));
rawBfr.Add_fmt("[{0}]", String_.Repeat(".", gapDigits));
symBfr.Add_fmt(" {0} ", String_.Repeat(" ", gapDigits));
}
if (curMark.Sym() != ' ')
symList.Add(String_.Format("[{0}] {1} {2}", Int_.To_str_pad_bgn_zero(curMark.Pos(), rawLenDigits), curMark.Sym(), curMark.Msg()));
}
if (rawBfrBgn == 0) {
posBfr.Add_at(0, "<");
rawBfr.Add_at(0, " ");
symBfr.Add_at(0, " ");
}
List_adp rv = List_adp_.New();
rv.Add(posBfr.To_str());
rv.Add(rawBfr.To_str());
rv.Add(symBfr.To_str());
if (symList.Count() > 0)
rv.Add("");
for (int i = 0; i < symList.Count(); i++)
rv.Add((String)symList.Get_at(i));
return rv.To_str_ary();
}
List_adp marks = List_adp_.New();
public static GfmlStringHighlighter new_() {
GfmlStringHighlighter rv = new GfmlStringHighlighter();
return rv;
} GfmlStringHighlighter() {}
}
class GfmlStringHighlighterMarker {
public int Pos() {return pos;} public GfmlStringHighlighterMarker Pos_(int v) {pos = v; return this;} int pos;
public char Sym() {return sym;} public GfmlStringHighlighterMarker Sym_(char v) {sym = v; return this;} char sym;
public String Msg() {return msg;} public GfmlStringHighlighterMarker Msg_(String v) {msg = v; return this;} private String msg;
public static final GfmlStringHighlighterMarker Null = new GfmlStringHighlighterMarker().Pos_(-1);
}

View File

@@ -1,102 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.stores.*; import gplx.core.gfo_ndes.*;
public class GfmlDataNde {
public GfmlDoc Doc() {return gdoc;} GfmlDoc gdoc;
public DataRdr XtoRdr() {
GfmlDataRdr rv = new GfmlDataRdr();
rv.SetNode(gdoc.RootNde());
return rv;
}
public DataWtr XtoWtr() {
GfmlDataWtr2 rv = new GfmlDataWtr2();
rv.Doc_set(gdoc);
return rv;
}
public static GfmlDataNde new_any_eol_(String raw) {return new_(String_.Replace(raw, String_.CrLf, String_.Lf));}
public static GfmlDataNde new_(String raw) {
GfmlDataNde rv = new GfmlDataNde();
GfmlBldr bldr = GfmlBldr_.default_();
bldr.Doc().RootLxr().SubLxr_Add
( GfmlDocLxrs.AtrSpr_lxr()
, GfmlDocLxrs.NdeDot_lxr()
, GfmlDocLxrs.NdeHdrBgn_lxr()
, GfmlDocLxrs.NdeHdrEnd_lxr()
);
rv.gdoc = bldr.XtoGfmlDoc(raw);
return rv;
}
public static GfoMsg XtoMsg(String raw) {
GfmlDoc gdoc = GfmlDataNde.new_any_eol_(raw).Doc();
return XtoMsg(gdoc.RootNde());
}
public static GfoMsg XtoMsgNoRoot(String raw) {
GfmlDoc gdoc = GfmlDataNde.new_any_eol_(raw).Doc();
GfoMsg msg = XtoMsg(gdoc.RootNde());
return (GfoMsg)msg.Subs_getAt(0);
}
static GfoMsg XtoMsg(GfmlNde gnde) {
String msgKey = String_.Coalesce(gnde.Key(), gnde.Hnd());
GfoMsg msg = GfoMsg_.new_parse_(msgKey);
for (int i = 0; i < gnde.SubKeys().Count(); i++) {
GfmlItm subItm = (GfmlItm)gnde.SubKeys().Get_at(i);
if (subItm.ObjType() == GfmlObj_.Type_atr) {
GfmlAtr subAtr = (GfmlAtr)subItm;
String subAtrKey = String_.Len_eq_0(subAtr.Key()) ? "" : subAtr.Key(); // NOTE: needs to be "" or else will fail in GfoConsole; key will be evaluated against NullKey in GfsCtx
msg.Add(subAtrKey, subAtr.DatTkn().Val());
}
else {
GfmlNde subNde = (GfmlNde)subItm;
GfoMsg subMsg = XtoMsg(subNde);
msg.Subs_add(subMsg);
}
}
for (int i = 0; i < gnde.SubHnds().Count(); i++) {
GfmlItm subItm = (GfmlItm)gnde.SubHnds().Get_at(i);
GfmlNde subNde = (GfmlNde)subItm;
GfoMsg subMsg = XtoMsg(subNde);
msg.Subs_add(subMsg);
}
return msg;
}
}
class GfmlDataWtr2 extends DataWtr_base implements DataWtr {
@Override public void WriteData(String name, Object val) {
GfmlTkn nameTkn = GfmlTkn_.raw_(name);
GfmlTkn valTkn = GfmlTkn_.raw_(To_str(val));
GfmlAtr atr = GfmlAtr.new_(nameTkn, valTkn, GfmlType_.String);
GfmlNde nde = gdoc.RootNde().SubHnds().Get_at(0);
nde.SubKeys().Add(atr);
}
public void InitWtr(String key, Object val) {}
public void WriteTableBgn(String name, GfoFldList fields) {}
@Override public void WriteNodeBgn(String nodeName) {}
public void WriteLeafBgn(String leafName) {}
@Override public void WriteNodeEnd() {}
public void WriteLeafEnd() {}
public void Clear() {}
public String To_str() {return "";}
String To_str(Object obj) {
if (obj == null) return "''";
String s = obj.toString();
return String_.Concat("'", String_.Replace(s, "'", "''"), "'");
}
@Override public SrlMgr SrlMgr_new(Object o) {return new GfmlDataWtr2();}
public void Doc_set(GfmlDoc v) {gdoc = v;} GfmlDoc gdoc;
}

View File

@@ -1,48 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.stores.*;
public class GfmlDataRdr extends GfmlDataRdr_base {
public static DataRdr raw_root_(String raw) {
GfmlDoc gdoc = GfmlDoc_.parse_any_eol_(raw);
GfmlDataRdr rv = new GfmlDataRdr();
rv.Parse_set(true);
rv.SetNode(gdoc.RootNde().SubHnds().Get_at(0));
return rv;
}
public static DataRdr raw_list_(String raw) {
GfmlDoc gdoc = GfmlDoc_.parse_any_eol_(raw);
GfmlDataRdr rv = new GfmlDataRdr();
rv.SetNode(gdoc.RootNde());
return rv;
}
public static GfmlDataRdr nde_(GfmlNde nde) {
GfmlDataRdr rv = new GfmlDataRdr();
rv.SetNode(nde);
return rv;
}
public static DataRdr wtr_(DataWtr wtr) {return raw_root_(wtr.To_str());}
@Override public SrlMgr SrlMgr_new(Object o) {return new GfmlDataRdr();}
@gplx.Internal protected GfmlDataRdr() {
this.Parse_set(true);
}
}
class GfmlDataRdrNde extends GfmlDataRdr_base {
public GfmlDataRdrNde(GfmlNde current) {SetNode(current);}
@Override public SrlMgr SrlMgr_new(Object o) {return new GfmlDataRdrNde(null);}
}

View File

@@ -1,60 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.stores.*; /*DataRdr_base*/
public abstract class GfmlDataRdr_base extends DataRdr_base implements DataRdr {
@Override public String NameOfNode() {return curNde.Hnd();}
@Override public int FieldCount() {return curNde.SubKeys().Count();}
@Override public String KeyAt(int idx) {return curNde.SubKeys().Get_at(idx).KeyTkn().Val();}
@Override public Object ReadAt(int idx) {return GfmlAtr.as_(curNde.SubKeys().Get_at(idx)).DatTkn().Val();}
@Override public Object Read(String name) {return curNde.SubKeys().FetchDataOrNull(name);}
public boolean MoveNextPeer() {
pos += 1;
if (list == null || pos >= list.Count()) return false; // TODO_9: makeCurNde null; invalidate FieldAt, etc?
curNde = list.Get_at(pos);
return true;
}
@Override public DataRdr Subs() {
GfmlDataRdrNde rv = new GfmlDataRdrNde(curNde); rv.Parse_set(this.Parse());
if (curNde != null) rv.list = curNde.SubHnds();
return rv;
}
@Override public DataRdr Subs_byName_moveFirst(String name) {
DataRdr subRdr = Subs_byName(name);
return subRdr.MoveNextPeer() ? subRdr : DataRdr_.Null;
}
public DataRdr Subs_byName(String name) {
GfmlDataRdrNde rv = new GfmlDataRdrNde(curNde);
rv.list = GfmlItmHnds.new_();
if (curNde == null) return rv;
for (int i = 0; i < curNde.SubHnds().Count(); i++) {
GfmlNde sub = (GfmlNde)curNde.SubHnds().Get_at(i);
String typeName = sub.Type().NdeName();
if ( sub.Type().IsTypeAny()) // isAnyType b/c match may not be exact; ex: type can be defined as item:key name; but actlNde may be item:key name size;
//|| sub.Type().IsTypeNull())
typeName = sub.Hnd();
if (String_.Eq(typeName, name))
rv.list.Add(sub);
}
return rv;
}
public void Rls() {}
public String To_str() {return curNde.To_str();}
@gplx.Internal protected void SetNode(GfmlNde curNde) {this.curNde = curNde; this.list = curNde.SubHnds();}
GfmlNde curNde; GfmlItmHnds list; int pos = -1;
}

View File

@@ -1,99 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.lists.*; /*StackAdp*/ import gplx.core.gfo_ndes.*; import gplx.core.stores.*;
public class GfmlDataWtr extends DataWtr_base implements DataWtr {
public void InitWtr(String key, Object val) {
if (!String_.Eq(key, GfmlDataWtrOpts.Key_const)) return;
GfmlDataWtrOpts layout = GfmlDataWtrOpts.cast(val);
keyedSpr = layout.KeyedSpr();
indentNodes = layout.IndentNodes();
ignoreNullNames = layout.IgnoreNullNames();
}
@Override public void WriteData(String name, Object val) {
if (nde.SubKeys().Count() != 0) AddTkn_nullVal(keyedSpr); // add keyedSprTkn if not first
GfmlTkn keyTkn = AddTkn_raw(name);
AddTkn_raw("=");
GfmlTkn valTkn = AddTkn_raw(To_str(val));
GfmlAtr atr = GfmlAtr.new_(keyTkn, valTkn, GfmlType_.String);
nde.SubObjs_Add(atr);
}
public void WriteLeafBgn(String leafName) {this.WriteNodeBgn(leafName);}
@Override public void WriteNodeBgn(String nodeName) {
stack.Push(nde);
if (stack.Count() != 1 // not root
&& nde.SubHnds().Count() == 0) { // first subNde
AddTkn_nullVal("{");
if (indentNodes) AddTkn_nullVal(String_.CrLf);
}
if (indentNodes) AddTkn_nullVal(String_.Repeat("\t", stack.Count() - 1));
GfmlTkn nameTkn = null;
if (ignoreNullNames && String_.Eq(nodeName, ""))
nameTkn = GfmlTkn_.Null;
else {
nameTkn = AddTkn_raw(String_.Eq(nodeName, "") ? "%" : nodeName);
AddTkn_nullVal(":");
}
nde = GfmlNde.named_(nameTkn, GfmlType_.new_any_());
}
public void WriteLeafEnd() {this.WriteNodeEnd();}
@Override public void WriteNodeEnd() {
if (nde.SubHnds().Count() == 0)
AddTkn_nullVal(";");
else {
if (indentNodes) AddTkn_nullVal(String_.Repeat("\t", stack.Count() - 1));
AddTkn_nullVal("}");
}
if (indentNodes) AddTkn_nullVal(String_.CrLf);
GfmlNde finishedNde = nde;
nde = GfmlNde.as_(stack.Pop());
nde.SubObjs_Add(finishedNde);
}
public void WriteComment(String comment) {
AddTkn_nullVal("/*");
AddTkn_raw(comment);
AddTkn_nullVal("*/");
}
public void Clear() {nde.SubObjs_Clear();}
public void WriteTableBgn(String name, GfoFldList fields) {}
public void CloseBranchHdr(boolean isInline) {}
public String To_str() {
while (stack.Count() > 0) { // auto-close all nodes
WriteNodeEnd();
}
return GfmlDocWtr_.xtoStr_(gdoc.RootNde());
}
String To_str(Object obj) {
if (obj == null) return "''";
String s = Object_.Xto_str_strict_or_empty(obj);
return String_.Concat("'", String_.Replace(s, "'", "''"), "'");
}
GfmlTkn AddTkn_raw(String raw) {return AddTkn(raw, raw);}
GfmlTkn AddTkn_nullVal(String raw) {return AddTkn(raw, GfmlTkn_.NullVal);}
GfmlTkn AddTkn(String raw, String val) {
GfmlTkn tkn = GfmlTkn_.new_(raw, val);
nde.SubObjs_Add(tkn);
return tkn;
}
@Override public SrlMgr SrlMgr_new(Object o) {return new GfmlDataWtr();}
StackAdp stack = StackAdp_.new_();
GfmlDoc gdoc = GfmlDoc.new_(); GfmlNde nde;
String keyedSpr = GfmlDataWtrOpts.Instance.KeyedSpr(); boolean indentNodes, ignoreNullNames;
public static GfmlDataWtr new_() {return new GfmlDataWtr();}
GfmlDataWtr() {this.nde = this.gdoc.RootNde();}
}

View File

@@ -1,27 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class GfmlDataWtrOpts {
public static final String Key_const = "GfmlDataWtrOpts";
public String KeyedSpr() {return keyedSeparator;} public GfmlDataWtrOpts KeyedSeparator_(String val) {keyedSeparator = val; return this;} private String keyedSeparator = " ";
public boolean IndentNodes() {return indentNodes;} public GfmlDataWtrOpts IndentNodesOn_() {indentNodes = true; return this;} private boolean indentNodes;
public boolean IgnoreNullNames() {return ignoreNullNames;} public GfmlDataWtrOpts IgnoreNullNamesOn_() {ignoreNullNames = true; return this;} private boolean ignoreNullNames;
public static final GfmlDataWtrOpts Instance = new GfmlDataWtrOpts();
public static GfmlDataWtrOpts new_() {return new GfmlDataWtrOpts();} GfmlDataWtrOpts() {}
public static GfmlDataWtrOpts cast(Object obj) {try {return (GfmlDataWtrOpts)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfmlDataWtrOpts.class, obj);}}
}

View File

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

View File

@@ -1,42 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
public class SqlConsts {
public static final String
Op_eq = "="
, Op_eqn = "!="
, Op_eqn2 = "<>"
, Op_lt = "<"
, Op_mt = ">"
, Op_lte = "<="
, Op_mte = ">="
, Op_like = "LIKE"
, Op_iomatch = "IOMATCH"
, Op_between = "BETWEEN"
, Op_between_and = "AND"
, Op_in = "IN"
, Op_in_bgn = "("
, Op_in_end = ")"
, Op_in_dlm = ","
, Kwd_or = "OR"
, Kwd_and = "AND"
, Kwd_not = "NOT"
, Grp_bgn = "("
, Grp_end = ")"
;
}

View File

@@ -1,144 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*; import gplx.core.criterias.*;
public class SqlDoc {
public static GfmlDoc XtoDoc(String raw) {
GfmlBldr bldr = GfmlBldr_.new_();
bldr.Doc().RootLxr_set(RootLxr_());
return bldr.XtoGfmlDoc(raw);
}
static GfmlLxr RootLxr_() {
GfmlTkn txtTkn = GfmlTkn_.cmd_("tkn:text", SqlCmd_root.Instance);
GfmlLxr rv = GfmlLxr_.general_("lxr:root", txtTkn);
whitespace_(rv);
operator_(rv
, SqlConsts.Op_eq
, SqlConsts.Op_eqn
, SqlConsts.Op_eqn2
, SqlConsts.Op_lt
, SqlConsts.Op_mt
, SqlConsts.Op_lte
, SqlConsts.Op_mte
, SqlConsts.Op_in_bgn
, SqlConsts.Op_in_end
, SqlConsts.Op_in_dlm
);
quote_(rv, "'");
quote_(rv, "\"");
return rv;
}
static GfmlLxr whitespace_(GfmlLxr lxr) {
GfmlTkn tkn = GfmlTkn_.cmd_("key:gfml.whitespace_0", GfmlBldrCmd_.Null);
GfmlLxr rv = GfmlLxr_.range_("lxr:gfml.whitespace_0", String_.Ary(" ", String_.Tab, String_.CrLf, String_.Lf), tkn, false);
lxr.SubLxr_Add(rv);
return rv;
}
static GfmlLxr quote_(GfmlLxr lxr, String quote) {
GfmlLxr rv = GfmlLxr_frame.new_("gfml.quote_0", SqlFrame_quote.Instance, quote, quote, SqlCmd_quote_str.Instance, SqlCmd_quote_end.Instance);
GfmlLxr escape = lxr_escape_("gfml.quote_0_escape", quote + quote, quote);
rv.SubLxr_Add(escape);
lxr.SubLxr_Add(rv);
return rv;
}
static GfmlLxr lxr_escape_(String key, String raw, String escape) {return GfmlLxr_.symbol_(key, raw, escape, GfmlBldrCmd_pendingTkns_add.Instance);}
static void operator_(GfmlLxr lxr, String... opAry) {
for (String op : opAry) {
GfmlLxr opLxr = GfmlLxr_.symbol_("sql:" + op, op, op, SqlCmd_operator.new_(op));
lxr.SubLxr_Add(opLxr);
}
}
}
class SqlCmd_quote_str implements GfmlBldrCmd {
public String Key() {return "sql:root";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
bldr.CurFrame().WaitingTkns().Add(GfmlTkn_.raw_(tkn.Raw()));
}
public static final SqlCmd_quote_str Instance = new SqlCmd_quote_str(); SqlCmd_quote_str() {}
}
class SqlCmd_quote_end implements GfmlBldrCmd {
public String Key() {return "sql:root";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
String_bldr sb = String_bldr_.new_();
GfmlObjList list = bldr.CurFrame().WaitingTkns();
for (int i = 0; i < list.Count(); i++) {
GfmlTkn pnd = (GfmlTkn)list.Get_at(i);
sb.Add(pnd.Val());
}
//Int_.To_str(bldr.CurNdeFrame().Nde().SubTkns().length)
GfmlAtr atr = GfmlAtr.new_(GfmlTkn_.raw_("word"), GfmlTkn_.raw_(sb.To_str()), GfmlType_.String);
bldr.CurNdeFrame().CurNde().SubObjs_Add(atr);
bldr.Frames_end();
}
public static final SqlCmd_quote_end Instance = new SqlCmd_quote_end(); SqlCmd_quote_end() {}
}
class SqlCmd_root implements GfmlBldrCmd {
public String Key() {return "sql:root";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
GfmlSqlUtl.Atr_add(bldr, "word", tkn);
}
public static final SqlCmd_root Instance = new SqlCmd_root(); SqlCmd_root() {}
}
class SqlFrame_quote extends GfmlFrame_base {
@Override public int FrameType() {return GfmlFrame_.Type_data;}
@Override public void Build_end(GfmlBldr bldr, GfmlFrame ownerFrame) {
}
@Override protected GfmlFrame_base MakeNew_hook() {return new SqlFrame_quote();}
public static final SqlFrame_quote Instance = new SqlFrame_quote(); SqlFrame_quote() {}
}
class SqlCmd_operator implements GfmlBldrCmd {
public String Key() {return "sql:operator";}
public void Exec(GfmlBldr bldr, GfmlTkn tkn) {
GfmlSqlUtl.Atr_add(bldr, "op", tkn);
}
String op;
public static SqlCmd_operator new_(String op) {
SqlCmd_operator rv = new SqlCmd_operator();
rv.op = op;
return rv;
} SqlCmd_operator() {}
}
class GfmlSqlUtl {
public static void Nde_bgn(GfmlBldr bldr, String name) {
bldr.CurNdeFrame().NdeBody_bgn(GfmlTkn_.Null);
bldr.CurNde().Hnd_set(name);
}
public static void Nde_end(GfmlBldr bldr) {
bldr.Frames_end();
}
public static void Atr_add(GfmlBldr bldr, String raw, GfmlTkn tkn) {
GfmlAtr atr = GfmlAtr.new_(GfmlTkn_.raw_(raw), tkn, GfmlType_.String);
bldr.CurNde().SubObjs_Add(atr);
}
}
class GfmlNdeWrapper {
public GfmlNde Nde() {return nde;} GfmlNde nde;
public GfmlNdeWrapper Name_(String v) {nde.Hnd_set(v); return this;}
public GfmlNdeWrapper Atrs_add_(String name, String val) {
GfmlAtr atr = GfmlAtr.new_(GfmlTkn_.raw_(name), GfmlTkn_.raw_(val), GfmlType_.String);
nde.SubObjs_Add(atr);
return this;
}
public static GfmlNdeWrapper new_() {
GfmlNdeWrapper rv = new GfmlNdeWrapper();
rv.nde = GfmlNde.new_(GfmlTkn_.Null, GfmlType_.Null, false);
return rv;
}
}

View File

@@ -1,120 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*; import gplx.core.stores.*;
public class GfmlDataRdr_tst {
@Test public void Raw() {
raw = "root:{}";
rdr = rdr_(raw);
Tfds.Eq(rdr.NameOfNode(), "root");
}
@Test public void Atrs() {
raw = "root:id=1 name=me isPresent=true dateOf='2006-12-08';";
rdr = rdr_(raw);
Tfds.Eq(rdr.ReadInt("id"), 1);
Tfds.Eq(rdr.ReadStr("name"), "me");
Tfds.Eq(rdr.ReadBool("isPresent"), true);
Tfds.Eq_date(rdr.ReadDate("dateOf"), DateAdp_.parse_gplx("2006-12-08"));
}
@Test public void Subs() {
raw = String_.Concat_any(
"root:{",
" computers:id=1 {",
" item:name=cpu;",
" item:name=monitor;",
" }",
" person:id=2 {",
" item:name=hardDrive;",
" item:name=networkCard;",
" }",
"}");
rdr = rdr_(raw);
DataRdr computers = rdr.Subs();
int idx = 0;
while (computers.MoveNextPeer()) {
int expd = idx == 0 ? 1 : 2;
Tfds.Eq(computers.ReadInt("id"), expd);
idx++;
}
Tfds.Eq(idx, 2);
DataRdr items = computers.Subs();
idx = 0;
while (items.MoveNextPeer()) {
String expdStr = idx == 0 ? "hardDrive" : "networkCard";
Tfds.Eq(items.ReadStr("name"), expdStr);
idx++;
}
Tfds.Eq(idx, 2);
}
@Test public void SelectRdr() {
raw = String_.Concat_any(
"root:{",
" person:name=me {}",
" computer:brand=noname {}",
"}");
rdr = rdr_(raw);
DataRdr person = rdr.Subs_byName_moveFirst("person");
Tfds.Eq(person.NameOfNode(), "person");
Tfds.Eq(person.ReadStr("name"), "me");
DataRdr computer = rdr.Subs_byName_moveFirst("computer");
Tfds.Eq(computer.NameOfNode(), "computer");
Tfds.Eq(computer.ReadStr("brand"), "noname");
}
// @Test public void Subs_byKey() {
// raw = String_.Concat_any(
// "root:",
// " person=(name=me)",
// ";");
// rdr = rdr_(raw);
//
// DataRdr person = rdr.Subs_byKey("person");
// Tfds.Eq(person.NameOfNode, "person");
// Tfds.Eq(person.ReadStr("name"), "me");
// }
// @Test public void Type() {
// raw = String_.Concat_any(
// "root:{",
// " _type:{example{explicit_val; bool_val; int_val; string_val; long_val; date_val; float_val; decimal_val;}}",
// " example:val1;",
// "}");
//
// rdr = rdr_(raw);
// DataRdr pointRdr = rdr.Subs(); rdr.MoveNextPeer();
//
// Tfds.Eq(rdr.FieldCount, 8);
// Tfds.Eq(rdr.ReadStr("explicit_val"), "val1");
// Tfds.Eq(rdr.ReadBool("bool_val"), false);
// Tfds.Eq(rdr.ReadInt("int_val"), 0);
// Tfds.Eq(rdr.ReadStr("string_val"), null);
// Tfds.Eq(rdr.ReadLongOrFail("long_val"), (long)0);
// Tfds.Eq(rdr.ReadDate("date_val"), DateAdp_.MinValue);
// Tfds.Eq(rdr.ReadFloat("float_val"), (float)0);
// Tfds.Eq(rdr.FieldAt(1), "bool_val");
// Tfds.Eq(rdr.Read(1), null);
// }
DataRdr rdr_(String raw) {
DataRdr rootRdr = GfmlDataRdr.raw_root_(raw);
return rootRdr;
}
String raw; DataRdr rdr;
}

View File

@@ -1,79 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlParse_fxt {
public GfmlNde_mok nde_() {return GfmlNde_mok.new_();}
public GfmlTkn_mok tkn_grp_ary_(String... ary) {return GfmlTkn_mok.new_().Subs_(GfmlTkn_mok.Xto_bry(ary));}
public GfmlTkn_mok tkn_grp_(GfmlTkn_mok... ary) {return GfmlTkn_mok.new_().Subs_(ary);}
public GfmlTkn_mok tkn_itm_(String r) {return GfmlTkn_mok.new_().Raw_(r);}
public void ini_RootLxr_Add(GfmlLxr... ary) {rootLxr.SubLxr_Add(ary);}
public void tst_Doc(String raw, GfmlNde_mok... expdAry) {
GfmlDoc gdoc = bldr.XtoGfmlDoc(raw);
GfmlNde_mok expd = GfmlNde_mok.new_();
for (GfmlNde_mok itm : expdAry)
expd.Subs_(itm);
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gdoc.RootNde()));
tstr.tst_Equal("parse");
}
public void tst_Tkn(String raw, GfmlTkn_mok... expdAry) {
GfmlDoc gdoc = bldr.XtoGfmlDoc(raw);
GfmlTkn_mok expd = GfmlTkn_mok.new_();
for (GfmlTkn_mok itm : expdAry)
expd.Subs_(itm);
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
GfmlTkn_mok.tst(tstr, expd, GfmlTkn_mok.gfmlNde_(gdoc.RootNde()));
tstr.tst_Equal("parse");
}
public static GfmlParse_fxt new_() {
GfmlParse_fxt rv = new GfmlParse_fxt();
rv.rootLxr = GfmlDocLxrs.Root_lxr();
rv.bldr = GfmlBldr_.new_();
rv.bldr.Doc().RootLxr_set(rv.rootLxr);
return rv;
}
public void tst_Err(String raw, UsrMsg_mok... expdErrs) {
bldr.ThrowErrors_set(false);
GfmlDoc actlDoc = bldr.XtoGfmlDoc(raw);
List_adp expd = List_adp_.New(), actl = actlDoc.UsrMsgs();
expd.Add_many((Object[])expdErrs);
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
int max = tstr.List_Max(expd, actl);
for (int i = 0; i < max; i++) {
UsrMsg_mok expdUm = (UsrMsg_mok)tstr.List_FetchAtOrNull(expd, i);
UsrMsg actlUm = (UsrMsg)tstr.List_FetchAtOrNull(actl, i);
UsrMsg_mok actlUmm = UsrMsg_mok.new_(actlUm);
tstr.Eq_str(expdUm.Main(), actlUmm.Main(), "main");
for (int j = 0; j < expdUm.Args().Count(); j++) {
Keyval expdKv = (Keyval)expdUm.Args().Get_at(j);
Keyval actlKv = (Keyval)actlUmm.Args().Get_by(expdKv.Key());
Object actlVal = actlKv == null ? String_.Null_mark : actlKv.Val();
tstr.Eq_str(expdKv.Val(), actlVal, expdKv.Key());
}
for (int j = 0; j < expdUm.Required().Count(); j++) {
String expdKv = (String)expdUm.Required().Get_at(j);
Keyval actlKv = (Keyval)actlUmm.Args().Get_by(expdKv);
Object actlVal = actlKv == null ? String_.Null_mark : actlKv.Val();
Object actlValV = actlKv == null ? "<<REQD>>" : actlKv.Val();
tstr.Eq_str(actlValV, actlVal, expdKv);
}
}
tstr.tst_Equal("errs");
}
GfmlBldr bldr; GfmlLxr rootLxr;
}

View File

@@ -1,102 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlTypeCompiler_fxt {
public GfmlTyp_mok typ_() {return GfmlTyp_mok.new_();}
public GfmlNde_mok nde_() {return GfmlNde_mok.new_();}
public GfmlFld_mok fld_() {return GfmlFld_mok.new_();}
public GfmlTypRegy Regy() {return typBldr.TypeRegy();}
public void ini_Typ(List_adp typs, GfmlTyp_mok typ) {typs.Add(typ);}
@gplx.Internal protected void run_InitPragma(GfmlTypRegy regy, GfmlPragma pragma) {
GfmlTypeMakr makr = GfmlTypeMakr.new_();
GfmlType[] typeAry = pragma.MakePragmaTypes(makr);
regy.Add_ary(typeAry);
}
public void tst_Type(GfmlTyp_mok expd, GfmlTyp_mok actl) {
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
tst(tstr, expd, actl);
tstr.tst_Equal("typ");
}
public void tst_Compile(GfmlNde_mok nde, GfmlTyp_mok expd) {
GfmlNde gnde = run_Resolve(this.Regy(), "_type/type", nde);
Ordered_hash list = Ordered_hash_.New();
GfmlType actlType = GfmlTypeCompiler.Compile(gnde, GfmlType_.Root, this.Regy(), list);
GfmlTyp_mok actl = GfmlTyp_mok.type_(actlType);
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
tst(tstr, expd, actl);
tstr.tst_Equal("typ");
}
public void tst_Parse(String raw, GfmlNde_mok... expdAry) {
GfmlDoc gdoc = GfmlDoc_.parse_any_eol_(raw);
GfmlNde_mok expd = GfmlNde_mok.new_();
for (GfmlNde_mok itm : expdAry)
expd.Subs_(itm);
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gdoc.RootNde()));
tstr.tst_Equal("parse");
}
public static void tst(TfdsTstr_fxt tstr, GfmlTyp_mok expd, GfmlTyp_mok actl) {
if (expd.Name() != null) tstr.Eq_str(expd.Name(), actl.Name(), "name");
if (expd.Key() != null) tstr.Eq_str(expd.Key(), actl.Key(), "key");
int max = tstr.List_Max(expd.Subs(), actl.Subs());
for (int i = 0; i < max; i++) {
GfmlFld_mok expdFld = (GfmlFld_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
GfmlFld_mok actlFld = (GfmlFld_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
tstr.SubName_push(Int_.To_str(i) + " fld");
tst(tstr, expdFld, actlFld);
tstr.SubName_pop();
}
}
static void tst(TfdsTstr_fxt tstr, GfmlFld_mok expd, GfmlFld_mok actl) {
expd = NullObj(expd); actl = NullObj(actl);
if (expd.Name() != null) tstr.Eq_str(expd.Name(), actl.Name(), "name");
if (expd.TypeKey() != null) tstr.Eq_str(expd.TypeKey(), actl.TypeKey(), "typekey");
if (expd.DefaultTkn() != null) tstr.Eq_str(expd.DefaultTknRaw(), actl.DefaultTknRaw(), "default");
}
static GfmlFld_mok NullObj(GfmlFld_mok v) {return (v == null) ? GfmlFld_mok.new_().ini_ndk_(String_.Null_mark, "") : v;}
public void tst_Resolve(GfmlTyp_mok typ, GfmlNde_mok nde, GfmlNde_mok expd) {
typBldr.TypeRegy().Add(typ.XtoGfmlType());
tst_Resolve(nde, expd);
}
public GfmlNde run_Resolve(GfmlTypRegy regy, String typKey, GfmlNde_mok nde) {
GfmlNde gfmlNde = nde.XtoGfmlItm(regy);
typBldr.OverridePool(regy.FetchOrNull(typKey));
tst_ResolveNde(gfmlNde, typKey);
return gfmlNde;
}
public void tst_Resolve(GfmlNde_mok nde, GfmlNde_mok expd) {
GfmlNde gfmlNde = nde.XtoGfmlItm(typBldr.TypeRegy());
tst_ResolveNde(gfmlNde, GfmlType_.AnyKey);
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gfmlNde));
tstr.tst_Equal("test");
}
void tst_ResolveNde(GfmlNde nde, String ownerKey) {
typBldr.NdeBgn(nde, ownerKey);
for (int i = 0; i < nde.SubObjs_Count(); i++) {
GfmlItm itm = (GfmlItm)nde.SubObjs_GetAt(i);
if (itm.ObjType() == GfmlObj_.Type_nde)
tst_ResolveNde((GfmlNde)itm, nde.Type().Key());
else
typBldr.AtrExec(nde, (GfmlAtr)itm);
}
typBldr.NdeEnd();
}
GfmlTypeMgr typBldr = GfmlTypeMgr.new_();
public static GfmlTypeCompiler_fxt new_() {return new GfmlTypeCompiler_fxt();} GfmlTypeCompiler_fxt() {}
}

View File

@@ -1,182 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import gplx.core.strings.*;
interface GfmlItm_mok {
int ObjType();
}
class GfmlAtr_mok implements GfmlItm_mok {
public int ObjType() {return GfmlObj_.Type_atr;}
public String Key() {return key;} public GfmlAtr_mok Key_(String v) {key = v; return this;} private String key;
public String Val() {return val;} public GfmlAtr_mok Val_(String v) {val = v; return this;} private String val;
public GfmlAtr XtoGfmlItm() {
GfmlAtr rv = GfmlAtr.new_(GfmlTkn_.raw_(key), GfmlTkn_.raw_(val), GfmlType_.String);
return rv;
}
public String XtoStrStub() {
String_bldr sb = String_bldr_.new_();
sb.Add_kv("key=", key).Add_kv("val=", val);
return sb.To_str();
}
public static final GfmlAtr_mok Null = new GfmlAtr_mok().Key_(String_.Null_mark).Val_(String_.Null_mark);
public static GfmlAtr_mok as_(Object obj) {return obj instanceof GfmlAtr_mok ? (GfmlAtr_mok)obj : null;}
public static GfmlAtr_mok new_(String key, String val) {
GfmlAtr_mok rv = new GfmlAtr_mok();
rv.key = key; rv.val = val;
return rv;
} GfmlAtr_mok() {}
}
class GfmlNde_mok implements GfmlItm_mok {
public int ObjType() {return GfmlObj_.Type_nde;}
public String Key() {return key;} public GfmlNde_mok Key_(String v) {key = v; return this;} private String key;
public String Hnd() {return hnd;} public GfmlNde_mok Hnd_(String v) {hnd = v; return this;} private String hnd;
public String Typ() {return typ;} public GfmlNde_mok Typ_(String v) {typ = v; return this;} private String typ;
public int ChainId() {return chainId;} public GfmlNde_mok ChainId_(int v) {chainId = v; return this;} int chainId = -1;
public boolean KeyedSubObj() {return keyed;}
public GfmlNde_mok KeyedSubObj_() {return KeyedSubObj_(true);}
public GfmlNde_mok KeyedSubObj_(boolean v) {keyed = v; return this;} private boolean keyed;
public List_adp Subs() {return subs;}
public String XtoStrStub() {
String_bldr sb = String_bldr_.new_();
sb.Add_kv("key=", key).Add_kv("hnd=", hnd).Add_kv("typ=", typ).Add_kv("subs=", Int_.To_str(subs.Count()));
return sb.To_str();
}
public GfmlNde_mok Subs_(GfmlItm_mok... ary) {
for (GfmlItm_mok itm : ary)
subs.Add(itm);
return this;
} List_adp subs = List_adp_.New();
public GfmlNde_mok Atrk_(String k, String v) {subs.Add(GfmlAtr_mok.new_(k, v)); return this;}
public GfmlNde_mok Atru_(String v) {subs.Add(GfmlAtr_mok.new_(GfmlTkn_.NullVal, v)); return this;}
public GfmlNde_mok Atrs_(String... ary) {
for (String itm : ary)
subs.Add(GfmlAtr_mok.new_(GfmlTkn_.NullVal, itm));
return this;
}
public GfmlNde XtoGfmlItm(GfmlTypRegy regy) {return XtoGfmlNde(regy, this);}
static GfmlNde XtoGfmlNde(GfmlTypRegy regy, GfmlNde_mok ownerMok) {
String tmpTypeKey = ownerMok.typ == null ? GfmlType_.AnyKey : ownerMok.typ;
String tmpHnd = ownerMok.hnd == null ? "" : ownerMok.hnd;
GfmlNde rv = GfmlNde.new_(GfmlTkn_.raw_(tmpHnd), regy.FetchOrNull(tmpTypeKey), ownerMok.key != null);
rv.ChainId_(ownerMok.chainId);
if (ownerMok.keyed) rv.KeyedSubObj_(ownerMok.keyed);
if (ownerMok.key != null) rv.KeyTkn_set(GfmlTkn_.val_(ownerMok.key));
for (int i = 0; i < ownerMok.subs.Count(); i++) {
GfmlItm_mok itm = (GfmlItm_mok)ownerMok.subs.Get_at(i);
if (itm.ObjType() == GfmlObj_.Type_nde) {
GfmlNde_mok itmMok = (GfmlNde_mok)itm;
rv.SubObjs_Add(itmMok.XtoGfmlItm(regy));
}
else {
GfmlAtr_mok atrMok = (GfmlAtr_mok)itm;
rv.SubObjs_Add(atrMok.XtoGfmlItm());
}
}
return rv;
}
public static GfmlNde_mok as_(Object obj) {return obj instanceof GfmlNde_mok ? (GfmlNde_mok)obj : null;}
public static final GfmlNde_mok Null = new GfmlNde_mok().Hnd_(String_.Null_mark).Typ_(String_.Null_mark);
public static final GfmlNde_mok ErrAtr = new GfmlNde_mok().Hnd_("<<ErrAtr>>").Typ_("<<ErrAtr>>");
public static GfmlNde_mok new_() {return new GfmlNde_mok();} GfmlNde_mok() {}
public static GfmlNde_mok gfmlNde_(GfmlNde nde) {return InitNde(nde);}
static GfmlNde_mok InitNde(GfmlNde nde) {
GfmlNde_mok rv = new GfmlNde_mok();
rv.typ = nde.Type().Key();
rv.hnd = nde.Hnd();
rv.keyed = nde.KeyedSubObj();
rv.chainId = nde.ChainId();
if (nde.Key() != null) rv.key = nde.Key();
for (int i = 0; i < nde.SubKeys().Count(); i++) {
GfmlItm subItm = (GfmlItm)nde.SubKeys().Get_at(i);
if (subItm.ObjType() == GfmlObj_.Type_atr) {
GfmlAtr subAtr = (GfmlAtr)subItm;
GfmlAtr_mok mokAtr = GfmlAtr_mok.new_(subAtr.Key(), subAtr.DatTkn().Val());
if (!String_.Len_eq_0(subAtr.Key())) mokAtr.Key_(subAtr.Key());
rv.subs.Add(mokAtr);
}
else {
GfmlNde subNde = (GfmlNde)subItm;
GfmlNde_mok mokNde = InitNde(subNde);
rv.subs.Add(mokNde);
}
}
for (int i = 0; i < nde.SubHnds().Count(); i++) {
GfmlNde subNde = (GfmlNde)nde.SubHnds().Get_at(i);
GfmlNde_mok mokNde = InitNde(subNde);
rv.subs.Add(mokNde);
}
return rv;
}
}
class GfmlTypeResolver_fxt {
public GfmlType ini_MakeType(GfmlTyp_mok mok) {
type = mok.XtoGfmlType();
regy.Add(type);
return type;
}
GfmlType type;
public static void tst_Nde(TfdsTstr_fxt tstr, GfmlNde_mok expd, GfmlNde_mok actl) {
expd = NullObj(expd); actl = NullObj(actl);
if (expd.Typ() != null) tstr.Eq_str(expd.Typ(), actl.Typ(), "typ");
if (expd.KeyedSubObj()) tstr.Eq_str(expd.KeyedSubObj(), actl.KeyedSubObj(), "keyed");
if (expd.Key() != null) tstr.Eq_str(expd.Key(), actl.Key(), "key");
if (expd.Hnd() != null) tstr.Eq_str(expd.Hnd(), actl.Hnd(), "hnd");
if (expd.ChainId() != -1) tstr.Eq_str(expd.ChainId(), actl.ChainId(), "chainId");
int max = tstr.List_Max(expd.Subs(), actl.Subs());
for (int i = 0; i < max; i++) {
GfmlItm_mok expdSub = (GfmlItm_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
GfmlItm_mok actlSub = (GfmlItm_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
tstr.SubName_push(Int_.To_str(i));
if (expdSub == null) {
GfmlNde_mok mm = GfmlNde_mok.as_(actlSub);
String actlSubStr = mm == null ? "sub:null" : mm.XtoStrStub();
tstr.Eq_str("nde:" + "sub:null", actlSubStr, "expdSub null");
tstr.Fail();
break;
}
else if (expdSub.ObjType() == GfmlObj_.Type_atr) {
GfmlAtr_mok actlAtrMok = GfmlAtr_mok.as_(actlSub);
tst_Nde(tstr, (GfmlAtr_mok)expdSub, actlAtrMok);
}
else {
GfmlNde_mok actlMok = GfmlNde_mok.as_(actlSub);
if (actlMok == null) {
String actlSubStr = actlSub == null ? "sub:null" : "atr:" + ((GfmlAtr_mok)actlSub).XtoStrStub();
tstr.Eq_str("nde:" + ((GfmlNde_mok)expdSub).XtoStrStub(), actlSubStr, "actlSub null");
tstr.Fail();
break;
}
tst_Nde(tstr, (GfmlNde_mok)expdSub, actlMok);
}
tstr.SubName_pop();
}
}
static GfmlNde_mok NullObj(GfmlNde_mok v) {return v == null ? GfmlNde_mok.Null : v;}
static GfmlAtr_mok NullObj(GfmlAtr_mok v) {return v == null ? GfmlAtr_mok.Null : v;}
static void tst_Nde(TfdsTstr_fxt tstr, GfmlAtr_mok expd, GfmlAtr_mok actl) {
expd = NullObj(expd); actl = NullObj(actl);
if (expd.Key() != null) tstr.Eq_str(expd.Key(), actl.Key(), "key");
if (expd.Val() != null) tstr.Eq_str(expd.Val(), actl.Val(), "val");
}
GfmlTypRegy regy = GfmlTypRegy.new_();
public static GfmlTypeResolver_fxt new_() {
GfmlTypeResolver_fxt rv = new GfmlTypeResolver_fxt();
return rv;
} GfmlTypeResolver_fxt() {}
}

View File

@@ -1,77 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlTkn_mok {
public String Raw() {return raw;} public GfmlTkn_mok Raw_(String v) {raw = v; return this;} private String raw;
public List_adp Subs() {return list;} List_adp list = List_adp_.New();
public GfmlTkn_mok Subs_(GfmlTkn_mok... ary) {
for (GfmlTkn_mok itm : ary)
list.Add(itm);
return this;
}
// statics
public static GfmlTkn_mok new_() {return new GfmlTkn_mok();} GfmlTkn_mok() {}
public static GfmlTkn_mok gfmlNde_(GfmlNde nde) {
GfmlTkn_mok rv = new GfmlTkn_mok();
InitItm(rv, nde);
return rv;
}
static void InitItm(GfmlTkn_mok rv, GfmlItm owner) {
for (int i = 0; i < owner.SubObjs_Count(); i++) {
GfmlObj subTkn = (GfmlObj)owner.SubObjs_GetAt(i);
GfmlTkn_mok subMok = GfmlTkn_mok.new_();
rv.Subs_(subMok);
GfmlItm subItm = GfmlItm_.as_(subTkn);
if (subItm != null)
InitItm(subMok, subItm);
else
InitTkn(subMok, (GfmlTkn)subTkn);
}
}
static void InitTkn(GfmlTkn_mok mok, GfmlTkn tkn) {
if (tkn.SubTkns().length == 0) // leafTkn; no subs; simply set
mok.Raw_(tkn.Raw());
else { // compTkn; createTkn and iterate
for (int i = 0; i < tkn.SubTkns().length; i++) {
GfmlTkn subTkn = (GfmlTkn)tkn.SubTkns()[i];
GfmlTkn_mok subMok = GfmlTkn_mok.new_();
InitTkn(subMok, subTkn);
mok.Subs_(subMok);
}
}
}
public static GfmlTkn_mok[] Xto_bry(String... ary) {
GfmlTkn_mok[] rv = new GfmlTkn_mok[ary.length];
for (int i = 0; i < rv.length; i++)
rv[i] = GfmlTkn_mok.new_().Raw_(ary[i]);
return rv;
}
public static void tst(TfdsTstr_fxt tstr, GfmlTkn_mok expd, GfmlTkn_mok actl) {
expd = NullObj(expd); actl = NullObj(actl);
if (expd.Raw() != null) tstr.Eq_str(expd.Raw(), actl.Raw(), "raw");
int max = tstr.List_Max(expd.Subs(), actl.Subs());
for (int i = 0; i < max; i++) {
GfmlTkn_mok expdSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
GfmlTkn_mok actlSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
tstr.SubName_push(Int_.To_str(i));
tst(tstr, expdSub, actlSub);
tstr.SubName_pop();
}
}
static GfmlTkn_mok NullObj(GfmlTkn_mok v) {return v == null ? GfmlTkn_mok.new_().Raw_(String_.Null_mark) : v;}
}

View File

@@ -1,83 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class GfmlFld_mok {
public String Name() {return name;} public GfmlFld_mok Name_(String v) {name = v; return this;} private String name;
public String TypeKey() {return typeKey;} public GfmlFld_mok TypeKey_(String v) {typeKey = v; return this;} private String typeKey;
public GfmlObj DefaultTkn() {return defaultTkn;}
public GfmlFld_mok DefaultTkn_(GfmlObj v) {defaultTkn = v; return this;} GfmlObj defaultTkn = GfmlTkn_.Null;
public GfmlFld_mok Default_(String v) {defaultTkn = GfmlTkn_.raw_(v); return this;}
public String DefaultTknRaw() {return GfmlFld_mok.XtoRaw(defaultTkn);}
public boolean KeyedSubObj() {return keyed;} private boolean keyed = false;
public GfmlFld XtoGfmlFld() {
GfmlFld rv = GfmlFld.new_(keyed, name, typeKey);
rv.DefaultTkn_(defaultTkn);
return rv;
}
public GfmlFld_mok ini_atr_(String name) {this.name = name; this.keyed = true; return this;}
public GfmlFld_mok ini_ndk_(String name, String typKey) {this.name = name; this.typeKey = typKey; this.keyed = true; return this;}
public static GfmlFld_mok new_() {return new GfmlFld_mok();} GfmlFld_mok() {}
public static String XtoRaw(GfmlObj gobj) {
if (gobj == null) return String_.Null_mark;
GfmlTkn tkn = GfmlTkn_.as_(gobj);
if (tkn != null) return tkn.Raw();
GfmlNde nde = GfmlNde.as_(gobj);
return nde.To_str();
}
}
class GfmlTyp_mok {
public String Name() {return name;} public GfmlTyp_mok Name_(String v) {name = v; return this;} private String name;
public String Key() {return key;} public GfmlTyp_mok Key_(String v) {key = v; return this;} private String key;
public List_adp Subs() {return subFlds;} List_adp subFlds = List_adp_.New();
public GfmlTyp_mok Atrs_(String... ary) {
for (String itm : ary)
subFlds.Add(GfmlFld_mok.new_().ini_atr_(itm));
return this;
}
public GfmlTyp_mok Subs_(GfmlFld_mok... ary) {
for (GfmlFld_mok itm : ary)
subFlds.Add(itm);
return this;
}
public GfmlType XtoGfmlType() {
GfmlType rv = GfmlType_.new_(key, name); // all types in tests are top-level
for (int i = 0; i < subFlds.Count(); i++) {
GfmlFld_mok fld = (GfmlFld_mok)subFlds.Get_at(i);
rv.SubFlds().Add(fld.XtoGfmlFld());
}
return rv;
}
public static GfmlTyp_mok new_() {return new GfmlTyp_mok();} GfmlTyp_mok() {}
public static GfmlTyp_mok simple_(String name, String... flds) {
GfmlTyp_mok rv = new GfmlTyp_mok();
rv.key = name; rv.name = name;
for (String fld : flds)
rv.subFlds.Add(GfmlFld_mok.new_().ini_atr_(fld));
return rv;
}
public static GfmlTyp_mok type_(GfmlType typ) {
GfmlTyp_mok rv = new GfmlTyp_mok();
rv.key = typ.Key(); rv.name = typ.NdeName();
for (int i = 0; i < typ.SubFlds().Count(); i++) {
GfmlFld fld = (GfmlFld)typ.SubFlds().Get_at(i);
GfmlFld_mok mkFld = GfmlFld_mok.new_().ini_ndk_(fld.Name(), fld.TypeKey()).DefaultTkn_(fld.DefaultTkn());
rv.subFlds.Add(mkFld);
}
return rv;
}
}

View File

@@ -1,36 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
class UsrMsg_mok {
public String Main() {return main;} public UsrMsg_mok Main_(String v) {main = v; return this;} private String main;
public UsrMsg_mok Add_(String k, Object o) {hash.Add(k, Keyval_.new_(k, o)); return this;}
public UsrMsg_mok Require_(String k) {required.Add(k, k); return this;}
public Ordered_hash Args() {return hash;} Ordered_hash hash = Ordered_hash_.New();
public Ordered_hash Required() {return required;} Ordered_hash required = Ordered_hash_.New();
public static UsrMsg_mok new_(UsrMsg um) {
UsrMsg_mok rv = new UsrMsg_mok();
if (um != null) {
rv.main = um.Hdr();
for (int i = 0; i < um.Args().Count(); i++) {
Keyval kv = (Keyval)um.Args().Get_at(i);
rv.Add_(kv.Key(), kv.Val());
}
}
return rv;
} UsrMsg_mok() {}
}

View File

@@ -1,63 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z011_IntObjHash_tst {
@Before public void setup() {
hash = new IntObjHash_base();
} IntObjHash_base hash;
@Test public void Empty() {
tst_Count(0);
tst_Fetch(1, null);
}
@Test public void Add() {
hash.Add(1, "1");
tst_Count(1);
tst_Fetch(1, "1");
tst_Fetch(2, null);
}
@Test public void Del() {
hash.Add(1, "1");
hash.Del(1);
tst_Count(0);
tst_Fetch(1, null);
}
@Test public void Clear() {
hash.Add(1, "1");
hash.Add(32, "32");
tst_Fetch(1, "1");
tst_Fetch(32, "32");
tst_Count(2);
hash.Clear();
tst_Count(0);
tst_Fetch(2, null);
tst_Fetch(32, null);
}
@Test public void Add_bug() { // fails after expanding ary, and fetching at key=n*16
hash.Add(1, "1");
tst_Count(1);
tst_Fetch(1, "1");
tst_Fetch(15, null); // works
tst_Fetch(17, null); // works
tst_Fetch(16, null); // used to fail
}
void tst_Fetch(int key, Object expd) {Tfds.Eq(expd, hash.Get_by(key));}
void tst_Count(int expd) {Tfds.Eq(expd, hash.Count());}
}

View File

@@ -1,73 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
import gplx.core.texts.*; /*CharStream*/
public class z012_GfmlTrie_tst {
@Before public void setup() {
trie = GfmlTrie.new_();
} GfmlTrie trie;
@Test public void Null() {
tst_FindMatch_first("", null);
tst_FindMatch_first("{", null);
}
@Test public void OneChar() {
trie.Add("{", "val0");
tst_FindMatch_first("{", "val0");
tst_FindMatch_first(":", null);
}
@Test public void TwoChar() {
trie.Add("/*", "val0");
tst_FindMatch_first("/*", "val0");
tst_FindMatch_first("//", null);
}
@Test public void ManySym() {
trie.Add(":", "val0");
trie.Add("{", "val1");
tst_FindMatch_first(":", "val0");
tst_FindMatch_first("{", "val1");
tst_FindMatch_first("-", null);
}
@Test public void Overlap_1_2() {
trie.Add("[", "val0");
trie.Add("[:", "val1");
tst_FindMatch_first("[", "val0");
tst_FindMatch_first("[:", "val1");
tst_FindMatch_first("[-", "val0");
tst_FindMatch_first(":", null);
}
@Test public void Overlap_2_1() {
trie.Add("[:", "val0");
trie.Add("[", "val1");
tst_FindMatch_first("[:", "val0");
tst_FindMatch_first("[", "val1");
tst_FindMatch_first("[-", "val1");
tst_FindMatch_first(":", null);
}
@Test public void Overlap_1_1() {
trie.Add("[", "val0");
trie.Add("[", "val1");
tst_FindMatch_first("[", "val1"); // return last added
tst_FindMatch_first(":", null);
}
void tst_FindMatch_first(String text, String expd) {
CharStream stream = CharStream.pos0_(text);
String actl = (String)trie.FindMatch(stream);
Tfds.Eq(expd, actl);
}
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z015_GfmlDocPos_tst {
GfmlDocPos root = GfmlDocPos_.Root;
@Test public void Root() {
tst_Path(root, "0");
}
@Test public void MoveDown() {
tst_Path(root.NewDown(0), "0_0");
tst_Path(root.NewDown(0).NewDown(0), "0_0_0");
tst_Path(root.NewDown(1).NewDown(2), "0_1_2");
}
@Test public void MoveUp() {
tst_Path(root.NewDown(1).NewDown(2).NewUp(), "0_1");
}
@Test public void CompareTo_same() {
GfmlDocPos lhs = root.NewDown(0);
GfmlDocPos rhs = root.NewDown(0);
tst_CompareTo(lhs, rhs, CompareAble_.Same);
}
@Test public void CompareTo_diffIndex() {
GfmlDocPos lhs = root.NewDown(0);
GfmlDocPos rhs = root.NewDown(1);
tst_CompareTo(lhs, rhs, CompareAble_.Less);
tst_CompareTo(rhs, lhs, CompareAble_.More);
}
@Test public void CompareTo_diffLevel() {
GfmlDocPos lhs = root;
GfmlDocPos rhs = root.NewDown(0);
tst_CompareTo(lhs, rhs, CompareAble_.Less);
tst_CompareTo(rhs, lhs, CompareAble_.More);
}
void tst_Path(GfmlDocPos pos, String expdPath) {Tfds.Eq(expdPath, pos.Path());}
void tst_CompareTo(GfmlDocPos lhs, GfmlDocPos rhs, int expd) {Tfds.Eq(expd, lhs.compareTo(rhs));}
}

View File

@@ -1,55 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z016_GfmlScopeList_tst {
@Before public void setup() {
list = GfmlScopeList.new_("test");
} GfmlScopeList list;
@Test public void None() {
tst_Itm(list, GfmlDocPos_.Root, null);
}
@Test public void One() {
run_Add(list, var_("val1"));
tst_Itm(list, GfmlDocPos_.Root, "val1");
}
@Test public void ByPos() {
run_Add(list, var_("val1").DocPos_(docPos_(0, 0)));
run_Add(list, var_("val2").DocPos_(docPos_(0, 0, 0)));
tst_Itm(list, docPos_(0, 0), "val1");
tst_Itm(list, docPos_(0, 0, 0), "val2");
tst_Itm(list, docPos_(0, 1), "val1");
tst_Itm(list, docPos_(0), null);
}
GfmlVarItm var_(String val) {return GfmlVarItm.new_("key", GfmlTkn_.raw_(val), GfmlVarCtx_.DefaultKey);}
GfmlDocPos docPos_(int... ary) {
int last = ary.length - 1;
int idx = ary[last];
int[] levels = (int[])Array_.Resize(ary, last);
return new GfmlDocPos(levels, idx);
}
void run_Add(GfmlScopeList list, GfmlScopeItm... ary) {
for (GfmlScopeItm itm : ary)
list.Add(itm);
}
void tst_Itm(GfmlScopeList list, GfmlDocPos pos, String expd) {
GfmlVarItm itm = (GfmlVarItm)list.Get_by(pos);
String actl = itm == null ? null : itm.TknVal();
Tfds.Eq(expd, actl);
}
}

View File

@@ -1,53 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z017_GfmlStringHighlighter_tst {
@Test public void Short() {
tst_Err(sh_().Raw_("a=").Mark_(1, '=', "key tkn").Mark_(2, '?', "EOS:missing data")
, "< >"
, " a= "
, " =?"
, ""
, "[1] = key tkn"
, "[2] ? EOS:missing data"
);
}
@Test public void Whitespace() {
tst_Err(sh_().Raw_("a\t\nb").Mark_(0, ' ', "")
, "< tn >"
, " a b "
, " "
);
}
@Test public void Long() {
tst_Err(sh_().Raw_("abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba").Mark_(0, '{', "bgn").Mark_(50, '}', "end")
, "< >"
, " abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba "
, " { } "
, ""
, "[00] { bgn"
, "[50] } end"
);
}
GfmlStringHighlighter sh_() {return GfmlStringHighlighter.new_();}
void tst_Err(GfmlStringHighlighter sh, String... expdLines) {
String[] actlLines = sh.Gen();
Tfds.Eq_ary_str(expdLines, actlLines);
}
}

View File

@@ -1,77 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z051_GfmlFldPool_keyed_tst {
@Before public void setup() {
GfmlTypeMakr makr = GfmlTypeMakr.new_();
GfmlType type = makr.MakeSubType("point", "x", "y", "z");
fldPool = GfmlFldPool.new_(type);
} GfmlFldPool fldPool;
@Test public void PopByKey_inOrder() {
tst_Keyed_PopByKey(fldPool, "x", "x", "y", "z");
}
@Test public void PopByKey_outOfOrder() {
tst_Keyed_PopByKey(fldPool, "y", "y", "x", "z");
}
@Test public void PopByKey_unknown() {
tst_Keyed_PopByKey(fldPool, "a", GfmlItmKeys.NullKey, "x", "y", "z");
}
@Test public void PopByKey_alreadyRemoved() {
tst_Keyed_PopByKey(fldPool, "x", "x", "y", "z");
tst_Keyed_PopByKey(fldPool, "x", GfmlItmKeys.NullKey, "y", "z");
}
@Test public void PopByKey_depleted() {
tst_Keyed_PopByKey(fldPool, "x", "x", "y", "z");
tst_Keyed_PopByKey(fldPool, "y", "y", "z");
tst_Keyed_PopByKey(fldPool, "z", "z");
tst_Keyed_PopByKey(fldPool, "x", GfmlItmKeys.NullKey);
}
@Test public void PopNext_inOrder() {
tst_Keyed_PopNext(fldPool, "x", "y", "z");
tst_Keyed_PopNext(fldPool, "y", "z");
tst_Keyed_PopNext(fldPool, "z");
try {
tst_Keyed_PopNext(fldPool, GfmlItmKeys.NullKey);
Tfds.Fail("should have failed");
}
catch (Exception exc) {Err_.Noop(exc);}
}
@Test public void PopByKey_PopNext() {
tst_Keyed_PopByKey(fldPool, "y", "y", "x", "z");
tst_Keyed_PopNext(fldPool, "x", "z");
}
void tst_Keyed_PopByKey(GfmlFldPool fldPool, String key, String expdFldId, String... expdSubs) {
GfmlFld actlFld = fldPool.Keyed_PopByKey(key);
Tfds.Eq(expdFldId, actlFld.Name());
String[] actlSubs = new String[fldPool.Keyd_Count()];
for (int i = 0; i < actlSubs.length; i++) {
actlSubs[i] = fldPool.Keyd_FetchAt(i).Name();
}
Tfds.Eq_ary(expdSubs, actlSubs);
}
void tst_Keyed_PopNext(GfmlFldPool fldPool, String expdFldId, String... expdSubs) {
GfmlFld actlFld = fldPool.Keyed_PopNext();
Tfds.Eq(expdFldId, actlFld.Name());
String[] actlSubs = new String[fldPool.Keyd_Count()];
for (int i = 0; i < actlSubs.length; i++) {
actlSubs[i] = fldPool.Keyd_FetchAt(i).Name();
}
Tfds.Eq_ary(expdSubs, actlSubs);
}
}

View File

@@ -1,71 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*; import gplx.core.stores.*;
public class z081_GfmlDataWtr_tst {
@Before public void setup() {
wtr = GfmlDataWtr.new_();
wtr.WriteNodeBgn("root");
} DataWtr wtr;
@Test public void Basic() {
tst_XtoStr(wtr, "root:;");
}
@Test public void Atr_one() {
wtr.WriteData("key", "data");;
tst_XtoStr(wtr, "root:key='data';");
}
@Test public void Atr_many() {
wtr.WriteData("key1", "data1");
wtr.WriteData("key2", "data2");
tst_XtoStr(wtr, "root:key1='data1' key2='data2';");
}
@Test public void Nde_one() {
wtr.WriteNodeBgn("sub0");
tst_XtoStr(wtr, "root:{sub0:;}");
}
@Test public void Nde_many() {
wtr.WriteNodeBgn("sub0");
wtr.WriteNodeEnd();
wtr.WriteNodeBgn("sub1");
tst_XtoStr(wtr, "root:{sub0:;sub1:;}");
}
@Test public void Nde_nested() {
wtr.WriteNodeBgn("sub0");
wtr.WriteNodeBgn("sub1");
tst_XtoStr(wtr, "root:{sub0:{sub1:;}}");
}
@Test public void OneAtrOneNde() {
wtr.WriteData("key1", "data1");
wtr.WriteNodeBgn("sub0");
tst_XtoStr(wtr, "root:key1='data1'{sub0:;}");
}
@Test public void OneAtrOneNdeOneAtr() {
wtr.WriteData("key1", "data1");
wtr.WriteNodeBgn("sub0");
wtr.WriteData("key2", "data2");
tst_XtoStr(wtr, "root:key1='data1'{sub0:key2='data2';}");
}
@Test public void EscapeQuote() {
wtr.WriteData("key", "data's");;
tst_XtoStr(wtr, "root:key='data''s';");
}
void tst_XtoStr(DataWtr wtr, String expd) {
String actl = wtr.To_str();
Tfds.Eq(expd, actl);
}
}

View File

@@ -1,54 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*; import gplx.core.stores.*;
public class z082_GfmlDataWtrOpts_tst {
@Before public void setup() {
wtr = GfmlDataWtr.new_();
wtr.WriteNodeBgn("root");
} DataWtr wtr;
@Test public void KeyedSpr() {
wtr.InitWtr(GfmlDataWtrOpts.Key_const, GfmlDataWtrOpts.new_().KeyedSeparator_("\t"));
wtr.WriteData("key1", "data1");
wtr.WriteData("key2", "data2");
tst_XtoStr(wtr, "root:key1='data1'\tkey2='data2';");
}
@Test public void IndentNamesOn() {
wtr.InitWtr(GfmlDataWtrOpts.Key_const, GfmlDataWtrOpts.new_().IndentNodesOn_());
wtr.WriteNodeBgn("nde1");
wtr.WriteNodeBgn("nde2");
wtr.WriteNodeEnd();
tst_XtoStr(wtr, String_.Concat_lines_crlf
( "root:{"
, " nde1:{"
, " nde2:;"
, " }"
, "}"
));
}
@Test public void IgnoreNullNamesOn() {
wtr.InitWtr(GfmlDataWtrOpts.Key_const, GfmlDataWtrOpts.new_().IgnoreNullNamesOn_());
wtr.WriteNodeBgn("");
wtr.WriteData("key1", "data1");
tst_XtoStr(wtr, String_.Concat("root:{key1='data1';}"));
}
void tst_XtoStr(DataWtr wtr, String expd) {
String actl = wtr.To_str();
Tfds.Eq(expd, actl);
}
}

View File

@@ -1,68 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
import gplx.core.texts.*; /*CharStream*/
public class z091_GfmlLxr_basic_tst {
@Before public void setup() {
rootLxr = GfmlLxr_.general_("gfml.root", GfmlTkn_.cmd_("tkn:text", GfmlBldrCmd_.Null));
} GfmlLxr rootLxr;
@Test public void Empty() {
tst_Fetch("");
}
@Test public void General() {
tst_Fetch("text", "text");
}
@Test public void Solo() {
ini_AddSymbol(",");
tst_Fetch(",", ",");
tst_Fetch(",data0", ",", "data0");
tst_Fetch("data0,", "data0", ",");
tst_Fetch("data0,data1", "data0", ",", "data1");
}
@Test public void Range() {
ini_AddRange(" ", "\t");
tst_Fetch(" ", " ");
tst_Fetch(" a", " ", "a");
tst_Fetch("\t ", "\t ");
tst_Fetch("\ta ", "\t", "a", " ");
}
void ini_AddSymbol(String symbol) {
GfmlTkn tkn = GfmlTkn_.singleton_("tkn", symbol, symbol, GfmlBldrCmd_.Null);
GfmlLxr lxr = GfmlLxr_.solo_(symbol, tkn);
rootLxr.SubLxr_Add(lxr);
}
void ini_AddRange(String... symbols) {
GfmlTkn tkn = GfmlTkn_.cmd_("tkn", GfmlBldrCmd_.Null);
GfmlLxr lxr = GfmlLxr_.range_("merge", symbols, tkn, false);
rootLxr.SubLxr_Add(lxr);
}
GfmlTkn tst_Fetch(String raw, String... expd) {
CharStream stream = CharStream.pos0_(raw);
List_adp list = List_adp_.New();
GfmlTkn tkn = null;
while (true) {
tkn = rootLxr.MakeTkn(stream, 0);
if (tkn == GfmlTkn_.EndOfStream) break;
list.Add(tkn.Raw());
}
String[] actl = (String[])list.To_ary(String.class);
Tfds.Eq_ary(expd, actl);
return tkn;
}
}

View File

@@ -1,50 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z101_core_ndeInline_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add(GfmlDocLxrs.NdeInline_lxr());
}
@Test public void One() {
fx.tst_Doc("a;", fx.nde_().Atru_("a"));
fx.tst_Tkn("a;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(";")
));
}
@Test public void Many() {
fx.tst_Doc("a;b;"
, fx.nde_().Atru_("a")
, fx.nde_().Atru_("b")
);
fx.tst_Tkn("a;b;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(";")
)
, fx.tkn_grp_
( fx.tkn_grp_ary_("b")
, fx.tkn_itm_(";")
)
);
}
}

View File

@@ -1,79 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z102_core_whitespace_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Whitespace_lxr()
);
}
@Test public void Space() {
fx.tst_Doc("a b;", fx.nde_().Atru_("a").Atru_("b"));
fx.tst_Tkn("a b;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(" ")
, fx.tkn_grp_ary_("b")
, fx.tkn_itm_(";")
)
);
}
@Test public void Tab() {
fx.tst_Doc("a\tb;", fx.nde_().Atru_("a").Atru_("b"));
}
@Test public void NewLine() {
fx.tst_Doc(String_.Format("a{0}b;", String_.CrLf), fx.nde_().Atru_("a").Atru_("b"));
}
@Test public void MergeSameWs() {
fx.tst_Doc("a b;", fx.nde_().Atru_("a").Atru_("b"));
}
@Test public void MergeDiffWs() {
fx.tst_Doc("a\t b;", fx.nde_().Atru_("a").Atru_("b"));
fx.tst_Tkn("a\t b;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_("\t ")
, fx.tkn_grp_ary_("b")
, fx.tkn_itm_(";")
)
);
}
@Test public void LeadingWs() {
fx.tst_Doc(" a;", fx.nde_().Atru_("a"));
fx.tst_Tkn(" a;"
, fx.tkn_itm_(" ")
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(";")
)
);
}
@Test public void TrailingWs() {
fx.tst_Doc("a ;", fx.nde_().Atru_("a"));
fx.tst_Tkn("a ;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(" ")
, fx.tkn_itm_(";")
)
);
}
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z103_core_elmKey_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.ElmKey_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("a=b;", fx.nde_().Atrk_("a", "b"));
fx.tst_Tkn("a=b;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a", "=", "b")
, fx.tkn_itm_(";")
)
);
}
@Test public void Ws() {
fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
fx.tst_Tkn("a = b;"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a", " ", "=", " ", "b")
, fx.tkn_itm_(";")
)
);
}
// @Test public void Err_NotNamed() {
// fx.tst_Err("=", GfmlOutCmds.DatTkn_notFound_Err_());
// }
// @Test public void Err_NotValued() {
// fx.tst_Err("a=;", GfmlOutCmds.elmKey_notValued_Err());
// }
}

View File

@@ -1,51 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z111_core_comment0_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Whitespace_lxr() // add whitespace to make sure it has no effect
, GfmlDocLxrs.Comment0_lxr() // bgn=// end=\n
);
}
@Test public void Basic() {
fx.tst_Doc("//a" + String_.Lf);
fx.tst_Tkn("//a" + String_.Lf
, fx.tkn_grp_ary_("//", "a", String_.Lf)
);
}
@Test public void Data() {
fx.tst_Doc("a;//b" + String_.Lf, fx.nde_().Atru_("a"));
fx.tst_Tkn("a;//b" + String_.Lf
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(";"))
, fx.tkn_grp_ary_("//", "b", String_.Lf)
);
}
// @Test public void DanglingBgn() {
// try {
// fx.tst_Err("//", GfmlOutCmds.Frame_danglingBgn_Err_());
// Tfds.Fail_expdError();
// }
// catch (Exception exc) {Err_.Noop(exc);}
// }
}

View File

@@ -1,69 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z112_core_comment1_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Comment1_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("/*a*/");
fx.tst_Tkn("/*a*/"
, fx.tkn_grp_ary_("/*", "a", "*/")
);
}
@Test public void Data() {
fx.tst_Doc("a;/*b*/", fx.nde_().Atru_("a"));
fx.tst_Tkn("a;/*b*/"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_itm_(";"))
, fx.tkn_grp_ary_("/*", "b", "*/")
);
}
@Test public void IgnoreWs() {
fx.tst_Tkn("/* b c */"
, fx.tkn_grp_ary_("/*", " b c ", "*/")
);
}
@Test public void EscapeBgn() {
fx.tst_Tkn("/* /*/* */"
, fx.tkn_grp_ary_("/*", " ", "/*/*", " ", "*/")
);
}
@Test public void EscapeEnd() {
fx.tst_Tkn("/* */*/ */"
, fx.tkn_grp_ary_("/*", " ", "*/*/", " ", "*/")
);
}
@Test public void Nest() {
fx.tst_Tkn("/* b0 /* c */ b1 */"
, fx.tkn_grp_
( fx.tkn_itm_("/*")
, fx.tkn_itm_(" b0 ")
, fx.tkn_grp_ary_("/*", " c ", "*/")
, fx.tkn_itm_(" b1 ")
, fx.tkn_itm_("*/")
)
);
}
}

View File

@@ -1,41 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z120_quotes_eval0_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Eval0_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("<~t>;", fx.nde_().Atru_("\t"));
fx.tst_Tkn("<~t>;"
, fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_grp_ary_("<~", "t", ">"))
, fx.tkn_itm_(";")
)
);
}
@Test public void DoublingIsNotEscaping() {
fx.tst_Doc("<~t>>>;", fx.nde_().Atru_("\t").Atru_(">>")); // >> does not resolve to >
}
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z121_quotes_quotes0_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Quote0_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("'abc';", fx.nde_().Atru_("abc"));
fx.tst_Tkn("'abc';"
, fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_grp_ary_("'", "abc", "'"))
, fx.tkn_itm_(";")
)
);
}
@Test public void Escape() {
fx.tst_Doc("'a''b';", fx.nde_().Atru_("a'b"));
fx.tst_Tkn("'a''b';"
, fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_grp_ary_("'", "a", "''", "b", "'"))
, fx.tkn_itm_(";")
)
);
}
@Test public void ManyAtrs_LastQuoted() { // bugfix
fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
fx.tst_Doc("a 'b';", fx.nde_().Atru_("a").Atru_("b"));
}
}

View File

@@ -1,64 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z122_quotes_quote0_eval0_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Quote0_Eval0_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("'a<~t>b';", fx.nde_().Atru_("a\tb"));
fx.tst_Tkn("'a<~t>b';"
, fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_itm_("'")
, fx.tkn_itm_("a")
, fx.tkn_grp_ary_("<~", "t", ">")
, fx.tkn_itm_("b")
, fx.tkn_itm_("'")
))
, fx.tkn_itm_(";")
)
);
}
@Test public void QuoteInside() {
fx.tst_Doc("'a<~'t'>b';", fx.nde_().Atru_("a\tb"));
fx.tst_Tkn("'a<~'t'>b';"
, fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_itm_("'")
, fx.tkn_itm_("a")
, fx.tkn_grp_
( fx.tkn_itm_("<~")
, fx.tkn_grp_ary_("'", "t", "'")
, fx.tkn_itm_(">")
)
, fx.tkn_itm_("b")
, fx.tkn_itm_("'")
))
, fx.tkn_itm_(";")
)
);
}
}

View File

@@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z123_quotes_quoteBlock_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.QuoteBlock_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("|'abc'|;", fx.nde_().Atru_("abc"));
}
@Test public void Escape_bgn() {
fx.tst_Doc("|'a|'|'b'|;", fx.nde_().Atru_("a|'b"));
}
@Test public void Escape_end() {
fx.tst_Doc("|'a'|'|b'|;", fx.nde_().Atru_("a'|b"));
}
@Test public void Nest() {
fx.tst_Doc("|'a|'-'|b'|;", fx.nde_().Atru_("a-b"));
}
}

View File

@@ -1,61 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z124_quotes_quoteFold_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.QuoteFold_lxr()
);
}
@Test public void Quote() {
fx.tst_Doc("^'a b'^;", fx.nde_().Atru_("a b"));
}
@Test public void Tab() {
fx.tst_Doc("^'a\tb'^;", fx.nde_().Atru_("ab"));
fx.tst_Tkn("^'a\tb'^;"
, fx.tkn_grp_
( fx.tkn_grp_
( fx.tkn_grp_ary_("^'", "a", "\t", "b", "'^"))
, fx.tkn_itm_(";"))
);
}
@Test public void NewLine() {
fx.tst_Doc(String_.Concat("^'a", String_.CrLf, "b'^;"), fx.nde_().Atru_("ab"));
}
@Test public void Eval() {
fx.tst_Doc("^'a<~t>b'^;", fx.nde_().Atru_("a\tb"));
}
@Test public void Nest() {
fx.tst_Doc("^'a^'-'^b'^;", fx.nde_().Atru_("a-b"));
}
@Test public void EscapeBgn() {
fx.tst_Doc("^'a^'^'b'^;", fx.nde_().Atru_("a^'b"));
}
@Test public void EscapeEnd() {
fx.tst_Doc("^'a'^'^b'^;", fx.nde_().Atru_("a'^b"));
}
@Test public void Comment0() {
fx.tst_Doc(String_.Concat("^'a//comment", String_.CrLf, "b'^;"), fx.nde_().Atru_("ab"));
}
@Test public void Comment1() {
fx.tst_Doc("^'a/*comment*/b'^;", fx.nde_().Atru_("ab"));
}
}

View File

@@ -1,65 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z151_ndeSubs_basic_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("{}", fx.nde_());
fx.tst_Tkn("{}"
, fx.tkn_grp_ary_("{", "}")
);
}
@Test public void Many() {
fx.tst_Doc("{}{}", fx.nde_(), fx.nde_());
}
@Test public void Nested() {
fx.tst_Doc("{{}}"
, fx.nde_().Subs_
( fx.nde_())
);
}
@Test public void NestedMany() {
fx.tst_Doc("{{}{}}"
, fx.nde_().Subs_
( fx.nde_()
, fx.nde_()
));
}
@Test public void Complex() {
fx.tst_Doc(String_.Concat
( "{"
, "{"
, "{}"
, "}"
, "{}"
, "}"
)
, fx.nde_().Subs_
( fx.nde_().Subs_
( fx.nde_())
, fx.nde_()
));
}
}

View File

@@ -1,68 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z152_ndeSubs_data_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Whitespace_lxr()
);
}
@Test public void ToInline() {
fx.tst_Doc("{a;}"
, fx.nde_().Subs_
( fx.nde_().Atru_("a"))
);
}
@Test public void ToInline_many() {
fx.tst_Doc("{a b;}"
, fx.nde_().Subs_
( fx.nde_().Atru_("a").Atru_("b"))
);
}
@Test public void ToBody() {
fx.tst_Doc("{a{}}"
, fx.nde_().Subs_
( fx.nde_().Atru_("a"))
);
}
@Test public void ToBody_many() {
fx.tst_Doc("{a b{}}"
, fx.nde_().Subs_
( fx.nde_().Atru_("a").Atru_("b"))
);
}
@Test public void ToBody_manyNest() {
fx.tst_Doc("a{b;}"
, fx.nde_().Atru_("a").Subs_
( fx.nde_().Atru_("b"))
);
}
@Test public void ToBody_many2() {
fx.tst_Doc("a{b{c;}}"
, fx.nde_().Atru_("a").Subs_
( fx.nde_().Atru_("b").Subs_
( fx.nde_().Atru_("c"))
)
);
}
}

View File

@@ -1,46 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z161_ndeHdrs_inline_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeHeader_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.Whitespace_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("a:;", fx.nde_().Hnd_("a"));
fx.tst_Tkn("a:;"
, fx.tkn_grp_ary_("a", ":", ";")
);
}
@Test public void Many() {
fx.tst_Doc("a:;b:;"
, fx.nde_().Hnd_("a")
, fx.nde_().Hnd_("b")
);
}
@Test public void Ws() {
fx.tst_Tkn("a : ;"
, fx.tkn_grp_ary_("a", " ", ":", " ", ";")
);
}
}

View File

@@ -1,33 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z162_ndeHdrs_err_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeHeader_lxr()
);
}
@Test public void NotNamed() {
fx.tst_Err(":", UsrMsg_mok.new_(GfmlUsrMsgs.fail_DatTkn_notFound()));
}
@Test public void Dangling() {
fx.tst_Err("a{", UsrMsg_mok.new_(GfmlUsrMsgs.fail_Frame_danglingBgn()));
}
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z163_ndeHdrs_body_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeHeader_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("a:{}", fx.nde_().Hnd_("a"));
}
@Test public void Many() {
fx.tst_Doc("a:{}b:{}"
, fx.nde_().Hnd_("a")
, fx.nde_().Hnd_("b")
);
}
@Test public void Nested() {
fx.tst_Doc("a:{b:{}}"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().Hnd_("b"))
);
}
@Test public void NestedMany() {
fx.tst_Doc("a:{b:{}c:{}}"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().Hnd_("b")
, fx.nde_().Hnd_("c")
)
);
}
}

View File

@@ -1,53 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z164_hdeHdrs_data_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.Whitespace_lxr()
, GfmlDocLxrs.NdeHeader_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
);
}
@Test public void Bas1() {
fx.tst_Tkn("a:b;"
, fx.tkn_grp_
( fx.tkn_itm_("a")
, fx.tkn_itm_(":")
, fx.tkn_grp_ary_("b")
, fx.tkn_itm_(";")
));
}
@Test public void Basic3() {
fx.tst_Tkn("a:b{c;}"
, fx.tkn_grp_
( fx.tkn_itm_("a")
, fx.tkn_itm_(":")
, fx.tkn_grp_ary_("b")
, fx.tkn_itm_("{")
, fx.tkn_grp_
( fx.tkn_grp_ary_("c")
, fx.tkn_itm_(";"))
, fx.tkn_itm_("}")
));
}
}

View File

@@ -1,65 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z181_ndeDots_basic_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeDot_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
);
}
@Test public void One() {
fx.tst_Doc("{a.b;c;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1)
)
, fx.nde_().Atru_("c").ChainId_(0)
));
fx.tst_Tkn("{a.b;c;}"
, fx.tkn_grp_
( fx.tkn_itm_("{")
, fx.tkn_grp_
( fx.tkn_itm_("a")
, fx.tkn_itm_(".")
, fx.tkn_grp_
( fx.tkn_itm_("b")
, fx.tkn_itm_(";"))
)
, fx.tkn_grp_
( fx.tkn_grp_ary_("c")
, fx.tkn_itm_(";"))
, fx.tkn_itm_("}")
));
}
@Test public void Many() {
fx.tst_Doc("{a.b.c.d;e;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).Subs_
( fx.nde_().Hnd_("c").ChainId_(1).Subs_
( fx.nde_().Hnd_("d").ChainId_(1)
)))
, fx.nde_().ChainId_(0).Atru_("e")
));
}
}

View File

@@ -1,73 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z182_ndeDots_subs_tst {
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeDot_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
);
} GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Test public void Basic() {
fx.tst_Doc("{a.b{}z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1)
)
, fx.nde_().Atru_("z").ChainId_(0)
));
}
@Test public void Nest() {
fx.ini_RootLxr_Add(GfmlDocLxrs.NdeHeader_lxr());
fx.tst_Doc("{a.b.c{d:e;}z;}" // shorthand of {a{b{c{d:e;}}}}
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).Subs_
( fx.nde_().Hnd_("c").ChainId_(1).Subs_
( fx.nde_().Hnd_("d").ChainId_(0).Atru_("e")
)
)
)
, fx.nde_().ChainId_(0).Atru_("z")
));
}
@Test public void Chain() {
fx.tst_Doc("{a.b.c;z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).Subs_
( fx.nde_().Hnd_("c").ChainId_(1))
)
, fx.nde_().ChainId_(0).Atru_("z")
));
}
@Test public void NdeHdr() {
fx.ini_RootLxr_Add(GfmlDocLxrs.NdeHeader_lxr());
fx.tst_Doc("{a:b.c;z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").Atru_("b").ChainId_(1).Subs_
( fx.nde_().Hnd_("c").ChainId_(1)//.Subs_
// ( fx.nde_().Hnd_("c"))
)
, fx.nde_().Atru_("z").ChainId_(0)
));
}
}

View File

@@ -1,140 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z183_ndeDots_parens_tst {
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeDot_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
, GfmlDocLxrs.NdeHdrBgn_lxr()
, GfmlDocLxrs.NdeHdrEnd_lxr()
);
} GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Test public void Basic() {
fx.tst_Doc("{a.b(c);z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c")
)
, fx.nde_().ChainId_(0).Atru_("z")
));
}
@Test public void Basic_tkn() {
//A_('1');
fx.tst_Tkn("a(c);"
, fx.tkn_grp_
( fx.tkn_itm_("a"), fx.tkn_itm_("(")
, fx.tkn_grp_(fx.tkn_itm_("c"))
, fx.tkn_itm_(")"), fx.tkn_itm_(";")
)
);
}
@Test public void Basic2_tkn() {
fx.tst_Tkn("a.b(c);"
, fx.tkn_grp_
( fx.tkn_itm_("a"), fx.tkn_itm_(".")
, fx.tkn_grp_
( fx.tkn_itm_("b"), fx.tkn_itm_("("), fx.tkn_grp_ary_("c"), fx.tkn_itm_(")"), fx.tkn_itm_(";")
)
)
);
}
@Test public void Many() {
fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
fx.tst_Doc("{a.b(c d e);z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c").Atru_("d").Atru_("e")
)
, fx.nde_().ChainId_(0).Atru_("z")
));
}
// @Test public void Many2() {
// fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
// fx.tst_Doc("{a.b(c){d();}}"
// , fx.nde_().ChainId_(0).Subs_
// ( fx.nde_().Hnd_("a").ChainId_(1).Subs_
// ( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c").Subs_
// ( fx.nde_().Hnd_("d")
// )
// )
// ));
// }
@Test public void Chain() {
fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
fx.tst_Doc("{a.b(c).d(e);z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c").Subs_
( fx.nde_().Hnd_("d").ChainId_(1).Atru_("e")
)
)
, fx.nde_().ChainId_(0).Atru_("z")
));
}
@Test public void Nest() {
fx.tst_Doc("{a.b(c.d);z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).KeyedSubObj_(false).Subs_
( fx.nde_().Hnd_("c").ChainId_(2).KeyedSubObj_(true).Subs_
( fx.nde_().Hnd_("d").ChainId_(2).KeyedSubObj_(false)
)
)
)
, fx.nde_().Atru_("z")
));
}
@Test public void Nest_longer() {
fx.tst_Doc("{a.b.c(d.e.f);z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").KeyedSubObj_(false).ChainId_(1).Subs_
( fx.nde_().Hnd_("c").KeyedSubObj_(false).ChainId_(1).Subs_
( fx.nde_().Hnd_("d").KeyedSubObj_(true).ChainId_(2).Subs_
( fx.nde_().Hnd_("e").KeyedSubObj_(false).ChainId_(2).Subs_
( fx.nde_().Hnd_("f").KeyedSubObj_(false).ChainId_(2)
)
)
)
)
)
, fx.nde_().Atru_("z")
));
}
@Test public void Nest_deeper() {
fx.tst_Doc("{a.b(c.d(e.f));z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").KeyedSubObj_(false).ChainId_(1).Subs_
( fx.nde_().Hnd_("c").KeyedSubObj_(true).ChainId_(2).Subs_
( fx.nde_().Hnd_("d").KeyedSubObj_(false).ChainId_(2).Subs_
( fx.nde_().Hnd_("e").KeyedSubObj_(true).ChainId_(3).Subs_
( fx.nde_().Hnd_("f").KeyedSubObj_(false).ChainId_(3)
)
)
)
)
)
, fx.nde_().Atru_("z")
));
}
}

View File

@@ -1,47 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z184_ndeDots_atrSpr_tst {
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeDot_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
, GfmlDocLxrs.NdeHdrBgn_lxr()
, GfmlDocLxrs.NdeHdrEnd_lxr()
, GfmlDocLxrs.AtrSpr_lxr()
);
} GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Test public void NestMult() {
fx.ini_RootLxr_Add(GfmlDocLxrs.AtrSpr_lxr());
fx.tst_Doc("{a.b(c.d,e.f);z;}"
, fx.nde_().ChainId_(0).Subs_
( fx.nde_().Hnd_("a").ChainId_(1).Subs_
( fx.nde_().Hnd_("b").ChainId_(1).KeyedSubObj_(false).Subs_
( fx.nde_().Hnd_("c").ChainId_(2).KeyedSubObj_(true).Subs_
( fx.nde_().Hnd_("d").ChainId_(2).KeyedSubObj_(false))
, fx.nde_().Hnd_("e").ChainId_(3).KeyedSubObj_(true).Subs_
( fx.nde_().Hnd_("f").ChainId_(3).KeyedSubObj_(false))
)
)
, fx.nde_().ChainId_(0).Atru_("z")
));
}
}

View File

@@ -1,120 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z191_ndeProps_basic_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdePropBgn_lxr()
, GfmlDocLxrs.NdePropEnd_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
, GfmlDocLxrs.NdeHeader_lxr()
, GfmlDocLxrs.NdeInline_lxr()
);
}
@Test public void Basic() {
fx.tst_Doc("a:[b]{}"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().KeyedSubObj_().Atru_("b"))
);
}
@Test public void Basic_empty() {
fx.tst_Tkn("[];"
, fx.tkn_grp_
( fx.tkn_grp_ary_("[", "]")
, fx.tkn_itm_(";")
));
}
@Test public void Hdr() {
fx.tst_Tkn("a[];"
, fx.tkn_grp_
( fx.tkn_grp_ary_("a")
, fx.tkn_grp_ary_("[", "]")
, fx.tkn_itm_(";")
));
}
@Test public void WithInnerNde() {
fx.tst_Doc("a:[b]{c;}"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().KeyedSubObj_().Atru_("b")
, fx.nde_().Atru_("c")
));
}
@Test public void DoesNotUsurpDatTknForName() {
fx.tst_Doc("a:b[c]{}"
, fx.nde_().Hnd_("a").Atru_("b").Subs_
( fx.nde_().KeyedSubObj_().Atru_("c")
));
}
@Test public void NoHeader_body() {
fx.tst_Doc("a[b]{}"
, fx.nde_().Atru_("a").Subs_
( fx.nde_().KeyedSubObj_().Atru_("b")
));
}
@Test public void NoHeader_inline() {
fx.tst_Doc("a[b];"
, fx.nde_().Atru_("a").Subs_
( fx.nde_().KeyedSubObj_().Atru_("b")
));
}
@Test public void Nesting() {
fx.tst_Doc("a:[b:;]{}"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().KeyedSubObj_().Subs_
( fx.nde_().Hnd_("b"))
));
}
@Test public void Nesting2() {
fx.tst_Doc("a:[b{}]{}"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().KeyedSubObj_().Atru_("b")
));
}
@Test public void CanBeKeyed_header() {
fx.ini_RootLxr_Add(GfmlDocLxrs.ElmKey_lxr());
fx.tst_Doc("a:b=[c];"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().KeyedSubObj_().Key_("b").Atru_("c")
));
}
@Test public void CanBeKeyed2_inline() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.Whitespace_lxr()
, GfmlDocLxrs.ElmKey_lxr()
);
fx.tst_Doc("a b=[c];"
, fx.nde_().Atru_("a").Subs_
( fx.nde_().KeyedSubObj_().Key_("b").Atru_("c")
));
}
@Test public void Sole() {
fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
fx.tst_Doc("[a b]"
, fx.nde_().KeyedSubObj_().Atru_("a").Atru_("b"));
}
@Test public void Nest1() {
fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr());
fx.tst_Doc("[a [b]]"
, fx.nde_().Atru_("a").Subs_
( fx.nde_().KeyedSubObj_().Atru_("b")
));
}
}

View File

@@ -1,39 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z192_ndeProps_dots_tst {
GfmlParse_fxt fx = GfmlParse_fxt.new_();
@Before public void setup() {
fx.ini_RootLxr_Add
( GfmlDocLxrs.NdeDot_lxr()
, GfmlDocLxrs.NdeInline_lxr()
, GfmlDocLxrs.NdeBodyBgn_lxr()
, GfmlDocLxrs.NdeBodyEnd_lxr()
, GfmlDocLxrs.NdePropBgn_lxr()
, GfmlDocLxrs.NdePropEnd_lxr()
);
}
@Test public void Stress() {
fx.tst_Doc("a.b[c];"
, fx.nde_().Hnd_("a").Subs_
( fx.nde_().Hnd_("b").Subs_
( fx.nde_().KeyedSubObj_().Atru_("c"))
));
}
}

View File

@@ -1,66 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z400_GfmlTypeMakr_tst {
@Before public void setup() {
makr = GfmlTypeMakr.new_();
} GfmlTypeMakr makr; GfmlType type; GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void MakeSubType() {
type = makr.MakeSubType("point", "x", "y");
fx.tst_Type
( fx.typ_().Key_("point").Subs_
( fx.fld_().ini_atr_("x").TypeKey_(GfmlType_.StringKey)
, fx.fld_().ini_atr_("y").TypeKey_(GfmlType_.StringKey)
)
, GfmlTyp_mok.type_(type)
);
tst_XtoAry(makr, "point");
}
@Test public void MakeSubTypeAsOwner() {
type = makr.MakeSubTypeAsOwner("item");
fx.tst_Type
( fx.typ_().Key_("item")
, GfmlTyp_mok.type_(type)
);
tst_Owner(makr, "item");
tst_XtoAry(makr, "item");
}
@Test public void MakeSubTypeAsOwner_MakeSubType() {
type = makr.MakeSubTypeAsOwner("item");
makr.MakeSubType("pos", "x", "y");
fx.tst_Type
( fx.typ_().Key_("item").Subs_
( fx.fld_().Name_("pos").TypeKey_("item/pos"))
, GfmlTyp_mok.type_(type)
);
tst_Owner(makr, "item");
tst_XtoAry(makr, "item", "item/pos");
}
void tst_Owner(GfmlTypeMakr typeMakr, String expdKey) {
Tfds.Eq(expdKey, typeMakr.Owner().Key());
}
void tst_XtoAry(GfmlTypeMakr typeMakr, String... expdAry) {
GfmlType[] actlTypeAry = typeMakr.Xto_bry();
String[] actlAry = new String[actlTypeAry.length];
for (int i = 0; i < actlAry.length; i++) {
actlAry[i] = actlTypeAry[i].Key();
}
Tfds.Eq_ary(expdAry, actlAry);
}
}

View File

@@ -1,65 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z401_types_compile_basic_tst {
@Before public void setup() {
fx.run_InitPragma(fx.Regy(), GfmlPragmaType.new_());
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void Basic() {
fx.tst_Compile
( fx.nde_().Atrs_("point", "gfml.point").Subs_
( fx.nde_().Atru_("x")
, fx.nde_().Atru_("y")
)
, fx.typ_().Name_("point").Key_("gfml.point").Atrs_("x", "y")
);
}
@Test public void Nest() {
fx.tst_Compile
( fx.nde_().Atrs_("item", "gfml.item").Subs_
( fx.nde_().Atru_("pos").Atrk_("type", "gfml.item.point")
)
, fx.typ_().Name_("item").Key_("gfml.item").Subs_
( fx.fld_().Name_("pos").TypeKey_("gfml.item.point")
)
);
}
@Test public void NestMany() {
fx.tst_Compile
( fx.nde_().Atrs_("item", "gfml.item").Subs_
( fx.nde_().Atru_("pos").Atrk_("type", "gfml.item.point")
, fx.nde_().Atru_("size").Atrk_("type", "gfml.item.size")
)
, fx.typ_().Name_("item").Key_("gfml.item").Subs_
( fx.fld_().Name_("pos").TypeKey_("gfml.item.point")
, fx.fld_().Name_("size").TypeKey_("gfml.item.size")
)
);
}
@Test public void Recurse() {
fx.tst_Compile
( fx.nde_().Atrs_("widget", "gfml.widget").Subs_
( fx.nde_().Atru_("widget").Atrk_("type", "gfml.widget")
)
, fx.typ_().Name_("widget").Key_("gfml.widget").Subs_
( fx.fld_().Name_("widget").TypeKey_("gfml.widget")
)
);
}
}

View File

@@ -1,63 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z402_types_compile_implicit_tst {
@Before public void setup() {
fx.run_InitPragma(fx.Regy(), GfmlPragmaType.new_());
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void Fld_typeKey_leaf() {
fx.tst_Compile
( fx.nde_().Atrs_("point", "gfml.point").Subs_
( fx.nde_().Atru_("x").Atrk_("type", "gfml.int") // explicit
, fx.nde_().Atru_("y") // implicit: GfmlType_.String
)
, fx.typ_().Name_("point").Key_("gfml.point").Subs_
( fx.fld_().Name_("x").TypeKey_("gfml.int")
, fx.fld_().Name_("y").TypeKey_("gfml.String")
));
}
@Test public void Fld_typeKey_nest() {
fx.tst_Compile
( fx.nde_().Atrs_("rect", "gfml.rect").Subs_
( fx.nde_().Atru_("pos").Atrk_("type", "gfml.point").Subs_ // explicit
( fx.nde_().Atru_("x")
, fx.nde_().Atru_("y")
)
, fx.nde_().Atru_("size").Subs_ // implicit: gfml.rect.size; (needs to have subs)
( fx.nde_().Atru_("w")
, fx.nde_().Atru_("h")
)
)
, fx.typ_().Name_("rect").Key_("gfml.rect").Subs_
( fx.fld_().Name_("pos").TypeKey_("gfml.point")
, fx.fld_().Name_("size").TypeKey_("gfml.rect/size")
));
}
@Test public void Typ_key() {
fx.tst_Compile
( fx.nde_().Atrs_("point", "gfml.point") // explicit: gfml.point
, fx.typ_().Name_("point").Key_("gfml.point")
);
fx.tst_Compile
( fx.nde_().Atrs_("point") // implicit: point
, fx.typ_().Name_("point").Key_("point")
);
}
}

View File

@@ -1,64 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z403_types_compile_default_tst {
@Before public void setup() {
fx.run_InitPragma(fx.Regy(), GfmlPragmaType.new_());
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void Basic() {
fx.tst_Compile
( fx.nde_().Atrs_("point", "gfml.point").Subs_
( fx.nde_().Atru_("x").Atrk_("default", "10")
, fx.nde_().Atru_("y")
)
, fx.typ_().Name_("point").Key_("gfml.point").Subs_
( fx.fld_().Name_("x").Default_("10")
, fx.fld_().Name_("y").Default_(GfmlTkn_.NullRaw)
));
}
@Test public void Nde() {
fx.tst_Compile
( fx.nde_().Atrs_("rect", "gfml.rect").Subs_
( fx.nde_().Atru_("point").Subs_
( fx.nde_().Key_("default").Atrk_("x", "1").Atrk_("y", "2") // NOTE: naming b/c unnamed attribs are not returned in SubKeys
))
, fx.typ_().Name_("rect").Key_("gfml.rect").Subs_
( fx.fld_().Name_("point").DefaultTkn_
( ndek_("point", atr_("x", "1"), atr_("y", "2")))
));
}
@Test public void Nde_unnamed() {
fx.tst_Compile
( fx.nde_().Atrs_("rect", "gfml.rect").Subs_
( fx.nde_().Atru_("point").Subs_
( fx.nde_().Key_("").Atru_("1").Atru_("2")
))
, fx.typ_().Name_("rect").Key_("gfml.rect").Subs_
( fx.fld_().Name_("point").DefaultTkn_
( ndek_("point", atr_("", "1"), atr_("", "2")))
));
}
static GfmlAtr atr_(String key, String val) {return GfmlAtr.string_(GfmlTkn_.raw_(key), GfmlTkn_.raw_(val));}
static GfmlNde ndek_(String key, GfmlItm... subs) {
GfmlNde rv = GfmlNde.new_(GfmlTkn_.raw_(key), GfmlType_.Null, true);
for (GfmlItm sub : subs)
rv.SubObjs_Add(sub);
return rv;
}
}

View File

@@ -1,66 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z411_types_apply_atrs_basic_tst {
@Before public void setup() {
pointType = fx.typ_().Key_("point").Atrs_("x", "y", "z");
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); GfmlTyp_mok pointType;
@Test public void Unnamed_one() {
fx.tst_Resolve
( pointType
, fx.nde_().Hnd_("point").Atru_("10")
, fx.nde_().Typ_("point").Atrk_("x", "10")
);
}
@Test public void Unnamed_three() {
fx.tst_Resolve
( pointType
, fx.nde_().Hnd_("point").Atrs_("10", "20", "30")
, fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("y", "20").Atrk_("z", "30")
);
}
@Test public void Keys_partial1() {
fx.tst_Resolve
( pointType
, fx.nde_().Hnd_("point").Atrk_("x", "10").Atrs_("20", "30")
, fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("y", "20").Atrk_("z", "30")
);
}
@Test public void Keys_partial2() {
fx.tst_Resolve
( pointType
, fx.nde_().Hnd_("point").Atrk_("x", "10").Atrk_("y", "20").Atru_("30")
, fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("y", "20").Atrk_("z", "30")
);
}
@Test public void OutOfOrder_z_1() {
fx.tst_Resolve
( pointType
, fx.nde_().Hnd_("point").Atrk_("z", "30").Atrs_("10", "20")
, fx.nde_().Typ_("point").Atrk_("z", "30").Atrk_("x", "10").Atrk_("y", "20")
);
}
@Test public void OutOfOrder_z_2() {
fx.tst_Resolve
( pointType
, fx.nde_().Hnd_("point").Atru_("10").Atrk_("z", "30").Atru_("20")
, fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("z", "30").Atrk_("y", "20")
);
}
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z421_types_apply_ndes_basic_tst {
@Before public void setup() {
fx.Regy().Add(
fx.typ_().Key_("pos").Subs_
( GfmlFld_mok.new_().ini_atr_("x")
, GfmlFld_mok.new_().ini_atr_("y")
).XtoGfmlType());
fx.Regy().Add(
fx.typ_().Key_("rect").Subs_
( GfmlFld_mok.new_().ini_ndk_("pos", "pos")
).XtoGfmlType());
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void NamedNde_but_UnnamedAtr() {
fx.tst_Resolve
( fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Key_("pos").Atrs_("1")
)
, fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Typ_("pos").Atrk_("x", "1")
)
);
}
@Test public void UnnamedNde() {
fx.tst_Resolve
( fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("1")
)
, fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Typ_("pos").Atrk_("x", "1")
)
);
}
}

View File

@@ -1,74 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z422_types_apply_ndes_multi_tst {
@Before public void setup() {
fx.Regy().Add
( fx.typ_().Key_("pos").Subs_
( GfmlFld_mok.new_().ini_atr_("x")
, GfmlFld_mok.new_().ini_atr_("y")
).XtoGfmlType());
fx.Regy().Add
( fx.typ_().Key_("size").Subs_
( GfmlFld_mok.new_().ini_atr_("w")
, GfmlFld_mok.new_().ini_atr_("h")
).XtoGfmlType());
fx.Regy().Add
( fx.typ_().Key_("rect").Subs_
( GfmlFld_mok.new_().ini_ndk_("pos", "pos")
, GfmlFld_mok.new_().ini_ndk_("size", "size")
).XtoGfmlType());
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void Unnamed() {
fx.tst_Resolve
( fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("1")
, fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("3")
)
, fx.nde_().Typ_("rect").Subs_
( fx.nde_().Typ_("pos").Atrk_("x", "1")
, fx.nde_().Typ_("size").Atrk_("w", "3")
)
);
}
@Test public void Partial() {
fx.tst_Resolve
( fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Key_("pos").Atrs_("1")
, fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("3")
)
, fx.nde_().Typ_("rect").Subs_
( fx.nde_().Typ_("pos").Atrk_("x", "1")
, fx.nde_().Typ_("size").Atrk_("w", "3")
)
);
}
@Test public void OutOfOrder() {
fx.tst_Resolve
( fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Key_("size").Atrs_("3")
, fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("1")
)
, fx.nde_().Typ_("rect").Subs_
( fx.nde_().Typ_("size").Atrk_("w", "3")
, fx.nde_().Typ_("pos").Atrk_("x", "1")
)
);
}
}

View File

@@ -1,49 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z423_types_apply_ndes_misc_tst {
@Before public void setup() {
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void Recurse() {
fx.Regy().Add(
fx.typ_().Key_("item").Subs_
( GfmlFld_mok.new_().ini_atr_("key")
, GfmlFld_mok.new_().ini_ndk_("item", "item")
).XtoGfmlType());
fx.tst_Resolve
( fx.nde_().Hnd_("item").Atru_("1").Subs_
( fx.nde_().Hnd_("item").Atru_("2"))
, fx.nde_().Hnd_("item").Atrk_("key", "1").Subs_
( fx.nde_().Hnd_("item").Atrk_("key", "2")
));
}
@Test public void OwnerTypePrecedesTopLevel() {
GfmlTypeMakr makr = GfmlTypeMakr.new_();
GfmlType topLevelSize = makr.MakeSubType("size", "width", "height");
GfmlType rect = makr.MakeSubTypeAsOwner("rect");
GfmlType rectSize = makr.MakeSubType("size", "w", "h");
fx.Regy().Add(topLevelSize).Add(rect).Add(rectSize);
fx.tst_Resolve
( fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Hnd_("size").Atru_("1").Atru_("2"))
, fx.nde_().Hnd_("rect").Subs_
( fx.nde_().Typ_("rect/size").Atrk_("w", "1").Atrk_("h", "2")
));
}
}

View File

@@ -1,67 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z424_types_apply_ndes_nest_tst {
@Before public void setup() {
GfmlTypeMakr makr = GfmlTypeMakr.new_();
makr.MakeRootType("gfml.item", "item");
makr.MakeSubType("pos", "x", "y");
fx.Regy().Add_ary(makr.Xto_bry());
} GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void InvokeByHnd() {
fx.tst_Resolve
( fx.nde_().Hnd_("gfml.item").Subs_
( fx.nde_().Hnd_("pos").Atrs_("10", "20"))
, fx.nde_().Typ_("gfml.item").Subs_
( fx.nde_().Typ_("gfml.item/pos").Atrk_("x", "10").Atrk_("y", "20")
));
}
@Test public void InvokeByTyp() {
fx.tst_Resolve
( fx.nde_().Hnd_("gfml.item").Subs_
( fx.nde_().Hnd_("gfml.item/pos").Atrs_("10", "20"))
, fx.nde_().Typ_("gfml.item").Subs_
( fx.nde_().Typ_("gfml.item/pos").Atrk_("x", "10").Atrk_("y", "20")
));
}
@Test public void NoInvokeByName() {
fx.tst_Resolve
( fx.nde_().Hnd_("gfml.item").Subs_
( fx.nde_().Hnd_("gfml.item").Atrs_("10", "20")) // item is not in .SubFlds, but is in regy
, fx.nde_().Typ_("gfml.item").Subs_
( fx.nde_().Typ_("gfml.item").Atrs_("10", "20")
));
}
@Test public void Name_subLevel() {
GfmlTypeMakr makr = GfmlTypeMakr.new_();
makr.MakeRootType("font", "size");
makr.MakeSubType("color", "name");
fx.Regy().Add_ary(makr.Xto_bry());
fx.tst_Resolve
( fx.nde_().Hnd_("color").Atru_("blue")
, fx.nde_().Typ_(GfmlType_.AnyKey).Atru_("blue")// confirm that subFlds in other types are not selectable by name; i.e.: must be font/color, not just color
);
}
@Test public void Unresolved() {
fx.tst_Resolve
( fx.nde_().Hnd_("").Atrs_("10", "20")
, fx.nde_().Typ_(GfmlType_.AnyKey).Atrs_("10", "20")
);
}
}

View File

@@ -1,53 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfml; import gplx.*;
import org.junit.*;
public class z441_types_parse_basic_tst {
GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_();
@Test public void Null() {
fx.tst_Parse(String_.Concat
( "point:1;"
)
, fx.nde_().Hnd_("point").Typ_(GfmlType_.AnyKey).Atru_("1")
);
}
@Test public void Basic() {
fx.tst_Parse(String_.Concat
( "_type:{"
, "point {"
, "x;"
, "}"
, "}"
, "point:1;"
)
, fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1")
);
}
@Test public void MultipleAtrs() {
fx.tst_Parse(String_.Concat
( "_type:{"
, "point {"
, "x; y;"
, "}"
, "}"
, "point:1 2;"
)
, fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1").Atrk_("y", "2")
);
}
}

Some files were not shown because too many files have changed in this diff Show More