Search in sources :

Example 71 with Node

use of de.be4.classicalb.core.parser.node.Node 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 72 with Node

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

the class ReferencedMachines method caseARefinementMachineParseUnit.

// REFINES
@Override
public void caseARefinementMachineParseUnit(ARefinementMachineParseUnit node) {
    node.getHeader().apply(this);
    String name = node.getRefMachine().getText();
    referncesTable.put(name, new MachineReference(name, node.getRefMachine()));
    for (Node mclause : node.getMachineClauses()) {
        mclause.apply(this);
    }
}
Also used : Node(de.be4.classicalb.core.parser.node.Node) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference)

Example 73 with Node

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

the class ReferencedMachines 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;
    try {
        dir = mainFile.getCanonicalFile();
    } catch (IOException e) {
        throw new VisitorIOException(e);
    }
    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)) {
            throw new VisitorException(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) VisitorIOException(de.be4.classicalb.core.parser.exceptions.VisitorIOException) VisitorIOException(de.be4.classicalb.core.parser.exceptions.VisitorIOException) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) File(java.io.File)

Example 74 with Node

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

the class OpSubstitutions method setTypeSubstDef.

private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
    final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
    final Node defRhs = oldDefinition.getRhs();
    final PSubstitution rhsSubst;
    if (defRhs instanceof AFunctionExpression) {
        final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
        rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
        rhsSubst.setStartPos(rhsFunction.getStartPos());
        rhsSubst.setEndPos(rhsFunction.getEndPos());
    } else if (defRhs instanceof AIdentifierExpression) {
        final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
        rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
        rhsSubst.setStartPos(rhsIdent.getStartPos());
        rhsSubst.setEndPos(rhsIdent.getEndPos());
    } else {
        // some other expression was parsed (NOT allowed)
        throw new VisitorException(new CheckException("Expecting operation", node));
    }
    final TIdentifierLiteral oldDefId = oldDefinition.getName();
    final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
    final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
    substDef.setStartPos(oldDefinition.getStartPos());
    substDef.setEndPos(oldDefinition.getEndPos());
    definitions.replaceDefinition(idString, Type.Substitution, substDef);
    oldDefinition.replaceBy(substDef);
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Node(de.be4.classicalb.core.parser.node.Node) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AFunctionExpression(de.be4.classicalb.core.parser.node.AFunctionExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) AOpSubstitution(de.be4.classicalb.core.parser.node.AOpSubstitution) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Example 75 with Node

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

the class OpSubstitutions method replaceWithDefExpression.

private ADefinitionExpression replaceWithDefExpression(final Node node, TIdentifierLiteral identifier, final List<PExpression> paramList) {
    final ADefinitionExpression newNode = new ADefinitionExpression();
    newNode.setDefLiteral(identifier);
    if (paramList != null) {
        newNode.setParameters(paramList);
    }
    final PositionedNode posNode = node;
    final PositionedNode newPosNode = newNode;
    newPosNode.setStartPos(posNode.getStartPos());
    newPosNode.setEndPos(posNode.getEndPos());
    node.replaceBy(newNode);
    return newNode;
}
Also used : ADefinitionExpression(de.be4.classicalb.core.parser.node.ADefinitionExpression) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode)

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