mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
100
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataNde.java
Normal file
100
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataNde.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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;
|
||||
}
|
||||
46
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataRdr.java
Normal file
46
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataRdr.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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);}
|
||||
}
|
||||
58
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataRdr_base.java
Normal file
58
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataRdr_base.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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;
|
||||
}
|
||||
97
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataWtr.java
Normal file
97
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataWtr.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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();}
|
||||
}
|
||||
25
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataWtrOpts.java
Normal file
25
110_gfml/src_600_rdrWtr/gplx/gfml/GfmlDataWtrOpts.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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);}}
|
||||
}
|
||||
21
110_gfml/src_600_rdrWtr/gplx/gfml/GfoMsgParser_gfml.java
Normal file
21
110_gfml/src_600_rdrWtr/gplx/gfml/GfoMsgParser_gfml.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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() {}
|
||||
}
|
||||
40
110_gfml/src_600_rdrWtr/gplx/gfml/SqlConsts.java
Normal file
40
110_gfml/src_600_rdrWtr/gplx/gfml/SqlConsts.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 = ")"
|
||||
;
|
||||
}
|
||||
142
110_gfml/src_600_rdrWtr/gplx/gfml/SqlDoc.java
Normal file
142
110_gfml/src_600_rdrWtr/gplx/gfml/SqlDoc.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user