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);
}
}
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);
}
}
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();
}
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);
}
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;
}
Aggregations