Search in sources :

Example 1 with ASTCategory

use of de.prob.animator.prologast.ASTCategory in project prob2 by bendisposto.

the class GetMachineStructureCommand method makeASTNode.

private static PrologASTNode makeASTNode(PrologTerm node) {
    if ("formula".equals(node.getFunctor())) {
        final PrologTerm term = node.getArgument(1);
        final PrologTerm prettyPrintTerm = node.getArgument(2);
        // It's not clear if this is the intended behavior, or if they should have been converted to atoms in the Prolog code.
        if (!prettyPrintTerm.isAtom() && !prettyPrintTerm.isNumber()) {
            throw new IllegalArgumentException("Formula pretty print must be an atom or number: " + prettyPrintTerm);
        }
        final String prettyPrint = prettyPrintTerm.getFunctor();
        return new ASTFormula(term, prettyPrint);
    } else if ("category".equals(node.getFunctor())) {
        final String name = node.getArgument(1).getFunctor();
        final List<String> infos = PrologTerm.atomicStrings((ListPrologTerm) node.getArgument(2));
        final List<PrologASTNode> subnodes = buildAST(BindingGenerator.getList(node.getArgument(3)));
        final boolean expanded = infos.contains("expanded");
        final boolean propagated = infos.contains("propagated");
        return new ASTCategory(subnodes, name, expanded, propagated);
    } else {
        throw new AssertionError("Unknown node type: " + node.getFunctor());
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ASTCategory(de.prob.animator.prologast.ASTCategory) ASTFormula(de.prob.animator.prologast.ASTFormula) List(java.util.List) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Aggregations

ASTCategory (de.prob.animator.prologast.ASTCategory)1 ASTFormula (de.prob.animator.prologast.ASTFormula)1 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)1 PrologTerm (de.prob.prolog.term.PrologTerm)1 List (java.util.List)1