use of de.be4.classicalb.core.parser.node.APredicateParseUnit in project probparsers by bendisposto.
the class PreParser method determineType.
private DefinitionType determineType(final Token definition, final Token rhsToken, final Set<String> untypedDefinitions) throws PreParseException {
final String definitionRhs = rhsToken.getText();
de.be4.classicalb.core.parser.node.Start start;
de.be4.classicalb.core.parser.node.Token errorToken = null;
try {
start = tryParsing(BParser.FORMULA_PREFIX, definitionRhs);
// Predicate?
PParseUnit parseunit = start.getPParseUnit();
if (parseunit instanceof APredicateParseUnit) {
return new DefinitionType(IDefinitions.Type.Predicate);
}
// Expression or Expression/Substituion (e.g. f(x))?
AExpressionParseUnit expressionParseUnit = (AExpressionParseUnit) parseunit;
PreParserIdentifierTypeVisitor visitor = new PreParserIdentifierTypeVisitor(untypedDefinitions);
expressionParseUnit.apply(visitor);
if (visitor.isKaboom()) {
return new DefinitionType();
}
PExpression expression = expressionParseUnit.getExpression();
if ((expression instanceof AIdentifierExpression) || (expression instanceof AFunctionExpression) || (expression instanceof ADefinitionExpression)) {
return new DefinitionType(IDefinitions.Type.ExprOrSubst);
}
return new DefinitionType(IDefinitions.Type.Expression);
} catch (de.be4.classicalb.core.parser.parser.ParserException e) {
errorToken = e.getToken();
try {
tryParsing(BParser.SUBSTITUTION_PREFIX, definitionRhs);
return new DefinitionType(IDefinitions.Type.Substitution, errorToken);
} catch (de.be4.classicalb.core.parser.parser.ParserException ex) {
final de.be4.classicalb.core.parser.node.Token errorToken2 = ex.getToken();
if (errorToken.getLine() > errorToken2.getLine() || (errorToken.getLine() == errorToken2.getLine() && errorToken.getPos() >= errorToken2.getPos())) {
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(definition, rhsToken, errorToken, e.getMessage());
return new DefinitionType(newMessage, errorToken);
} else {
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(definition, rhsToken, errorToken2, ex.getMessage());
return new DefinitionType(newMessage, errorToken2);
}
} catch (BLexerException e1) {
errorToken = e1.getLastToken();
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(definition, rhsToken, errorToken, e.getMessage());
throw new PreParseException(newMessage);
} catch (de.be4.classicalb.core.parser.lexer.LexerException e3) {
throw new PreParseException(determineNewErrorMessageWithCorrectedPositionInformationsWithoutToken(definition, rhsToken, e3.getMessage()));
} catch (IOException e1) {
throw new PreParseException(e.getMessage());
}
} catch (BLexerException e) {
errorToken = e.getLastToken();
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(definition, rhsToken, errorToken, e.getMessage());
throw new PreParseException(newMessage);
} catch (de.be4.classicalb.core.parser.lexer.LexerException e) {
throw new PreParseException(determineNewErrorMessageWithCorrectedPositionInformationsWithoutToken(definition, rhsToken, e.getMessage()));
} catch (IOException e) {
throw new PreParseException(e.getMessage());
}
}
use of de.be4.classicalb.core.parser.node.APredicateParseUnit in project prob2 by bendisposto.
the class DomBuilder method createPredicateAST.
private Start createPredicateAST(final PPredicate pPredicate) {
Start start = new Start();
APredicateParseUnit node2 = new APredicateParseUnit();
start.setPParseUnit(node2);
start.setEOF(EOF);
node2.setPredicate((PPredicate) pPredicate.clone());
node2.getPredicate().apply(new RenameIdentifiers());
return start;
}
Aggregations