Search in sources :

Example 1 with AMachineReference

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

the class BMachine method addIncludesClause.

public void addIncludesClause(String machineName) {
    AIncludesMachineClause includes = new AIncludesMachineClause();
    List<PMachineReference> referencesList = new ArrayList<>();
    List<TIdentifierLiteral> idList = new ArrayList<>();
    idList.add(new TIdentifierLiteral(machineName));
    referencesList.add(new AMachineReference(idList, new ArrayList<PExpression>()));
    includes.setMachineReferences(referencesList);
    this.parseUnit.getMachineClauses().add(includes);
}
Also used : PMachineReference(de.be4.classicalb.core.parser.node.PMachineReference) ArrayList(java.util.ArrayList) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference) AIncludesMachineClause(de.be4.classicalb.core.parser.node.AIncludesMachineClause) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 2 with AMachineReference

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

the class RulesReferencesFinder method registerMachineReference.

private void registerMachineReference(AMachineReference mchRef) {
    String name = mchRef.getMachineName().get(0).getText();
    try {
        final File file = lookupFile(mainFile.getParentFile(), name, mchRef);
        RulesMachineReference rulesMachineReference = new RulesMachineReference(file, name, mchRef);
        referncesTable.put(name, rulesMachineReference);
    } catch (CheckException e) {
        errorList.add(e);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) File(java.io.File)

Example 3 with AMachineReference

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

Example 4 with AMachineReference

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

the class RulesReferencesFinder method registerMachineNames.

private void registerMachineNames(final PMachineReference machineReference) {
    if (machineReference instanceof AFileMachineReference) {
        registerMachineByFilePragma((AFileMachineReference) machineReference);
    } else {
        AMachineReference mchRef = (AMachineReference) machineReference;
        registerMachineReference(mchRef);
    }
}
Also used : AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference)

Example 5 with AMachineReference

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

the class RulesReferencesFinder method registerMachineByFilePragma.

private void registerMachineByFilePragma(AFileMachineReference fileNode) {
    final String filePath = fileNode.getFile().getText().replaceAll("\"", "");
    final AMachineReference ref = (AMachineReference) fileNode.getReference();
    final String name = ref.getMachineName().get(0).getText();
    File file = null;
    File tempFile = new File(filePath);
    if (tempFile.exists() && tempFile.isAbsolute() && !tempFile.isDirectory()) {
        file = tempFile;
    } else {
        tempFile = new File(mainFile.getParentFile(), filePath);
        if (tempFile.exists() && !tempFile.isDirectory()) {
            file = tempFile;
        }
    }
    if (tempFile.isDirectory()) {
        errorList.add(new CheckException(String.format("File '%s' is a directory.", filePath), fileNode.getFile()));
        return;
    } else if (file == null) {
        errorList.add(new CheckException(String.format("File '%s' does not exist.", filePath), fileNode.getFile()));
        return;
    } else {
        RulesMachineReference rulesMachineReference = new RulesMachineReference(file, name, fileNode.getReference());
        referncesTable.put(name, rulesMachineReference);
        return;
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) File(java.io.File)

Aggregations

AMachineReference (de.be4.classicalb.core.parser.node.AMachineReference)4 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)3 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)3 AFileMachineReference (de.be4.classicalb.core.parser.node.AFileMachineReference)2 PMachineReference (de.be4.classicalb.core.parser.node.PMachineReference)2 File (java.io.File)2 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 AIncludesMachineClause (de.be4.classicalb.core.parser.node.AIncludesMachineClause)1 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 ArrayList (java.util.ArrayList)1