mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-29 23:10:52 +00:00
Xomw.Preprocessor: Integrate rest of Preprocessor_Hash tests [#508]
This commit is contained in:
parent
0280254e8a
commit
0854cf9ba1
@ -21,7 +21,7 @@ public class String_ {
|
|||||||
public static final Class<?> Cls_ref_type = String.class;
|
public static final Class<?> Cls_ref_type = String.class;
|
||||||
public static final String Cls_val_name = "str" + "ing";
|
public static final String Cls_val_name = "str" + "ing";
|
||||||
public static final int Find_none = -1, Pos_neg1 = -1;
|
public static final int Find_none = -1, Pos_neg1 = -1;
|
||||||
public static final String Empty = "", Null_mark = "<<NULL>>", Tab = "\t", Lf = "\n", CrLf = "\r\n";
|
public static final String Empty = "", Null_mark = "<<NULL>>", Tab = "\t", Lf = "\n", CrLf = "\r\n", Nl = "\n";
|
||||||
|
|
||||||
public static boolean Eq(String lhs, String rhs) {return lhs == null ? rhs == null : lhs.equals(rhs);}
|
public static boolean Eq(String lhs, String rhs) {return lhs == null ? rhs == null : lhs.equals(rhs);}
|
||||||
public static int Len(String s) {return s.length();}
|
public static int Len(String s) {return s.length();}
|
||||||
|
@ -140,4 +140,14 @@ public class XophpArrayUtl {
|
|||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
// ( array $array , int $offset [, int $length = NULL [, boolean $preserve_keys = FALSE ]] ) :
|
||||||
|
public static XophpArray array_slice(XophpArray array, int offset) {return array_slice(array, offset, array.Len());}
|
||||||
|
public static XophpArray array_slice(XophpArray array, int offset, int length) {
|
||||||
|
XophpArray rv = new XophpArray();
|
||||||
|
int end = offset + length;
|
||||||
|
for (int i = offset; i< end; i++) {
|
||||||
|
rv.Add(array.Get_at(i));
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,12 +160,13 @@ public class XophpString {
|
|||||||
public static int strlen(byte[] src) {return src.length;}
|
public static int strlen(byte[] src) {return src.length;}
|
||||||
public static String str_repeat(String val, int count) {
|
public static String str_repeat(String val, int count) {
|
||||||
int val_len = String_.Len(val);
|
int val_len = String_.Len(val);
|
||||||
char[] chry = new char[val_len];
|
int chry_len = val_len * count;
|
||||||
|
char[] chry = new char[chry_len];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
for (int j = 0; i < val_len; j++) {
|
for (int j = 0; j < val_len; j++) {
|
||||||
chry[(i * val_len) + j] = String_.CharAt(val, j);
|
chry[(i * val_len) + j] = String_.CharAt(val, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return String_.new_charAry_(chry, 0, val_len);
|
return String_.new_charAry_(chry, 0, chry_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,11 @@ public class XophpString_tst {
|
|||||||
fxt.Test_strtr_by_trie("01_ab" , "89_ab"); // BOS
|
fxt.Test_strtr_by_trie("01_ab" , "89_ab"); // BOS
|
||||||
fxt.Test_strtr_by_trie("ab_01" , "ab_89"); // EOS
|
fxt.Test_strtr_by_trie("ab_01" , "ab_89"); // EOS
|
||||||
}
|
}
|
||||||
|
@Test public void Str_repeat() {
|
||||||
|
fxt.Test_str_repeat("abc", 3, "abcabcabc");
|
||||||
|
fxt.Test_str_repeat("", 3, "");
|
||||||
|
fxt.Test_str_repeat("abc", 0, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class XophpString_fxt {
|
class XophpString_fxt {
|
||||||
public void Test_strspn_fwd__byte(String src_str, byte find, int bgn, int max, int expd) {
|
public void Test_strspn_fwd__byte(String src_str, byte find, int bgn, int max, int expd) {
|
||||||
@ -82,4 +87,7 @@ class XophpString_fxt {
|
|||||||
Btrie_rv trv = new Btrie_rv();
|
Btrie_rv trv = new Btrie_rv();
|
||||||
Gftest.Eq__str(expd, XophpString.strtr(Bry_.new_u8(src), strtr_trie, tmp, trv));
|
Gftest.Eq__str(expd, XophpString.strtr(Bry_.new_u8(src), strtr_trie, tmp, trv));
|
||||||
}
|
}
|
||||||
|
public void Test_str_repeat(String str, int count, String expd) {
|
||||||
|
Gftest.Eq__str(expd, XophpString.str_repeat(str, count));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,6 @@ public class XophpType {
|
|||||||
return type_id == Type_ids_.Id__array;
|
return type_id == Type_ids_.Id__array;
|
||||||
}
|
}
|
||||||
public static XophpType New(Object o) {
|
public static XophpType New(Object o) {
|
||||||
return new XophpType(Type_ids_.To_id_by_obj(o));
|
return new XophpType(XophpTypeUtl.To_type_id(o));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,23 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|||||||
*/
|
*/
|
||||||
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||||
public class XophpTypeUtl {
|
public class XophpTypeUtl {
|
||||||
// REF.PHP: https://www.php.net/manual/en/function.is-scalar.php
|
public static int To_type_id(Object o) {
|
||||||
public static boolean is_scalar(Object obj) {
|
int type_id = Type_ids_.To_id_by_obj(o);
|
||||||
if (obj == null) return false;
|
switch (type_id) {
|
||||||
int type_id = Type_ids_.To_id_by_type(obj.getClass());
|
case Type_ids_.Id__bry:
|
||||||
|
type_id = Type_ids_.Id__str;
|
||||||
|
break;
|
||||||
|
case Type_ids_.Id__obj:
|
||||||
|
if (Type_.Eq_by_obj(o, XophpArray.class)) {
|
||||||
|
type_id = Type_ids_.Id__array;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return type_id;
|
||||||
|
}
|
||||||
|
public static boolean is_scalar(Object o) { // REF.PHP: https://www.php.net/manual/en/function.is-scalar.php
|
||||||
|
if (o == null) return false;
|
||||||
|
int type_id = To_type_id(o);
|
||||||
switch (type_id) {
|
switch (type_id) {
|
||||||
case Type_ids_.Id__int:
|
case Type_ids_.Id__int:
|
||||||
case Type_ids_.Id__float:
|
case Type_ids_.Id__float:
|
||||||
@ -29,6 +42,7 @@ public class XophpTypeUtl {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static boolean is_string(Object o) {
|
||||||
public static boolean is_string(Object obj) {return Type_.Eq_by_obj(obj, String.class);}
|
return To_type_id(o) == Type_ids_.Id__str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ public abstract class XomwPreprocessor {
|
|||||||
private final Btrie_slim_mgr elements_trie__y = Btrie_slim_mgr.ci_a7(), elements_trie__n = Btrie_slim_mgr.ci_a7();
|
private final Btrie_slim_mgr elements_trie__y = Btrie_slim_mgr.ci_a7(), elements_trie__n = Btrie_slim_mgr.ci_a7();
|
||||||
private final Hash_adp_bry xmlish_allow_missing_end_tag = Hash_adp_bry.cs().Add_many_str("includeonly", "noinclude", "onlyinclude");
|
private final Hash_adp_bry xmlish_allow_missing_end_tag = Hash_adp_bry.cs().Add_many_str("includeonly", "noinclude", "onlyinclude");
|
||||||
private final Hash_adp_bry no_more_closing_tag = Hash_adp_bry.cs();
|
private final Hash_adp_bry no_more_closing_tag = Hash_adp_bry.cs();
|
||||||
private final XomwPPDStackOld stack;
|
private final XomwPPDStack stack;
|
||||||
private final Btrie_rv trv = new Btrie_rv();
|
private final Btrie_rv trv = new Btrie_rv();
|
||||||
private Xomw_prepro_accum accum = null;
|
private Xomw_prepro_accum accum = null;
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ public abstract class XomwPreprocessor {
|
|||||||
trie.Add_obj(hook, new Xomw_prepro_elem(type_is_comment ? Xomw_prepro_elem.Type__comment : Xomw_prepro_elem.Type__other, Bry_.new_a7(name)));
|
trie.Add_obj(hook, new Xomw_prepro_elem(type_is_comment ? Xomw_prepro_elem.Type__comment : Xomw_prepro_elem.Type__other, Bry_.new_a7(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract byte[] preprocessToDbg(byte[] src, boolean for_inclusion);
|
public abstract String preprocessToDbg(byte[] src, boolean for_inclusion);
|
||||||
/**
|
/**
|
||||||
* @param String $text
|
* @param String $text
|
||||||
* @param int $flags
|
* @param int $flags
|
||||||
@ -241,7 +241,7 @@ public abstract class XomwPreprocessor {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// Current accumulator
|
// Current accumulator
|
||||||
accum = this.Accum__set(stack.Get_accum());
|
accum = this.Accum__set(stack.getAccum());
|
||||||
this.preprocessToObj_root();
|
this.preprocessToObj_root();
|
||||||
|
|
||||||
// True to find equals signs in arguments
|
// True to find equals signs in arguments
|
||||||
@ -270,7 +270,7 @@ public abstract class XomwPreprocessor {
|
|||||||
int src_len = src.length;
|
int src_len = src.length;
|
||||||
int found = -1;
|
int found = -1;
|
||||||
byte[] cur_char = Bry_.Empty;
|
byte[] cur_char = Bry_.Empty;
|
||||||
byte[] cur_closing = Bry_.Empty;
|
String cur_closing = "";
|
||||||
byte[] inner = null;
|
byte[] inner = null;
|
||||||
Xomw_prepro_rule rule = null;
|
Xomw_prepro_rule rule = null;
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ public abstract class XomwPreprocessor {
|
|||||||
// Find next opening brace, closing brace or pipe
|
// Find next opening brace, closing brace or pipe
|
||||||
// RELIC.REGEX: $search = $searchBase;
|
// RELIC.REGEX: $search = $searchBase;
|
||||||
if (stack.top == null) {
|
if (stack.top == null) {
|
||||||
cur_closing = Bry_.Empty;
|
cur_closing = "";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cur_closing = stack.top.close;
|
cur_closing = stack.top.close;
|
||||||
@ -332,10 +332,10 @@ public abstract class XomwPreprocessor {
|
|||||||
if (findEquals) loop_stop = true;
|
if (findEquals) loop_stop = true;
|
||||||
break;
|
break;
|
||||||
default: // handle "cur_closing"; specified by piece.close and rule.close, so "\n", "}", "]" and "}-"
|
default: // handle "cur_closing"; specified by piece.close and rule.close, so "\n", "}", "]" and "}-"
|
||||||
if (cur_closing != Bry_.Empty) {
|
if (String_.EqNot(cur_closing, "")) {
|
||||||
byte cur_closing_0 = cur_closing[0];
|
byte cur_closing_0 = (byte)String_.CharAt(cur_closing, 0);
|
||||||
if (b == cur_closing_0) {
|
if (b == cur_closing_0) {
|
||||||
if (cur_closing.length == 1) { // handle "\n", "}", "]"
|
if (String_.Len(cur_closing) == 1) { // handle "\n", "}", "]"
|
||||||
loop_stop = true;
|
loop_stop = true;
|
||||||
}
|
}
|
||||||
else {// handle "}-"
|
else {// handle "}-"
|
||||||
@ -357,7 +357,7 @@ public abstract class XomwPreprocessor {
|
|||||||
i += literal_len;
|
i += literal_len;
|
||||||
}
|
}
|
||||||
if (i >= src_len) {
|
if (i >= src_len) {
|
||||||
if (Bry_.Eq(cur_closing, Byte_ascii.Nl_bry)) {
|
if (String_.Eq(cur_closing, String_.Nl)) {
|
||||||
// Do a past-the-end run to finish off the heading
|
// Do a past-the-end run to finish off the heading
|
||||||
cur_char = Bry_.Empty;
|
cur_char = Bry_.Empty;
|
||||||
found = Found__line_end;
|
found = Found__line_end;
|
||||||
@ -487,7 +487,7 @@ public abstract class XomwPreprocessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stack.top != null) {
|
if (stack.top != null) {
|
||||||
XomwPPDPart part = stack.top.Get_current_part();
|
XomwPPDPart part = stack.top.getCurrentPart();
|
||||||
if (!(part.commentEnd != -1 && part.commentEnd == ws_bgn - 1)) {
|
if (!(part.commentEnd != -1 && part.commentEnd == ws_bgn - 1)) {
|
||||||
part.visualEnd = ws_bgn;
|
part.visualEnd = ws_bgn;
|
||||||
}
|
}
|
||||||
@ -617,11 +617,11 @@ public abstract class XomwPreprocessor {
|
|||||||
// complex.
|
// complex.
|
||||||
}
|
}
|
||||||
else if (count > 0) {
|
else if (count > 0) {
|
||||||
Xomw_prepro_piece piece = new Xomw_prepro_piece(Factory__part(), Byte_ascii.Nl_bry, Byte_ascii.Nl_bry, count, i, false);
|
XomwPPDStackElement piece = Factory__stack_element(Factory__part(), String_.Nl, String_.Nl, count, i, false);
|
||||||
piece.Add_part(Bry_.Repeat(Byte_ascii.Eq, count));
|
piece.addPart(XophpString.str_repeat("=", count));
|
||||||
stack.Push(piece);
|
stack.push(piece);
|
||||||
accum = this.Accum__set(stack.Get_accum());
|
accum = this.Accum__set(stack.getAccum());
|
||||||
Xomw_prepro_flags flags = stack.Get_flags();
|
XomwPPDStackElementFlags flags = stack.getFlags();
|
||||||
findPipe = flags.findPipe;
|
findPipe = flags.findPipe;
|
||||||
findEquals = flags.findEquals;
|
findEquals = flags.findEquals;
|
||||||
inHeading = flags.inHeading;
|
inHeading = flags.inHeading;
|
||||||
@ -629,10 +629,10 @@ public abstract class XomwPreprocessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (found == Found__line_end) {
|
else if (found == Found__line_end) {
|
||||||
Xomw_prepro_piece piece = stack.top;
|
XomwPPDStackElement piece = stack.top;
|
||||||
// A heading must be open, otherwise \n wouldn't have been in the search list
|
// A heading must be open, otherwise \n wouldn't have been in the search list
|
||||||
if (!Bry_.Eq(piece.open, Byte_ascii.Nl_bry)) throw Err_.new_wo_type("assertion:piece must start with \\n");
|
if (!String_.Eq(piece.open, String_.Nl)) throw Err_.new_wo_type("assertion:piece must start with \\n");
|
||||||
XomwPPDPart part = piece.Get_current_part();
|
XomwPPDPart part = piece.getCurrentPart();
|
||||||
|
|
||||||
// Search back through the input to see if it has a proper close.
|
// Search back through the input to see if it has a proper close.
|
||||||
// Do this using the reversed String since the other solutions
|
// Do this using the reversed String since the other solutions
|
||||||
@ -683,10 +683,10 @@ public abstract class XomwPreprocessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unwind the stack
|
// Unwind the stack
|
||||||
stack.Pop();
|
stack.pop();
|
||||||
this.accum = this.Accum__set(stack.Get_accum());
|
this.accum = this.Accum__set(stack.getAccum());
|
||||||
|
|
||||||
Xomw_prepro_flags flags = stack.Get_flags();
|
XomwPPDStackElementFlags flags = stack.getFlags();
|
||||||
findPipe = flags.findPipe;
|
findPipe = flags.findPipe;
|
||||||
findEquals = flags.findEquals;
|
findEquals = flags.findEquals;
|
||||||
inHeading = flags.inHeading;
|
inHeading = flags.inHeading;
|
||||||
@ -706,11 +706,10 @@ public abstract class XomwPreprocessor {
|
|||||||
// we need to add to stack only if opening brace count is enough for one of the rules
|
// we need to add to stack only if opening brace count is enough for one of the rules
|
||||||
if (count >= rule.min) {
|
if (count >= rule.min) {
|
||||||
// Add it to the stack
|
// Add it to the stack
|
||||||
Xomw_prepro_piece piece = new Xomw_prepro_piece(Factory__part(), cur_char, rule.end, count, -1, i > 0 && src[i - 1] == Byte_ascii.Nl);
|
XomwPPDStackElement piece = Factory__stack_element(Factory__part(), String_.new_u8(cur_char), String_.new_u8(rule.end), count, -1, i > 0 && src[i - 1] == Byte_ascii.Nl);
|
||||||
|
stack.push(piece);
|
||||||
stack.Push(piece);
|
this.accum = this.Accum__set(stack.getAccum());
|
||||||
this.accum = this.Accum__set(stack.Get_accum());
|
XomwPPDStackElementFlags flags = stack.getFlags();
|
||||||
Xomw_prepro_flags flags = stack.Get_flags();
|
|
||||||
findPipe = flags.findPipe;
|
findPipe = flags.findPipe;
|
||||||
findEquals = flags.findEquals;
|
findEquals = flags.findEquals;
|
||||||
inHeading = flags.inHeading;
|
inHeading = flags.inHeading;
|
||||||
@ -723,7 +722,7 @@ public abstract class XomwPreprocessor {
|
|||||||
i += count;
|
i += count;
|
||||||
}
|
}
|
||||||
else if (found == Found__close) {
|
else if (found == Found__close) {
|
||||||
Xomw_prepro_piece piece = stack.top;
|
XomwPPDStackElement piece = stack.top;
|
||||||
// lets check if there are enough characters for closing brace
|
// lets check if there are enough characters for closing brace
|
||||||
int max_count = piece.count;
|
int max_count = piece.count;
|
||||||
int count = XophpString.strspn_fwd__byte(src, cur_char[0], i, max_count, src_len);
|
int count = XophpString.strspn_fwd__byte(src, cur_char[0], i, max_count, src_len);
|
||||||
@ -759,7 +758,7 @@ public abstract class XomwPreprocessor {
|
|||||||
Xomw_prepro_accum element = null;
|
Xomw_prepro_accum element = null;
|
||||||
if (name_type == Xomw_prepro_rule.Name__null) {
|
if (name_type == Xomw_prepro_rule.Name__null) {
|
||||||
// No element, just literal text
|
// No element, just literal text
|
||||||
element = this.preprocessToObj_text(element, piece, rule.end, matching_count);
|
element = this.preprocessToObj_text(piece, rule.end, matching_count);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create XML element
|
// Create XML element
|
||||||
@ -770,8 +769,8 @@ public abstract class XomwPreprocessor {
|
|||||||
i += matching_count;
|
i += matching_count;
|
||||||
|
|
||||||
// Unwind the stack
|
// Unwind the stack
|
||||||
stack.Pop();
|
stack.pop();
|
||||||
this.accum = this.Accum__set(stack.Get_accum());
|
this.accum = this.Accum__set(stack.getAccum());
|
||||||
|
|
||||||
// Re-add the old stack element if it still has unmatched opening characters remaining
|
// Re-add the old stack element if it still has unmatched opening characters remaining
|
||||||
if (matching_count < piece.count) {
|
if (matching_count < piece.count) {
|
||||||
@ -781,15 +780,15 @@ public abstract class XomwPreprocessor {
|
|||||||
// do we still qualify for any callback with remaining count?
|
// do we still qualify for any callback with remaining count?
|
||||||
int min = Get_rule(piece.open).min;
|
int min = Get_rule(piece.open).min;
|
||||||
if (piece.count >= min) {
|
if (piece.count >= min) {
|
||||||
stack.Push(piece);
|
stack.push(piece);
|
||||||
this.accum = this.Accum__set(stack.Get_accum());
|
this.accum = this.Accum__set(stack.getAccum());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.preprocessToObj_literal(Bry_.Repeat_bry(piece.open, piece.count));
|
this.preprocessToObj_literal(Bry_.new_u8(XophpString.str_repeat(piece.open, piece.count)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Xomw_prepro_flags flags = stack.Get_flags();
|
XomwPPDStackElementFlags flags = stack.getFlags();
|
||||||
findPipe = flags.findPipe;
|
findPipe = flags.findPipe;
|
||||||
findEquals = flags.findEquals;
|
findEquals = flags.findEquals;
|
||||||
inHeading = flags.inHeading;
|
inHeading = flags.inHeading;
|
||||||
@ -799,8 +798,8 @@ public abstract class XomwPreprocessor {
|
|||||||
}
|
}
|
||||||
else if (found == Found__pipe) {
|
else if (found == Found__pipe) {
|
||||||
findEquals = true; // shortcut for getFlags()
|
findEquals = true; // shortcut for getFlags()
|
||||||
stack.Add_part(Bry_.Empty);
|
stack.addPart("");
|
||||||
this.accum = this.Accum__set(stack.Get_accum());
|
this.accum = this.Accum__set(stack.getAccum());
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
else if (found == Found__equals) {
|
else if (found == Found__equals) {
|
||||||
@ -814,6 +813,7 @@ public abstract class XomwPreprocessor {
|
|||||||
return this.preprocessToObj_term(stack);
|
return this.preprocessToObj_term(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Xomw_prepro_rule Get_rule(String str) {return Get_rule(Bry_.new_u8(str));}
|
||||||
private Xomw_prepro_rule Get_rule(byte[] bry) {
|
private Xomw_prepro_rule Get_rule(byte[] bry) {
|
||||||
if (Bry_.Eq(bry, rule_curly.bgn)) return rule_curly;
|
if (Bry_.Eq(bry, rule_curly.bgn)) return rule_curly;
|
||||||
else if (Bry_.Eq(bry, rule_brack.bgn)) return rule_brack;
|
else if (Bry_.Eq(bry, rule_brack.bgn)) return rule_brack;
|
||||||
@ -864,7 +864,8 @@ public abstract class XomwPreprocessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract XomwPPDPart Factory__part();
|
protected abstract XomwPPDPart Factory__part();
|
||||||
protected abstract XomwPPDStackOld Factory__stack();
|
protected abstract XomwPPDStack Factory__stack();
|
||||||
|
protected abstract XomwPPDStackElement Factory__stack_element(XomwPPDPart part_factory, String open, String close, int count, int start_pos, boolean lineStart);
|
||||||
|
|
||||||
protected abstract Xomw_prepro_accum Accum__set(Xomw_prepro_accum accum);
|
protected abstract Xomw_prepro_accum Accum__set(Xomw_prepro_accum accum);
|
||||||
|
|
||||||
@ -880,10 +881,10 @@ public abstract class XomwPreprocessor {
|
|||||||
protected abstract Xomw_prepro_accum preprocessToObj_heading_init(int count, int heading_index);
|
protected abstract Xomw_prepro_accum preprocessToObj_heading_init(int count, int heading_index);
|
||||||
protected abstract void preprocessToObj_heading_end(Xomw_prepro_accum element);
|
protected abstract void preprocessToObj_heading_end(Xomw_prepro_accum element);
|
||||||
protected abstract void preprocessToObj_removeLeadingWhitespaceFromEnd(int ws_len);
|
protected abstract void preprocessToObj_removeLeadingWhitespaceFromEnd(int ws_len);
|
||||||
protected abstract Xomw_prepro_accum preprocessToObj_text(Xomw_prepro_accum element, Xomw_prepro_piece piece, byte[] rule_end, int matching_count);
|
protected abstract Xomw_prepro_accum preprocessToObj_text(XomwPPDStackElement piece, byte[] rule_end, int matching_count);
|
||||||
protected abstract Xomw_prepro_accum preprocessToObj_xml(Xomw_prepro_piece piece, byte[] name_bry, int max_count, int matching_count);
|
protected abstract Xomw_prepro_accum preprocessToObj_xml(XomwPPDStackElement piece, byte[] name_bry, int max_count, int matching_count);
|
||||||
protected abstract void preprocessToObj_add_element(Xomw_prepro_accum element);
|
protected abstract void preprocessToObj_add_element(Xomw_prepro_accum element);
|
||||||
protected abstract void preprocessToObj_equals(XomwPPDStackOld stack);
|
protected abstract void preprocessToObj_equals(XomwPPDStack stack);
|
||||||
protected abstract Object preprocessToObj_term(XomwPPDStackOld stack);
|
protected abstract Object preprocessToObj_term(XomwPPDStack stack);
|
||||||
public abstract XomwPreprocessor Make_new(XomwParser parser);
|
public abstract XomwPreprocessor Make_new(XomwParser parser);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,9 @@ import gplx.xowa.mediawiki.includes.parsers.preprocessors.*;
|
|||||||
class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
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("");
|
private Xomw_prepro_accum__dom accum_dom = new Xomw_prepro_accum__dom("");
|
||||||
|
|
||||||
@Override protected XomwPPDStackOld Factory__stack() {return new XomwPPDStackOld(Xomw_prepro_accum__dom.Instance);}
|
|
||||||
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_DOM("");}
|
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_DOM("");}
|
||||||
|
@Override protected XomwPPDStack Factory__stack() {return new XomwPPDStack(Xomw_prepro_accum__dom.Instance);}
|
||||||
|
@Override protected XomwPPDStackElement Factory__stack_element(XomwPPDPart part_factory, String open, String close, int count, int start_pos, boolean lineStart) {return new XomwPPDStackElement(part_factory, open, close, count, start_pos, lineStart);}
|
||||||
|
|
||||||
@Override public XomwPPFrame newFrame() {
|
@Override public XomwPPFrame newFrame() {
|
||||||
return null;
|
return null;
|
||||||
@ -34,7 +35,7 @@ class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr
|
|||||||
return accum;
|
return accum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public byte[] preprocessToDbg(byte[] src, boolean for_inclusion) {return (byte[])this.preprocessToObj_base(src, for_inclusion);}
|
@Override public String preprocessToDbg(byte[] src, boolean for_inclusion) {return String_.new_u8((byte[])this.preprocessToObj_base(src, for_inclusion));}
|
||||||
@Override public XomwPPNode preprocessToObj(String text, int flags) {
|
@Override public XomwPPNode preprocessToObj(String text, int flags) {
|
||||||
return (XomwPPNode)preprocessToObj_base(Bry_.new_u8(text), gplx.core.bits.Bitmask_.Has_int(flags, XomwParser.PTD_FOR_INCLUSION));
|
return (XomwPPNode)preprocessToObj_base(Bry_.new_u8(text), gplx.core.bits.Bitmask_.Has_int(flags, XomwParser.PTD_FOR_INCLUSION));
|
||||||
}
|
}
|
||||||
@ -89,25 +90,22 @@ class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr
|
|||||||
@Override protected void preprocessToObj_heading_end(Xomw_prepro_accum element) {
|
@Override protected void preprocessToObj_heading_end(Xomw_prepro_accum element) {
|
||||||
accum_dom.Add_bry(((Xomw_prepro_accum__dom)element).To_bry());
|
accum_dom.Add_bry(((Xomw_prepro_accum__dom)element).To_bry());
|
||||||
}
|
}
|
||||||
@Override protected Xomw_prepro_accum preprocessToObj_text(Xomw_prepro_accum element_obj, Xomw_prepro_piece piece, byte[] rule_end, int matching_count) {
|
@Override protected Xomw_prepro_accum preprocessToObj_text(XomwPPDStackElement piece, byte[] rule_end, int matching_count) {
|
||||||
Xomw_prepro_accum__dom element = (Xomw_prepro_accum__dom)element_obj;
|
tmp_bfr.Add_str_u8((String)piece.breakSyntax(matching_count));
|
||||||
tmp_bfr.Add(piece.Break_syntax(tmp_bfr, matching_count));
|
|
||||||
if (element != null)
|
|
||||||
tmp_bfr.Add(element.To_bry());
|
|
||||||
tmp_bfr.Add(Bry_.Repeat_bry(rule_end, matching_count));
|
tmp_bfr.Add(Bry_.Repeat_bry(rule_end, matching_count));
|
||||||
byte[] rv = tmp_bfr.To_bry_and_clear();
|
byte[] rv = tmp_bfr.To_bry_and_clear();
|
||||||
return new Xomw_prepro_accum__dom(String_.new_u8(rv));
|
return new Xomw_prepro_accum__dom(String_.new_u8(rv));
|
||||||
}
|
}
|
||||||
@Override protected Xomw_prepro_accum preprocessToObj_xml(Xomw_prepro_piece piece, byte[] name_bry, int max_count, int matching_count) {
|
@Override protected Xomw_prepro_accum preprocessToObj_xml(XomwPPDStackElement piece, byte[] name_bry, int max_count, int matching_count) {
|
||||||
// Note: $parts is already XML, does not need to be encoded further
|
// Note: $parts is already XML, does not need to be encoded further
|
||||||
List_adp parts = piece.parts;
|
XophpArray parts = piece.parts;
|
||||||
byte[] title = ((XomwPPDPart_DOM)parts.Get_at(0)).To_bry();
|
byte[] title = ((XomwPPDPart_DOM)parts.Get_at(0)).To_bry();
|
||||||
parts.Del_at(0);
|
parts.Del_at(0);
|
||||||
|
|
||||||
// The invocation is at the start of the line if lineStart is set in
|
// The invocation is at the start of the line if lineStart is set in
|
||||||
// the stack, and all opening brackets are used up.
|
// the stack, and all opening brackets are used up.
|
||||||
byte[] attr = null;
|
byte[] attr = null;
|
||||||
if (max_count == matching_count && piece.line_start) { // RELIC:!empty( $piece->lineStart )
|
if (max_count == matching_count && piece.lineStart) { // RELIC:!empty( $piece->lineStart )
|
||||||
attr = Bry_.new_a7(" lineStart=\"1\"");
|
attr = Bry_.new_a7(" lineStart=\"1\"");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -138,11 +136,11 @@ class XomwPreprocessor_DOM extends XomwPreprocessor { private final Bry_bfr
|
|||||||
@Override protected void preprocessToObj_add_element(Xomw_prepro_accum element) {
|
@Override protected void preprocessToObj_add_element(Xomw_prepro_accum element) {
|
||||||
accum_dom.Add_bry(((Xomw_prepro_accum__dom)element).To_bry());
|
accum_dom.Add_bry(((Xomw_prepro_accum__dom)element).To_bry());
|
||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_equals(XomwPPDStackOld stack) {
|
@Override protected void preprocessToObj_equals(XomwPPDStack stack) {
|
||||||
stack.Get_current_part().eqpos = accum_dom.Len();
|
stack.getCurrentPart().eqpos = accum_dom.Len();
|
||||||
accum_dom.Add_bry(Byte_ascii.Eq_bry);
|
accum_dom.Add_bry(Byte_ascii.Eq_bry);
|
||||||
}
|
}
|
||||||
@Override protected Object preprocessToObj_term(XomwPPDStackOld stack) {
|
@Override protected Object preprocessToObj_term(XomwPPDStack stack) {
|
||||||
Bry_bfr root_accum = Bry_bfr_.New().Add_str_u8(((Xomw_prepro_accum__dom)stack.Get_root_accum()).To_str());
|
Bry_bfr root_accum = Bry_bfr_.New().Add_str_u8(((Xomw_prepro_accum__dom)stack.Get_root_accum()).To_str());
|
||||||
int stack_len = stack.stack.Len();
|
int stack_len = stack.stack.Len();
|
||||||
for (int j = 0; j < stack_len; j++) {
|
for (int j = 0; j < stack_len; j++) {
|
||||||
|
@ -25,16 +25,18 @@ class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected XomwPPDStackOld Factory__stack() {return new XomwPPDStackOld_Hash(Xomw_prepro_accum__hash.Instance);}
|
|
||||||
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_Hash("");}
|
@Override protected XomwPPDPart Factory__part() {return new XomwPPDPart_Hash("");}
|
||||||
|
@Override protected XomwPPDStack Factory__stack() {return new XomwPPDStack(Xomw_prepro_accum__hash.Instance);}
|
||||||
|
@Override protected XomwPPDStackElement Factory__stack_element(XomwPPDPart part_factory, String open, String close, int count, int start_pos, boolean lineStart) {return new XomwPPDStackElement_Hash(part_factory, open, close, count, start_pos, lineStart);}
|
||||||
|
|
||||||
@Override protected Xomw_prepro_accum Accum__set(Xomw_prepro_accum accum_obj) {
|
@Override protected Xomw_prepro_accum Accum__set(Xomw_prepro_accum accum_obj) {
|
||||||
this.accum = ((Xomw_prepro_accum__hash)accum_obj).Ary();
|
this.accum = ((Xomw_prepro_accum__hash)accum_obj).Ary();
|
||||||
return accum_obj;
|
return accum_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public byte[] preprocessToDbg(byte[] src, boolean for_inclusion) {
|
@Override public String preprocessToDbg(byte[] src, boolean for_inclusion) {
|
||||||
XomwPPNode_Hash_Tree node = (XomwPPNode_Hash_Tree)this.preprocessToObj_base(src, for_inclusion);
|
XomwPPNode_Hash_Tree node = (XomwPPNode_Hash_Tree)this.preprocessToObj_base(src, for_inclusion);
|
||||||
return Bry_.new_u8(node.toString());
|
return node.toString();
|
||||||
}
|
}
|
||||||
@Override public XomwPPNode preprocessToObj(String text, int flags) {
|
@Override public XomwPPNode preprocessToObj(String text, int flags) {
|
||||||
return (XomwPPNode)preprocessToObj_base(Bry_.new_u8(text), gplx.core.bits.Bitmask_.Has_int(flags, XomwParser.PTD_FOR_INCLUSION));
|
return (XomwPPNode)preprocessToObj_base(Bry_.new_u8(text), gplx.core.bits.Bitmask_.Has_int(flags, XomwParser.PTD_FOR_INCLUSION));
|
||||||
@ -42,22 +44,22 @@ class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum
|
|||||||
@Override protected void preprocessToObj_root() {} // NOTE: deliberately empty;
|
@Override protected void preprocessToObj_root() {} // NOTE: deliberately empty;
|
||||||
|
|
||||||
@Override protected void preprocessToObj_ignore(byte[] src, int bgn, int end) {
|
@Override protected void preprocessToObj_ignore(byte[] src, int bgn, int end) {
|
||||||
accum.Add(XophpArray.New("ignore", XophpString.substr(src, bgn, end)));
|
accum.Add(XophpArray.New("ignore", XophpArray.New(XophpString.substr(src, bgn, end - bgn))));
|
||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_literal(byte[] src, int bgn, int end) {
|
@Override protected void preprocessToObj_literal(byte[] src, int bgn, int end) {
|
||||||
addLiteral(accum, XophpString.substr(src, bgn, end));
|
addLiteral(accum, XophpString.substr(src, bgn, end - bgn));
|
||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_comment(byte[] src, int bgn, int end) {
|
@Override protected void preprocessToObj_comment(byte[] src, int bgn, int end) {
|
||||||
accum.Add(XophpArray.New("comment", XophpString.substr(src, bgn, end)));
|
accum.Add(XophpArray.New("comment", XophpArray.New(XophpString.substr(src, bgn, end - bgn))));
|
||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_removeLeadingWhitespaceFromEnd(int ws_len) {
|
@Override protected void preprocessToObj_removeLeadingWhitespaceFromEnd(int ws_len) {
|
||||||
int endIndex = accum.Len() - 1;
|
int endIndex = accum.Len() - 1;
|
||||||
if ( ws_len > 0
|
if ( ws_len > 0
|
||||||
&& endIndex >= 0) {
|
&& endIndex >= 0) {
|
||||||
Object itm_obj = accum.Get_at(endIndex);
|
Object itm_obj = accum.Get_at(endIndex);
|
||||||
if (Type_.Eq_by_obj(itm_obj, Bry_.Cls_ref_type)) {
|
if (XophpTypeUtl.is_string(itm_obj)) {
|
||||||
byte[] itm = (byte[])itm_obj;
|
byte[] itm = Bry_.new_u8((String)itm_obj);
|
||||||
if (XophpString.strspn_fwd__space_or_tab(itm, 0, itm.length, itm.length) == ws_len) {
|
if (XophpString.strspn_fwd__space_or_tab(itm, itm.length - ws_len, -1, itm.length) == ws_len) {
|
||||||
accum.Set(endIndex, XophpString.substr(itm, 0, -ws_len));
|
accum.Set(endIndex, XophpString.substr(itm, 0, -ws_len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,19 +71,19 @@ class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum
|
|||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_ext(byte[] src, byte[] name, int atr_bgn, int atr_end, byte[] inner, byte[] close) {
|
@Override protected void preprocessToObj_ext(byte[] src, byte[] name, int atr_bgn, int atr_end, byte[] inner, byte[] close) {
|
||||||
XophpArray children = XophpArray.New();
|
XophpArray children = XophpArray.New();
|
||||||
children.Add(XophpArray.New("name", name));
|
children.Add(XophpArray.New("name", XophpArray.New(name)));
|
||||||
children.Add(XophpArray.New("attr", Bry_.Mid(src, atr_bgn, atr_end)));
|
children.Add(XophpArray.New("attr", XophpArray.New(String_.new_u8(Bry_.Mid(src, atr_bgn, atr_end)))));
|
||||||
if (inner != null)
|
if (inner != null)
|
||||||
children.Add(XophpArray.New("inner", inner));
|
children.Add(XophpArray.New("inner", XophpArray.New(inner)));
|
||||||
if (close != null)
|
if (close != null)
|
||||||
children.Add(XophpArray.New("close", close));
|
children.Add(XophpArray.New("close", XophpArray.New(close)));
|
||||||
accum.Add(XophpArray.New("ext", children));
|
accum.Add(XophpArray.New("ext", children));
|
||||||
}
|
}
|
||||||
@Override protected Xomw_prepro_accum preprocessToObj_heading_init(int count, int heading_index) {
|
@Override protected Xomw_prepro_accum preprocessToObj_heading_init(int count, int heading_index) {
|
||||||
Xomw_prepro_accum__hash rv = new Xomw_prepro_accum__hash();
|
Xomw_prepro_accum__hash rv = new Xomw_prepro_accum__hash(XophpArray.New());
|
||||||
rv.Ary().Add
|
rv.Ary().Add
|
||||||
( XophpArray.New
|
( XophpArray.New
|
||||||
( "possible-h",
|
( "h",
|
||||||
XophpArrayUtl.array_merge
|
XophpArrayUtl.array_merge
|
||||||
( XophpArray.New
|
( XophpArray.New
|
||||||
( XophpArray.New("@level", XophpArray.New(count))
|
( XophpArray.New("@level", XophpArray.New(count))
|
||||||
@ -97,62 +99,57 @@ class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum
|
|||||||
XophpArrayUtl.array_splice(accum, accum.Len(), 0, ((Xomw_prepro_accum__hash)element).Ary());
|
XophpArrayUtl.array_splice(accum, accum.Len(), 0, ((Xomw_prepro_accum__hash)element).Ary());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected Xomw_prepro_accum preprocessToObj_text(Xomw_prepro_accum element_obj, Xomw_prepro_piece piece, byte[] rule_end, int matching_count) {
|
@Override protected Xomw_prepro_accum preprocessToObj_text(XomwPPDStackElement piece, byte[] rule_end, int matching_count) {
|
||||||
Xomw_prepro_accum__hash element = (Xomw_prepro_accum__hash)element_obj;
|
XophpArray array = (XophpArray)((XomwPPDStackElement)piece).breakSyntax(matching_count);
|
||||||
// element = piece.breakSyntax(matchingCount);
|
addLiteral(array, XophpString.str_repeat(String_.new_u8(rule_end), matching_count));
|
||||||
addLiteral(element.Ary(), String_.new_u8(Bry_.Repeat_bry(rule_end, matching_count)));
|
return new Xomw_prepro_accum__hash(array);
|
||||||
return element;
|
|
||||||
}
|
}
|
||||||
@Override protected Xomw_prepro_accum preprocessToObj_xml(Xomw_prepro_piece piece, byte[] name_bry, int max_count, int matching_count) {
|
@Override protected Xomw_prepro_accum preprocessToObj_xml(XomwPPDStackElement piece, byte[] name_bry, int max_count, int matching_count) {
|
||||||
List_adp parts = piece.parts;
|
XophpArray parts = piece.parts;
|
||||||
byte[] title = ((XomwPPDPart_DOM)parts.Get_at(0)).To_bry();
|
Xomw_prepro_accum title = ((XomwPPDPart_Hash)parts.Get_at(0)).Accum();
|
||||||
parts.Del_at(0);
|
parts.Del_at(0);
|
||||||
|
|
||||||
XophpArray children = XophpArray.New();
|
XophpArray children = XophpArray.New();
|
||||||
|
|
||||||
// The invocation is at the start of the line if lineStart is set in
|
// The invocation is at the start of the line if lineStart is set in
|
||||||
// the stack, and all opening brackets are used up.
|
// the stack, and all opening brackets are used up.
|
||||||
if (max_count == matching_count && piece.line_start) { // RELIC:!empty( $piece->lineStart )
|
if (max_count == matching_count && piece.lineStart) { // RELIC:!empty( $piece->lineStart )
|
||||||
children.Add(XophpArray.New("@lineStart", XophpArray.New(1)));
|
children.Add(XophpArray.New("@lineStart", XophpArray.New(1)));
|
||||||
}
|
}
|
||||||
XophpArray titleNode = XophpArray.New("title", title);
|
XophpArray titleNode = XophpArray.New("title", title);
|
||||||
children.Add(titleNode);
|
children.Add(titleNode);
|
||||||
|
|
||||||
// int argIndex = 1;
|
int argIndex = 1;
|
||||||
int parts_len = parts.Len();
|
int parts_len = parts.Len();
|
||||||
for (int j = 0; j < parts_len; j++) {
|
for (int j = 0; j < parts_len; j++) {
|
||||||
XomwPPDPart part = (XomwPPDPart)parts.Get_at(j);
|
XomwPPDPart_Hash part = (XomwPPDPart_Hash)parts.Get_at(j);
|
||||||
|
XophpArray part_out = (XophpArray)part.Accum_hash().Ary();
|
||||||
if (part.eqpos != -1) {
|
if (part.eqpos != -1) {
|
||||||
/*
|
Object equalsNode = part_out.Get_at(part.eqpos);
|
||||||
Object equalsNode = part.Out()[part.eqpos];
|
XophpArray nameNode = XophpArray.New("name" , XophpArrayUtl.array_slice(part_out, 0, part.eqpos));
|
||||||
XophpArray nameNode = XophpArray.New("name" , XophpArrayUtl.array_splice(part.Out(), 0, part.eqpos));
|
XophpArray valueNode = XophpArray.New("value", XophpArrayUtl.array_slice(part_out, part.eqpos + 1));
|
||||||
XophpArray valueNode = XophpArray.New("value", XophpArrayUtl.array_splice(part.Out(), part.eqpos + 1));
|
|
||||||
XophpArray partNode = XophpArray.New("part" , XophpArray.New(nameNode, equalsNode, valueNode));
|
XophpArray partNode = XophpArray.New("part" , XophpArray.New(nameNode, equalsNode, valueNode));
|
||||||
children.Add(partNode);
|
children.Add(partNode);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/*
|
|
||||||
XophpArray nameNode = XophpArray.New("name" , XophpArray.New(XophpArray.New("@index", XophpArray.New(argIndex++))));
|
XophpArray nameNode = XophpArray.New("name" , XophpArray.New(XophpArray.New("@index", XophpArray.New(argIndex++))));
|
||||||
XophpArray valueNode = XophpArray.New("value", part.Out());
|
XophpArray valueNode = XophpArray.New("value", part_out);
|
||||||
XophpArray partNode = XophpArray.New("part" , XophpArray.New(nameNode, valueNode));
|
XophpArray partNode = XophpArray.New("part" , XophpArray.New(nameNode, valueNode));
|
||||||
children.Add(partNode);
|
children.Add(partNode);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// XophpArray element = XophpArray.New(XophpArray.New(name, children));
|
XophpArray element = XophpArray.New(XophpArray.New(String_.new_u8(name_bry), children));
|
||||||
// return new Xomw_prepro_piece__hash(element);
|
return new Xomw_prepro_accum__hash(element);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_add_element(Xomw_prepro_accum element) {
|
@Override protected void preprocessToObj_add_element(Xomw_prepro_accum element) {
|
||||||
XophpArrayUtl.array_splice(accum, accum.Len(), 0, ((Xomw_prepro_accum__hash)element).Ary());
|
XophpArrayUtl.array_splice(accum, accum.Len(), 0, ((Xomw_prepro_accum__hash)element).Ary());
|
||||||
}
|
}
|
||||||
@Override protected void preprocessToObj_equals(XomwPPDStackOld stack) {
|
@Override protected void preprocessToObj_equals(XomwPPDStack stack) {
|
||||||
accum.Add(XophpArray.New("equals", XophpArray.New("=")));
|
accum.Add(XophpArray.New("equals", XophpArray.New("=")));
|
||||||
stack.Get_current_part().eqpos = accum.Len() - 1;
|
stack.getCurrentPart().eqpos = accum.Len() - 1;
|
||||||
}
|
}
|
||||||
@Override protected Object preprocessToObj_term(XomwPPDStackOld stack) {
|
@Override protected Object preprocessToObj_term(XomwPPDStack stack) {
|
||||||
Xomw_prepro_accum__hash stack_accum = (Xomw_prepro_accum__hash)stack.Get_accum();
|
Xomw_prepro_accum__hash stack_accum = (Xomw_prepro_accum__hash)stack.getAccum();
|
||||||
XophpArray stack_ary = stack_accum.Ary();
|
XophpArray stack_ary = stack_accum.Ary();
|
||||||
int len = stack_ary.Len();
|
int len = stack_ary.Len();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
@ -186,15 +183,14 @@ class XomwPreprocessor_Hash extends XomwPreprocessor { private XophpArray accum
|
|||||||
private static void addLiteral(XophpArray accum, byte[] text) {addLiteral(accum, String_.new_u8(text));}
|
private static void addLiteral(XophpArray accum, byte[] text) {addLiteral(accum, String_.new_u8(text));}
|
||||||
private static void addLiteral(XophpArray accum, String text) {
|
private static void addLiteral(XophpArray accum, String text) {
|
||||||
int n = accum.Len();
|
int n = accum.Len();
|
||||||
if (n > 0) {
|
|
||||||
Object itm = accum.Get_at(n - 1);
|
Object itm = accum.Get_at(n - 1);
|
||||||
if (itm != null) {
|
if (n > 0 && XophpTypeUtl.is_string(itm)) {
|
||||||
accum.Set(n - 1, ((String)itm) + text);
|
accum.Set(n - 1, ((String)itm) + text);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
accum.Add(text);
|
accum.Add(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_Hash();}
|
@Override public XomwPreprocessor Make_new(XomwParser parser) {return new XomwPreprocessor_Hash();}
|
||||||
public static final XomwPreprocessor Instance = new XomwPreprocessor_Hash();
|
public static final XomwPreprocessor Instance = new XomwPreprocessor_Hash();
|
||||||
|
@ -220,7 +220,7 @@ public class XomwPreprocessor__tst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class XomwPreprocessor__fxt {
|
class XomwPreprocessor__fxt {
|
||||||
private boolean dom_enabled = Bool_.Y, hash_enabled = Bool_.N;
|
private boolean dom_enabled = Bool_.Y, hash_enabled = Bool_.Y;
|
||||||
private boolean for_inclusion = false;
|
private boolean for_inclusion = false;
|
||||||
public XomwPreprocessor__fxt() {
|
public XomwPreprocessor__fxt() {
|
||||||
}
|
}
|
||||||
@ -248,8 +248,8 @@ class XomwPreprocessor__fxt {
|
|||||||
for (int i = 0; i < list.Len(); i++) {
|
for (int i = 0; i < list.Len(); i++) {
|
||||||
XomwPreprocessor wkr = (XomwPreprocessor)list.Get_at(i);
|
XomwPreprocessor wkr = (XomwPreprocessor)list.Get_at(i);
|
||||||
byte[] src_bry = Bry_.new_u8(src_str);
|
byte[] src_bry = Bry_.new_u8(src_str);
|
||||||
byte[] actl = wkr.preprocessToDbg(src_bry, for_inclusion);
|
String actl = wkr.preprocessToDbg(src_bry, for_inclusion);
|
||||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl), src_str);
|
Tfds.Eq_str_lines(expd, actl, src_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,14 @@ package gplx.xowa.mediawiki.includes.parsers.preprocessors; import gplx.*; impor
|
|||||||
/**
|
/**
|
||||||
* @ingroup Parser
|
* @ingroup Parser
|
||||||
*/
|
*/
|
||||||
// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
|
public class XomwPPDPart_Hash extends XomwPPDPart { private final Xomw_prepro_accum__hash accum = new Xomw_prepro_accum__hash(XophpArray.New());
|
||||||
public class XomwPPDPart_Hash extends XomwPPDPart { // @codingStandardsIgnoreEnd
|
|
||||||
private final Xomw_prepro_accum__hash accum = new Xomw_prepro_accum__hash();
|
|
||||||
public XomwPPDPart_Hash(String output) {super(output);
|
public XomwPPDPart_Hash(String output) {super(output);
|
||||||
if (output != String_.Empty) {
|
if (output != String_.Empty) {
|
||||||
accum.Ary().Add(output);
|
accum.Ary().Add(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override public Xomw_prepro_accum Accum() {return accum;}
|
@Override public Xomw_prepro_accum Accum() {return accum;}
|
||||||
|
public Xomw_prepro_accum__hash Accum_hash() {return (Xomw_prepro_accum__hash)accum;}
|
||||||
@Override public XomwPPDPart Make_new(String val) {
|
@Override public XomwPPDPart Make_new(String val) {
|
||||||
return new XomwPPDPart_Hash(val);
|
return new XomwPPDPart_Hash(val);
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,12 @@ public class XomwPPDStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void push(XomwPPDStackElement data) {
|
public void push(XomwPPDStackElement data) {
|
||||||
if (Type_.Eq_by_obj(data, XomwPPDStackElement.class)) {
|
|
||||||
this.stack.Add(data);
|
this.stack.Add(data);
|
||||||
}
|
// PHP.IGNORE:strong-typing
|
||||||
else {
|
// else {
|
||||||
// $class = this.elementClass;
|
// $class = this.elementClass;
|
||||||
// this.stack[] = new $class($data);
|
// this.stack[] = new $class($data);
|
||||||
}
|
// }
|
||||||
this.top = (XomwPPDStackElement)this.stack.Get_at(this.stack.Count() - 1);
|
this.top = (XomwPPDStackElement)this.stack.Get_at(this.stack.Count() - 1);
|
||||||
this.accum = this.top.getAccum();
|
this.accum = this.top.getAccum();
|
||||||
}
|
}
|
||||||
@ -101,4 +100,11 @@ public class XomwPPDStack {
|
|||||||
return this.top.getFlags();
|
return this.top.getFlags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear() {
|
||||||
|
stack.Clear();
|
||||||
|
accum.Clear();
|
||||||
|
top = null;
|
||||||
|
}
|
||||||
|
public Xomw_prepro_accum Get_root_accum() {return this.rootAccum;}
|
||||||
}
|
}
|
||||||
|
@ -43,31 +43,38 @@ public class XomwPPDStackElement {
|
|||||||
* @var boolean True if the open char appeared at the start of the input line.
|
* @var boolean True if the open char appeared at the start of the input line.
|
||||||
* Not set for headings.
|
* Not set for headings.
|
||||||
*/
|
*/
|
||||||
// public boolean lineStart;
|
public boolean lineStart;
|
||||||
|
|
||||||
public String partClass = "PPDPart";
|
public String partClass = "PPDPart";
|
||||||
|
|
||||||
public XomwPPDStackElement(String open, String close, int count) {
|
public int start_pos;
|
||||||
|
private final XomwPPDPart part_factory;
|
||||||
|
public XomwPPDStackElement(XomwPPDPart part_factory, String open, String close, int count, int start_pos, boolean lineStart) {
|
||||||
this.parts = new XophpArray();
|
this.parts = new XophpArray();
|
||||||
|
|
||||||
this.open = open;
|
this.open = open;
|
||||||
this.close = close;
|
this.close = close;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
|
|
||||||
|
this.part_factory = part_factory;
|
||||||
|
this.start_pos = start_pos;
|
||||||
|
this.lineStart = lineStart;
|
||||||
|
parts.Add(part_factory.Make_new(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Xomw_prepro_accum getAccum() {
|
public Xomw_prepro_accum getAccum() {
|
||||||
return (Xomw_prepro_accum)Get_at(this.parts.Count() - 1);
|
return (Xomw_prepro_accum)Get_at(this.parts.Count() - 1).Accum();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPart(String s) {
|
public void addPart(String s) {
|
||||||
this.parts.Add(Make_part(s));
|
this.parts.Add(Make_part(s));
|
||||||
}
|
}
|
||||||
@gplx.Virtual protected XomwPPDPart Make_part(String s) {
|
@gplx.Virtual protected XomwPPDPart Make_part(String s) {
|
||||||
return new XomwPPDPart_DOM(s);
|
return part_factory.Make_new(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XomwPPDPart getCurrentPart() {
|
public XomwPPDPart getCurrentPart() {
|
||||||
return (XomwPPDPart)this.parts.Get_at(this.parts.Count() - 1);
|
return (XomwPPDPart)Get_at(this.parts.Count() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,10 +96,11 @@ public class XomwPPDStackElement {
|
|||||||
* @param boolean|int $openingCount
|
* @param boolean|int $openingCount
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@gplx.Virtual public String breakSyntax(int openingCount) {
|
@gplx.Virtual public Object breakSyntax(int openingCount) {
|
||||||
Char_bfr bfr = new Char_bfr(16);
|
Char_bfr bfr = new Char_bfr(16);
|
||||||
if (String_.Eq(this.open, "\n")) {
|
if (String_.Eq(this.open, "\n")) {
|
||||||
bfr.Add_bry(Get_at(0).To_bry());
|
XomwPPDPart_DOM part_0 = (XomwPPDPart_DOM)Get_at(0);
|
||||||
|
bfr.Add_bry(part_0.To_bry());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (openingCount == -1) {
|
if (openingCount == -1) {
|
||||||
@ -102,7 +110,7 @@ public class XomwPPDStackElement {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
int parts_len = parts.Len();
|
int parts_len = parts.Len();
|
||||||
for (int i = 0; i < parts_len; i++) {
|
for (int i = 0; i < parts_len; i++) {
|
||||||
XomwPPDPart_DOM part = Get_at(i);
|
XomwPPDPart_DOM part = (XomwPPDPart_DOM)Get_at(i);
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@ -113,63 +121,12 @@ public class XomwPPDStackElement {
|
|||||||
}
|
}
|
||||||
return bfr.To_str_and_clear();
|
return bfr.To_str_and_clear();
|
||||||
}
|
}
|
||||||
private XomwPPDPart_DOM Get_at(int i) {
|
public void Parts__renew() {
|
||||||
return (XomwPPDPart_DOM)this.parts.Get_at(i);
|
parts.Clear();
|
||||||
|
this.addPart("");
|
||||||
}
|
}
|
||||||
}
|
private XomwPPDPart Get_at(int i) {
|
||||||
// MW.FILE:Preprocessor_Hash
|
return (XomwPPDPart)this.parts.Get_at(i);
|
||||||
/**
|
|
||||||
* @ingroup Parser
|
|
||||||
*/
|
|
||||||
class XomwPPDStackElement_Hash extends XomwPPDStackElement { public XomwPPDStackElement_Hash(String open, String close, int count) {super(open, close, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private XomwPPDPart_Hash Get_at_hash(int i) {
|
|
||||||
return (XomwPPDPart_Hash)this.parts.Get_at(i);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Get the accumulator that would result if the close is not found.
|
|
||||||
*
|
|
||||||
* @param int|boolean $openingCount
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public XophpArray breakSyntax_Hash(int openingCount) {
|
|
||||||
XophpArray accum = null;
|
|
||||||
if (String_.Eq(this.open, "\n")) {
|
|
||||||
accum = (XophpArray)Get_at_hash(0).Accum();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (openingCount == -1) {
|
|
||||||
openingCount = this.count;
|
|
||||||
}
|
|
||||||
accum = XophpArray.New(XophpString.str_repeat(this.open, openingCount));
|
|
||||||
int lastIndex = 0;
|
|
||||||
boolean first = true;
|
|
||||||
int parts_len = parts.Len();
|
|
||||||
for (int i = 0; i < parts_len; i++) {
|
|
||||||
XomwPPDPart_Hash part = Get_at_hash(i);
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else if (XophpTypeUtl.is_string(accum.Get_at_str(lastIndex))) {
|
|
||||||
accum.Set(lastIndex, accum.Get_at_str(lastIndex) + "|");
|
|
||||||
} else {
|
|
||||||
accum.Set(++lastIndex, "|");
|
|
||||||
}
|
|
||||||
|
|
||||||
XophpArray part_out = ((Xomw_prepro_accum__hash)part.Accum()).Ary();
|
|
||||||
int part_out_len = part_out.Len();
|
|
||||||
for (int j = 0; j < part_out_len; j++) {
|
|
||||||
Object node = part_out.Get_at(j);
|
|
||||||
if (XophpTypeUtl.is_string(node) && XophpTypeUtl.is_string(accum.Get_at(lastIndex))) {
|
|
||||||
accum.Set(lastIndex, accum.Get_at_str(lastIndex) + (String)node);
|
|
||||||
} else {
|
|
||||||
accum.Set(++lastIndex, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return accum;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///**
|
///**
|
||||||
|
@ -20,9 +20,9 @@ public class XomwPPDStackElementFlags {
|
|||||||
this.findEquals = findEquals;
|
this.findEquals = findEquals;
|
||||||
this.inHeading = inHeading;
|
this.inHeading = inHeading;
|
||||||
}
|
}
|
||||||
public boolean FindPipe() {return findPipe;} private final boolean findPipe;
|
public final boolean findPipe;
|
||||||
public boolean FindEquals() {return findEquals;} private final boolean findEquals;
|
public final boolean findEquals;
|
||||||
public boolean InHeading() {return inHeading;} private final boolean inHeading;
|
public final boolean inHeading;
|
||||||
|
|
||||||
public static final XomwPPDStackElementFlags Empty = new XomwPPDStackElementFlags(false, false, false);
|
public static final XomwPPDStackElementFlags Empty = new XomwPPDStackElementFlags(false, false, false);
|
||||||
}
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
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.*;
|
||||||
|
// MW.FILE:Preprocessor_Hash
|
||||||
|
/**
|
||||||
|
* @ingroup Parser
|
||||||
|
*/
|
||||||
|
public class XomwPPDStackElement_Hash extends XomwPPDStackElement { public XomwPPDStackElement_Hash(XomwPPDPart part_factory, String open, String close, int count, int start_pos, boolean lineStart) {super(part_factory, open, close, count, start_pos, lineStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private XomwPPDPart_Hash Get_at_hash(int i) {
|
||||||
|
return (XomwPPDPart_Hash)this.parts.Get_at(i);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Get the accumulator that would result if the close is not found.
|
||||||
|
*
|
||||||
|
* @param int|boolean $openingCount
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
@Override public Object breakSyntax(int openingCount) {
|
||||||
|
XophpArray accum = null;
|
||||||
|
if (String_.Eq(this.open, "\n")) {
|
||||||
|
accum = (XophpArray)Get_at_hash(0).Accum();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (openingCount == -1) {
|
||||||
|
openingCount = this.count;
|
||||||
|
}
|
||||||
|
accum = XophpArray.New(XophpString.str_repeat(this.open, openingCount));
|
||||||
|
int lastIndex = 0;
|
||||||
|
boolean first = true;
|
||||||
|
int parts_len = parts.Len();
|
||||||
|
for (int i = 0; i < parts_len; i++) {
|
||||||
|
XomwPPDPart_Hash part = Get_at_hash(i);
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else if (XophpTypeUtl.is_string(accum.Get_at_str(lastIndex))) {
|
||||||
|
accum.Set(lastIndex, accum.Get_at_str(lastIndex) + "|");
|
||||||
|
} else {
|
||||||
|
accum.Set(++lastIndex, "|");
|
||||||
|
}
|
||||||
|
|
||||||
|
XophpArray part_out = ((Xomw_prepro_accum__hash)part.Accum()).Ary();
|
||||||
|
int part_out_len = part_out.Len();
|
||||||
|
for (int j = 0; j < part_out_len; j++) {
|
||||||
|
Object node = part_out.Get_at(j);
|
||||||
|
if (XophpTypeUtl.is_string(node) && XophpTypeUtl.is_string(accum.Get_at(lastIndex))) {
|
||||||
|
accum.Set(lastIndex, accum.Get_at_str(lastIndex) + (String)node);
|
||||||
|
} else {
|
||||||
|
accum.Set(++lastIndex, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return accum;
|
||||||
|
}
|
||||||
|
}
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
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.*;
|
|
||||||
// MW.FILE:Preprocessor_DOM
|
|
||||||
/**
|
|
||||||
* Stack class to help Preprocessor::preprocessToObj()
|
|
||||||
* @ingroup Parser
|
|
||||||
*/
|
|
||||||
public class XomwPPDStackOld {
|
|
||||||
public final List_adp stack = List_adp_.New();
|
|
||||||
public Xomw_prepro_piece top;
|
|
||||||
private final Xomw_prepro_flags flags = new Xomw_prepro_flags();
|
|
||||||
protected Xomw_prepro_accum root_accum;
|
|
||||||
protected Xomw_prepro_accum accum;
|
|
||||||
|
|
||||||
public XomwPPDStackOld(Xomw_prepro_accum prototype) {
|
|
||||||
root_accum = prototype.Make_new();
|
|
||||||
accum = root_accum;
|
|
||||||
}
|
|
||||||
public void Clear() {
|
|
||||||
stack.Clear();
|
|
||||||
accum.Clear();
|
|
||||||
top = null;
|
|
||||||
}
|
|
||||||
public int Count() {return stack.Len();}
|
|
||||||
|
|
||||||
public Xomw_prepro_accum Get_accum() {return accum;}
|
|
||||||
public Xomw_prepro_accum Get_root_accum() {return root_accum;}
|
|
||||||
|
|
||||||
public XomwPPDPart Get_current_part() {
|
|
||||||
if (top == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return top.Get_current_part();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Push(Xomw_prepro_piece item) {
|
|
||||||
stack.Add(item);
|
|
||||||
this.top = (Xomw_prepro_piece)stack.Get_at(stack.Len() - 1);
|
|
||||||
accum = top.Get_accum();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Xomw_prepro_piece Pop() {
|
|
||||||
int len = stack.Count();
|
|
||||||
if (len == 0) {
|
|
||||||
throw Err_.new_wo_type("XomwPPDStackOld: no elements remaining");
|
|
||||||
}
|
|
||||||
|
|
||||||
Xomw_prepro_piece rv = (Xomw_prepro_piece)stack.Get_at(len - 1);
|
|
||||||
stack.Del_at(len - 1);
|
|
||||||
len--;
|
|
||||||
|
|
||||||
if (len > 0) {
|
|
||||||
this.top = (Xomw_prepro_piece)stack.Get_at(stack.Len() - 1);
|
|
||||||
this.accum = top.Get_accum();
|
|
||||||
} else {
|
|
||||||
this.top = null;
|
|
||||||
this.accum = root_accum;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add_part(byte[] bry) {
|
|
||||||
top.Add_part(bry);
|
|
||||||
accum = top.Get_accum();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Xomw_prepro_flags Get_flags() {
|
|
||||||
if (stack.Count() == 0) {
|
|
||||||
flags.findEquals = false;
|
|
||||||
flags.findPipe = false;
|
|
||||||
flags.inHeading = false;
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
top.Set_flags(flags);
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
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.*;
|
|
||||||
public class XomwPPDStackOld_Hash extends XomwPPDStackOld { public XomwPPDStackOld_Hash(Xomw_prepro_accum prototype) {super(prototype);
|
|
||||||
this.root_accum = prototype.Make_new();
|
|
||||||
this.accum = root_accum;
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,12 +30,15 @@ public class XomwPPNode_Hash_Attr extends XomwPPNode { public String name, valu
|
|||||||
* @param integer $index
|
* @param integer $index
|
||||||
*/
|
*/
|
||||||
public XomwPPNode_Hash_Attr(XophpArray store, int index) {
|
public XomwPPNode_Hash_Attr(XophpArray store, int index) {
|
||||||
// XophpArray descriptor = (XophpArray)store.Get_at_val(index);
|
XophpArray descriptor = (XophpArray)store.Get_at(index);
|
||||||
// if (!String_.Eq(XophpArrayUtl.Get_nest_val(XomwPPNode_Hash_Tree.NAME, 0), '@')) {
|
String descriptor_name = descriptor.Get_at_str(XomwPPNode_Hash_Tree.NAME);
|
||||||
// throw Err_.new_wo_type("XomwPPNode_Hash_Attr.CTOR: invalid name in attribute descriptor");
|
if (!(String_.CharAt(descriptor_name, 0) == '@')) {
|
||||||
// }
|
throw Err_.new_wo_type("XomwPPNode_Hash_Attr.CTOR: invalid name in attribute descriptor");
|
||||||
// this.name = substr($descriptor[PPNode_Hash_Tree::NAME], 1);
|
}
|
||||||
// this.value = $descriptor[PPNode_Hash_Tree::CHILDREN][0];
|
this.name = String_.new_u8(XophpString.substr(Bry_.new_u8(descriptor_name), 1));
|
||||||
|
XophpArray descriptor_children = (XophpArray)descriptor.Get_at(XomwPPNode_Hash_Tree.CHILDREN);
|
||||||
|
Object value_obj = descriptor_children.Get_at(0);
|
||||||
|
this.value = Type_.Eq_by_obj(value_obj, byte[].class) ? String_.new_u8((byte[])value_obj): value_obj.toString();
|
||||||
this.store = store;
|
this.store = store;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,13 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
|||||||
* The offset of the name within descriptors, used in some places for
|
* The offset of the name within descriptors, used in some places for
|
||||||
* readability.
|
* readability.
|
||||||
*/
|
*/
|
||||||
private static final int NAME = 0;
|
public static final int NAME = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The offset of the child list within descriptors, used in some places for
|
* The offset of the child list within descriptors, used in some places for
|
||||||
* readability.
|
* readability.
|
||||||
*/
|
*/
|
||||||
// private static final int CHILDREN = 1;
|
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
|
||||||
@ -62,7 +62,13 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
|||||||
|
|
||||||
XophpArray list = this.store.Get_at_ary(index);
|
XophpArray list = this.store.Get_at_ary(index);
|
||||||
this.name = list.Get_at_str(0);
|
this.name = list.Get_at_str(0);
|
||||||
this.rawChildren = ((Xomw_prepro_accum__hash)(list.Get_at(1))).Ary();
|
Object rawChildrenObj = list.Get_at(1);
|
||||||
|
if (XophpTypeUtl.To_type_id(rawChildrenObj) == Type_ids_.Id__array) {
|
||||||
|
this.rawChildren = (XophpArray)rawChildrenObj;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.rawChildren = ((Xomw_prepro_accum__hash)rawChildrenObj).Ary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,12 +91,12 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
|||||||
}
|
}
|
||||||
else if (type.is_array()) {
|
else if (type.is_array()) {
|
||||||
XophpArray descriptor_array = (XophpArray)descriptor;
|
XophpArray descriptor_array = (XophpArray)descriptor;
|
||||||
XophpArray name_array = (XophpArray)(descriptor_array.Get_by(NAME));
|
String name = (String)(descriptor_array.Get_by(NAME));
|
||||||
if (String_.Has_at_bgn(name_array.Get_at_str(0), "@")) {
|
if (String_.CharAt(name, 0) == '@') {
|
||||||
return new XomwPPNode_Hash_Attr(store, index);
|
return new XomwPPNode_Hash_Attr(store, index);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new XomwPPNode_Hash_Text(store, index);
|
return new XomwPPNode_Hash_Tree(store, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -107,17 +113,22 @@ public class XomwPPNode_Hash_Tree extends XomwPPNode { public final String na
|
|||||||
for (XomwPPNode node = this.getFirstChild(); node != null; node = node.getNextSibling()) {
|
for (XomwPPNode node = this.getFirstChild(); node != null; node = node.getNextSibling()) {
|
||||||
if (Type_.Eq_by_obj(node, XomwPPNode_Hash_Attr.class)) {
|
if (Type_.Eq_by_obj(node, XomwPPNode_Hash_Attr.class)) {
|
||||||
XomwPPNode_Hash_Attr node_attr = (XomwPPNode_Hash_Attr)node;
|
XomwPPNode_Hash_Attr node_attr = (XomwPPNode_Hash_Attr)node;
|
||||||
attribs += " " + node_attr.name + "=\"" + Bry_.Escape_html(Bry_.new_u8(node_attr.value)) + "\"";
|
attribs += " " + node_attr.name + "=\"" + String_.new_u8(Bry_.Escape_html(Bry_.new_u8(node_attr.value))) + "\"";
|
||||||
} else {
|
} else {
|
||||||
inner += node.toString();
|
inner += node.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (String_.Eq(inner, "")) {
|
if (String_.Eq(inner, "") && String_.Eq(name, "name")) {
|
||||||
return "<" + this.name + attribs + " />";
|
return "<" + this.name + attribs + " />";
|
||||||
} else {
|
} else {
|
||||||
|
if (String_.Eq(name, "equals")) {
|
||||||
|
return inner;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return "<" + this.name + attribs + ">" + inner + "</" + this.name + ">";
|
return "<" + this.name + attribs + ">" + inner + "</" + this.name + ">";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return PPNode_Hash_Array
|
// * @return PPNode_Hash_Array
|
||||||
|
@ -15,11 +15,13 @@ 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.*;
|
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.*;
|
||||||
public class Xomw_prepro_accum__hash implements Xomw_prepro_accum {
|
public class Xomw_prepro_accum__hash implements Xomw_prepro_accum {
|
||||||
public Xomw_prepro_accum__hash() {
|
private final XophpArray ary;
|
||||||
|
public Xomw_prepro_accum__hash(XophpArray ary) {
|
||||||
|
this.ary = ary;
|
||||||
}
|
}
|
||||||
public XophpArray Ary() {return ary;} private final XophpArray ary = new XophpArray();
|
public XophpArray Ary() {return ary;}
|
||||||
public void Clear() {ary.Clear();}
|
public void Clear() {ary.Clear();}
|
||||||
|
|
||||||
public static final Xomw_prepro_accum__hash Instance = new Xomw_prepro_accum__hash();
|
public static final Xomw_prepro_accum__hash Instance = new Xomw_prepro_accum__hash(null);
|
||||||
public Xomw_prepro_accum Make_new() {return new Xomw_prepro_accum__hash();}
|
public Xomw_prepro_accum Make_new() {return new Xomw_prepro_accum__hash(XophpArray.New());}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user