Search in sources :

Example 1 with LexerException

use of io.github.wysohn.triggerreactor.core.script.lexer.LexerException in project TriggerReactor by wysohn.

the class Trigger method init.

/**
 * @throws IOException                low level exception from Lexer
 * @throws LexerException             throws if lexical analysis failed
 * @throws ParserException            throws if parsing failed
 * @throws TriggerInitFailedException
 */
public void init() throws TriggerInitFailedException {
    try {
        if (script == null) {
            throw new NullPointerException("init() was invoked, yet 'script' was null. Make sure to override " + "init() method to in order to construct a customized Trigger.");
        }
        Charset charset = StandardCharsets.UTF_8;
        Lexer lexer = new Lexer(script, charset);
        Parser parser = new Parser(lexer);
        root = parser.parse(true);
        List<Warning> warnings = parser.getWarnings();
        AbstractTriggerManager.reportWarnings(warnings, this);
        executorMap = TriggerReactorCore.getInstance().getExecutorManager().getBackedMap();
        placeholderMap = TriggerReactorCore.getInstance().getPlaceholderManager().getBackedMap();
        gvarMap = TriggerReactorCore.getInstance().getVariableManager().getGlobalVariableAdapter();
    } catch (Exception ex) {
        throw new TriggerInitFailedException("Failed to initialize Trigger [" + this.getClass().getSimpleName() + " -- " + info + "]!", ex);
    }
}
Also used : Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Warning(io.github.wysohn.triggerreactor.core.script.warning.Warning) Charset(java.nio.charset.Charset) TriggerInitFailedException(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.TriggerInitFailedException) ParserException(io.github.wysohn.triggerreactor.core.script.parser.ParserException) TriggerInitFailedException(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.TriggerInitFailedException) InterpreterException(io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException) IOException(java.io.IOException) LexerException(io.github.wysohn.triggerreactor.core.script.lexer.LexerException) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser)

Example 2 with LexerException

use of io.github.wysohn.triggerreactor.core.script.lexer.LexerException in project TriggerReactor by wysohn.

the class TestInterpreter method testPlaceholderNull.

@Test
public void testPlaceholderNull() throws IOException, LexerException, ParserException, InterpreterException {
    Charset charset = StandardCharsets.UTF_8;
    String text = "a = $merp";
    Lexer lexer = new Lexer(text, charset);
    Parser parser;
    parser = new Parser(lexer);
    Node root = parser.parse();
    Map<String, Placeholder> placeholderMap = new HashMap<>();
    placeholderMap.put("merp", new Placeholder() {

        @Override
        public Object parse(Timings.Timing timing, Object context, Map<String, Object> vars, Object... args) throws Exception {
            return null;
        }
    });
    Interpreter interpreter = new Interpreter(root);
    interpreter.setPlaceholderMap(placeholderMap);
    interpreter.startWithContext(null);
    assertEquals(null, interpreter.getVars().get("a"));
}
Also used : Timings(io.github.wysohn.triggerreactor.tools.timings.Timings) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Charset(java.nio.charset.Charset) ParserException(io.github.wysohn.triggerreactor.core.script.parser.ParserException) IOException(java.io.IOException) LexerException(io.github.wysohn.triggerreactor.core.script.lexer.LexerException) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser) Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Test(org.junit.Test)

Example 3 with LexerException

use of io.github.wysohn.triggerreactor.core.script.lexer.LexerException in project TriggerReactor by wysohn.

the class Parser method nextToken.

private void nextToken() throws IOException, ParserException {
    try {
        token = lexer.getToken();
        if (showWarnings && token != null) {
            int row = lexer.getRow();
            Type type = token.type;
            String value = String.valueOf(token.value);
            if (type == null || value == null)
                return;
            if (deprecationSupervisors.stream().anyMatch(deprecationSupervisor -> deprecationSupervisor.isDeprecated(type, value))) {
                this.warnings.add(new DeprecationWarning(row, value, lexer.getScriptLines()[row - 1]));
            }
        }
    } catch (LexerException lex) {
        ParserException pex = new ParserException("Error occured while processing a token after " + token);
        pex.initCause(lex);
        throw pex;
    }
}
Also used : Type(io.github.wysohn.triggerreactor.core.script.Token.Type) DeprecationWarning(io.github.wysohn.triggerreactor.core.script.warning.DeprecationWarning) LexerException(io.github.wysohn.triggerreactor.core.script.lexer.LexerException)

Aggregations

LexerException (io.github.wysohn.triggerreactor.core.script.lexer.LexerException)3 Lexer (io.github.wysohn.triggerreactor.core.script.lexer.Lexer)2 Parser (io.github.wysohn.triggerreactor.core.script.parser.Parser)2 ParserException (io.github.wysohn.triggerreactor.core.script.parser.ParserException)2 IOException (java.io.IOException)2 Charset (java.nio.charset.Charset)2 TriggerInitFailedException (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.TriggerInitFailedException)1 Type (io.github.wysohn.triggerreactor.core.script.Token.Type)1 InterpreterException (io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException)1 Node (io.github.wysohn.triggerreactor.core.script.parser.Node)1 DeprecationWarning (io.github.wysohn.triggerreactor.core.script.warning.DeprecationWarning)1 Warning (io.github.wysohn.triggerreactor.core.script.warning.Warning)1 Timings (io.github.wysohn.triggerreactor.tools.timings.Timings)1 Test (org.junit.Test)1