Search in sources :

Example 51 with CheckException

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

the class StructuralTest method checkForInvalidSemicolon.

@Test
public void checkForInvalidSemicolon() throws Exception {
    String s = "MACHINE MissingSemicolon\nOPERATIONS\n Foo=BEGIN skip END\n;\nEND";
    try {
        getTreeAsString(s);
        fail("Invalid Semicolon was not detected");
    } catch (BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        Node node = cause.getNodes()[0];
        System.out.println(cause.getMessage());
        assertEquals(4, node.getStartPos().getLine());
        assertEquals(1, node.getStartPos().getPos());
        assertTrue(e.getMessage().contains("Invalid semicolon after last operation"));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Node(de.be4.classicalb.core.parser.node.Node) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 52 with CheckException

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

the class ReferencedMachines method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    machineName = Utils.getTIdentifierListAsString(node.getName());
    final String fileNameWithoutExtension = Utils.getFileWithoutExtension(mainFile.getName());
    if (isMachineNameMustMatchFileName && !machineName.equals(fileNameWithoutExtension)) {
        CheckException ch = new CheckException(String.format("Machine name does not match the file name: '%s' vs '%s'", machineName, fileNameWithoutExtension), node);
        throw new VisitorException(ch);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Example 53 with CheckException

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

the class ReferencedMachines method caseAMachineReference.

/**
 * INCLUDES, EXTENDS, IMPORTS
 */
@Override
public void caseAMachineReference(AMachineReference node) {
    String name = getIdentifier(node.getMachineName());
    if (node.parent() instanceof AFileMachineReference) {
        final AFileMachineReference fileNode = (AFileMachineReference) node.parent();
        String file = fileNode.getFile().getText().replaceAll("\"", "");
        MachineReference ref;
        try {
            ref = new MachineReference(name, node, file);
            referncesTable.put(name, ref);
        } catch (CheckException e) {
            throw new VisitorException(e);
        }
    } else {
        MachineReference machineReference = new MachineReference(name, node);
        if (this.filePathTable.containsKey(name)) {
            machineReference.setDirectoryPath(filePathTable.get(name));
        }
        referncesTable.put(name, machineReference);
    }
}
Also used : AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference)

Example 54 with CheckException

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

the class ReferencedMachines method registerMachineNames.

private void registerMachineNames(List<PExpression> referencedMachineList) {
    for (PExpression machineExpression : referencedMachineList) {
        if (machineExpression instanceof AIdentifierExpression) {
            AIdentifierExpression identifier = (AIdentifierExpression) machineExpression;
            String name = getIdentifier(identifier.getIdentifier());
            final MachineReference machineReference = new MachineReference(name, identifier);
            if (this.filePathTable.containsKey(name)) {
                machineReference.setDirectoryPath(filePathTable.get(name));
            }
            referncesTable.put(name, machineReference);
        } else if (machineExpression instanceof AFileExpression) {
            final AFileExpression fileNode = (AFileExpression) machineExpression;
            final AIdentifierExpression identifier = (AIdentifierExpression) fileNode.getIdentifier();
            String file = fileNode.getContent().getText().replaceAll("\"", "");
            String name = getIdentifier(identifier.getIdentifier());
            MachineReference machineReference;
            try {
                machineReference = new MachineReference(name, identifier, file);
                referncesTable.put(name, machineReference);
            } catch (CheckException e) {
                throw new VisitorException(e);
            }
        } else {
            throw new AssertionError("Not supported class: " + machineExpression.getClass());
        }
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) AFileExpression(de.be4.classicalb.core.parser.node.AFileExpression) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) PExpression(de.be4.classicalb.core.parser.node.PExpression) AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference)

Example 55 with CheckException

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

the class ReferencedMachines method determineRootDirectory.

private void determineRootDirectory(final TPragmaIdOrString packageTerminal, final Node node) {
    final String text = packageTerminal.getText();
    if ((text.startsWith("\"") && text.endsWith("\""))) {
        this.packageName = text.replaceAll("\"", "");
    } else {
        this.packageName = text;
    }
    final String[] packageNameArray = determinePackage(packageTerminal, node);
    File dir;
    try {
        dir = mainFile.getCanonicalFile();
    } catch (IOException e) {
        throw new VisitorIOException(e);
    }
    for (int i = packageNameArray.length - 1; i >= 0; i--) {
        final String name1 = packageNameArray[i];
        dir = dir.getParentFile();
        final String name2 = dir.getName();
        if (!name1.equals(name2)) {
            throw new VisitorException(new CheckException(String.format("Package declaration '%s' does not match the folder structure: %s vs %s", this.packageName, name1, name2), node));
        }
    }
    rootDirectory = dir.getParentFile();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) IOException(java.io.IOException) VisitorIOException(de.be4.classicalb.core.parser.exceptions.VisitorIOException) VisitorIOException(de.be4.classicalb.core.parser.exceptions.VisitorIOException) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) File(java.io.File)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)78 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)19 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)17 PExpression (de.be4.classicalb.core.parser.node.PExpression)16 Test (org.junit.Test)15 BException (de.be4.classicalb.core.parser.exceptions.BException)14 ArrayList (java.util.ArrayList)13 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)12 Ast2String (util.Ast2String)10 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)9 Node (de.be4.classicalb.core.parser.node.Node)8 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)8 File (java.io.File)8 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)4 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)4 Helpers.getTreeAsString (util.Helpers.getTreeAsString)4 Type (de.be4.classicalb.core.parser.IDefinitions.Type)3 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3