use of io.github.wysohn.triggerreactor.core.script.warning.DeprecationWarning in project TriggerReactor by wysohn.
the class TestParser method testParseWithDeprecation.
@Test
public void testParseWithDeprecation() throws IOException, LexerException, ParserException {
Parser.addDeprecationSupervisor((type, value) -> type == Type.ID && "#MODIFYPLAYER".equals(value));
Charset charset = Charset.forName("UTF-8");
String text = "#MESSAGE (1+(4/2.0)/3*4-(2/(3*-4)) >= 0)\n" + "#MODIFYPLAYER \"text\"\n";
Lexer lexer = new Lexer(text, charset);
Parser parser = new Parser(lexer);
Node root = parser.parse(true);
Queue<Node> queue = new LinkedList<Node>();
serializeNode(queue, root);
assertEquals(new Node(new Token(Type.INTEGER, "1")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "4")), queue.poll());
assertEquals(new Node(new Token(Type.DECIMAL, "2.0")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "/")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "3")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "/")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "4")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "*")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "+")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "2")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "3")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "4")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_UNARY, "-")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "*")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "/")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_A, "-")), queue.poll());
assertEquals(new Node(new Token(Type.INTEGER, "0")), queue.poll());
assertEquals(new Node(new Token(Type.OPERATOR_L, ">=")), queue.poll());
assertEquals(new Node(new Token(Type.EXECUTOR, "MESSAGE")), queue.poll());
assertEquals(new Node(new Token(Type.STRING, "text")), queue.poll());
assertEquals(new Node(new Token(Type.EXECUTOR, "MODIFYPLAYER")), queue.poll());
assertEquals(new Node(new Token(Type.ROOT, "<ROOT>")), queue.poll());
assertEquals(0, queue.size());
assertEquals(1, parser.getWarnings().size());
assertEquals(new DeprecationWarning(2, "#MODIFYPLAYER", "#MODIFYPLAYER \"text\""), parser.getWarnings().get(0));
}
use of io.github.wysohn.triggerreactor.core.script.warning.DeprecationWarning 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;
}
}
Aggregations