Search in sources :

Example 86 with BCompoundException

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

the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDuplicateSemicolon.

@Test
public void checkForDuplicateSemicolon() throws Exception {
    String s = "MACHINE DuplicateSemicolon\nOPERATIONS\n Foo = BEGIN skip END;\n ;r <-- Get = BEGIN r := xx END\nEND";
    try {
        getTreeAsString(s);
        fail("Missing Semicolon was not detected");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("Two succeeding"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 87 with BCompoundException

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

the class SyntaxErrorsDetectedOnTokenStreamTest method checkForSingleLineCommentBetweenDuplicateAnd.

@Test
public void checkForSingleLineCommentBetweenDuplicateAnd() throws Exception {
    String s = "MACHINE Definitions\nPROPERTIES 1=1 & // comment 1 comment \n &  2 = 2  END";
    try {
        getTreeAsString(s);
        fail("Duplicate & was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("& &"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 88 with BCompoundException

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

the class SyntaxErrorsDetectedOnTokenStreamTest method checkForCommentBetweenDuplicateAnd.

@Test
public void checkForCommentBetweenDuplicateAnd() throws Exception {
    String s = "MACHINE Definitions\nPROPERTIES 1=1 & /* comment */\n &  2 = 2  END";
    try {
        getTreeAsString(s);
        fail("Duplicate & was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("& &"));
        final BLexerException ex = (BLexerException) e.getCause();
        // checking the position of the second &
        assertEquals(3, ex.getLastLine());
        assertEquals(2, ex.getLastPos());
    }
}
Also used : BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 89 with BCompoundException

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

the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateDefinitionClause.

@Test
public void checkForDublicateDefinitionClause() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS\n foo == 1\n CONSTANTS k \n DEFINITIONS\n bar == 1  \nEND";
    try {
        getTreeAsString(s);
        fail("Duplicate 'DEFINITION' clause was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("[5,2] Clause 'DEFINITIONS' is used more than once"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 90 with BCompoundException

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

the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateAndInDefinitionsClause.

@Test
public void checkForDublicateAndInDefinitionsClause() throws Exception {
    String s = "MACHINE Definitions\nDEFINITIONS\n foo == 1=1 && 2=2  \nEND";
    try {
        getTreeAsString(s);
        fail("Duplicate & was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        // there is no token available, hence the position is in the text
        assertTrue(e.getMessage().contains("[3,14]"));
        assertTrue(e.getMessage().contains("& &"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Aggregations

BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)73 Test (org.junit.Test)64 Ast2String (util.Ast2String)62 Start (de.be4.classicalb.core.parser.node.Start)52 BParser (de.be4.classicalb.core.parser.BParser)29 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)19 File (java.io.File)15 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)7 BException (de.be4.classicalb.core.parser.exceptions.BException)7 Helpers.getTreeAsString (util.Helpers.getTreeAsString)7 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)5 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)5 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 Node (de.be4.classicalb.core.parser.node.Node)5 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)4 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)4