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));
}
}
}
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();
}
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;
}
}
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);
}
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);
}
}
}
Aggregations