XomwTemplateParser: Port other XomwPPTemplateFrame classes [#632]

staging
gnosygnu 4 years ago
parent 9809dfd6c7
commit 17d7a7ebed

@ -20,6 +20,7 @@ import gplx.core.brys.*;
public class XophpArray implements Bry_bfr_able {
private final Ordered_hash hash = Ordered_hash_.New();
private int nxt_idx;
public int Len() {return hash.Len();}
public int count() {return hash.Len();}
public boolean count_bool() {return hash.Len() > 0;}
public boolean isset(String key) {return hash.Has(key);}

@ -16,12 +16,14 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
import gplx.core.brys.*;
public class XophpArrayItm implements Bry_bfr_able {
XophpArrayItm(boolean key_is_int, String key, Object val) {
XophpArrayItm(boolean key_is_int, int key_as_int, String key, Object val) {
this.key_is_int = key_is_int;
this.key_as_int = key_as_int;
this.key = key;
this.val = val;
}
public boolean Key_is_int() {return key_is_int;} private final boolean key_is_int;
public int Key_as_int() {return key_as_int;} private final int key_as_int;
public String Key() {return key;} private final String key;
public Object Val() {return val;} public void Val_(Object v) {this.val = v;} private Object val;
@ -38,6 +40,6 @@ public class XophpArrayItm implements Bry_bfr_able {
}
}
public static XophpArrayItm New_int(int key, Object val) {return new XophpArrayItm(Bool_.Y, Int_.To_str(key), val);}
public static XophpArrayItm New_str(String key, Object val) {return new XophpArrayItm(Bool_.N, key , val);}
public static XophpArrayItm New_int(int key, Object val) {return new XophpArrayItm(Bool_.Y, key, Int_.To_str(key), val);}
public static XophpArrayItm New_str(String key, Object val) {return new XophpArrayItm(Bool_.N, -1, key , val);}
}

@ -203,4 +203,8 @@ public class XophpArray_ {
}
return sb.To_str_and_clear();
}
public static int count(XophpArray array) {
return array.count();
}
}

