use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class OpPatternTest method checkParser.
private void checkParser(final String description, final String oppattern, final String expected) throws BCompoundException {
final Start ast = parser.parse(BParser.OPERATION_PATTERN_PREFIX + oppattern, false);
final Ast2String ast2String = new Ast2String();
ast.apply(ast2String);
final String parsed = ast2String.toString();
assertEquals(description, "Start(AOppatternParseUnit(" + expected + "))", parsed);
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class PredicatesTest method testBFalse.
@Test
public void testBFalse() throws BCompoundException {
parser.getOptions().setRestrictProverExpressions(true);
try {
getPredicateAsString("bfalse");
fail("exception expected");
} catch (BCompoundException e) {
assertTrue(e.getFirstException().getCause() instanceof CheckException);
}
parser.getOptions().setRestrictProverExpressions(false);
final String actual = getPredicateAsString("bfalse");
final String expected = "AFalsityPredicate()";
assertEquals(expected, actual);
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class PredicatesTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
final Start startNode = parser.parse(testMachine, false);
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
return ast2String.toString();
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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.BCompoundException in project probparsers by bendisposto.
the class PreParser method parse.
public void parse() throws PreParseException, IOException, BException, BCompoundException {
final PreLexer preLexer = new PreLexer(pushbackReader);
final Parser preParser = new Parser(preLexer);
Start rootNode = null;
try {
rootNode = preParser.parse();
} catch (final ParserException e) {
if (e.getToken() instanceof de.be4.classicalb.core.preparser.node.TDefinitions) {
final Token errorToken = e.getToken();
final String message = "[" + errorToken.getLine() + "," + errorToken.getPos() + "] " + "Clause 'DEFINITIONS' is used more than once";
throw new PreParseException(e.getToken(), message);
} else {
throw new PreParseException(e.getToken(), e.getLocalizedMessage());
}
} catch (final LexerException e) {
throw new PreParseException(e.getLocalizedMessage());
}
final DefinitionPreCollector collector = new DefinitionPreCollector();
rootNode.apply(collector);
evaluateDefinitionFiles(collector.getFileDefinitions());
List<Token> sortedDefinitionList = sortDefinitionsByTopologicalOrderAndCheckForCycles(collector.getDefinitions());
evaluateTypes(sortedDefinitionList, collector.getDefinitions());
}
Aggregations