use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class RulesProject method findTransitiveDependencies.
private Set<AbstractOperation> findTransitiveDependencies(final AbstractOperation operation, final List<AbstractOperation> ancestors) {
ancestors.add(operation);
List<TIdentifierLiteral> directDependencies = new ArrayList<>();
directDependencies.addAll(convertAIdentifierListToTIdentifierLiteralList(operation.getDependsOnComputationList()));
directDependencies.addAll(convertAIdentifierListToTIdentifierLiteralList(operation.getDependsOnRulesList()));
directDependencies.addAll(operation.getImplicitDependenciesToComputations());
directDependencies.addAll(operation.getFunctionCalls());
// check for cycle
Set<AbstractOperation> transitiveDependenciesFound = new HashSet<>();
boolean cycleDetected = checkForCycles(operation, directDependencies, ancestors);
if (cycleDetected) {
operation.setTransitiveDependencies(transitiveDependenciesFound);
return transitiveDependenciesFound;
}
for (TIdentifierLiteral tIdentifierLiteral : directDependencies) {
String opName = tIdentifierLiteral.getText();
AbstractOperation nextOperation = allOperations.get(opName);
transitiveDependenciesFound.add(nextOperation);
if (nextOperation.getTransitiveDependencies() != null) {
transitiveDependenciesFound.addAll(nextOperation.getTransitiveDependencies());
} else {
transitiveDependenciesFound.addAll(findTransitiveDependencies(nextOperation, new ArrayList<>(ancestors)));
}
}
operation.setTransitiveDependencies(transitiveDependenciesFound);
return new HashSet<>(transitiveDependenciesFound);
}
use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class ASTPrologTest method testEvent.
@Test
public void testEvent() throws BCompoundException {
final AEventBModelParseUnit model = new AEventBModelParseUnit();
model.setName(new TIdentifierLiteral("mm"));
final AEventsModelClause events = new AEventsModelClause();
model.setModelClauses(Arrays.asList((PModelClause) events));
AEvent event = new AEvent();
events.setEvent(Arrays.asList((PEvent) event));
event.setEventName(new TIdentifierLiteral("testevent"));
event.setVariables(Arrays.asList(createId("param")));
event.setGuards(Arrays.asList((PPredicate) new ATruthPredicate()));
PSubstitution subst1 = new AAssignSubstitution(Arrays.asList(createId("x")), Arrays.asList(createId("param")));
event.setAssignments(Arrays.asList(subst1));
PWitness witness = new AWitness(new TIdentifierLiteral("ab"), new AEqualPredicate(createId("ab"), createId("y")));
event.setWitness(Arrays.asList(witness));
event.setRefines(Arrays.asList(new TIdentifierLiteral("abstract1"), new TIdentifierLiteral("abstract2")));
checkAST(0, "event_b_model($,mm,[events($,[" + "event($,testevent,[abstract1,abstract2],[identifier($,param)],[truth($)],[]," + "[assign($,[identifier($,x)],[identifier($,param)])]," + "[witness($,identifier(%,ab),equal($,identifier($,ab),identifier($,y)))])])])", model);
}
use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class PreParser method determineDependencies.
private Map<String, Set<String>> determineDependencies(Set<String> definitionNames, Map<Token, Token> definitions) throws PreParseException {
HashMap<String, Set<String>> dependencies = new HashMap<>();
for (Entry<Token, Token> entry : definitions.entrySet()) {
Token nameToken = entry.getKey();
Token rhsToken = entry.getValue();
// The FORMULA_PREFIX is needed to switch the lexer state from
// section to normal. Note, that we do not parse the right hand side
// of the definition here. Hence FORMULA_PREFIX has no further
// meaning and substitutions can also be handled by the lexer.
final Reader reader = new StringReader(BParser.FORMULA_PREFIX + "\n" + rhsToken.getText());
final BLexer lexer = new BLexer(new PushbackReader(reader, BLexer.PUSHBACK_BUFFER_SIZE), new DefinitionTypes());
lexer.setParseOptions(parseOptions);
Set<String> set = new HashSet<>();
de.be4.classicalb.core.parser.node.Token next = null;
try {
next = lexer.next();
while (!(next instanceof EOF)) {
if (next instanceof TIdentifierLiteral) {
TIdentifierLiteral id = (TIdentifierLiteral) next;
String name = id.getText();
if (definitionNames.contains(name)) {
set.add(name);
}
}
next = lexer.next();
}
} catch (IOException e) {
} catch (BLexerException e) {
de.be4.classicalb.core.parser.node.Token errorToken = e.getLastToken();
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(nameToken, rhsToken, errorToken, e.getMessage());
throw new PreParseException(newMessage);
} catch (de.be4.classicalb.core.parser.lexer.LexerException e) {
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformationsWithoutToken(nameToken, rhsToken, e.getMessage());
throw new PreParseException(newMessage);
}
dependencies.put(nameToken.getText(), set);
}
return dependencies;
}
use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class CTagsGenerator method createCTagsFromMachines.
private static Collection<? extends CTagsEntry> createCTagsFromMachines(RulesProject project) {
List<CTagsEntry> list = new ArrayList<>();
for (IModel model : project.bModels) {
if (model instanceof RulesParseUnit) {
RulesParseUnit parseUnit = (RulesParseUnit) model;
if (null != parseUnit.getRulesMachineChecker()) {
TIdentifierLiteral literal = parseUnit.getRulesMachineChecker().getNameLiteral();
list.add(new CTagsEntry(literal.getText(), parseUnit.getPath(), literal.getStartPos(), TYPE_MACHINE));
}
}
}
return list;
}
use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class EnumeratedSetElement method createASTNode.
public PExpression createASTNode(Typechecker typechecker) {
TIdentifierLiteral literal = new TIdentifierLiteral(name);
ArrayList<TIdentifierLiteral> idList = new ArrayList<TIdentifierLiteral>();
idList.add(literal);
AIdentifierExpression id = new AIdentifierExpression(idList);
typechecker.setType(id, new SetType(this));
return id;
}
Aggregations