use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class PredVarsTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
final BParser parser = new BParser("testcase");
Start ast = parser.eparse(testMachine, new Definitions());
final Ast2String ast2String = new Ast2String();
ast.apply(ast2String);
final String string = ast2String.toString();
return string;
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class ASTBuilder method addPrintSubDefinitionToIdefinitions.
public static void addPrintSubDefinitionToIdefinitions(IDefinitions definitions) {
if (definitions.containsDefinition(PRINT)) {
return;
}
/*-
* PRINT(x) == skip;
* EXTERNAL_SUBSTITUTION_PRINT(T) == T; /* declare as external for any type T
*/
ASubstitutionDefinitionDefinition printDef = new ASubstitutionDefinitionDefinition();
printDef.setName(new TDefLiteralSubstitution(PRINT));
printDef.setParameters(createIdentifierList("value"));
printDef.setRhs(new ASkipSubstitution());
definitions.addDefinition(printDef, IDefinitions.Type.Substitution);
AExpressionDefinitionDefinition forceDefType = new AExpressionDefinitionDefinition();
forceDefType.setName(new TIdentifierLiteral("EXTERNAL_SUBSTITUTION_" + PRINT));
forceDefType.setParameters(createIdentifierList("T"));
forceDefType.setRhs(createIdentifier("T"));
definitions.addDefinition(forceDefType, IDefinitions.Type.Expression);
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class OpSubstitutions method caseAIdentifierExpression.
@Override
public void caseAIdentifierExpression(final AIdentifierExpression node) {
final String identifierString = Utils.getTIdentifierListAsString(node.getIdentifier());
final Integer number = scopedVariables.get(identifierString);
final Type type = definitions.getType(identifierString);
if (number == null && type != Type.NoDefinition) {
if (type == Type.Expression || type == Type.ExprOrSubst) {
/*
* getFirst() is enough cause definitions cannot have composed
* identifiers
*/
replaceWithDefExpression(node, node.getIdentifier().getFirst(), null);
if (type == Type.ExprOrSubst) {
// type is determined now => set to Expression
definitions.setDefinitionType(identifierString, Type.Expression);
}
} else {
// finding some other type here is an error!
throw new VisitorException(new CheckException("Expecting expression here but found definition with type '" + type + "'", node));
}
}
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class RulesProject method createMainMachine.
private BMachine createMainMachine(List<PDefinition> mainDefinitions) {
BMachine mainMachine = new BMachine(MAIN_MACHINE_NAME);
mainMachine.addIncludesClause(COMPOSITION_MACHINE_NAME);
mainMachine.addPromotesClause(getPromotesList());
mainMachine.addPropertiesPredicates(this.constantStringValues);
IDefinitions idefinitions = new Definitions();
if (mainDefinitions != null) {
for (PDefinition pDefinition : mainDefinitions) {
idefinitions.addDefinition(pDefinition);
}
}
addToStringDefinition(idefinitions);
addSortDefinition(idefinitions);
addFormatToStringDefinition(idefinitions);
addChooseDefinition(idefinitions);
addBooleanPreferenceDefinition(idefinitions, "SET_PREF_ALLOW_LOCAL_OPERATION_CALLS", true);
mainMachine.replaceDefinition(idefinitions);
return mainMachine;
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class PreParser method evaluateDefinitionFiles.
private void evaluateDefinitionFiles(final List<Token> list) throws PreParseException, BException, BCompoundException {
IDefinitionFileProvider cache = null;
if (contentProvider instanceof IDefinitionFileProvider) {
cache = (IDefinitionFileProvider) contentProvider;
}
for (final Token fileNameToken : list) {
final List<String> newDoneList = new ArrayList<String>(doneDefFiles);
try {
final String fileName = fileNameToken.getText();
if (doneDefFiles.contains(fileName)) {
StringBuilder sb = new StringBuilder();
for (String string : doneDefFiles) {
sb.append(string).append(" -> ");
}
sb.append(fileName);
throw new PreParseException(fileNameToken, "Cyclic references in definition files: " + sb.toString());
}
IDefinitions definitions;
if (cache != null && cache.getDefinitions(fileName) != null) {
definitions = cache.getDefinitions(fileName);
} else {
final String content = contentProvider.getFileContent(directory, fileName);
newDoneList.add(fileName);
final File file = contentProvider.getFile(directory, fileName);
String filePath = fileName;
if (file != null) {
filePath = file.getCanonicalPath();
}
final BParser parser = new BParser(filePath, parseOptions);
parser.setDirectory(directory);
parser.setDoneDefFiles(newDoneList);
parser.setDefinitions(new Definitions(file));
parser.parse(content, debugOutput, contentProvider);
definitions = parser.getDefinitions();
if (cache != null) {
cache.storeDefinition(fileName, definitions);
}
}
defFileDefinitions.addDefinitions(definitions);
definitionTypes.addAll(definitions.getTypes());
} catch (final IOException e) {
throw new PreParseException(fileNameToken, "Definition file cannot be read: " + e.getLocalizedMessage());
} finally {
}
}
}
Aggregations