use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RulesReferencesFinder method determinePackage.
private String[] determinePackage(final TPragmaIdOrString packageTerminal, final Node node) {
String text = packageTerminal.getText();
// "foo.bar" or foo.bar
if ((text.startsWith("\"") && text.endsWith("\""))) {
text = text.replaceAll("\"", "");
}
final String[] packageNameArray = text.split("\\.");
final Pattern VALID_IDENTIFIER = Pattern.compile("([\\p{L}][\\p{L}\\p{N}_]*)");
for (int i = 0; i < packageNameArray.length; i++) {
boolean matches = VALID_IDENTIFIER.matcher(packageNameArray[i]).matches();
if (!matches) {
errorList.add(new CheckException(String.format("Invalid folder name '%s' in package declaration.", text), node));
}
}
return packageNameArray;
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class IdentListCheck method runChecks.
/**
* <p>
* See class description. First {@link AAssignSubstitution} nodes are
* checked, then the other nodes.
* </p>
* <p>
* An {@link CheckException} is thrown if there are
* {@link AAssignSubstitution} or {@link AOperationCallSubstitution} nodes
* with illegal elements in the LHS. Otherwise the other relevant nodes are
* checked for illegal entries in their identifier lists.
* </p>
* <p>
* In both cases the erroneous nodes are collected, so that only one
* exception is thrown for the {@link AAssignSubstitution} and
* {@link AOperationCallSubstitution} nodes respectively one for all other
* nodes.
* </p>
*
* @param rootNode
* the start node of the AST
*/
public void runChecks(final Start rootNode) {
nonIdentifiers.clear();
/*
* First check all assignment nodes if the LHS only contains identifiers
* or functions.
*/
final AssignCheck assignCheck = new AssignCheck();
rootNode.apply(assignCheck);
final Set<Node> assignErrorNodes = assignCheck.nonIdentifiers;
if (!assignErrorNodes.isEmpty()) {
exceptions.add(new CheckException("Identifier or function expected", assignErrorNodes.toArray(new Node[assignErrorNodes.size()])));
}
/*
* Then check other constructs which can only contain identifiers at
* special places.
*/
rootNode.apply(this);
if (!nonIdentifiers.isEmpty()) {
// at least one error was found
exceptions.add(new CheckException("Identifier expected", nonIdentifiers.toArray(new Node[nonIdentifiers.size()])));
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class PrologExceptionPrinter method printCheckException.
private static void printCheckException(final IPrologTermOutput pto, final CheckException cause, final String filename, final boolean useIndentation, final boolean lineOneOff) {
final Node[] nodes = cause.getNodes();
final SourcePosition startPos;
if (nodes != null && nodes.length > 0) {
startPos = nodes[0].getStartPos();
} else {
startPos = null;
}
printExceptionWithSourcePosition(pto, cause, filename, startPos, useIndentation, lineOneOff);
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class PrologExceptionPrinter method printBException.
public static void printBException(IPrologTermOutput pto, final BException e, boolean useIndentation, boolean lineOneOff) {
Throwable cause = e.getCause();
String filename = e.getFilename();
if (cause == null) {
printGeneralException(pto, e, filename, useIndentation, lineOneOff, true);
} else {
while (cause.getClass().equals(BException.class) && cause.getCause() != null) {
BException bex = (BException) cause;
cause = bex.getCause();
filename = bex.getFilename();
}
if (cause instanceof BLexerException) {
printBLexerException(pto, (BLexerException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof LexerException) {
printLexerException(pto, (LexerException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof BParseException) {
printBParseException(pto, (BParseException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof PreParseException) {
printPreParseException(pto, (PreParseException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof CheckException) {
printCheckException(pto, (CheckException) cause, filename, useIndentation, lineOneOff);
} else {
printGeneralException(pto, cause, filename, useIndentation, lineOneOff, false);
}
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RecursiveMachineLoader method lookupFile.
/**
* Tries to find a file containing the machine with the given file name.
*
* @param ancestors
*
* @param machineName
* Name of the machine to include, never <code>null</code>
* @param paths
*
* @return reference to a file containing the machine, may be non-existent
* but never <code>null</code>.
* @throws CheckException
* if the file cannot be found
*/
private File lookupFile(final File parentMachineDirectory, final MachineReference machineRef, List<String> ancestors, List<String> paths) throws CheckException {
for (final String suffix : SUFFICES) {
try {
final String directoryString = machineRef.getDirectoryPath() != null ? machineRef.getDirectoryPath() : parentMachineDirectory.getAbsolutePath();
return new FileSearchPathProvider(directoryString, machineRef.getName() + suffix, paths).resolve();
} catch (FileNotFoundException e) {
// could not resolve the combination of prefix, machineName and
// suffix, trying next one
}
}
StringBuilder sb = new StringBuilder();
sb.append("Machine not found: '");
sb.append(machineRef.getName());
sb.append("'");
String fileNameOfErrorMachine = parsedFiles.get(ancestors.get(ancestors.size() - 1)).getName();
sb.append(" in '").append(fileNameOfErrorMachine).append("'");
for (int i = ancestors.size() - 2; i >= 0; i--) {
String name = ancestors.get(i);
String fileName = parsedFiles.get(name).getName();
sb.append(" loaded by ").append("'").append(fileName).append("'");
}
throw new CheckException(sb.toString(), machineRef.getNode());
}
Aggregations