Search in sources :

Example 1 with VariablePrologTerm

use of de.prob.prolog.term.VariablePrologTerm in project probparsers by bendisposto.

the class PrologTermGenerator method toPrologTerm.

private static PrologTerm toPrologTerm(final PTerm node) {
    PrologTerm term;
    if (node instanceof ANumberTerm) {
        String text = ((ANumberTerm) node).getNumber().getText();
        term = new IntegerPrologTerm(new BigInteger(text));
    } else if (node instanceof AAtomTerm) {
        String text = ((AAtomTerm) node).getName().getText();
        if ("[]".equals(text)) {
            term = new ListPrologTerm(EMPTY_PROLOG_LIST);
        } else {
            text = removeQuotes(text);
            term = new CompoundPrologTerm(text);
        }
    } else if (node instanceof ATerm) {
        ATerm aterm = (ATerm) node;
        int listSize = getListSize(node);
        if (listSize >= 0) {
            PrologTerm[] list = new PrologTerm[listSize];
            fillListWithElements(list, aterm);
            term = new ListPrologTerm(list);
        } else {
            String functor = removeQuotes(aterm.getFunctor().getText());
            PrologTerm[] params = evalParameters((AParams) aterm.getParams());
            term = new CompoundPrologTerm(functor, params);
        }
    } else if (node instanceof AVariableTerm) {
        String text = removeQuotes(((AVariableTerm) node).getVariable().getText());
        term = new VariablePrologTerm(text);
    } else
        throw new IllegalStateException("Unexpected subclass of PTerm: " + node.getClass().getCanonicalName());
    return term;
}
Also used : VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) AAtomTerm(de.prob.core.sablecc.node.AAtomTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ANumberTerm(de.prob.core.sablecc.node.ANumberTerm) ATerm(de.prob.core.sablecc.node.ATerm) BigInteger(java.math.BigInteger) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) AVariableTerm(de.prob.core.sablecc.node.AVariableTerm)

Example 2 with VariablePrologTerm

use of de.prob.prolog.term.VariablePrologTerm in project probparsers by bendisposto.

the class FastReadTransformer method fastwrite.

private void fastwrite(PrologTerm term) {
    if (term instanceof IntegerPrologTerm) {
        IntegerPrologTerm intTerm = (IntegerPrologTerm) term;
        write(intTerm);
    }
    if (term instanceof CompoundPrologTerm) {
        write(term);
    }
    if (term instanceof VariablePrologTerm) {
        write((VariablePrologTerm) term);
    }
    if (term instanceof ListPrologTerm) {
        ListPrologTerm list = (ListPrologTerm) term;
        write(list);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Example 3 with VariablePrologTerm

use of de.prob.prolog.term.VariablePrologTerm in project prob2 by bendisposto.

the class ProBPreferenceTest method test.

@Test
public void test() {
    VariablePrologTerm typeAwesome = new VariablePrologTerm("TypeAwesome");
    CompoundPrologTerm cpt = new CompoundPrologTerm("cpt", new CompoundPrologTerm("IamAwesome"), typeAwesome, new CompoundPrologTerm("descriptionAwesome"), new CompoundPrologTerm("categoryAwesome"), new CompoundPrologTerm("awesomeDefaultValue"));
    ProBPreference a = new ProBPreference(cpt);
    assertEquals("IamAwesome", a.name);
    assertEquals(typeAwesome, a.type);
    assertEquals("descriptionAwesome", a.description);
    assertEquals("categoryAwesome", a.category);
    assertEquals("awesomeDefaultValue", a.defaultValue);
    assertEquals("IamAwesome(cat. categoryAwesome, type TypeAwesome, default awesomeDefaultValue) descriptionAwesome", a.toString());
    CompoundPrologTerm cpt2 = new CompoundPrologTerm("cpt", new CompoundPrologTerm("IamAwesome"), typeAwesome, new CompoundPrologTerm("descriptionAwesome"), new CompoundPrologTerm("categoryAwesome"), new CompoundPrologTerm("awesomeDefaultValue", new CompoundPrologTerm("I"), new CompoundPrologTerm(" am"), new CompoundPrologTerm(" not"), new CompoundPrologTerm(" simple.")));
    a = new ProBPreference(cpt2);
    assertEquals("IamAwesome", a.name);
    assertEquals(typeAwesome, a.type);
    assertEquals("descriptionAwesome", a.description);
    assertEquals("categoryAwesome", a.category);
    assertEquals("awesomeDefaultValue('I',' am',' not',' simple.')", a.defaultValue);
}
Also used : VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) Test(org.junit.Test)

Aggregations

CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)3 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)3 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)2 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)2 AAtomTerm (de.prob.core.sablecc.node.AAtomTerm)1 ANumberTerm (de.prob.core.sablecc.node.ANumberTerm)1 ATerm (de.prob.core.sablecc.node.ATerm)1 AVariableTerm (de.prob.core.sablecc.node.AVariableTerm)1 PrologTerm (de.prob.prolog.term.PrologTerm)1 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1