diff --git a/frontend/webEditor/src/constraint/language.ts b/frontend/webEditor/src/constraint/language.ts index 38591e26..fe29ba83 100644 --- a/frontend/webEditor/src/constraint/language.ts +++ b/frontend/webEditor/src/constraint/language.ts @@ -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: new ConstantWord("vertex"), children: destinationSelectors, @@ -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: 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 = { @@ -132,6 +120,21 @@ export namespace ConstraintDslTreeBuilder { return result; } + function getAllLeaves(words: LanguageTreeNode[]) { + return words.flatMap(getLeaves); + } + + function appendChildrenToLeaves( + words: LanguageTreeNode[], + children: LanguageTreeNode[], + makeFinal: boolean, + ) { + getAllLeaves(words).forEach((n) => { + n.canBeFinal = makeFinal; + n.children.push(...children); + }); + } + function getAbstractSelectors( modelSource: LocalModelSource, labelTypeRegistry: LabelTypeRegistry,