use of de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition in project probparsers by bendisposto.
the class OpSubstitutions method setTypeSubstDef.
private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
final Node defRhs = oldDefinition.getRhs();
final PSubstitution rhsSubst;
if (defRhs instanceof AFunctionExpression) {
final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
rhsSubst.setStartPos(rhsFunction.getStartPos());
rhsSubst.setEndPos(rhsFunction.getEndPos());
} else if (defRhs instanceof AIdentifierExpression) {
final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
rhsSubst.setStartPos(rhsIdent.getStartPos());
rhsSubst.setEndPos(rhsIdent.getEndPos());
} else {
// some other expression was parsed (NOT allowed)
throw new VisitorException(new CheckException("Expecting operation", node));
}
final TIdentifierLiteral oldDefId = oldDefinition.getName();
final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
substDef.setStartPos(oldDefinition.getStartPos());
substDef.setEndPos(oldDefinition.getEndPos());
definitions.replaceDefinition(idString, Type.Substitution, substDef);
oldDefinition.replaceBy(substDef);
}
use of de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition in project probparsers by bendisposto.
the class RulesMachineChecker method caseAExpressionDefinitionDefinition.
@Override
public void caseAExpressionDefinitionDefinition(AExpressionDefinitionDefinition node) {
final String name = node.getName().getText();
this.definitions.add(name);
if ("GOAL".equals(name)) {
errorList.add(new CheckException("The GOAL definition must be a predicate.", node));
return;
}
this.identifierScope.createNewScope(new LinkedList<>(node.getParameters()));
node.getRhs().apply(this);
this.identifierScope.removeScope();
}
use of de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition in project probparsers by bendisposto.
the class LTLFormulaVisitor method parseDefinition.
public void parseDefinition(AExpressionDefinitionDefinition def) {
if (!(def.getRhs() instanceof AStringExpression)) {
throw new LTLParseException("Error: LTL formula is not in a string representation.");
}
AStringExpression stringNode = (AStringExpression) def.getRhs();
this.ltlFormula = stringNode.getContent().getText();
try {
this.ltlFormulaStart = parseLTLFormula(ltlFormula);
} catch (Exception e) {
String message = "Parsing definition " + name + " (line " + def.getStartPos().getLine() + "):\n";
throw new LTLParseException(message + e.getMessage());
}
}
use of de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition in project probparsers by bendisposto.
the class DefinitionCollector method caseAConversionDefinition.
@Override
public void caseAConversionDefinition(AConversionDefinition node) {
PDefinition def = node.getDefinition();
if (def instanceof AExpressionDefinitionDefinition) {
AExpressionDefinitionDefinition exprDef = (AExpressionDefinitionDefinition) def;
final String defName = exprDef.getName().getText();
final Type type = defTypes.getType(defName);
addDefinition(node, type, defName);
} else {
this.exceptions.add(new CheckException("Only an expression is allowed on the right hand side of a conversion definition.", node));
}
}
use of de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition in project probparsers by bendisposto.
the class DefinitionCollector method inAExpressionDefinitionDefinition.
@Override
public void inAExpressionDefinitionDefinition(final AExpressionDefinitionDefinition node) {
final String defName = node.getName().getText();
final Type type = defTypes.getType(defName);
addDefinition(node, type, defName);
}
Aggregations