Search in sources :

Example 1 with Expression

use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.

the class TestUtils method mockExpression.

public static Expression mockExpression(RedsObject value) {
    Expression e = mock(Expression.class);
    when(e.execute(any())).thenReturn(value);
    return e;
}
Also used : Expression(net.taken.redsnake.tree.statements.expressions.Expression)

Example 2 with Expression

use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.

the class IfTest method createIfWithAssignments.

private static If createIfWithAssignments(String variableName, boolean condition, int trueValue, int falseValue) {
    Variable var = mockVariable(variableName);
    Expression cond = mockExpression(new RedsBoolean(condition));
    StatementList thenBody = new StatementList(ImmutableList.of(new Assignment(mockVariable(variableName), mockExpression(trueValue))));
    StatementList elseBody = new StatementList(ImmutableList.of(new Assignment(mockVariable(variableName), mockExpression(falseValue))));
    return new If(cond, thenBody, elseBody);
}
Also used : Assignment(net.taken.redsnake.tree.statements.expressions.Assignment) Variable(net.taken.redsnake.tree.Variable) Expression(net.taken.redsnake.tree.statements.expressions.Expression) RedsBoolean(net.taken.redsnake.lang.RedsBoolean) StatementList(net.taken.redsnake.tree.statements.StatementList) If(net.taken.redsnake.tree.statements.If)

Example 3 with Expression

use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.

the class CallTest method createCall.

private static Call createCall(String name, int... parameters) {
    Variable var = mockVariable(name);
    List<Expression> params = Arrays.stream(parameters).mapToObj(TestUtils::mockExpression).collect(Collectors.toList());
    return new Call(var, params);
}
Also used : TestUtils.mockVariable(net.taken.redsnake.tree.TestUtils.mockVariable) Expression(net.taken.redsnake.tree.statements.expressions.Expression)

Example 4 with Expression

use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.

the class TestUtils method parseStatement.

public static Statement parseStatement(@NotNull String s) {
    CharStream inputStream = CharStreams.fromString(s);
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.expression();
    return (Expression) new ASTBuilder().visit(t);
}
Also used : RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) Expression(net.taken.redsnake.tree.statements.expressions.Expression) ASTBuilder(net.taken.redsnake.parser.visitors.ASTBuilder) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

Expression (net.taken.redsnake.tree.statements.expressions.Expression)4 RedsBoolean (net.taken.redsnake.lang.RedsBoolean)1 RedsnakeLexer (net.taken.redsnake.parser.RedsnakeLexer)1 RedsnakeParser (net.taken.redsnake.parser.RedsnakeParser)1 ASTBuilder (net.taken.redsnake.parser.visitors.ASTBuilder)1 TestUtils.mockVariable (net.taken.redsnake.tree.TestUtils.mockVariable)1 Variable (net.taken.redsnake.tree.Variable)1 If (net.taken.redsnake.tree.statements.If)1 StatementList (net.taken.redsnake.tree.statements.StatementList)1 Assignment (net.taken.redsnake.tree.statements.expressions.Assignment)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1