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