Skip to content

Commit 3fa06d6

Browse files
committed
improved handling of magicword int
added support of mediawiki localization files for magicword int
1 parent 43da51e commit 3fa06d6

12 files changed

Lines changed: 766 additions & 4 deletions

File tree

info/bliki/extensions/scribunto/engine/lua/ScribuntoLuaEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public LuaValue call(LuaValue frameId, LuaValue function, LuaValue args) {
333333
if (mw != null) {
334334
final LuaTable arguments = args.checktable();
335335
final String argument = arguments.get(1).checkjstring();
336-
final String processed = MagicWords.evaluate(mw, argument, wp.getPagename(), wp.getRevision());
336+
final String processed = MagicWords.evaluate(mw, argument, wp);
337337
return processed == null ? NIL : toLuaString(processed);
338338
} else {
339339
System.out.println("unknown name:" + name);

json/JSONArray.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
License Information, 2023 Livio (javalc6)
3+
4+
Feel free to modify, re-use this software, please give appropriate
5+
credit by referencing this Github repository.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
IMPORTANT NOTICE
18+
Note that this software is freeware and it is not designed, licensed or
19+
intended for use in mission critical, life support and military purposes.
20+
The use of this software is at the risk of the user.
21+
22+
DO NOT USE THIS SOFTWARE IF YOU DON'T AGREE WITH STATED CONDITIONS.
23+
*/
24+
package json;
25+
import java.math.BigDecimal;
26+
import java.util.ArrayList;
27+
import java.util.LinkedHashMap;
28+
/* JSONArray holds a JSON array
29+
30+
array ::= '[' [ value ( ',' value )* ] ']'
31+
32+
int size() returns number of elements
33+
JSONValue get(idx) returns element at index idx
34+
Object toJava();//return Java value
35+
String toString();//return JSON value
36+
boolean equals(Object o)//check equal
37+
*/
38+
final public class JSONArray extends JSONValue {
39+
final ArrayList<JSONValue> value = new ArrayList<>();
40+
41+
public JSONArray(ArrayList<Object> val) {//Java oriented constructor
42+
for (Object element: val) {
43+
if (element == null)
44+
value.add(null);
45+
else if (element instanceof Boolean) {
46+
value.add(new JSONBoolean((Boolean) element));
47+
} else if (element instanceof BigDecimal) {
48+
value.add(new JSONNumber((BigDecimal) element));
49+
} else if (element instanceof String) {
50+
try {
51+
value.add(new JSONString((String) element, false));
52+
} catch (JSONException je) {
53+
//never happen
54+
}
55+
} else if (element instanceof ArrayList) {
56+
value.add(new JSONArray((ArrayList<Object>) element));
57+
} else if (element instanceof LinkedHashMap) {
58+
value.add(new JSONObject((LinkedHashMap<String, Object>) element));
59+
}
60+
}
61+
}
62+
63+
public int size() {
64+
return value.size();
65+
}
66+
67+
public JSONValue get(int idx) {
68+
return value.get(idx);
69+
}
70+
71+
public JSONArray(String str) throws JSONException {//constructor parsing a string representing a JSON array
72+
Scanner scanner = new Scanner(str);
73+
_parse(scanner);
74+
if (!scanner.eos()) throw new JSONException("parsing error due to unexpected trailing characters");
75+
}
76+
77+
public JSONArray(Scanner scanner) throws JSONException {//constructor using Scanner, note that parsing stops after a json value is found, even if extra characters remain in scanner
78+
_parse(scanner);
79+
}
80+
81+
private void _parse(Scanner scanner) throws JSONException {
82+
Character ch = scanner.getChar("[", true, true);
83+
while (((ch = scanner.getChar(true, true)) != null) && ((ch = scanner.getChar("]", true, false)) == null)) {
84+
value.add(JSONValue.parse(scanner));
85+
ch = scanner.getChar(",]", true, true);
86+
if (ch == ']')
87+
break;
88+
}
89+
if (ch == null) throw new JSONException("parsing error, expecting ]");
90+
}
91+
92+
public Object toJava() {
93+
ArrayList<Object> result = new ArrayList<>();
94+
for (JSONValue element: value) {
95+
result.add(element == null ? "null" : element.toJava());
96+
}
97+
return result;
98+
}
99+
100+
public String toString() {
101+
StringBuilder sb = new StringBuilder().append('[');
102+
boolean first = true;
103+
for (JSONValue element: value) {
104+
if (first)
105+
first = false;
106+
else sb.append(',');
107+
sb.append(element == null ? "null" : element.toString());
108+
}
109+
sb.append(']');
110+
return sb.toString();
111+
}
112+
113+
}

json/JSONBoolean.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
License Information, 2023 Livio (javalc6)
3+
4+
Feel free to modify, re-use this software, please give appropriate
5+
credit by referencing this Github repository.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
IMPORTANT NOTICE
18+
Note that this software is freeware and it is not designed, licensed or
19+
intended for use in mission critical, life support and military purposes.
20+
The use of this software is at the risk of the user.
21+
22+
DO NOT USE THIS SOFTWARE IF YOU DON'T AGREE WITH STATED CONDITIONS.
23+
*/
24+
package json;
25+
26+
/* JSONBoolean holds a JSON boolean
27+
28+
booelan = 'false' | 'true'
29+
30+
*/
31+
final public class JSONBoolean extends JSONValue {
32+
final boolean value;
33+
34+
public JSONBoolean(boolean val) {//Java oriented constructor
35+
value = val;
36+
}
37+
38+
public Object toJava() {
39+
return value;
40+
}
41+
42+
public String toString() {
43+
return value ? "true" : "false";
44+
}
45+
46+
}

json/JSONException.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package json;
2+
3+
public final class JSONException extends Exception {
4+
public JSONException(Exception e) {
5+
super(e);
6+
}
7+
8+
public JSONException(String s) {
9+
super(s);
10+
}
11+
}

json/JSONNumber.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
License Information, 2023 Livio (javalc6)
3+
4+
Feel free to modify, re-use this software, please give appropriate
5+
credit by referencing this Github repository.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
IMPORTANT NOTICE
18+
Note that this software is freeware and it is not designed, licensed or
19+
intended for use in mission critical, life support and military purposes.
20+
The use of this software is at the risk of the user.
21+
22+
DO NOT USE THIS SOFTWARE IF YOU DON'T AGREE WITH STATED CONDITIONS.
23+
*/
24+
package json;
25+
import java.math.BigDecimal;
26+
27+
/* JSONNumber holds a JSON number
28+
29+
number ::= [ '-' ] int [ frac ] [ exp ]
30+
int ::= '0' | ( digit1-9 digit* )
31+
frac ::= '.' digit+
32+
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
33+
exp ::= ('e' | 'E') [ '+' | '-' ] digit+
34+
35+
Object toJava();//return Java value
36+
String toString();//return JSON value
37+
boolean equals(Object o)//check equal
38+
*/
39+
final public class JSONNumber extends JSONValue {
40+
BigDecimal value;
41+
42+
public JSONNumber(BigDecimal val) {//Java oriented constructor
43+
value = val;
44+
}
45+
46+
public JSONNumber(String str) throws JSONException {//constructor parsing a string representing a JSON number
47+
Scanner scanner = new Scanner(str);
48+
_parse(scanner);
49+
if (!scanner.eos()) throw new JSONException("parsing error due to unexpected trailing characters");
50+
}
51+
52+
public JSONNumber(Scanner scanner) throws JSONException {//constructor using Scanner, note that parsing stops after a json value is found, even if extra characters remain in scanner
53+
_parse(scanner);
54+
}
55+
56+
private void _parse(Scanner scanner) throws JSONException {
57+
StringBuilder sb = new StringBuilder();
58+
Character ch = scanner.getChar("-0123456789", true, true);
59+
if (ch == '-') {
60+
sb.append(ch);
61+
ch = scanner.getChar("0123456789", false, true);
62+
}
63+
if (ch == '0') {
64+
sb.append(ch);
65+
} else if (ch > '0' && ch <= '9') {
66+
sb.append(ch);
67+
while ((ch = scanner.getChar("0123456789", false, false)) != null) {
68+
sb.append(ch);
69+
}
70+
}
71+
72+
ch = scanner.getChar(".eE", false, false);
73+
if ((ch != null) && ch == '.') {
74+
int decimals = 0;
75+
sb.append(ch);
76+
while ((ch = scanner.getChar("0123456789", false, false)) != null) {
77+
decimals++;
78+
sb.append(ch);
79+
}
80+
if (decimals == 0) throw new JSONException("parsing error");
81+
ch = scanner.getChar("eE", false, false);
82+
}
83+
if (ch != null) {//if ch != null then ch is either 'e' or 'E'
84+
sb.append(ch);
85+
ch = scanner.getChar("+-", false, false);
86+
if (ch != null)
87+
sb.append(ch);
88+
boolean first = true;
89+
while ((ch = scanner.getChar("0123456789", false, first)) != null) {
90+
sb.append(ch);
91+
first = false;
92+
}
93+
}
94+
value = new BigDecimal(sb.toString());
95+
}
96+
97+
public Object toJava() {
98+
return value;
99+
}
100+
101+
public String toString() {
102+
return value.toString();
103+
}
104+
}

0 commit comments

Comments
 (0)