Skip to content

Commit deb070d

Browse files
Kr0noxEntenwilli
authored andcommitted
add and function
1 parent 0016e5b commit deb070d

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

frontend/webEditor/src/constraint/language.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ export namespace ConstraintDslTreeBuilder {
6565
};
6666

6767
const destinationSelectors = getAbstractSelectors(modelSource, labelTypeRegistry);
68-
destinationSelectors.forEach((destinationSelector) => {
69-
getLeaves(destinationSelector).forEach((n) => {
70-
n.canBeFinal = true;
71-
n.children.push(conditionalSelector);
72-
});
73-
});
68+
appendChildrenToLeaves(destinationSelectors, [...destinationSelectors, conditionalSelector], true);
69+
7470
const nodeDestinationSelector: LanguageTreeNode<Word> = {
7571
word: new ConstantWord("vertex"),
7672
children: destinationSelectors,
@@ -88,24 +84,16 @@ export namespace ConstraintDslTreeBuilder {
8884
};
8985

9086
const nodeSelectors = getAbstractSelectors(modelSource, labelTypeRegistry);
91-
nodeSelectors.forEach((nodeSelector) => {
92-
getLeaves(nodeSelector).forEach((n) => {
93-
n.children.push(dataSourceSelector);
94-
n.children.push(neverFlows);
95-
});
96-
});
87+
appendChildrenToLeaves(nodeSelectors, [...nodeSelectors, dataSourceSelector, neverFlows], false);
88+
9789
const nodeSourceSelector: LanguageTreeNode<Word> = {
9890
word: new ConstantWord("vertex"),
9991
children: nodeSelectors,
10092
};
10193

10294
const dataSelectors = getAbstractSelectors(modelSource, labelTypeRegistry);
103-
dataSelectors.forEach((dataSelector) => {
104-
getLeaves(dataSelector).forEach((n) => {
105-
n.children.push(nodeSourceSelector);
106-
n.children.push(neverFlows);
107-
});
108-
});
95+
appendChildrenToLeaves(dataSelectors, [...dataSelectors, nodeSourceSelector, neverFlows], false);
96+
10997
dataSourceSelector.children = dataSelectors;
11098

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

123+
function getAllLeaves(words: LanguageTreeNode<Word>[]) {
124+
return words.flatMap(getLeaves);
125+
}
126+
127+
function appendChildrenToLeaves(
128+
words: LanguageTreeNode<Word>[],
129+
children: LanguageTreeNode<Word>[],
130+
makeFinal: boolean,
131+
) {
132+
getAllLeaves(words).forEach((n) => {
133+
n.canBeFinal = makeFinal;
134+
n.children.push(...children);
135+
});
136+
}
137+
135138
function getAbstractSelectors(
136139
modelSource: LocalModelSource,
137140
labelTypeRegistry: LabelTypeRegistry,

0 commit comments

Comments
 (0)