Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions frontend/webEditor/src/constraint/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ export namespace ConstraintDslTreeBuilder {
};

const destinationSelectors = getAbstractSelectors(modelSource, labelTypeRegistry);
destinationSelectors.forEach((destinationSelector) => {
getLeaves(destinationSelector).forEach((n) => {
n.canBeFinal = true;
n.children.push(conditionalSelector);
});
});
appendChildrenToLeaves(destinationSelectors, [...destinationSelectors, conditionalSelector], true);

const nodeDestinationSelector: LanguageTreeNode<Word> = {
word: new ConstantWord("vertex"),
children: destinationSelectors,
Expand All @@ -88,24 +84,16 @@ export namespace ConstraintDslTreeBuilder {
};

const nodeSelectors = getAbstractSelectors(modelSource, labelTypeRegistry);
nodeSelectors.forEach((nodeSelector) => {
getLeaves(nodeSelector).forEach((n) => {
n.children.push(dataSourceSelector);
n.children.push(neverFlows);
});
});
appendChildrenToLeaves(nodeSelectors, [...nodeSelectors, dataSourceSelector, neverFlows], false);

const nodeSourceSelector: LanguageTreeNode<Word> = {
word: new ConstantWord("vertex"),
children: nodeSelectors,
};

const dataSelectors = getAbstractSelectors(modelSource, labelTypeRegistry);
dataSelectors.forEach((dataSelector) => {
getLeaves(dataSelector).forEach((n) => {
n.children.push(nodeSourceSelector);
n.children.push(neverFlows);
});
});
appendChildrenToLeaves(dataSelectors, [...dataSelectors, nodeSourceSelector, neverFlows], false);

dataSourceSelector.children = dataSelectors;

const nameNode: LanguageTreeNode<Word> = {
Expand All @@ -132,6 +120,21 @@ export namespace ConstraintDslTreeBuilder {
return result;
}

function getAllLeaves(words: LanguageTreeNode<Word>[]) {
return words.flatMap(getLeaves);
}

function appendChildrenToLeaves(
words: LanguageTreeNode<Word>[],
children: LanguageTreeNode<Word>[],
makeFinal: boolean,
) {
getAllLeaves(words).forEach((n) => {
n.canBeFinal = makeFinal;
n.children.push(...children);
});
}

function getAbstractSelectors(
modelSource: LocalModelSource,
labelTypeRegistry: LabelTypeRegistry,
Expand Down