|
@@ -2,13 +2,11 @@ package org.openzen.zenscript.scriptingexample;
|
2
|
2
|
|
3
|
3
|
import java.io.File;
|
4
|
4
|
import java.io.IOException;
|
5
|
|
-import java.util.Collections;
|
6
|
5
|
import java.util.HashMap;
|
7
|
6
|
import java.util.Map;
|
8
|
7
|
import java.util.Optional;
|
9
|
8
|
import org.openzen.zencode.java.JavaNativeModule;
|
10
|
9
|
import org.openzen.zencode.java.ScriptingEngine;
|
11
|
|
-import org.openzen.zencode.shared.CodePosition;
|
12
|
10
|
import org.openzen.zencode.shared.CompileException;
|
13
|
11
|
import org.openzen.zencode.shared.FileSourceFile;
|
14
|
12
|
import org.openzen.zencode.shared.SourceFile;
|
|
@@ -16,15 +14,11 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
|
16
|
14
|
import org.openzen.zenscript.codemodel.SemanticModule;
|
17
|
15
|
import org.openzen.zenscript.codemodel.type.StringTypeID;
|
18
|
16
|
import org.openzen.zenscript.lexer.ParseException;
|
19
|
|
-import org.openzen.zenscript.lexer.ZSToken;
|
20
|
|
-import org.openzen.zenscript.lexer.ZSTokenParser;
|
21
|
|
-import org.openzen.zenscript.lexer.ZSTokenType;
|
22
|
17
|
import org.openzen.zenscript.parser.BracketExpressionParser;
|
23
|
|
-import org.openzen.zenscript.parser.expression.ParsedExpression;
|
24
|
|
-import org.openzen.zenscript.parser.expression.ParsedExpressionString;
|
|
18
|
+import org.openzen.zenscript.parser.SimpleBracketParser;
|
25
|
19
|
|
26
|
20
|
public class Main {
|
27
|
|
- public static void main(String[] args) throws CompileException, ParseException, IOException {
|
|
21
|
+ public static void main(String[] args) throws CompileException, ParseException, IOException, NoSuchMethodException {
|
28
|
22
|
ScriptingEngine scriptingEngine = new ScriptingEngine();
|
29
|
23
|
scriptingEngine.debug = true;
|
30
|
24
|
|
|
@@ -39,8 +33,9 @@ public class Main {
|
39
|
33
|
for (int i = 0; i < inputFiles.length; i++)
|
40
|
34
|
sourceFiles[i] = new FileSourceFile(inputFiles[i].getName(), inputFiles[i]);
|
41
|
35
|
|
|
36
|
+ BracketExpressionParser bracketParser = new SimpleBracketParser(scriptingEngine.registry, example.loadStaticMethod(Globals.class.getMethod("bracket", String.class)));
|
42
|
37
|
FunctionParameter parameter = new FunctionParameter(scriptingEngine.registry.getArray(StringTypeID.AUTO, 1).stored(), "args");
|
43
|
|
- SemanticModule scripts = scriptingEngine.createScriptedModule("script", sourceFiles, new TestBracketParser(), new FunctionParameter[] { parameter });
|
|
38
|
+ SemanticModule scripts = scriptingEngine.createScriptedModule("script", sourceFiles, bracketParser, new FunctionParameter[] { parameter });
|
44
|
39
|
if (!scripts.isValid())
|
45
|
40
|
return;
|
46
|
41
|
|
|
@@ -50,18 +45,4 @@ public class Main {
|
50
|
45
|
scriptArgs.put(parameter, new String[] { "hello", "world", "example" });
|
51
|
46
|
scriptingEngine.run(scriptArgs);
|
52
|
47
|
}
|
53
|
|
-
|
54
|
|
- private static class TestBracketParser implements BracketExpressionParser {
|
55
|
|
- @Override
|
56
|
|
- public ParsedExpression parse(CodePosition position, ZSTokenParser tokens) throws ParseException {
|
57
|
|
- StringBuilder result = new StringBuilder();
|
58
|
|
- while (tokens.optional(ZSTokenType.T_GREATER) == null) {
|
59
|
|
- ZSToken token = tokens.next();
|
60
|
|
- result.append(token.content);
|
61
|
|
- result.append(tokens.getLastWhitespace());
|
62
|
|
- }
|
63
|
|
-
|
64
|
|
- return new ParsedExpressionString(position.until(tokens.getPosition()), result.toString(), false);
|
65
|
|
- }
|
66
|
|
- }
|
67
|
48
|
}
|