use of de.be4.classicalb.core.parser.node.Node 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);
}
}
}
use of de.be4.classicalb.core.parser.node.Node 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.node.Node in project probparsers by bendisposto.
the class ClausesCollector method inAAbstractMachineParseUnit.
@Override
public void inAAbstractMachineParseUnit(final AAbstractMachineParseUnit node) {
super.inAAbstractMachineParseUnit(node);
final LinkedList<PMachineClause> machineClauses = node.getMachineClauses();
for (final Iterator<PMachineClause> iterator = machineClauses.iterator(); iterator.hasNext(); ) {
final PMachineClause clause = iterator.next();
final String className = clause.getClass().getSimpleName();
Set<Node> nodesForclause = availableClauses.get(className);
if (nodesForclause == null) {
nodesForclause = new HashSet<Node>();
}
nodesForclause.add(clause);
availableClauses.put(className, nodesForclause);
}
}
use of de.be4.classicalb.core.parser.node.Node 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.node.Node 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);
}
Aggregations