@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
public class XophpInt_ {
public static final int False = 0; // REF.PHP:https://www.php.net/manual/en/language.types.boolean.php
public static boolean is_true(int val) {return val != -1;} // handles code like "if ($var === false)" where var is an Object;
public static String strval(int number) {
return Int_.To_str(number);

@ -45,4 +45,10 @@ public class XophpType_ {
public static boolean is_string(Object o) {
return To_type_id(o) == Type_ids_.Id__str;
}
public static boolean is_array(Object o) {
return Type_.Eq_by_obj(o, XophpArray.class);
}
public static boolean instance_of(Object o, Class<?> t) {
return Type_.Eq_by_obj(o, t);
}
}

@ -4129,13 +4129,13 @@ public class XomwDefaultSettings {
// * Maximum indent level of toc.
// */
// $wgMaxTocLevel = 999;
//
// /**
// * A complexity limit on template expansion: the maximum number of nodes visited
// * by PPFrame::expand()
// */
// $wgMaxPPNodeCount = 1000000;
//
/**
* A complexity limit on template expansion: the maximum number of nodes visited
* by PPFrame::expand()
*/
public static int wgMaxPPNodeCount = 1000000;
// /**
// * A complexity limit on template expansion: the maximum number of elements
// * generated by Preprocessor::preprocessToObj(). This allows you to limit the
@ -4154,12 +4154,12 @@ public class XomwDefaultSettings {
// * stop the parser before it hits the xdebug limit.
// */
// $wgMaxTemplateDepth = 40;
//
// /**
// * @see $wgMaxTemplateDepth
// */
// $wgMaxPPExpandDepth = 40;
//
/**
* @see $wgMaxTemplateDepth
*/
public static int wgMaxPPExpandDepth = 40;
// /**
// * URL schemes that should be recognized as valid by wfParseUrl().
// *

@ -21,4 +21,7 @@ public class XomwMWException extends Err {
public static Err New_by_method(Class<?> type, String method, String msg) {
return Err_.new_wo_type(Type_.Name(type) + "." + method + ":" + msg);
}
public static Err New_by_method_obj(Object obj, String method, String msg) {
return Err_.new_wo_type(Type_.Name_by_obj(obj) + "." + method + msg);
}
}

@ -192,7 +192,7 @@ public class XomwParser implements XomwParserIface {
private int mLinkID;
public int mIncludeSizes, mPPNodeCount, mGeneratedPPNodeCount, mHighestExpansionDepth;
// public mDefaultSort;
// public mTplRedirCache, mTplDomCache, mHeadings, mDoubleUnderscores;
public XophpArray mTplRedirCache = null, mTplDomCache = null, mHeadings = null, mDoubleUnderscores = null;
// public mExpensiveFunctionCount; // number of expensive parser function calls
// public mShowToc, mForceTocPosition;
//
@ -441,7 +441,7 @@ public class XomwParser implements XomwParserIface {
// this.mGeneratedPPNodeCount = 0;
// this.mHighestExpansionDepth = 0;
// this.mDefaultSort = false;
// this.mHeadings = [];
this.mHeadings = XophpArray.New();
// this.mDoubleUnderscores = [];
// this.mExpensiveFunctionCount = 0;
//

@ -74,21 +74,21 @@ public class XomwParserOptions {
*/
private int mMaxIncludeSize;
// /**
// * Maximum number of nodes touched by PPFrame::expand()
// */
// private $mMaxPPNodeCount;
//
/**
* Maximum number of nodes touched by PPFrame::expand()
*/
private int mMaxPPNodeCount;
// /**
// * Maximum number of nodes generated by Preprocessor::preprocessToObj()
// */
// private $mMaxGeneratedPPNodeCount;
//
// /**
// * Maximum recursion depth in PPFrame::expand()
// */
// private $mMaxPPExpandDepth;
//
/**
* Maximum recursion depth in PPFrame::expand()
*/
private int mMaxPPExpandDepth;
// /**
// * Maximum recursion depth for templates within templates
// */
@ -276,18 +276,18 @@ public class XomwParserOptions {
return this.mMaxIncludeSize;
}
// public function getMaxPPNodeCount() {
// return this.mMaxPPNodeCount;
// }
//
public int getMaxPPNodeCount() {
return this.mMaxPPNodeCount;
}
// public function getMaxGeneratedPPNodeCount() {
// return this.mMaxGeneratedPPNodeCount;
// }
//
// public function getMaxPPExpandDepth() {
// return this.mMaxPPExpandDepth;
// }
//
public int getMaxPPExpandDepth() {
return this.mMaxPPExpandDepth;
}
// public function getMaxTemplateDepth() {
// return this.mMaxTemplateDepth;
// }
@ -703,9 +703,9 @@ public class XomwParserOptions {
// this.mEnableImageWhitelist = $wgEnableImageWhitelist;
// this.mAllowSpecialInclusion = $wgAllowSpecialInclusion;
this.mMaxIncludeSize = XomwDefaultSettings.wgMaxArticleSize * 1024;
// this.mMaxPPNodeCount = $wgMaxPPNodeCount;
this.mMaxPPNodeCount = XomwDefaultSettings.wgMaxPPNodeCount;
// this.mMaxGeneratedPPNodeCount = $wgMaxGeneratedPPNodeCount;
// this.mMaxPPExpandDepth = $wgMaxPPExpandDepth;
this.mMaxPPExpandDepth = XomwDefaultSettings.wgMaxPPExpandDepth;
// this.mMaxTemplateDepth = $wgMaxTemplateDepth;
// this.mExpensiveParserFunctionLimit = $wgExpensiveParserFunctionLimit;
// this.mCleanSignatures = $wgCleanSignatures;

@ -65,6 +65,7 @@ public class XomwStripState {
this.addItem(TYPE_NOWIKI, marker, val);
}
public void addGeneral(String marker, String val) {this.addGeneral(Bry_.new_u8(marker), Bry_.new_u8(val));}
/**
* @param String $marker
* @param String $value

@ -112,7 +112,7 @@ class XomwPPFrame_Hash extends XomwPPFrame { /**
// this.parser.addTrackingCategory('duplicate-args-category');
}
numberedArgs.Set(index, bits.Get_by("value"));
// XophpArray_.unset_by_idx(namedArgs, index);
namedArgs.unset(index);
} else {
// Named parameter
String name = String_.Trim(this.expand(bits.Get_by("name"), XomwPPFrame.STRIP_COMMENTS));
@ -123,13 +123,12 @@ class XomwPPFrame_Hash extends XomwPPFrame { /**
// wfEscapeWikiText(name)).text());
// this.parser.addTrackingCategory('duplicate-args-category');
}
// namedArgs.Set(name, bits.Get_by("value"));
// XophpArray_.unset(numberedArgs, name);
namedArgs.Set(name, bits.Get_by("value"));
numberedArgs.unset(name);
}
}
}
// return new PPTemplateFrame_Hash(this.preprocessor, this, numberedArgs, namedArgs, title);
return null;
return new XomwPPTemplateFrame_Hash(this.preprocessor, this, numberedArgs, namedArgs, title);
}
/**
@ -157,20 +156,20 @@ class XomwPPFrame_Hash extends XomwPPFrame { /**
return (String)root;
}
// if (++this.parser.mPPNodeCount > this.parser.mOptions.getMaxPPNodeCount()) {
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()) {
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>';
// }
return "<span class=\"error\">Expansion depth limit exceeded</span>";
}
++expansionDepth;
if (expansionDepth > this.parser.mHighestExpansionDepth) {
this.parser.mHighestExpansionDepth = expansionDepth;
@ -342,12 +341,12 @@ class XomwPPFrame_Hash extends XomwPPFrame { /**
// 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;
String titleText = this.title.getPrefixedDBkeyStr();
this.parser.mHeadings.Add(titleText, bits.Get_by("i"));
int serial = XophpArray_.count(this.parser.mHeadings) - 1;
String marker = XomwParser.MARKER_PREFIX + "-h-" + Int_.To_str(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, '');
this.parser.mStripState.addGeneral(marker, "");
outItm += s;
} else {
// Expand in virtual stack
@ -384,29 +383,34 @@ class XomwPPFrame_Hash extends XomwPPFrame { /**
* @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;
// }
public String implodeWithFlags(String sep, int flags, XophpArray args) {
// args = XophpArray_.array_slice(func_get_args(), 2);
boolean first = true;
String s = "";
int len = args.Len();
for (int i = 0; i < len; i++) {
Object root_obj = args.Get_at(i);
XophpArray root = null;
if (XophpType_.instance_of(root_obj, XomwPPNode_Hash_Array.class)) {
root = (XophpArray)((XomwPPNode_Hash_Array)root_obj).value;
}
if (!XophpType_.is_array(root_obj)) {
root = XophpArray.New().Add(root_obj);
}
int root_len = root.Len();
for (int j = 0; j < root_len; j++) {
XomwPPNode node = (XomwPPNode)root.Get_at(j);
if (first) {
first = false;
} else {
s += sep;
}
s += this.expand(node, flags);
}
}
return s;
}
/**
* Implode with no flags specified
@ -510,10 +514,10 @@ class XomwPPFrame_Hash extends XomwPPFrame { /**
return new XomwPPNode_Hash_Array(outItm);
}
// public function __toString() {
// return 'frame{}';
// }
//
@Override public String toString() {
return "frame{}";
}
/**
* @param boolean $level
* @return array|boolean|String

@ -34,7 +34,7 @@ public abstract class XomwPPNode {
* Returns false if this is not a tree node.
* @return PPNode
*/
// public abstract XomwPPNode[] getChildren();
public abstract XomwPPNode_Hash_Array getChildren();
/**
* Get the first child of a tree node. False if there isn't one.
@ -55,19 +55,19 @@ public abstract class XomwPPNode {
* @param String $type
* @return boolean|PPNode
*/
// public abstract XomwPPNode getChildrenOfType(String type);
public abstract XomwPPNode_Hash_Array getChildrenOfType(String type);
/**
* Returns the length of the array, or false if this is not an array-type node
*/
// public abstract int getLength();
public abstract int getLength();
/**
* Returns an item of an array-type node
* @param int $i
* @return boolean|PPNode
*/
// public abstract XomwPPNode item(int i);
public abstract XomwPPNode item(int i);
/**
* Get the name of this node. The following names are defined here:
@ -91,20 +91,20 @@ public abstract class XomwPPNode {
* value PPNode value
* @return array
*/
@gplx.Virtual public XophpArray splitArg() {return null;}
public abstract XophpArray splitArg();
/**
* Split an "<ext>" node into an associative array containing name, attr, inner and close
* All values in the resulting array are PPNodes. Inner and close are optional.
* @return array
*/
// public abstract Hash_adp splitExt();
public abstract XophpArray splitExt();
/**
* Split an "<h>" node
* @return array
*/
// public abstract Hash_adp splitHeading();
public abstract XophpArray splitHeading();
public abstract String toString();
}

@ -14,6 +14,7 @@ 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.*;
// MW.FILE:Preprocessor_Hash
/**
* @ingroup Parser
@ -25,18 +26,16 @@ public class XomwPPNode_Hash_Array extends XomwPPNode { public XophpArray value
}
@Override public String toString() {
// return var_export( $this, true );
return null;
// return var_export($this, true);
return value.To_str();
}
public int getLength() {
return -1;
// return count( this.value );
@Override public int getLength() {
return XophpArray_.count(this.value);
}
public Object item(int i) {
return null;
// return this.value[$i];
@Override public XomwPPNode item(int i) {
return (XomwPPNode)this.value.Get_at(i);
}
@Override public String getName() {
@ -47,27 +46,27 @@ public class XomwPPNode_Hash_Array extends XomwPPNode { public XophpArray value
return null;
}
// public function getChildren() {
// return false;
// }
@Override public XomwPPNode_Hash_Array getChildren() {
return null;
}
@Override public XomwPPNode getFirstChild() {
return null;
}
// public function getChildrenOfType( $name ) {
// return false;
// }
//
// public function splitArg() {
// throw new MWException( __METHOD__ . ': not supported' );
// }
//
// public function splitExt() {
// throw new MWException( __METHOD__ . ': not supported' );
// }
//
// public function splitHeading() {
// throw new MWException( __METHOD__ . ': not supported' );
// }
@Override public XomwPPNode_Hash_Array getChildrenOfType(String name) {
return null;
}
@Override public XophpArray splitArg() {
throw XomwMWException.New_by_method_obj(this, "splitArg", ": not supported");
}
@Override public XophpArray splitExt() {
throw XomwMWException.New_by_method_obj(this, "splitExt", ": not supported");
}
@Override public XophpArray splitHeading() {
throw XomwMWException.New_by_method_obj(this, "splitHeading", ": not supported");
}
}

@ -14,6 +14,7 @@ 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.*;
// MW.FILE:Preprocessor_Hash
/**
* @ingroup Parser
@ -55,35 +56,35 @@ public class XomwPPNode_Hash_Attr extends XomwPPNode { public String name, valu
return XomwPPNode_Hash_Tree.factory(this.store, this.index + 1);
}
// public function getChildren() {
// return false;
// }
//
@Override public XomwPPNode_Hash_Array getChildren() {
return null;
}
@Override public XomwPPNode getFirstChild() {
return null;
}
// public function getChildrenOfType($name) {
// return false;
// }
//
// public function getLength() {
// return false;
// }
//
// public function item($i) {
// return false;
// }
//
// public function splitArg() {
// throw new MWException(__METHOD__ . ': not supported');
// }
//
// public function splitExt() {
// throw new MWException(__METHOD__ . ': not supported');
// }
//
// public function splitHeading() {
// throw new MWException(__METHOD__ . ': not supported');
// }
@Override public XomwPPNode_Hash_Array getChildrenOfType(String name) {
return null;
}
@Override public int getLength() {
return XophpInt_.False;
}
@Override public XomwPPNode item(int i) {
return null;
}
@Override public XophpArray splitArg() {
throw XomwMWException.New_by_method_obj(this, "splitArg", ": not supported");
}
@Override public XophpArray splitExt() {
throw XomwMWException.New_by_method_obj(this, "splitExt", ": not supported");
}
@Override public XophpArray splitHeading() {
throw XomwMWException.New_by_method_obj(this, "splitHeading", ": not supported");
}
}

@ -48,39 +48,39 @@ public class XomwPPNode_Hash_Text extends XomwPPNode { public String value;
return XomwPPNode_Hash_Tree.factory(this.store, this.index + 1);
}
// public function getChildren() {
// return false;
// }
@Override public XomwPPNode_Hash_Array getChildren() {
return null;
}
@Override public XomwPPNode getFirstChild() {
return null;
}
// public function getChildrenOfType($name) {
// return false;
// }
//
// public function getLength() {
// return false;
// }
//
// public function item($i) {
// return false;
// }
@Override public XomwPPNode_Hash_Array getChildrenOfType(String name) {
return null;
}
@Override public int getLength() {
return XophpInt_.False;
}
@Override public XomwPPNode item(int i) {
return null;
}
@Override public String getName() {
return "#text";
}
// public function splitArg() {
// throw new MWException(__METHOD__ . ': not supported');
// }
//
// public function splitExt() {
// throw new MWException(__METHOD__ . ': not supported');
// }
//
// public function splitHeading() {
// throw new MWException(__METHOD__ . ': not supported');
// }
@Override public XophpArray splitArg() {
throw XomwMWException.New_by_method_obj(this, "splitArg", ": not supported");
}
@Override public XophpArray splitExt() {
throw XomwMWException.New_by_method_obj(this, "splitExt", ": not supported");
}
@Override public XophpArray splitHeading() {
throw XomwMWException.New_by_method_obj(this, "splitHeading", ": not supported");
}
}

@ -133,13 +133,14 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
/**
* @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 null;
@Override public XomwPPNode_Hash_Array getChildren() {
XophpArray children = XophpArray.New();
int rawChildrenLen = rawChildren.Len();
for (int i = 0; i < rawChildrenLen; i++) {
XophpArrayItm itm = rawChildren.Get_at_itm(i);
children.Add(XomwPPNode_Hash_Tree.factory(this.rawChildren, itm.Key_as_int()));
}
return new XomwPPNode_Hash_Array(children);
}
/**
@ -169,45 +170,47 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
return factory(this.store, this.index + 1);
}
// /**
// * Get an array of the children with a given node 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);
// }
// }
// return new PPNode_Hash_Array(children);
// }
/**
* Get an array of the children with a given node name
*
* @param String name
* @return PPNode_Hash_Array
*/
@Override public XomwPPNode_Hash_Array getChildrenOfType(String name) {
XophpArray children = XophpArray.New();
int rawChildren_len = this.rawChildren.Len();
for (int idx = 0; idx < rawChildren_len; idx++) {
XophpArrayItm itm = this.rawChildren.Get_at_itm(idx);
Object child = itm.Val();
if (XophpType_.is_array(child) && String_.Eq(((XophpArray)child).Get_at_str(XomwPPNode_Hash_Tree.NAME), name)) {
children.Add(XomwPPNode_Hash_Tree.factory(this.rawChildren, itm.Key_as_int()));
}
}
return new XomwPPNode_Hash_Array(children);
}
/**
* Get the raw child array. For @gplx.Internal protected use.
* @return array
*/
public XophpArray getRawChildren() {
// return this.rawChildren;
return null;
return this.rawChildren;
}
// /**
// * @return boolean
// */
// public function getLength() {
// return false;
// }
//
// /**
// * @param int i
// * @return boolean
// */
// public function item(i) {
// return false;
// }
/**
* @return boolean
*/
@Override public int getLength() {
return XophpInt_.False;
}
/**
* @param int i
* @return boolean
*/
@Override public XomwPPNode item(int i) {
return null;
}
/**
* @return String
@ -216,59 +219,65 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
return this.name;
}
// /**
// * Split a "<part>" node into an associative array containing:
// * - name PPNode name
// * - index String index
// * - value PPNode value
// *
// * @throws MWException
// * @return array
// */
// public function splitArg() {
// return self::splitRawArg(this.rawChildren);
// }
//
// /**
// * 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)) {
// 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'
// ) {
// bits['index'] = child[self::CHILDREN][0][self::CHILDREN][0];
// }
// } elseif (child[self::NAME] === 'value') {
// bits['value'] = new self(children, i);
// }
// }
//
// if (!isset(bits['name'])) {
// throw new MWException('Invalid brace node passed to ' . __METHOD__);
// }
// if (!isset(bits['index'])) {
// bits['index'] = "";
// }
// return bits;
// }
//
// /**
// * Split an "<ext>" node into an associative array containing name, attr, inner and close
// * All values in the resulting array are PPNodes. Inner and close are optional.
// *
// * @throws MWException
// * @return array
// */
// public function splitExt() {
// return self::splitRawExt(this.rawChildren);
// }
/**
* Split a "<part>" node into an associative array containing:
* - name PPNode name
* - index String index
* - value PPNode value
*
* @throws MWException
* @return array
*/
@Override public XophpArray splitArg() {
return XomwPPNode_Hash_Tree.splitRawArg(this.rawChildren);
}
/**
* Like splitArg() but for a raw child array. For @gplx.Internal protected use only.
*/
public static XophpArray splitRawArg(XophpArray children) {
XophpArray bits = XophpArray.New();
int childrenLen = children.Len();
for (int j = 0; j < childrenLen; j++) {
XophpArrayItm itm = children.Get_at_itm(j);
Object childObj = itm.Val();
if (!XophpType_.is_array(childObj)) {
continue;
}
XophpArray child = (XophpArray)childObj;
int i = itm.Key_as_int();
if (String_.Eq(child.Get_at_str(XomwPPNode_Hash_Tree.NAME), "name")) {
bits.Set("name", new XomwPPNode_Hash_Tree(children, i));
if (XophpObject_.isset_obj(child.Get_at_ary(XomwPPNode_Hash_Tree.CHILDREN).Get_at_ary(0).Get_at(XomwPPNode_Hash_Tree.NAME))
&& String_.Eq(child.Get_at_ary(XomwPPNode_Hash_Tree.CHILDREN).Get_at_ary(0).Get_at_str(XomwPPNode_Hash_Tree.NAME), "@index")
) {
bits.Set("index", child.Get_at_ary(XomwPPNode_Hash_Tree.CHILDREN).Get_at_ary(0).Get_at_ary(XomwPPNode_Hash_Tree.CHILDREN).Get_at(0));
}
}
else if (String_.Eq(child.Get_at_str(XomwPPNode_Hash_Tree.NAME), "value")) {
bits.Set("value", new XomwPPNode_Hash_Tree(children, i));
}
}
if (!XophpObject_.isset_obj(bits.Get_by("name"))) {
throw XomwMWException.New_by_method(XomwPPNode_Hash_Tree.class, "splitRawArg", "Invalid brace node passed to " + "splitRawArg");
}
if (!XophpObject_.isset_obj(bits.Get_by("index"))) {
bits.Set("index", "");
}
return bits;
}
/**
* Split an "<ext>" node into an associative array containing name, attr, inner and close
* All values in the resulting array are PPNodes. Inner and close are optional.
*
* @throws MWException
* @return array
*/
@Override public XophpArray splitExt() {
return XomwPPNode_Hash_Tree.splitRawExt(this.rawChildren);
}
/**
* Like splitExt() but for a raw child array. For @gplx.Internal protected use only.
@ -308,7 +317,7 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
* @throws MWException
* @return array
*/
public XophpArray splitHeading() {
@Override public XophpArray splitHeading() {
if (!String_.Eq(this.name, "h")) {
throw new XomwMWException("Invalid h node passed to " + "splitHeading");
}

Loading…
Cancel
Save