All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.intelie.pipes.ast.AstVisitor Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
package net.intelie.pipes.ast;

import net.intelie.pipes.PipeException;

import java.util.ArrayList;
import java.util.List;

public abstract class AstVisitor {
    public T visit(AstNode node) throws PipeException {
        if (node instanceof CallNode)
            return visitCall((CallNode) node);
        if (node instanceof LiteralNode)
            return visitLiteral((LiteralNode) node);
        if (node instanceof RawNode)
            return visitRaw((RawNode) node);
        return visitUnknown(node);
    }

    public List visitList(List nodes) throws PipeException {
        List list = new ArrayList<>();
        for (AstNode node : nodes)
            list.add(visit(node));
        return list;
    }

    public T visitUnknown(AstNode node) throws PipeException {
        throw new PipeException("Unknown node type: %s", node);
    }

    public abstract T visitRaw(RawNode node) throws PipeException;

    public abstract T visitLiteral(LiteralNode node) throws PipeException;

    public abstract T visitCall(CallNode node) throws PipeException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy