use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.
the class RulesMachineChecker method checkFailedRuleErrorTypeOperator.
private void checkFailedRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
if (arguments.size() != 2) {
this.errorList.add(new CheckException("The FAILED_RULE_ERROR_TYPE predicate operator expects exactly two arguments.", node));
return;
}
PExpression pExpression = node.getIdentifiers().get(0);
if (!(pExpression instanceof AIdentifierExpression)) {
this.errorList.add(new CheckException("The first argument of FAILED_RULE_ERROR_TYPE must be an identifier.", node));
return;
}
PExpression secondArg = node.getIdentifiers().get(1);
if (!(secondArg instanceof AIntegerExpression)) {
this.errorList.add(new CheckException("The second argument of FAILED_RULE_ERROR_TYPE must be an integer literal.", node));
return;
}
this.referencedRuleOperations.add((AIdentifierExpression) arguments.get(0));
return;
}
use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.
the class SourcePositionsTest method testAddExpression.
@Test
public void testAddExpression() throws Exception {
final String testMachine = "#EXPRESSION xx + 5";
final Start result = getAst(testMachine);
final AExpressionParseUnit exprParseUnit = (AExpressionParseUnit) result.getPParseUnit();
assertEquals(1, exprParseUnit.getStartPos().getLine());
assertEquals(1, exprParseUnit.getStartPos().getPos());
assertEquals(1, exprParseUnit.getEndPos().getLine());
assertEquals(19, exprParseUnit.getEndPos().getPos());
final AAddExpression addExpression = (AAddExpression) exprParseUnit.getExpression();
assertEquals(1, addExpression.getStartPos().getLine());
assertEquals(13, addExpression.getStartPos().getPos());
assertEquals(1, addExpression.getEndPos().getLine());
assertEquals(19, addExpression.getEndPos().getPos());
final AIdentifierExpression varExpression = (AIdentifierExpression) addExpression.getLeft();
assertEquals(1, varExpression.getStartPos().getLine());
assertEquals(13, varExpression.getStartPos().getPos());
assertEquals(1, varExpression.getEndPos().getLine());
assertEquals(15, varExpression.getEndPos().getPos());
final AIntegerExpression intExpression = (AIntegerExpression) addExpression.getRight();
assertEquals(1, intExpression.getStartPos().getLine());
assertEquals(18, intExpression.getStartPos().getPos());
assertEquals(1, intExpression.getEndPos().getLine());
assertEquals(19, intExpression.getEndPos().getPos());
}
use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.
the class ASTPrologTest method testPartition.
@Test
public void testPartition() {
final PExpression set = createId("set");
final PExpression one = new AIntegerExpression(new TIntegerLiteral("1"));
final PExpression two = new AIntegerExpression(new TIntegerLiteral("2"));
final PExpression three = new AIntegerExpression(new TIntegerLiteral("3"));
final APartitionPredicate pred = new APartitionPredicate(set, Arrays.asList(one, two, three));
final String expected = "partition($,identifier($,set),[integer($,1),integer($,2),integer($,3)])";
checkAST(0, expected, pred);
}
use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.
the class ExpressionTest method testProverComprehensionSets.
@Test
public void testProverComprehensionSets() throws Exception {
final String expression = "SET(i).(i>0)";
parser.getOptions().setRestrictProverExpressions(false);
final String expected = "AProverComprehensionSetExpression([AIdentifierExpression([i])],AGreaterPredicate(AIdentifierExpression([i]),AIntegerExpression(0)))";
final String prover = getExpressionAsString(expression);
assertEquals(expected, prover);
parser.getOptions().setRestrictProverExpressions(true);
try {
getExpressionAsString(expression);
fail("exception expected");
} catch (BCompoundException e) {
assertTrue(e.getCause() instanceof CheckException);
}
}
use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.
the class RulesMachineChecker method checkErrorTypesAttribute.
private void checkErrorTypesAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
if (currentOperation instanceof RuleOperation) {
final RuleOperation rule = (RuleOperation) currentOperation;
if (arguments.size() == 1 && arguments.get(0) instanceof AIntegerExpression) {
AIntegerExpression intExpr = (AIntegerExpression) arguments.get(0);
rule.setErrrorTypes(intExpr);
} else {
errorList.add(new CheckException("Expected exactly one integer after ERROR_TYPES.", pOperationAttribute));
}
} else {
errorList.add(new CheckException("ERROR_TYPES is not an attribute of a FUNCTION or COMPUTATION operation.", pOperationAttribute));
}
return;
}
Aggregations