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;
}
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);
}
}
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);
}
Aggregations