Search in sources :

Example 81 with Node

use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.

the class RulesMachineChecker method caseAExpressionDefinitionDefinition.

@Override
public void caseAExpressionDefinitionDefinition(AExpressionDefinitionDefinition node) {
    final String name = node.getName().getText();
    this.definitions.add(name);
    if ("GOAL".equals(name)) {
        errorList.add(new CheckException("The GOAL definition must be a predicate.", node));
        return;
    }
    this.identifierScope.createNewScope(new LinkedList<>(node.getParameters()));
    node.getRhs().apply(this);
    this.identifierScope.removeScope();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Example 82 with Node

use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.

the class RulesMachineChecker method caseARuleOperation.

@Override
public void caseARuleOperation(ARuleOperation node) {
    currentOperation = new RuleOperation(node.getRuleName(), this.fileName, this.machineName, machineReferences);
    if (containsRule(currentOperation.getName())) {
        errorList.add(new CheckException("Duplicate operation name '" + currentOperation.getName() + "'.", node.getRuleName()));
    }
    RuleOperation ruleOp = (RuleOperation) currentOperation;
    rulesMap.put(node, ruleOp);
    visitOperationAttributes(node.getAttributes());
    node.getRuleBody().apply(this);
    checkAllErrorTypesImplemented(ruleOp);
    currentOperation = null;
}
Also used : ARuleOperation(de.be4.classicalb.core.parser.node.ARuleOperation) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Example 83 with Node

use of de.be4.classicalb.core.parser.node.Node 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();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) IOException(java.io.IOException) File(java.io.File)

Example 84 with Node

use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.

the class RulesReferencesFinder method caseAPackageParseUnit.

@Override
public void caseAPackageParseUnit(APackageParseUnit node) {
    determineRootDirectory(node.getPackage(), node);
    List<PImportPackage> copy = new ArrayList<>(node.getImports());
    for (PImportPackage e : copy) {
        e.apply(this);
    }
    node.getParseUnit().apply(this);
    // delete this node
    node.replaceBy(node.getParseUnit());
}
Also used : PImportPackage(de.be4.classicalb.core.parser.node.PImportPackage) ArrayList(java.util.ArrayList)

Example 85 with Node

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

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