Search in sources :

Example 11 with BParseException

use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.

the class PrologExceptionPrinter method printBParseException.

private static void printBParseException(final IPrologTermOutput pto, final BParseException e, final String filename, final boolean useIndentation, final boolean lineOneOff) {
    final Token token = e.getToken();
    final SourcePosition pos = token == null ? null : new SourcePosition(token.getLine(), token.getPos());
    printExceptionWithSourcePosition(pto, e, filename, pos, useIndentation, lineOneOff);
}
Also used : SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) Token(de.be4.classicalb.core.parser.node.Token)

Example 12 with BParseException

use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.

the class PrologExceptionPrinter method printBException.

public static void printBException(IPrologTermOutput pto, final BException e, boolean useIndentation, boolean lineOneOff) {
    Throwable cause = e.getCause();
    String filename = e.getFilename();
    if (cause == null) {
        printGeneralException(pto, e, filename, useIndentation, lineOneOff, true);
    } else {
        while (cause.getClass().equals(BException.class) && cause.getCause() != null) {
            BException bex = (BException) cause;
            cause = bex.getCause();
            filename = bex.getFilename();
        }
        if (cause instanceof BLexerException) {
            printBLexerException(pto, (BLexerException) cause, filename, useIndentation, lineOneOff);
        } else if (cause instanceof LexerException) {
            printLexerException(pto, (LexerException) cause, filename, useIndentation, lineOneOff);
        } else if (cause instanceof BParseException) {
            printBParseException(pto, (BParseException) cause, filename, useIndentation, lineOneOff);
        } else if (cause instanceof PreParseException) {
            printPreParseException(pto, (PreParseException) cause, filename, useIndentation, lineOneOff);
        } else if (cause instanceof CheckException) {
            printCheckException(pto, (CheckException) cause, filename, useIndentation, lineOneOff);
        } else {
            printGeneralException(pto, cause, filename, useIndentation, lineOneOff, false);
        }
    }
}
Also used : BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) BParseException(de.be4.classicalb.core.parser.exceptions.BParseException) BException(de.be4.classicalb.core.parser.exceptions.BException) BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException)

Example 13 with BParseException

use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.

the class PredicatesTest method testNoPredicateSubstitutionsInNormalMode.

@Test
public void testNoPredicateSubstitutionsInNormalMode() {
    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);
    }
}
Also used : BParseException(de.be4.classicalb.core.parser.exceptions.BParseException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 14 with BParseException

use of de.be4.classicalb.core.parser.exceptions.BParseException in project probparsers by bendisposto.

the class PredicatesTest method testNonIdentifiersInQuantificationFormula.

@Test
public void testNonIdentifiersInQuantificationFormula() {
    final String testMachine = "#FORMULA ! a,5. (a=5 => a/=5 )";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception");
    } catch (final BCompoundException e) {
        assertTrue(e.getFirstException().getCause() instanceof BParseException);
    }
}
Also used : BParseException(de.be4.classicalb.core.parser.exceptions.BParseException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Aggregations

BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)10 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)9 Test (org.junit.Test)9 Ast2String (util.Ast2String)8 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)2 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)2 Token (de.be4.classicalb.core.parser.node.Token)2 LinkedList (java.util.LinkedList)2 Type (de.be4.classicalb.core.parser.IDefinitions.Type)1 DefinitionCollector (de.be4.classicalb.core.parser.analysis.checking.DefinitionCollector)1 BException (de.be4.classicalb.core.parser.exceptions.BException)1 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)1 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 ADefinitionSubstitution (de.be4.classicalb.core.parser.node.ADefinitionSubstitution)1 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)1 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)1 AOpSubstitution (de.be4.classicalb.core.parser.node.AOpSubstitution)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 Start (de.be4.classicalb.core.parser.node.Start)1