Search in sources :

Example 66 with CheckException

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

the class RulesMachineChecker method checkThatIdentifiersAreLocalVariables.

private void checkThatIdentifiersAreLocalVariables(List<PExpression> copy) {
    for (PExpression e : copy) {
        if (e instanceof AIdentifierExpression) {
            AIdentifierExpression id = (AIdentifierExpression) e;
            String name = id.getIdentifier().get(0).getText();
            if (!this.identifierScope.isAssignableVariable(name)) {
                errorList.add(new CheckException("Identifier '" + name + "' is not a local variable (VAR). Hence, it can not be assigned here.", id));
            }
        } else {
            errorList.add(new CheckException("There must be an identifier on the left side of the assign substitution. A function assignment 'f(1) := 1' is also not permitted.", e));
        }
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 67 with CheckException

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

the class RulesReferencesFinder 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 = null;
    try {
        dir = mainFile.getCanonicalFile();
    } catch (IOException e) {
        errorList.add(new CheckException(e.getMessage(), (Node) null, e));
        return;
    }
    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)) {
            errorList.add(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) File(java.io.File)

Example 68 with CheckException

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

the class RulesReferencesFinder method registerMachineByFilePragma.

private void registerMachineByFilePragma(AFileMachineReference fileNode) {
    final String filePath = fileNode.getFile().getText().replaceAll("\"", "");
    final AMachineReference ref = (AMachineReference) fileNode.getReference();
    final String name = ref.getMachineName().get(0).getText();
    File file = null;
    File tempFile = new File(filePath);
    if (tempFile.exists() && tempFile.isAbsolute() && !tempFile.isDirectory()) {
        file = tempFile;
    } else {
        tempFile = new File(mainFile.getParentFile(), filePath);
        if (tempFile.exists() && !tempFile.isDirectory()) {
            file = tempFile;
        }
    }
    if (tempFile.isDirectory()) {
        errorList.add(new CheckException(String.format("File '%s' is a directory.", filePath), fileNode.getFile()));
        return;
    } else if (file == null) {
        errorList.add(new CheckException(String.format("File '%s' does not exist.", filePath), fileNode.getFile()));
        return;
    } else {
        RulesMachineReference rulesMachineReference = new RulesMachineReference(file, name, fileNode.getReference());
        referncesTable.put(name, rulesMachineReference);
        return;
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) File(java.io.File)

Example 69 with CheckException

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

the class RulesReferencesFinder method caseAImportPackage.

@Override
public void caseAImportPackage(AImportPackage node) {
    final String[] packageArray = determinePackage(node.getPackage(), node);
    final File pathFile = getFileStartingAtRootDirectory(packageArray);
    final String path = pathFile.getAbsolutePath();
    if (!pathFile.exists()) {
        errorList.add(new CheckException(String.format("Imported package does not exist: %s", path), node.getPackage()));
        return;
    }
    if (this.pathList.contains(path)) {
        errorList.add(new CheckException(String.format("Duplicate package import: %s", node.getPackage().getText()), node));
        return;
    }
    this.pathList.add(path);
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) File(java.io.File)

Example 70 with CheckException

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

the class RulesReferencesFinder method caseAMachineHeader.

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

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