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

net.intelie.pipes.ast.AutomatonVisitor 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 net.intelie.pipes.util.AutomatonRepr;

public class AutomatonVisitor extends AstVisitor {
    private AutomatonRepr.LabelLines makeLabel(SourceLocation location, Object value) {
        AutomatonRepr.LabelLines label = new AutomatonRepr.LabelLines();
        if (location != null && location.getCode() != null) {
            String code = location.getCode();
            if (code.length() > 43)
                code = code.substring(0, 30) + "..." + code.substring(code.length() - 10);
            label.setTooltip(code);
        }
        label.addLine(6, location != null && location.getType() != SourceLocation.Type.NONE ? location.getType() : "");
        label.addLine(10, value);
        label.addLine(8, location);
        return label;
    }

    @Override
    public AutomatonRepr visitRaw(RawNode node) throws PipeException {
        AutomatonRepr repr = new AutomatonRepr("x");
        repr.addNode("note", "x", makeLabel(node.getLocation(), node.getValue()));
        return repr;
    }

    @Override
    public AutomatonRepr visitLiteral(LiteralNode node) throws PipeException {
        AutomatonRepr repr = new AutomatonRepr("x");
        repr.addNode("rectangle", "x", makeLabel(node.getLocation(), node));
        return repr;
    }

    @Override
    public AutomatonRepr visitCall(CallNode node) throws PipeException {
        AutomatonRepr repr = new AutomatonRepr("x");
        repr.addNode("rectangle", "x", makeLabel(node.getLocation(), node.getName() + "()"));

        int i = 0;
        for (AstNode child : node.getArgs()) {
            repr.addEdge("x", "p" + i++ + "_", visit(child), "");
        }
        return repr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy