Search in sources :

Example 1 with ASTBuilder

use of net.taken.redsnake.parser.visitors.ASTBuilder in project redsnake by Taken0711.

the class TestUtils method parseProgram.

public static Program parseProgram(@NotNull String... s) {
    StringBuilder str = new StringBuilder();
    Arrays.stream(s).forEach(st -> str.append(st).append(System.lineSeparator()));
    CharStream inputStream = CharStreams.fromString(str.toString());
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.program();
    return (Program) new ASTBuilder().visit(t);
}
Also used : RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) ASTBuilder(net.taken.redsnake.parser.visitors.ASTBuilder) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 2 with ASTBuilder

use of net.taken.redsnake.parser.visitors.ASTBuilder 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

RedsnakeLexer (net.taken.redsnake.parser.RedsnakeLexer)2 RedsnakeParser (net.taken.redsnake.parser.RedsnakeParser)2 ASTBuilder (net.taken.redsnake.parser.visitors.ASTBuilder)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 Expression (net.taken.redsnake.tree.statements.expressions.Expression)1