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

net.intelie.pipes.ast.AstVisitorBase 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 class AstVisitorBase extends AstVisitor {
    @Override
    public List visitList(List nodes) throws PipeException {
        List list = null;
        for (int i = 0; i < nodes.size(); i++) {
            AstNode node = nodes.get(i);

            List expanded = visitExpanding(node);
            if (expanded != null) {
                if (list == null)
                    list = new ArrayList<>(nodes.subList(0, i));
                list.addAll(expanded);
            } else {
                AstNode visited = visit(node);
                if (node != visited || list != null) {
                    if (list == null)
                        list = new ArrayList<>(nodes.subList(0, i));
                    list.add(visited);
                }
            }
        }
        return list != null ? list : nodes;
    }

    public List visitExpanding(AstNode node) throws PipeException {
        return null;
    }

    @Override
    public AstNode visitRaw(RawNode node) {
        return node;
    }

    @Override
    public AstNode visitLiteral(LiteralNode node) {
        return node;
    }

    @Override
    public AstNode visitCall(CallNode node) throws PipeException {
        List children = node.getArgs();
        List newChildren = visitList(children);
        if (children == newChildren)
            return node;

        return new CallNode(node.getLocation(), node.getName(), newChildren);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy