use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.
the class OpSubstitutions method caseAFuncOpSubstitution.
@Override
public void caseAFuncOpSubstitution(final AFuncOpSubstitution node) {
final PExpression expression = node.getFunction();
PExpression idExpr = null;
LinkedList<PExpression> parameters = null;
Type type = null;
TIdentifierLiteral idToken = null;
String idString = null;
if (expression instanceof AFunctionExpression) {
// the operation was parsed as a function expression
final AFunctionExpression function = (AFunctionExpression) expression;
final PExpression funcId = function.getIdentifier();
if (funcId instanceof AIdentifierExpression) {
final AIdentifierExpression identifier = (AIdentifierExpression) funcId;
idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
idToken = identifier.getIdentifier().get(0);
type = definitions.getType(idString);
} else {
type = Type.NoDefinition;
}
idExpr = function.getIdentifier();
parameters = new LinkedList<>(function.getParameters());
} else if (expression instanceof AIdentifierExpression) {
// the operation was parsed as an identifier expression
final AIdentifierExpression identifier = (AIdentifierExpression) expression;
idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
idToken = identifier.getIdentifier().get(0);
type = definitions.getType(idString);
idExpr = expression;
parameters = new LinkedList<>();
} else {
// some other expression was parsed (NOT allowed)
throw new BParseException(null, "Expecting operation");
}
if (type != Type.NoDefinition && idToken != null) {
if (type == Type.Substitution || type == Type.ExprOrSubst) {
// create DefinitionSubstitution
final ADefinitionSubstitution defSubst = new ADefinitionSubstitution(new TDefLiteralSubstitution(idToken.getText(), idToken.getLine(), idToken.getPos()), parameters);
if (type == Type.ExprOrSubst) {
// type is determined now => set to Substitution
setTypeSubstDef(node, idString);
}
// transfer position information
final PositionedNode posNode = node;
final PositionedNode newPosNode = defSubst;
newPosNode.setStartPos(posNode.getStartPos());
newPosNode.setEndPos(posNode.getEndPos());
node.replaceBy(defSubst);
defSubst.apply(this);
} else {
// finding some other type here is an error!
throw new VisitorException(new CheckException("Expecting substitution here but found definition with type '" + type + "'", node));
}
} else {
// no def, no problem ;-)
final AOpSubstitution opSubst = new AOpSubstitution(idExpr, parameters);
opSubst.setStartPos(idExpr.getStartPos());
opSubst.setEndPos(idExpr.getEndPos());
node.replaceBy(opSubst);
opSubst.apply(this);
}
}
use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.
the class PredicatesTest method testNonIdentifiersInQuantification.
@Test
public void testNonIdentifiersInQuantification() {
final String testMachine = "#PREDICATE ! a,5. (a=5 => a/=5 )";
try {
getTreeAsString(testMachine);
fail("Expected exception");
} catch (final BCompoundException e) {
assertTrue(e.getFirstException().getCause() instanceof BParseException);
}
}
use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.
the class DefinitionsTest method testUnparsableRhs.
@Test
public void testUnparsableRhs() {
final String testMachine = "MACHINE Test\nDEFINITIONS def_expr1 == 42 < \n OPERATIONS op = PRE def_expr1 THEN skip END END";
try {
getTreeAsString(testMachine);
fail("Was expecting BParseException");
} catch (final BCompoundException e) {
System.out.println(e.getLocalizedMessage());
// IGNORE is expected
}
}
use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.
the class ErrorMessagesTest method testKeywordAsIdentifierInConstantsClause.
@Test
public void testKeywordAsIdentifierInConstantsClause() throws Exception {
final String testMachine = "MACHINE Test CONSTANTS right PROPERTIES right = 1 END";
try {
getTreeAsString(testMachine);
fail("Invalid identifier not detected");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
BParseException e1 = (BParseException) e.getFirstException().getCause();
assertTrue(e1.getToken().getText().equals("right"));
}
}
use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.
the class PrimedIdentifierTest method testPrimedIdentifiersInQuantifiers.
@Test
public void testPrimedIdentifiersInQuantifiers() throws BCompoundException {
final String testMachine = "#PREDICATE !a$0.(a$0=5 => b=6)";
try {
getTreeAsString(testMachine);
fail("exception expected");
} catch (BCompoundException e) {
assertTrue(e.getCause() instanceof BParseException);
// ok
}
}
Aggregations