Search in sources :

Example 1 with Placeholder

use of io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder in project TriggerReactor by wysohn.

the class TriggerTest method testSimpleIf.

@Test
public void testSimpleIf() throws Exception {
    Charset charset = Charset.forName("UTF-8");
    String text = "x = 4.0;" + "IF x > 0.0;" + "    #TEST \"pass\";" + "ENDIF;";
    Lexer lexer = new Lexer(text, charset);
    Parser parser = new Parser(lexer);
    Node root = parser.parse();
    Map<String, Executor> executorMap = new HashMap<>();
    executorMap.put("TEST", new Executor() {

        @Override
        protected Integer execute(boolean sync, Object context, Object... args) throws Exception {
            Assert.assertEquals("pass", args[0]);
            return null;
        }
    });
    Map<String, Placeholder> placeholderMap = new HashMap<>();
    Interpreter interpreter = new Interpreter(root, executorMap, placeholderMap, new HashMap<String, Object>(), new HashMap<>(), new CommonFunctions(null));
    interpreter.startWithContext(null);
}
Also used : Placeholder(io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) HashMap(java.util.HashMap) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Charset(java.nio.charset.Charset) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser) Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Executor(io.github.wysohn.triggerreactor.core.script.interpreter.Executor) CommonFunctions(io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.CommonFunctions) Test(org.junit.Test)

Example 2 with Placeholder

use of io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder in project TriggerReactor by wysohn.

the class TriggerTest method testNestedIf.

@Test
public void testNestedIf() throws Exception {
    Charset charset = Charset.forName("UTF-8");
    String text = "x = 4.0;" + "IF x < 0.0;" + "    #TEST \"no\";" + "ELSEIF x > 0.0;" + "    #TEST \"pass\";" + "ELSE;" + "    #TEST \"no\";" + "ENDIF;";
    Lexer lexer = new Lexer(text, charset);
    Parser parser = new Parser(lexer);
    Node root = parser.parse();
    Map<String, Executor> executorMap = new HashMap<>();
    executorMap.put("TEST", new Executor() {

        @Override
        protected Integer execute(boolean sync, Object context, Object... args) throws Exception {
            Assert.assertEquals("pass", args[0]);
            return null;
        }
    });
    Map<String, Placeholder> placeholderMap = new HashMap<>();
    Interpreter interpreter = new Interpreter(root, executorMap, placeholderMap, new HashMap<String, Object>(), new HashMap<>(), new CommonFunctions(null));
    interpreter.startWithContext(null);
}
Also used : Placeholder(io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) HashMap(java.util.HashMap) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Charset(java.nio.charset.Charset) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser) Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Executor(io.github.wysohn.triggerreactor.core.script.interpreter.Executor) CommonFunctions(io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.CommonFunctions) Test(org.junit.Test)

Example 3 with Placeholder

use of io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder in project TriggerReactor by wysohn.

the class TriggerTest method testIfWithElse.

@Test
public void testIfWithElse() throws Exception {
    Charset charset = Charset.forName("UTF-8");
    String text = "x = 4.0;" + "IF x < 0.0;" + "    #TEST \"no\";" + "ELSE;" + "    #TEST \"pass\";" + "ENDIF;";
    Lexer lexer = new Lexer(text, charset);
    Parser parser = new Parser(lexer);
    Node root = parser.parse();
    Map<String, Executor> executorMap = new HashMap<>();
    executorMap.put("TEST", new Executor() {

        @Override
        protected Integer execute(boolean sync, Object context, Object... args) throws Exception {
            Assert.assertEquals("pass", args[0]);
            return null;
        }
    });
    Map<String, Placeholder> placeholderMap = new HashMap<>();
    Interpreter interpreter = new Interpreter(root, executorMap, placeholderMap, new HashMap<String, Object>(), new HashMap<>(), new CommonFunctions(null));
    interpreter.startWithContext(null);
}
Also used : Placeholder(io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) HashMap(java.util.HashMap) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Charset(java.nio.charset.Charset) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser) Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Executor(io.github.wysohn.triggerreactor.core.script.interpreter.Executor) CommonFunctions(io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.CommonFunctions) Test(org.junit.Test)

Example 4 with Placeholder

use of io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder in project TriggerReactor by wysohn.

the class TriggerTest method testNestedIf2.

@Test
public void testNestedIf2() throws Exception {
    Charset charset = Charset.forName("UTF-8");
    String text = "x = 4.0;" + "IF x < 0.0;" + "    #TEST \"no\";" + "ELSEIF x < -5.0;" + "    #TEST \"no\";" + "ELSE;" + "    #TEST \"pass\";" + "ENDIF;";
    Lexer lexer = new Lexer(text, charset);
    Parser parser = new Parser(lexer);
    Node root = parser.parse();
    Map<String, Executor> executorMap = new HashMap<>();
    executorMap.put("TEST", new Executor() {

        @Override
        protected Integer execute(boolean sync, Object context, Object... args) throws Exception {
            Assert.assertEquals("pass", args[0]);
            return null;
        }
    });
    Map<String, Placeholder> placeholderMap = new HashMap<>();
    Interpreter interpreter = new Interpreter(root, executorMap, placeholderMap, new HashMap<String, Object>(), new HashMap<>(), new CommonFunctions(null));
    interpreter.startWithContext(null);
}
Also used : Placeholder(io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) HashMap(java.util.HashMap) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Charset(java.nio.charset.Charset) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser) Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Executor(io.github.wysohn.triggerreactor.core.script.interpreter.Executor) CommonFunctions(io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.CommonFunctions) Test(org.junit.Test)

Example 5 with Placeholder

use of io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder in project TriggerReactor by wysohn.

the class TriggerTest method testNestedIfNoElse.

@Test
public void testNestedIfNoElse() throws Exception {
    Charset charset = Charset.forName("UTF-8");
    String text = "x = 4.0;" + "IF x < 0.0;" + "    #TEST \"no\";" + "ELSEIF x > 0.0;" + "    #TEST \"pass\";" + "ENDIF;";
    Lexer lexer = new Lexer(text, charset);
    Parser parser = new Parser(lexer);
    Node root = parser.parse();
    Map<String, Executor> executorMap = new HashMap<>();
    executorMap.put("TEST", new Executor() {

        @Override
        protected Integer execute(boolean sync, Object context, Object... args) throws Exception {
            Assert.assertEquals("pass", args[0]);
            return null;
        }
    });
    Map<String, Placeholder> placeholderMap = new HashMap<>();
    Interpreter interpreter = new Interpreter(root, executorMap, placeholderMap, new HashMap<String, Object>(), new HashMap<>(), new CommonFunctions(null));
    interpreter.startWithContext(null);
}
Also used : Placeholder(io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) HashMap(java.util.HashMap) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Charset(java.nio.charset.Charset) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser) Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Executor(io.github.wysohn.triggerreactor.core.script.interpreter.Executor) CommonFunctions(io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.CommonFunctions) Test(org.junit.Test)

Aggregations

CommonFunctions (io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.CommonFunctions)7 Executor (io.github.wysohn.triggerreactor.core.script.interpreter.Executor)7 Interpreter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter)7 Placeholder (io.github.wysohn.triggerreactor.core.script.interpreter.Placeholder)7 Lexer (io.github.wysohn.triggerreactor.core.script.lexer.Lexer)7 Node (io.github.wysohn.triggerreactor.core.script.parser.Node)7 Parser (io.github.wysohn.triggerreactor.core.script.parser.Parser)7 Charset (java.nio.charset.Charset)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7