1
0
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:
gnosygnu
2017-10-23 20:50:50 -04:00
parent 1336d44f34
commit 66877212bf
4537 changed files with 311750 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/*
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.*;/*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

@@ -0,0 +1,131 @@
/*
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.*;
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

@@ -0,0 +1,62 @@
/*
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.*;
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_.Name_by_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

@@ -0,0 +1,54 @@
/*
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.*;
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

@@ -0,0 +1,77 @@
/*
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.*;
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

@@ -0,0 +1,76 @@
/*
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.*;
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

@@ -0,0 +1,60 @@
/*
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.*;
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

@@ -0,0 +1,30 @@
/*
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.*;
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

@@ -0,0 +1,37 @@
/*
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.*;
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);
}
}