Search in sources :

Example 6 with BObject

use of de.prob.translator.types.BObject in project probparsers by bendisposto.

the class TranslatingVisitor method listToSet.

private java.util.Set<BObject> listToSet(LinkedList<PExpression> elements) {
    java.util.Set<BObject> s = de.prob.translator.types.Set.newStorage();
    for (PExpression p : elements) {
        p.apply(this);
        s.add(this.getResult());
    }
    return s;
}
Also used : BObject(de.prob.translator.types.BObject) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 7 with BObject

use of de.prob.translator.types.BObject in project probparsers by bendisposto.

the class TranslatingVisitor method caseARecEntry.

@Override
public void caseARecEntry(ARecEntry node) {
    Atom key = null;
    BObject value = null;
    node.getIdentifier().apply(this);
    key = (Atom) this.getResult();
    node.getValue().apply(this);
    value = this.getResult();
    this.setResult(new RecordEntry(key, value));
}
Also used : BObject(de.prob.translator.types.BObject) Atom(de.prob.translator.types.Atom)

Example 8 with BObject

use of de.prob.translator.types.BObject in project probparsers by bendisposto.

the class TranslatingVisitor method caseARecExpression.

@Override
public void caseARecExpression(ARecExpression node) {
    Map<java.lang.String, BObject> s = Record.newStorage();
    // TODO or make the record immutable after filling it
    for (PRecEntry e : node.getEntries()) {
        e.apply(this);
        RecordEntry entry = (RecordEntry) this.getResult();
        s.put(entry.getKey().getValue(), entry.getValue());
    }
    this.setResult(new Record(s));
}
Also used : BObject(de.prob.translator.types.BObject) PRecEntry(de.be4.classicalb.core.parser.node.PRecEntry) Record(de.prob.translator.types.Record) String(de.prob.translator.types.String)

Example 9 with BObject

use of de.prob.translator.types.BObject in project prob2 by bendisposto.

the class RuleResult method transformCounterExamples.

private void transformCounterExamples(AbstractEvalResult abstractEvalResult) {
    EvalResult evalCurrent = (EvalResult) abstractEvalResult;
    TranslatedEvalResult translatedResult = null;
    try {
        translatedResult = evalCurrent.translate();
    } catch (Exception e) {
        /*- fall back solution if the result can not be parsed (e.g. {1,...,1000}) 
			 * should not not happen because MAX_DISPLAY_SET is set to -1 
			 * and hence, no truncated terms are delivered by ProBCore
			 * */
        final String message = evalCurrent.getValue().replaceAll("\"", "");
        counterExamples.add(new CounterExample(1, message));
        return;
    }
    if (translatedResult.getValue() instanceof de.prob.translator.types.Set) {
        de.prob.translator.types.Set set = (de.prob.translator.types.Set) translatedResult.getValue();
        for (final BObject object : set) {
            if (object instanceof Tuple) {
                final Tuple tuple = (Tuple) object;
                de.prob.translator.types.Number first = (de.prob.translator.types.Number) tuple.getFirst();
                int errorType = first.intValue();
                de.prob.translator.types.String second = (de.prob.translator.types.String) tuple.getSecond();
                String message = second.getValue();
                counterExamples.add(new CounterExample(errorType, message));
            } else {
                throw new AssertionError();
            }
        }
    } else if (translatedResult.getValue() instanceof de.prob.translator.types.Sequence) {
        de.prob.translator.types.Sequence sequence = (de.prob.translator.types.Sequence) translatedResult.getValue();
        for (int i = 1; i <= sequence.size(); i++) {
            de.prob.translator.types.String value = (de.prob.translator.types.String) sequence.get(i);
            String message = value.getValue();
            counterExamples.add(new CounterExample(i, message));
        }
    } else {
        // fall back: should not happen
        counterExamples.add(new CounterExample(1, evalCurrent.getValue()));
    }
}
Also used : BObject(de.prob.translator.types.BObject) Set(java.util.Set) EvalResult(de.prob.animator.domainobjects.EvalResult) TranslatedEvalResult(de.prob.animator.domainobjects.TranslatedEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) TranslatedEvalResult(de.prob.animator.domainobjects.TranslatedEvalResult) Tuple(de.prob.translator.types.Tuple)

Aggregations

BObject (de.prob.translator.types.BObject)9 PExpression (de.be4.classicalb.core.parser.node.PExpression)3 Tuple (de.prob.translator.types.Tuple)2 ArrayList (java.util.ArrayList)2 PRecEntry (de.be4.classicalb.core.parser.node.PRecEntry)1 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)1 EvalResult (de.prob.animator.domainobjects.EvalResult)1 TranslatedEvalResult (de.prob.animator.domainobjects.TranslatedEvalResult)1 Atom (de.prob.translator.types.Atom)1 Record (de.prob.translator.types.Record)1 Sequence (de.prob.translator.types.Sequence)1 String (de.prob.translator.types.String)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Test (org.junit.Test)1