mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
XomwTemplateParser: Initial port of PPFrame_Hash [#632]
This commit is contained in:
parent
3285a3c87d
commit
694c3bb133
@ -59,6 +59,7 @@ public class XophpArray implements Bry_bfr_able {
|
||||
}
|
||||
public XophpArray Get_at_ary(int i) {return (XophpArray)Get_at(i);}
|
||||
public String Get_at_str(int i) {return (String)Get_at(i);}
|
||||
public int Get_at_int(int i) {return Int_.Cast(Get_at(i));}
|
||||
public Object Get_at(int i) {
|
||||
if (i < 0 || i >= hash.Len()) return null;
|
||||
XophpArrayItm itm = (XophpArrayItm)hash.Get_at(i);
|
||||
@ -78,6 +79,8 @@ public class XophpArray implements Bry_bfr_able {
|
||||
}
|
||||
public Object Get_by_obj(Object key) {return Get_by(Object_.Xto_str_strict_or_null(key));}
|
||||
public Object Get_by(int key) {return Get_by(Int_.To_str(key));}
|
||||
public int Get_by_int(String key) {return Int_.Cast(this.Get_by(key));}
|
||||
public Object Get_by_str(String key) {return (String)this.Get_by(key);}
|
||||
public Object Get_by(String key) {
|
||||
XophpArrayItm itm = (XophpArrayItm)hash.Get_by(key);
|
||||
return itm.Val();
|
||||
@ -93,6 +96,7 @@ public class XophpArray implements Bry_bfr_able {
|
||||
public boolean Has(String key) {
|
||||
return hash.Has(key);
|
||||
}
|
||||
public boolean is_set(String key) {return hash.Has(key);}
|
||||
public XophpArrayItm[] To_ary() {
|
||||
return (XophpArrayItm[])hash.To_ary(XophpArrayItm.class);
|
||||
}
|
||||
@ -117,10 +121,25 @@ public class XophpArray implements Bry_bfr_able {
|
||||
cur.Val_(itm.Val());
|
||||
}
|
||||
}
|
||||
public Object Pop() {
|
||||
int pos = this.Count() - 1;
|
||||
XophpArrayItm itm = (XophpArrayItm)hash.Get_at(pos);
|
||||
this.Del_at(pos);
|
||||
return itm.Val();
|
||||
}
|
||||
public void Itm_str_concat_end(int idx, String v) {
|
||||
String itm = (String)this.Get_at(idx);
|
||||
itm += v;
|
||||
this.Set(idx, itm);
|
||||
}
|
||||
public static XophpArray New(Object... vals) {
|
||||
XophpArray rv = new XophpArray();
|
||||
for (Object val : vals)
|
||||
rv.Add(val);
|
||||
return rv;
|
||||
}
|
||||
public static boolean is_array(Object val) {
|
||||
return Type_.Eq_by_obj(val, XophpArray.class);
|
||||
}
|
||||
public static final XophpArray False = null; // handles code like "if ($var === false)" where var is an Object;
|
||||
}
|
||||
|
@ -120,8 +120,30 @@ public class XophpArray_tst { // REF: http://php.net/manual/en/language.types.ar
|
||||
ary.Add("c");
|
||||
fxt.Test__array(ary, XophpArrayItm.New_int(2, "c"));
|
||||
}
|
||||
@Test public void Pop() {
|
||||
XophpArray ary = XophpArray.New();
|
||||
ary.Add(0, "a").Add(1, "b").Add(2, "c");
|
||||
|
||||
// pop all
|
||||
fxt.Test__Pop(ary, "c");
|
||||
fxt.Test__Pop(ary, "b");
|
||||
fxt.Test__Pop(ary, "a");
|
||||
fxt.Test__Count(ary, 0);
|
||||
}
|
||||
@Test public void Itm_str_concat_end() {
|
||||
XophpArray ary = XophpArray.New();
|
||||
ary.Add(0, "a").Add(1, "b").Add(2, "c");
|
||||
|
||||
// pop all
|
||||
fxt.Test__Itm_str_concat_end(ary, "a0", 0, "0");
|
||||
fxt.Test__Itm_str_concat_end(ary, "b1", 1, "1");
|
||||
fxt.Test__Itm_str_concat_end(ary, "c2", 2, "2");
|
||||
}
|
||||
}
|
||||
class XophpArray_fxt {
|
||||
public void Test__Count(XophpArray ary, int expd) {
|
||||
Gftest.Eq__int(expd, ary.Count());
|
||||
}
|
||||
public void Test__array(XophpArray ary, XophpArrayItm... expd) {
|
||||
XophpArrayItm[] actl = ary.To_ary();
|
||||
Gftest.Eq__ary(expd, actl);
|
||||
@ -130,4 +152,13 @@ class XophpArray_fxt {
|
||||
XophpArrayItm[] actl = ary.To_ary();
|
||||
Gftest.Eq__ary(expd, actl);
|
||||
}
|
||||
public void Test__Pop(XophpArray ary, String expd) {
|
||||
String actl = (String)ary.Pop();
|
||||
Gftest.Eq__str(expd, actl);
|
||||
}
|
||||
public void Test__Itm_str_concat_end(XophpArray ary, String expd, int idx, String v) {
|
||||
ary.Itm_str_concat_end(idx, v);
|
||||
String actl = ary.Get_at_str(idx);
|
||||
Gftest.Eq__str(expd, actl);
|
||||
}
|
||||
}
|
||||
|
19
400_xowa/src/gplx/xowa/mediawiki/XophpBry_.java
Normal file
19
400_xowa/src/gplx/xowa/mediawiki/XophpBry_.java
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
public class XophpBry_ {
|
||||
public static final byte[] False = null; // handles code like "if ($var === false)" where var is an Object;
|
||||
}
|
20
400_xowa/src/gplx/xowa/mediawiki/XophpObject.java
Normal file
20
400_xowa/src/gplx/xowa/mediawiki/XophpObject.java
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
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.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
public class XophpObject {
|
||||
public static final Object False = null; // handles code like "if ($var === false)" where var is an Object;
|
||||
public static boolean is_true(Object val) {return val != null;}
|
||||
}
|
@ -20,6 +20,8 @@ public class XophpString {
|
||||
public static int strpos(byte[] src, byte find, int bgn, int end) {
|
||||
return Bry_find_.Find_fwd(src, find, bgn, end);
|
||||
}
|
||||
public static String substr(String src, int bgn, int len) {return String_.new_u8(substr(Bry_.new_u8(src), bgn, len));}
|
||||
public static String substr(String src, int bgn) {return String_.new_u8(substr(Bry_.new_u8(src), bgn, String_.Len(src)));}
|
||||
public static byte[] substr(byte[] src, int bgn) {return substr(src, bgn, src.length);}
|
||||
public static byte[] substr(byte[] src, int bgn, int len) {
|
||||
int src_len = src.length;
|
||||
@ -169,4 +171,7 @@ public class XophpString {
|
||||
}
|
||||
return String_.new_charAry_(chry, 0, chry_len);
|
||||
}
|
||||
public static boolean is_string(Object o) {
|
||||
return String_.as_(o) != null;
|
||||
}
|
||||
}
|
||||
|
19
400_xowa/src/gplx/xowa/mediawiki/XophpString_.java
Normal file
19
400_xowa/src/gplx/xowa/mediawiki/XophpString_.java
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
public class XophpString_ {
|
||||
public static final String False = null; // handles code like "if ($var === false)" where var is an Object;
|
||||
}
|
@ -1438,6 +1438,7 @@ public class XomwTitle {
|
||||
s = XophpString.strtr(s, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
return s;
|
||||
}
|
||||
public String getPrefixedDBkeyStr() {return String_.new_u8(getPrefixedDBkey());}
|
||||
|
||||
/**
|
||||
* Get the prefixed title with spaces.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -99,10 +99,10 @@ public class XomwParserOptions {
|
||||
// */
|
||||
// private $mExpensiveParserFunctionLimit;
|
||||
//
|
||||
// /**
|
||||
// * Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
|
||||
// */
|
||||
// private $mRemoveComments = true;
|
||||
/**
|
||||
* Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
|
||||
*/
|
||||
private boolean mRemoveComments = true;
|
||||
//
|
||||
// /**
|
||||
// * @var callable Callback for current revision fetching; first argument to call_user_func().
|
||||
@ -297,9 +297,9 @@ public class XomwParserOptions {
|
||||
// return this.mExpensiveParserFunctionLimit;
|
||||
// }
|
||||
//
|
||||
// public function getRemoveComments() {
|
||||
// return this.mRemoveComments;
|
||||
// }
|
||||
public boolean getRemoveComments() {
|
||||
return this.mRemoveComments;
|
||||
}
|
||||
//
|
||||
// /* @since 1.24 */
|
||||
// public function getCurrentRevisionCallback() {
|
||||
|
@ -20,6 +20,7 @@ import gplx.xowa.mediawiki.includes.parsers.preprocessors.*;
|
||||
* @ingroup Parser
|
||||
*/
|
||||
public abstract class XomwPreprocessor {
|
||||
public abstract XomwParser Parser(); // XOWA: not in MW, but both Preprocessor_DOM and Preprocessor_Hash have the member variable
|
||||
|
||||
// private static final int CACHE_VERSION = 1;
|
||||
|
||||
|
@ -19,6 +19,8 @@ import gplx.xowa.mediawiki.includes.parsers.preprocessors.*;
|
||||
// THREAD.UNSAFE: caching for repeated calls
|
||||
class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private Xomw_prepro_accum__dom accum_dom = new Xomw_prepro_accum__dom("");
|
||||
public XomwPreprocessor_DOM(XomwParser parser) {this.parser = parser;}
|
||||
@Override public XomwParser Parser() {return parser;} private final XomwParser parser;
|
||||
|
||||
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_DOM("");}
|
||||
@Override protected XomwPPDStack Factory__stack() {return new XomwPPDStack(Xomw_prepro_accum__dom.Instance);}
|
||||
@ -152,6 +154,6 @@ class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr
|
||||
return root_accum.To_bry_and_clear();
|
||||
}
|
||||
|
||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_DOM();}
|
||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_DOM();
|
||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_DOM(parser);}
|
||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_DOM(null);
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.xowa.mediawiki.includes.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.xowa.mediawiki.includes.parsers.preprocessors.*;
|
||||
class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum;
|
||||
public XomwPreprocessor_Hash(XomwParser parser) {this.parser = parser;}
|
||||
@Override public XomwParser Parser() {return parser;} private final XomwParser parser;
|
||||
|
||||
@Override public XomwPPFrame newFrame() {
|
||||
return null;
|
||||
@ -192,6 +194,6 @@ class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum
|
||||
}
|
||||
}
|
||||
|
||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_Hash();}
|
||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_Hash();
|
||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_Hash(parser);}
|
||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_Hash(null);
|
||||
}
|
||||
|
@ -235,12 +235,12 @@ class XomwPreprocessor__fxt {
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
List_adp list = List_adp_.New();
|
||||
if (hash_enabled) {
|
||||
XomwPreprocessor_Hash wkr_hash = new XomwPreprocessor_Hash();
|
||||
XomwPreprocessor_Hash wkr_hash = new XomwPreprocessor_Hash(null);
|
||||
wkr_hash.Init_by_wiki("pre");
|
||||
list.Add(wkr_hash);
|
||||
}
|
||||
if (dom_enabled) {
|
||||
XomwPreprocessor_DOM wkr_dom = new XomwPreprocessor_DOM();
|
||||
XomwPreprocessor_DOM wkr_dom = new XomwPreprocessor_DOM(null);
|
||||
wkr_dom.Init_by_wiki("pre");
|
||||
list.Add(wkr_dom);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; impor
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*/
|
||||
// XOWA: TODO: change VIRTUAL back to ABSTRACT; WHEN: after adding _DOM classes
|
||||
public abstract class XomwPPFrame {
|
||||
public static final int NO_ARGS = 1;
|
||||
public static final int NO_TEMPLATES = 2;
|
||||
@ -40,7 +41,7 @@ public abstract class XomwPPFrame {
|
||||
*
|
||||
* @return PPFrame
|
||||
*/
|
||||
public abstract XomwPPFrame newChild(Object args, XomwTitle title, int indexOffset);
|
||||
@gplx.Virtual public XomwPPFrame newChild(XophpArray args, XomwTitle title, int indexOffset) {return null;}
|
||||
|
||||
/**
|
||||
* Expand a document tree node, caching the result on its parent with the given key
|
||||
@ -49,7 +50,7 @@ public abstract class XomwPPFrame {
|
||||
* @param int $flags
|
||||
* @return String
|
||||
*/
|
||||
public abstract String cachedExpand(String key, XomwPPNode root, int flags);
|
||||
@gplx.Virtual public String cachedExpand(String key, XomwPPNode root, int flags) {return null;}
|
||||
|
||||
/**
|
||||
* Expand a document tree node
|
||||
@ -57,7 +58,7 @@ public abstract class XomwPPFrame {
|
||||
* @param int $flags
|
||||
* @return String
|
||||
*/
|
||||
public abstract String expand(XomwPPNode root, int flags);
|
||||
@gplx.Virtual public String expand(XomwPPNode root, int flags) {return null;}
|
||||
|
||||
/**
|
||||
* Implode with flags for expand()
|
||||
@ -66,7 +67,7 @@ public abstract class XomwPPFrame {
|
||||
* @param String|PPNode $args,...
|
||||
* @return String
|
||||
*/
|
||||
public abstract String implodeWithFlags(String sep, int flags, Object... args);
|
||||
@gplx.Virtual public String implodeWithFlags(String sep, int flags, Object... args) {return null;}
|
||||
|
||||
/**
|
||||
* Implode with no flags specified
|
||||
@ -74,7 +75,7 @@ public abstract class XomwPPFrame {
|
||||
* @param String|PPNode $args,...
|
||||
* @return String
|
||||
*/
|
||||
public abstract String implode(String sep, Object... args);
|
||||
@gplx.Virtual public String implode(String sep, Object... args) {return null;}
|
||||
|
||||
/**
|
||||
* Makes an Object that, when expand()ed, will be the same as one obtained
|
||||
@ -83,7 +84,7 @@ public abstract class XomwPPFrame {
|
||||
* @param String|PPNode $args,...
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode virtualImplode(String sep, Object... args);
|
||||
@gplx.Virtual public XomwPPNode virtualImplode(String sep, Object... args) {return null;}
|
||||
|
||||
/**
|
||||
* Virtual implode with brackets
|
||||
@ -93,39 +94,39 @@ public abstract class XomwPPFrame {
|
||||
* @param String|PPNode $args,...
|
||||
* @return PPNode
|
||||
*/
|
||||
public abstract XomwPPNode virtualBracketedImplode(String start, String sep, String end, Object... args);
|
||||
@gplx.Virtual public XomwPPNode virtualBracketedImplode(String start, String sep, String end, Object... args) {return null;}
|
||||
|
||||
/**
|
||||
* Returns true if there are no arguments in this frame
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isEmpty();
|
||||
@gplx.Virtual public boolean isEmpty() {return false;}
|
||||
|
||||
/**
|
||||
* Returns all arguments of this frame
|
||||
* @return array
|
||||
*/
|
||||
public abstract Object[] getArguments();
|
||||
@gplx.Virtual public XophpArray getArguments() {return null;}
|
||||
|
||||
/**
|
||||
* Returns all numbered arguments of this frame
|
||||
* @return array
|
||||
*/
|
||||
public abstract Object[] getNumberedArguments();
|
||||
@gplx.Virtual public XophpArray getNumberedArguments() {return null;}
|
||||
|
||||
/**
|
||||
* Returns all named arguments of this frame
|
||||
* @return array
|
||||
*/
|
||||
public abstract Object[] getNamedArguments();
|
||||
@gplx.Virtual public XophpArray getNamedArguments() {return null;}
|
||||
|
||||
/**
|
||||
* Get an argument to this frame by name
|
||||
* @param int|String $name
|
||||
* @return String|boolean
|
||||
*/
|
||||
public abstract String getArgument(String name);
|
||||
@gplx.Virtual public String getArgument(String name) {return null;}
|
||||
|
||||
/**
|
||||
* Returns true if the infinite loop check is OK, false if a loop is detected
|
||||
@ -133,13 +134,13 @@ public abstract class XomwPPFrame {
|
||||
* @param Title $title
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean loopCheck(XomwTitle title);
|
||||
@gplx.Virtual public boolean loopCheck(XomwTitle title) {return false;}
|
||||
|
||||
/**
|
||||
* Return true if the frame is a template frame
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isTemplate();
|
||||
@gplx.Virtual public boolean isTemplate() {return false;}
|
||||
|
||||
/**
|
||||
* Set the "volatile" flag.
|
||||
@ -152,7 +153,7 @@ public abstract class XomwPPFrame {
|
||||
*
|
||||
* @param boolean $flag
|
||||
*/
|
||||
public abstract void setVolatile(boolean flag);
|
||||
@gplx.Virtual public void setVolatile(boolean flag) {}
|
||||
|
||||
/**
|
||||
* Get the "volatile" flag.
|
||||
@ -163,7 +164,7 @@ public abstract class XomwPPFrame {
|
||||
* @see self::setVolatile()
|
||||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isVolatile();
|
||||
@gplx.Virtual public boolean isVolatile() {return false;}
|
||||
|
||||
/**
|
||||
* Get the TTL of the frame's output.
|
||||
@ -177,7 +178,7 @@ public abstract class XomwPPFrame {
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public abstract int getTTL();
|
||||
@gplx.Virtual public int getTTL() {return 0;}
|
||||
|
||||
/**
|
||||
* Set the TTL of the output of this frame and all of its ancestors.
|
||||
@ -188,12 +189,12 @@ public abstract class XomwPPFrame {
|
||||
* @see self::getTTL()
|
||||
* @param int $ttl
|
||||
*/
|
||||
public abstract void setTTL(int ttl);
|
||||
@gplx.Virtual public void setTTL(int ttl) {}
|
||||
|
||||
/**
|
||||
* Get a title of frame
|
||||
*
|
||||
* @return Title
|
||||
*/
|
||||
public abstract XomwTitle getTitle();
|
||||
@gplx.Virtual public XomwTitle getTitle() {return null;}
|
||||
}
|
||||
|
@ -0,0 +1,626 @@
|
||||
/*
|
||||
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.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
import gplx.xowa.mediawiki.includes.exception.*;
|
||||
import gplx.core.bits.*;
|
||||
/**
|
||||
* An expansion frame, used as a context to expand the result of preprocessToObj()
|
||||
* @ingroup Parser
|
||||
*/
|
||||
class XomwPPFrame_Hash extends XomwPPFrame { /**
|
||||
* @var Parser
|
||||
*/
|
||||
public XomwParser parser;
|
||||
|
||||
/**
|
||||
* @var Preprocessor
|
||||
*/
|
||||
public XomwPreprocessor preprocessor;
|
||||
|
||||
/**
|
||||
* @var Title
|
||||
*/
|
||||
public XomwTitle title;
|
||||
public XophpArray titleCache;
|
||||
|
||||
/**
|
||||
* Hashtable listing templates which are disallowed for expansion in this frame,
|
||||
* having been encountered previously in parent frames.
|
||||
*/
|
||||
public XophpArray loopCheckHash;
|
||||
|
||||
/**
|
||||
* Recursion depth of this frame, top = 0
|
||||
* Note that this is NOT the same as expansion depth in expand()
|
||||
*/
|
||||
public int depth;
|
||||
|
||||
private boolean volatile_bool;
|
||||
private int ttl;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected XophpArray childExpansionCache;
|
||||
|
||||
/**
|
||||
* Construct a new preprocessor frame.
|
||||
* @param Preprocessor preprocessor The parent preprocessor
|
||||
*/
|
||||
public XomwPPFrame_Hash(XomwPreprocessor preprocessor) {
|
||||
this.preprocessor = preprocessor;
|
||||
this.parser = preprocessor.Parser();
|
||||
this.title = this.parser.mTitle;
|
||||
this.titleCache = XophpArray.New().Add(XophpObject.is_true(this.title) ? this.title.getPrefixedDBkeyStr() : XophpString_.False);
|
||||
this.loopCheckHash = XophpArray.New();
|
||||
this.depth = 0;
|
||||
this.childExpansionCache = XophpArray.New();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Create a new child frame
|
||||
// * $args is optionally a multi-root PPNode or array containing the template arguments
|
||||
// *
|
||||
// * @param array|boolean|PPNode_Hash_Array $args
|
||||
// * @param Title|boolean $title
|
||||
// * @param int $indexOffset
|
||||
// * @throws MWException
|
||||
// * @return PPTemplateFrame_Hash
|
||||
// */
|
||||
// public function newChild($args = false, $title = false, $indexOffset = 0) {
|
||||
// $namedArgs = [];
|
||||
// $numberedArgs = [];
|
||||
// if ($title === false) {
|
||||
// $title = this.title;
|
||||
// }
|
||||
// if ($args !== false) {
|
||||
// if ($args instanceof PPNode_Hash_Array) {
|
||||
// $args = $args.value;
|
||||
// } else if (!is_array($args)) {
|
||||
// throw new MWException(__METHOD__ . ': $args must be array or PPNode_Hash_Array');
|
||||
// }
|
||||
// foreach ($args as $arg) {
|
||||
// $bits = $arg.splitArg();
|
||||
// if ($bits['index'] !== '') {
|
||||
// // Numbered parameter
|
||||
// $index = $bits['index'] - $indexOffset;
|
||||
// if (isset($namedArgs[$index]) || isset($numberedArgs[$index])) {
|
||||
// this.parser.getOutput().addWarning(wfMessage('duplicate-args-warning',
|
||||
// wfEscapeWikiText(this.title),
|
||||
// wfEscapeWikiText($title),
|
||||
// wfEscapeWikiText($index)).text());
|
||||
// this.parser.addTrackingCategory('duplicate-args-category');
|
||||
// }
|
||||
// $numberedArgs[$index] = $bits['value'];
|
||||
// unset($namedArgs[$index]);
|
||||
// } else {
|
||||
// // Named parameter
|
||||
// $name = trim(this.expand($bits['name'], PPFrame.STRIP_COMMENTS));
|
||||
// if (isset($namedArgs[$name]) || isset($numberedArgs[$name])) {
|
||||
// this.parser.getOutput().addWarning(wfMessage('duplicate-args-warning',
|
||||
// wfEscapeWikiText(this.title),
|
||||
// wfEscapeWikiText($title),
|
||||
// wfEscapeWikiText($name)).text());
|
||||
// this.parser.addTrackingCategory('duplicate-args-category');
|
||||
// }
|
||||
// $namedArgs[$name] = $bits['value'];
|
||||
// unset($numberedArgs[$name]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return new PPTemplateFrame_Hash(this.preprocessor, $this, $numberedArgs, $namedArgs, $title);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @throws MWException
|
||||
* @param String|int $key
|
||||
* @param String|PPNode $root
|
||||
* @param int $flags
|
||||
* @return String
|
||||
*/
|
||||
public String cachedExpand(String key, Object root, int flags) { // DEFAULT:flags=0
|
||||
// we don't have a parent, so we don't have a cache
|
||||
return this.expand(root, flags);
|
||||
}
|
||||
|
||||
private static int expansionDepth = 0; // MW.GLOBAL:expand
|
||||
private static int expand_flags_default = 0;
|
||||
/**
|
||||
* @throws MWException
|
||||
* @param String|PPNode $root
|
||||
* @param int $flags
|
||||
* @return String
|
||||
*/
|
||||
public String expand(Object root, int flags) {
|
||||
if (XophpString.is_string(root)) {
|
||||
return (String)root;
|
||||
}
|
||||
|
||||
// if (++this.parser.mPPNodeCount > this.parser.mOptions.getMaxPPNodeCount()) {
|
||||
// this.parser.limitationWarn('node-count-exceeded',
|
||||
// this.parser.mPPNodeCount,
|
||||
// this.parser.mOptions.getMaxPPNodeCount()
|
||||
// );
|
||||
// return '<span class="error">Node-count limit exceeded</span>';
|
||||
// }
|
||||
// if (expansionDepth > this.parser.mOptions.getMaxPPExpandDepth()) {
|
||||
// this.parser.limitationWarn('expansion-depth-exceeded',
|
||||
// expansionDepth,
|
||||
// this.parser.mOptions.getMaxPPExpandDepth()
|
||||
// );
|
||||
// return '<span class="error">Expansion depth limit exceeded</span>';
|
||||
// }
|
||||
++expansionDepth;
|
||||
if (expansionDepth > this.parser.mHighestExpansionDepth) {
|
||||
this.parser.mHighestExpansionDepth = expansionDepth;
|
||||
}
|
||||
|
||||
XophpArray outStack = XophpArray.New("", "");
|
||||
XophpArray iteratorStack = XophpArray.New(XophpObject.False, root);
|
||||
XophpArray indexStack = XophpArray.New(0, 0);
|
||||
|
||||
while (iteratorStack.Count() > 1) {
|
||||
int level = outStack.Count() - 1;
|
||||
Object iteratorNode = iteratorStack.Get_at(level);
|
||||
String outItm = outStack.Get_at_str(level);
|
||||
int index = indexStack.Get_at_int(level);
|
||||
Object contextNode;
|
||||
if (XophpArray.is_array(iteratorNode)) {
|
||||
XophpArray iteratorNodeArray = (XophpArray)iteratorNode;
|
||||
if (index >= iteratorNodeArray.Count()) {
|
||||
// All done with this iterator
|
||||
iteratorStack.Set(level, XophpObject.False);
|
||||
contextNode = XophpObject.False;
|
||||
} else {
|
||||
contextNode = iteratorNodeArray.Get_at(index);
|
||||
index++;
|
||||
}
|
||||
} else if (Type_.Eq_by_obj(iteratorNode, XomwPPNode_Hash_Array.class)) {
|
||||
XomwPPNode_Hash_Array iteratorNodeHashArray = (XomwPPNode_Hash_Array)iteratorNode;
|
||||
if (index >= iteratorNodeHashArray.getLength()) {
|
||||
// All done with this iterator
|
||||
iteratorStack.Set(level, XophpObject.False);
|
||||
contextNode = XophpObject.False;
|
||||
} else {
|
||||
contextNode = iteratorNodeHashArray.item(index);
|
||||
index++;
|
||||
}
|
||||
} else {
|
||||
// Copy to contextNode and then delete from iterator stack,
|
||||
// because this is not an iterator but we do have to execute it once
|
||||
contextNode = iteratorStack.Get_at(level);
|
||||
iteratorStack.Set(level, XophpObject.False);
|
||||
}
|
||||
|
||||
Object newIterator = XophpObject.False;
|
||||
String contextName = XophpString_.False;
|
||||
XophpArray contextChildren = XophpArray.False;
|
||||
|
||||
if (contextNode == XophpObject.False) {
|
||||
// nothing to do
|
||||
} else if (XophpString.is_string(contextNode)) {
|
||||
outItm += (String)contextNode;
|
||||
} else if (Type_.Eq_by_obj(contextNode, XomwPPNode_Hash_Array.class)) {
|
||||
newIterator = contextNode;
|
||||
} else if (Type_.Eq_by_obj(contextNode, XomwPPNode_Hash_Attr.class)) {
|
||||
// No output
|
||||
} else if (Type_.Eq_by_obj(contextNode, XomwPPNode_Hash_Text.class)) {
|
||||
outItm += ((XomwPPNode_Hash_Text)contextNode).value;
|
||||
} else if (Type_.Eq_by_obj(contextNode, XomwPPNode_Hash_Tree.class)) {
|
||||
XomwPPNode_Hash_Tree contextNodeHashTree = (XomwPPNode_Hash_Tree)contextNode;
|
||||
contextName = contextNodeHashTree.name;
|
||||
contextChildren = contextNodeHashTree.getRawChildren();
|
||||
} else if (XophpArray.is_array(contextNode)) {
|
||||
XophpArray contextNodeArray = (XophpArray)contextNode;
|
||||
// Node descriptor array
|
||||
if (contextNodeArray.Count() != 2) {
|
||||
throw XomwMWException.New_by_method(XomwPPFrame_Hash.class, "expand",
|
||||
": found an array where a node descriptor should be");
|
||||
}
|
||||
contextName = (String)contextNodeArray.Get_at(0);
|
||||
contextChildren = contextNodeArray.Get_at_ary(1);
|
||||
} else {
|
||||
throw XomwMWException.New_by_method(XomwPPFrame_Hash.class, "expand", ": Invalid parameter type");
|
||||
}
|
||||
|
||||
// Handle node descriptor array or tree Object
|
||||
if (contextName == XophpString_.False) {
|
||||
// Not a node, already handled above
|
||||
} else if (String_.CharAt(contextName, 0) == '@') {
|
||||
// Attribute: no output
|
||||
} else if (String_.Eq(contextName, "template")) {
|
||||
// Double-brace expansion
|
||||
XophpArray bits = XomwPPNode_Hash_Tree.splitRawTemplate(contextChildren);
|
||||
if (Bitmask_.Has_int(flags, XomwPPFrame.NO_TEMPLATES)) {
|
||||
newIterator = this.virtualBracketedImplode(
|
||||
"{{", "|", "}}",
|
||||
bits.Get_by("title"),
|
||||
bits.Get_by("parts")
|
||||
);
|
||||
} else {
|
||||
XophpArray ret = this.parser.braceSubstitution(bits, this);
|
||||
if (ret.is_set(Object_.Cls_val_name)) {// NOTE: using Cls_val_name b/c of transpilation and Object . Object
|
||||
newIterator = ret.Get_by(Object_.Cls_val_name);
|
||||
} else {
|
||||
outItm += ret.Get_by_str("text");
|
||||
}
|
||||
}
|
||||
} else if (String_.Eq(contextName, "tplarg")) {
|
||||
// Triple-brace expansion
|
||||
XophpArray bits = XomwPPNode_Hash_Tree.splitRawTemplate(contextChildren);
|
||||
if (Bitmask_.Has_int(flags, XomwPPFrame.NO_ARGS)) {
|
||||
newIterator = this.virtualBracketedImplode(
|
||||
"{{{", "|", "}}}",
|
||||
bits.Get_by("title"),
|
||||
bits.Get_by("parts")
|
||||
);
|
||||
} else {
|
||||
XophpArray ret = this.parser.argSubstitution(bits, this);
|
||||
if (ret.is_set(Object_.Cls_val_name)) {// NOTE: using Cls_val_name b/c of transpilation and Object . Object
|
||||
newIterator = ret.Get_by("Object");
|
||||
} else {
|
||||
outItm += ret.Get_by_str("text");
|
||||
}
|
||||
}
|
||||
} else if (String_.Eq(contextName, "comment")) {
|
||||
// HTML-style comment
|
||||
// Remove it in HTML, pre+remove and STRIP_COMMENTS modes
|
||||
// Not in RECOVER_COMMENTS mode (msgnw) though.
|
||||
if ((this.parser.ot.Has("html"))
|
||||
|| (this.parser.ot.Has("pre") && this.parser.mOptions.getRemoveComments())
|
||||
|| (Bitmask_.Has_int(flags, XomwPPFrame.STRIP_COMMENTS))
|
||||
&& !(Bitmask_.Has_int(flags, XomwPPFrame.RECOVER_COMMENTS))
|
||||
) {
|
||||
outItm += ""; // XOWA: no purpose?
|
||||
} else if (this.parser.ot.Has("wiki") && !(Bitmask_.Has_int(flags, XomwPPFrame.RECOVER_COMMENTS))) {
|
||||
// Add a strip marker in PST mode so that pstPass2() can
|
||||
// run some old-fashioned regexes on the result.
|
||||
// Not in RECOVER_COMMENTS mode (extractSections) though.
|
||||
outItm += this.parser.insertStripItem(contextChildren.Get_at_str(0));
|
||||
} else {
|
||||
// Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
|
||||
outItm += contextChildren.Get_at_str(0);
|
||||
}
|
||||
} else if (String_.Eq(contextName, "ignore")) {
|
||||
// Output suppression used by <includeonly> etc.
|
||||
// OT_WIKI will only respect <ignore> in substed templates.
|
||||
// The other output types respect it unless NO_IGNORE is set.
|
||||
// extractSections() sets NO_IGNORE and so never respects it.
|
||||
// if ((!XophpUtility.isset(this.parent) && this.parser.ot.Has("wiki")) // this.parent doesn't exist?
|
||||
if ((this.parser.ot.Has("wiki"))
|
||||
|| (Bitmask_.Has_int(flags, XomwPPFrame.NO_IGNORE))
|
||||
) {
|
||||
outItm += contextChildren.Get_at_str(0);
|
||||
} else {
|
||||
// outItm .= '';
|
||||
}
|
||||
} else if (String_.Eq(contextName, "ext")) {
|
||||
// Extension tag
|
||||
XophpArray bits = XomwPPNode_Hash_Tree.splitRawExt(contextChildren)
|
||||
.Add("attr", null).Add("inner", null).Add("close", null);
|
||||
if (Bitmask_.Has_int(flags, XomwPPFrame.NO_TAGS)) {
|
||||
String s = '<' + ((XomwPPNode_Hash_Text)((XomwPPNode)bits.Get_by("name")).getFirstChild()).value;
|
||||
if (bits.Has("attr")) {
|
||||
s += ((XomwPPNode_Hash_Text)((XomwPPNode)bits.Get_by("attr")).getFirstChild()).value;
|
||||
}
|
||||
if (bits.Has("inner")) {
|
||||
s += '>' + ((XomwPPNode_Hash_Text)((XomwPPNode)bits.Get_by("inner")).getFirstChild()).value;
|
||||
if (bits.Has("close")) {
|
||||
s += ((XomwPPNode_Hash_Text)((XomwPPNode)bits.Get_by("close")).getFirstChild()).value;
|
||||
}
|
||||
} else {
|
||||
s += "/>";
|
||||
}
|
||||
outItm += s;
|
||||
} else {
|
||||
outItm += this.parser.extensionSubstitution(bits, this);
|
||||
}
|
||||
} else if (String_.Eq(contextName, "h")) {
|
||||
// Heading
|
||||
if (this.parser.ot.Has("html")) {
|
||||
// Expand immediately and insert heading index marker
|
||||
String s = this.expand(contextChildren, flags);
|
||||
XophpArray bits = XomwPPNode_Hash_Tree.splitRawHeading(contextChildren);
|
||||
// String titleText = this.title.getPrefixedDBkey();
|
||||
// this.parser.mHeadings[] = [titleText, bits['i']];
|
||||
// serial = count(this.parser.mHeadings) - 1;
|
||||
String marker = XomwParser.MARKER_PREFIX + "-h-serial-" + XomwParser.MARKER_SUFFIX;
|
||||
s = XophpString.substr(s, 0, bits.Get_by_int("level")) + marker + XophpString.substr(s, bits.Get_by_int("level"));
|
||||
// this.parser.mStripState.addGeneral(marker, '');
|
||||
outItm += s;
|
||||
} else {
|
||||
// Expand in virtual stack
|
||||
newIterator = contextChildren;
|
||||
}
|
||||
} else {
|
||||
// Generic recursive expansion
|
||||
newIterator = contextChildren;
|
||||
}
|
||||
|
||||
if (newIterator != XophpObject.False) {
|
||||
outStack.Add("");
|
||||
iteratorStack.Add(newIterator);
|
||||
indexStack.Add(0);
|
||||
} else if (iteratorStack.Get_at(level) == XophpObject.False) {
|
||||
// Return accumulated value to parent
|
||||
// With tail recursion
|
||||
while (iteratorStack.Get_at(level) == XophpObject.False && level > 0) {
|
||||
outStack.Itm_str_concat_end(level - 1, outItm);
|
||||
outStack.Pop();
|
||||
iteratorStack.Pop();
|
||||
indexStack.Pop();
|
||||
level--;
|
||||
}
|
||||
}
|
||||
}
|
||||
--expansionDepth;
|
||||
return outStack.Get_at_str(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $sep
|
||||
* @param int $flags
|
||||
* @param String|PPNode $args,...
|
||||
* @return String
|
||||
*/
|
||||
// public function implodeWithFlags($sep, $flags /*, ... */) {
|
||||
// $args = array_slice(func_get_args(), 2);
|
||||
//
|
||||
// $first = true;
|
||||
// $s = '';
|
||||
// foreach ($args as $root) {
|
||||
// if ($root instanceof PPNode_Hash_Array) {
|
||||
// $root = $root.value;
|
||||
// }
|
||||
// if (!is_array($root)) {
|
||||
// $root = [$root];
|
||||
// }
|
||||
// foreach ($root as $node) {
|
||||
// if ($first) {
|
||||
// $first = false;
|
||||
// } else {
|
||||
// $s .= $sep;
|
||||
// }
|
||||
// $s .= this.expand($node, $flags);
|
||||
// }
|
||||
// }
|
||||
// return $s;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Implode with no flags specified
|
||||
* This previously called implodeWithFlags but has now been inlined to reduce stack depth
|
||||
* @param String $sep
|
||||
* @param String|PPNode $args,...
|
||||
* @return String
|
||||
*/
|
||||
@Override public String implode(String sep, Object... args) {
|
||||
boolean first = true;
|
||||
String s = "";
|
||||
for (Object rootObj : args) {
|
||||
XophpArray root = null;
|
||||
if (Type_.Eq_by_obj(root, XomwPPNode_Hash_Array.class)) {
|
||||
root = ((XomwPPNode_Hash_Array)rootObj).value;
|
||||
}
|
||||
if (!XophpArray.is_array(rootObj)) {
|
||||
root = XophpArray.New().Add(root);
|
||||
}
|
||||
int rootLen = root.Len();
|
||||
for (int i = 0; i < rootLen; i++) {
|
||||
Object node = root.Get_at(i);
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
s += sep;
|
||||
}
|
||||
s += this.expand(node, expand_flags_default);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an Object that, when expand()ed, will be the same as one obtained
|
||||
* with implode()
|
||||
*
|
||||
* @param String $sep
|
||||
* @param String|PPNode $args,...
|
||||
* @return PPNode_Hash_Array
|
||||
*/
|
||||
@Override public XomwPPNode virtualImplode(String sep, Object... args) {
|
||||
XophpArray outItm = XophpArray.New();
|
||||
boolean first = true;
|
||||
|
||||
for (Object rootObj : args) {
|
||||
XophpArray root = null;
|
||||
if (Type_.Eq_by_obj(root, XomwPPNode_Hash_Array.class)) {
|
||||
root = ((XomwPPNode_Hash_Array)rootObj).value;
|
||||
}
|
||||
if (!XophpArray.is_array(rootObj)) {
|
||||
root = XophpArray.New().Add(root);
|
||||
}
|
||||
int rootLen = root.Len();
|
||||
for (int i = 0; i < rootLen; i++) {
|
||||
Object node = root.Get_at(i);
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
outItm.Add(sep);
|
||||
}
|
||||
outItm.Add(node);
|
||||
}
|
||||
}
|
||||
return new XomwPPNode_Hash_Array(outItm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual implode with brackets
|
||||
*
|
||||
* @param String $start
|
||||
* @param String $sep
|
||||
* @param String $end
|
||||
* @param String|PPNode $args,...
|
||||
* @return PPNode_Hash_Array
|
||||
*/
|
||||
@Override public XomwPPNode virtualBracketedImplode(String start, String sep, String end, Object... args) {
|
||||
XophpArray outItm = XophpArray.New(start);
|
||||
boolean first = true;
|
||||
|
||||
for (Object rootObj : args) {
|
||||
XophpArray root = null;
|
||||
if (Type_.Eq_by_obj(rootObj, XomwPPNode_Hash_Array.class)) {
|
||||
root = ((XomwPPNode_Hash_Array)rootObj).value;
|
||||
}
|
||||
if (!XophpArray.is_array(rootObj)) {
|
||||
root = XophpArray.New((String)rootObj);
|
||||
}
|
||||
int root_len = root.Len();
|
||||
for (int i = 0; i < root_len; i++) {
|
||||
String node = root.Get_at_str(i);
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
outItm.Add(sep);
|
||||
}
|
||||
outItm.Add(node);
|
||||
}
|
||||
}
|
||||
outItm.Add(end);
|
||||
return new XomwPPNode_Hash_Array(outItm);
|
||||
}
|
||||
|
||||
// public function __toString() {
|
||||
// return 'frame{}';
|
||||
// }
|
||||
//
|
||||
/**
|
||||
* @param boolean $level
|
||||
* @return array|boolean|String
|
||||
*/
|
||||
public String getPDBK(boolean level) { // DEFAULT:false
|
||||
if (level == false) {
|
||||
return this.title.getPrefixedDBkeyStr();
|
||||
} else {
|
||||
// return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] : false;
|
||||
return this.titleCache.Count() > 0 ? ((String)this.titleCache.Get_at(0)) : XophpString_.False;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@Override public XophpArray getArguments() {
|
||||
return XophpArray.False;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@Override public XophpArray getNumberedArguments() {
|
||||
return XophpArray.False;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@Override public XophpArray getNamedArguments() {
|
||||
return XophpArray.False;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are no arguments in this frame
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|String $name
|
||||
* @return boolean Always false in this implementation.
|
||||
*/
|
||||
@Override public String getArgument(String name) {
|
||||
return XophpString_.False;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the infinite loop check is OK, false if a loop is detected
|
||||
*
|
||||
* @param Title $title
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override public boolean loopCheck(XomwTitle title) {
|
||||
return !this.loopCheckHash.is_set(title.getPrefixedDBkeyStr());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the frame is a template frame
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override public boolean isTemplate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a title of frame
|
||||
*
|
||||
* @return Title
|
||||
*/
|
||||
@Override public XomwTitle getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volatile_bool flag
|
||||
*
|
||||
* @param boolean $flag
|
||||
*/
|
||||
@Override public void setVolatile(boolean flag) { // DEFAULT: flag = true
|
||||
this.volatile_bool = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the volatile_bool flag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override public boolean isVolatile() {
|
||||
return this.volatile_bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the TTL
|
||||
*
|
||||
* @param int ttl
|
||||
*/
|
||||
@Override public void setTTL(int val) {
|
||||
if (this.ttl == Int_.Null || val < this.ttl) {
|
||||
this.ttl = val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TTL
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
@Override public int getTTL() {
|
||||
return this.ttl;
|
||||
}
|
||||
}
|
@ -18,24 +18,26 @@ package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; impor
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*/
|
||||
public class XomwPPNode_Hash_Array extends XomwPPNode { // public $value;
|
||||
//
|
||||
// public function __construct( $value ) {
|
||||
// $this->value = $value;
|
||||
// }
|
||||
public class XomwPPNode_Hash_Array extends XomwPPNode { public XophpArray value;
|
||||
|
||||
public XomwPPNode_Hash_Array(XophpArray value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
// return var_export( $this, true );
|
||||
return null;
|
||||
}
|
||||
//
|
||||
// public function getLength() {
|
||||
// return count( $this->value );
|
||||
// }
|
||||
//
|
||||
// public function item( $i ) {
|
||||
// return $this->value[$i];
|
||||
// }
|
||||
|
||||
public int getLength() {
|
||||
return -1;
|
||||
// return count( this.value );
|
||||
}
|
||||
|
||||
public Object item(int i) {
|
||||
return null;
|
||||
// return this.value[$i];
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
return "#nodelist";
|
||||
|
@ -50,11 +50,11 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
public static final int CHILDREN = 1;
|
||||
|
||||
/**
|
||||
* Construct an Object using the data from $store[$index]. The rest of the
|
||||
* Construct an Object using the data from store[index]. The rest of the
|
||||
* store array can be accessed via getNextSibling().
|
||||
*
|
||||
* @param array $store
|
||||
* @param integer $index
|
||||
* @param array store
|
||||
* @param integer index
|
||||
*/
|
||||
public XomwPPNode_Hash_Tree(XophpArray store, int index) {
|
||||
this.store = store;
|
||||
@ -75,8 +75,8 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
* Construct an appropriate PPNode_Hash_* Object with a class that depends
|
||||
* on what is at the relevant store index.
|
||||
*
|
||||
* @param array $store
|
||||
* @param integer $index
|
||||
* @param array store
|
||||
* @param integer index
|
||||
* @return PPNode_Hash_Tree|PPNode_Hash_Attr|PPNode_Hash_Text
|
||||
*/
|
||||
public static XomwPPNode factory(XophpArray store, int index) {
|
||||
@ -130,16 +130,17 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return PPNode_Hash_Array
|
||||
// */
|
||||
// public function getChildren() {
|
||||
// $children = [];
|
||||
// foreach (this.rawChildren as $i => $child) {
|
||||
// $children[] = self::factory(this.rawChildren, $i);
|
||||
/**
|
||||
* @return PPNode_Hash_Array
|
||||
*/
|
||||
public XomwPPNode_Hash_Array getChildren() {
|
||||
// children = [];
|
||||
// foreach (this.rawChildren as i => child) {
|
||||
// children[] = self::factory(this.rawChildren, i);
|
||||
// }
|
||||
// return new PPNode_Hash_Array($children);
|
||||
// }
|
||||
// return new PPNode_Hash_Array(children);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first child, or false if there is none. Note that this will
|
||||
@ -171,27 +172,28 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
// /**
|
||||
// * Get an array of the children with a given node name
|
||||
// *
|
||||
// * @param String $name
|
||||
// * @param String name
|
||||
// * @return PPNode_Hash_Array
|
||||
// */
|
||||
// public function getChildrenOfType($name) {
|
||||
// $children = [];
|
||||
// foreach (this.rawChildren as $i => $child) {
|
||||
// if (is_array($child) && $child[self::NAME] === $name) {
|
||||
// $children[] = self::factory(this.rawChildren, $i);
|
||||
// public function getChildrenOfType(name) {
|
||||
// children = [];
|
||||
// foreach (this.rawChildren as i => child) {
|
||||
// if (is_array(child) && child[self::NAME] === name) {
|
||||
// children[] = self::factory(this.rawChildren, i);
|
||||
// }
|
||||
// }
|
||||
// return new PPNode_Hash_Array($children);
|
||||
// return new PPNode_Hash_Array(children);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get the raw child array. For @gplx.Internal protected use.
|
||||
// * @return array
|
||||
// */
|
||||
// public function getRawChildren() {
|
||||
|
||||
/**
|
||||
* Get the raw child array. For @gplx.Internal protected use.
|
||||
* @return array
|
||||
*/
|
||||
public XophpArray getRawChildren() {
|
||||
// return this.rawChildren;
|
||||
// }
|
||||
//
|
||||
return null;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return boolean
|
||||
// */
|
||||
@ -200,10 +202,10 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param int $i
|
||||
// * @param int i
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function item($i) {
|
||||
// public function item(i) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@ -230,31 +232,31 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
// /**
|
||||
// * Like splitArg() but for a raw child array. For @gplx.Internal protected use only.
|
||||
// */
|
||||
// public static function splitRawArg(array $children) {
|
||||
// $bits = [];
|
||||
// foreach ($children as $i => $child) {
|
||||
// if (!is_array($child)) {
|
||||
// public static function splitRawArg(array children) {
|
||||
// bits = [];
|
||||
// foreach (children as i => child) {
|
||||
// if (!is_array(child)) {
|
||||
// continue;
|
||||
// }
|
||||
// if ($child[self::NAME] === 'name') {
|
||||
// $bits['name'] = new self($children, $i);
|
||||
// if (isset($child[self::CHILDREN][0][self::NAME])
|
||||
// && $child[self::CHILDREN][0][self::NAME] === '@index'
|
||||
// if (child[self::NAME] === 'name') {
|
||||
// bits['name'] = new self(children, i);
|
||||
// if (isset(child[self::CHILDREN][0][self::NAME])
|
||||
// && child[self::CHILDREN][0][self::NAME] === '@index'
|
||||
// ) {
|
||||
// $bits['index'] = $child[self::CHILDREN][0][self::CHILDREN][0];
|
||||
// bits['index'] = child[self::CHILDREN][0][self::CHILDREN][0];
|
||||
// }
|
||||
// } elseif ($child[self::NAME] === 'value') {
|
||||
// $bits['value'] = new self($children, $i);
|
||||
// } elseif (child[self::NAME] === 'value') {
|
||||
// bits['value'] = new self(children, i);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!isset($bits['name'])) {
|
||||
// if (!isset(bits['name'])) {
|
||||
// throw new MWException('Invalid brace node passed to ' . __METHOD__);
|
||||
// }
|
||||
// if (!isset($bits['index'])) {
|
||||
// $bits['index'] = "";
|
||||
// if (!isset(bits['index'])) {
|
||||
// bits['index'] = "";
|
||||
// }
|
||||
// return $bits;
|
||||
// return bits;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@ -267,107 +269,115 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
||||
// public function splitExt() {
|
||||
// return self::splitRawExt(this.rawChildren);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Like splitExt() but for a raw child array. For @gplx.Internal protected use only.
|
||||
// */
|
||||
// public static function splitRawExt(array $children) {
|
||||
// $bits = [];
|
||||
// foreach ($children as $i => $child) {
|
||||
// if (!is_array($child)) {
|
||||
// continue;
|
||||
// }
|
||||
// switch ($child[self::NAME]) {
|
||||
// case 'name':
|
||||
// $bits['name'] = new self($children, $i);
|
||||
// break;
|
||||
// case 'attr':
|
||||
// $bits['attr'] = new self($children, $i);
|
||||
// break;
|
||||
// case 'inner':
|
||||
// $bits['inner'] = new self($children, $i);
|
||||
// break;
|
||||
// case 'close':
|
||||
// $bits['close'] = new self($children, $i);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!isset($bits['name'])) {
|
||||
// throw new MWException('Invalid ext node passed to ' . __METHOD__);
|
||||
// }
|
||||
// return $bits;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Split an "<h>" node
|
||||
// *
|
||||
// * @throws MWException
|
||||
// * @return array
|
||||
// */
|
||||
// public function splitHeading() {
|
||||
// if (this.name !== 'h') {
|
||||
// throw new MWException('Invalid h node passed to ' . __METHOD__);
|
||||
// }
|
||||
// return self::splitRawHeading(this.rawChildren);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Like splitHeading() but for a raw child array. For @gplx.Internal protected use only.
|
||||
// */
|
||||
// public static function splitRawHeading(array $children) {
|
||||
// $bits = [];
|
||||
// foreach ($children as $i => $child) {
|
||||
// if (!is_array($child)) {
|
||||
// continue;
|
||||
// }
|
||||
// if ($child[self::NAME] === '@i') {
|
||||
// $bits['i'] = $child[self::CHILDREN][0];
|
||||
// } elseif ($child[self::NAME] === '@level') {
|
||||
// $bits['level'] = $child[self::CHILDREN][0];
|
||||
// }
|
||||
// }
|
||||
// if (!isset($bits['i'])) {
|
||||
// throw new MWException('Invalid h node passed to ' . __METHOD__);
|
||||
// }
|
||||
// return $bits;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Split a "<template>" or "<tplarg>" node
|
||||
// *
|
||||
// * @throws MWException
|
||||
// * @return array
|
||||
// */
|
||||
// public function splitTemplate() {
|
||||
// return self::splitRawTemplate(this.rawChildren);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Like splitTemplate() but for a raw child array. For @gplx.Internal protected use only.
|
||||
// */
|
||||
// public static function splitRawTemplate(array $children) {
|
||||
// $parts = [];
|
||||
// $bits = [ 'lineStart' => '' ];
|
||||
// foreach ($children as $i => $child) {
|
||||
// if (!is_array($child)) {
|
||||
// continue;
|
||||
// }
|
||||
// switch ($child[self::NAME]) {
|
||||
// case 'title':
|
||||
// $bits['title'] = new self($children, $i);
|
||||
// break;
|
||||
// case 'part':
|
||||
// $parts[] = new self($children, $i);
|
||||
// break;
|
||||
// case '@lineStart':
|
||||
// $bits['lineStart'] = '1';
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!isset($bits['title'])) {
|
||||
// throw new MWException('Invalid node passed to ' . __METHOD__);
|
||||
// }
|
||||
// $bits['parts'] = new PPNode_Hash_Array($parts);
|
||||
// return $bits;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Like splitExt() but for a raw child array. For @gplx.Internal protected use only.
|
||||
*/
|
||||
public static XophpArray splitRawExt(XophpArray children) {
|
||||
XophpArray bits = XophpArray.New();
|
||||
int len = children.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object childObj = children.Get_at(i);
|
||||
if (!XophpArray.is_array(childObj)) {
|
||||
continue;
|
||||
}
|
||||
XophpArray child = (XophpArray)childObj;
|
||||
String childName = child.Get_at_str(XomwPPNode_Hash_Tree.NAME);
|
||||
if (String_.Eq(childName, "name")) {
|
||||
bits.Add("name", new XomwPPNode_Hash_Tree(children, i));
|
||||
}
|
||||
else if (String_.Eq(childName, "attr")) {
|
||||
bits.Add("attr", new XomwPPNode_Hash_Tree(children, i));
|
||||
}
|
||||
else if (String_.Eq(childName, "inner")) {
|
||||
bits.Add("inner", new XomwPPNode_Hash_Tree(children, i));
|
||||
}
|
||||
else if (String_.Eq(childName, "close")) {
|
||||
bits.Add("close", new XomwPPNode_Hash_Tree(children, i));
|
||||
}
|
||||
}
|
||||
if (!bits.is_set("name")) {
|
||||
throw new XomwMWException("Invalid ext node passed to " + "splitRawExt");
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an "<h>" node
|
||||
*
|
||||
* @throws MWException
|
||||
* @return array
|
||||
*/
|
||||
public XophpArray splitHeading() {
|
||||
if (!String_.Eq(this.name, "h")) {
|
||||
throw new XomwMWException("Invalid h node passed to " + "splitHeading");
|
||||
}
|
||||
return XomwPPNode_Hash_Tree.splitRawHeading(this.rawChildren);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like splitHeading() but for a raw child array. For @gplx.Internal protected use only.
|
||||
*/
|
||||
public static XophpArray splitRawHeading(XophpArray children) {
|
||||
XophpArray bits = XophpArray.New();
|
||||
int len = children.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object childObj = children.Get_at(i);
|
||||
if (!XophpArray.is_array(childObj)) {
|
||||
continue;
|
||||
}
|
||||
XophpArray child = (XophpArray)childObj;
|
||||
String childName = child.Get_at_str(XomwPPNode_Hash_Tree.NAME);
|
||||
XophpArray childChildren = child.Get_at_ary(XomwPPNode_Hash_Tree.CHILDREN);
|
||||
if (String_.Eq(childName, "@i")) {
|
||||
bits.Add("i", childChildren.Get_at(0));
|
||||
} else if (String_.Eq(childName, "@level")) {
|
||||
bits.Add("level", childChildren.Get_at(0));
|
||||
}
|
||||
}
|
||||
if (!bits.is_set("i")) {
|
||||
throw new XomwMWException("Invalid h node passed to " + "splitRawHeading");
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a "<template>" or "<tplarg>" node
|
||||
*
|
||||
* @throws MWException
|
||||
* @return array
|
||||
*/
|
||||
public XophpArray splitTemplate() {
|
||||
return XomwPPNode_Hash_Tree.splitRawTemplate(this.rawChildren);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like splitTemplate() but for a raw child array. For @gplx.Internal protected use only.
|
||||
*/
|
||||
public static XophpArray splitRawTemplate(XophpArray children) {
|
||||
XophpArray parts = XophpArray.New();
|
||||
XophpArray bits = XophpArray.New().Add("lineStart" , "");
|
||||
int len = children.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object childObj = children.Get_at(i);
|
||||
if (!XophpArray.is_array(childObj)) {
|
||||
continue;
|
||||
}
|
||||
XophpArray child = (XophpArray)childObj;
|
||||
String childName = child.Get_at_str(XomwPPNode_Hash_Tree.NAME);
|
||||
XophpArray childChildren = child.Get_at_ary(XomwPPNode_Hash_Tree.CHILDREN);
|
||||
if (String_.Eq(childName, "title")) {
|
||||
bits.Add("title", new XomwPPNode_Hash_Tree(childChildren, i));
|
||||
} else if (String_.Eq(childName, "part")) {
|
||||
parts.Add(new XomwPPNode_Hash_Tree(childChildren, i));
|
||||
} else if (String_.Eq(childName, "@lineStart")) {
|
||||
bits.Add("lineStart", "1");
|
||||
}
|
||||
}
|
||||
if (!bits.is_set("title")) {
|
||||
throw new XomwMWException("Invalid node passed to " + "splitRawTemplate");
|
||||
}
|
||||
bits.Add("parts", new XomwPPNode_Hash_Array(parts));
|
||||
return bits;
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,5 @@ public class Pfunc_defaultsort extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_page_defaultsort;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_defaultsort().Name_(name);}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {}
|
||||
public static final Pfunc_defaultsort Instance = new Pfunc_defaultsort(); Pfunc_defaultsort() {}
|
||||
public static final Pfunc_defaultsort Instance = new Pfunc_defaultsort(); Pfunc_defaultsort() {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user