Search in sources :

Example 86 with Node

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);
        }
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString)

Example 87 with Node

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;
}
Also used : Pattern(java.util.regex.Pattern) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString)

Example 88 with Node

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);
    }
}
Also used : Node(de.be4.classicalb.core.parser.node.Node) PMachineClause(de.be4.classicalb.core.parser.node.PMachineClause)

Example 89 with Node

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()])));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Node(de.be4.classicalb.core.parser.node.Node)

Example 90 with Node

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);
}
Also used : Node(de.be4.classicalb.core.parser.node.Node) SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)42 PExpression (de.be4.classicalb.core.parser.node.PExpression)30 ArrayList (java.util.ArrayList)30 Node (de.be4.classicalb.core.parser.node.Node)20 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)16 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)11 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)8 HashSet (java.util.HashSet)8 Token (de.be4.ltl.core.parser.node.Token)7 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 IOException (java.io.IOException)6 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)5 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)5 LinkedList (java.util.LinkedList)5 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3