From f99a8f8bd1afde8c65d0a148f37a53546fe59c10 Mon Sep 17 00:00:00 2001 From: Alexandre Hajjar Date: Mon, 27 Apr 2020 11:45:42 +0200 Subject: [PATCH] =?UTF-8?q?WIP=20=E2=9A=99=EF=B8=8F=20Detect=20cycles:=20r?= =?UTF-8?q?emove=20RecalculBroken=20(not=20needed=20anymore)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mon-entreprise/test/cycles.test.js | 3 ++ publicodes/source/cyclesLib.ts | 57 ++++++------------------------ 2 files changed, 13 insertions(+), 47 deletions(-) diff --git a/mon-entreprise/test/cycles.test.js b/mon-entreprise/test/cycles.test.js index 3e85b842a..20a0d2e91 100644 --- a/mon-entreprise/test/cycles.test.js +++ b/mon-entreprise/test/cycles.test.js @@ -10,8 +10,11 @@ import rules from 'Rules' describe('DottedNames graph', () => { it("shouldn't have cycles", () => { + // debugger let parsedRules = parseRules(rules) let ruleDependencies = buildRulesDependencies(parsedRules) + + // console.log(ruleDependencies) let g = new graphlib.Graph() ruleDependencies.forEach(([ruleDottedName, dependenciesDottedNames]) => { diff --git a/publicodes/source/cyclesLib.ts b/publicodes/source/cyclesLib.ts index f19e059e5..3d8160026 100644 --- a/publicodes/source/cyclesLib.ts +++ b/publicodes/source/cyclesLib.ts @@ -92,18 +92,19 @@ type FormuleExplanation = | Possibilities | Possibilities2 | Reference - | RecalculBroken | AnyMechanism export function isFormuleExplanation( node: ASTNode ): node is FormuleExplanation { + if (node.avec && node.règle) { + debugger + } return ( isValue(node) || isOperation(node) || isReference(node) || isPossibilities(node) || isPossibilities2(node) || - isRecalculBroken(node) || isAnyMechanism(node) ) } @@ -182,26 +183,6 @@ export function isReference( ) } -type RecalculBroken = ASTNode & { - avec: Record // Note: TS doesn't allow `Record`! - règle?: Name - evaluate: Function -} -export function isRecalculBroken( - node: ASTNode -): node is RecalculBroken { - const recalculBroken = node as RecalculBroken - // Very defensive because we don't want to take risks with this not-well-defined kind of node: - return ( - R.all( - key => R.includes(key, ['avec', 'règle', 'evaluate']), - R.keys(recalculBroken) - ) && - typeof recalculBroken.avec === 'object' && - recalculBroken.evaluate instanceof Function - ) -} - type AbstractMechanism = ASTNode & { category: 'mecanism' name: string @@ -693,14 +674,6 @@ export function ruleDependenciesOfNode( return [reference.dottedName] } - function ruleDependenciesOfRecalculBroken( - depth: number, - recalculBroken: RecalculBroken - ): Array { - logVisit(depth, 'recalcul broken', recalculBroken.règle || '') - return recalculBroken.règle ? [recalculBroken.règle] : [] - } - function ruleDependenciesOfRecalculMech( depth: number, recalculMech: RecalculMech @@ -1021,8 +994,6 @@ export function ruleDependenciesOfNode( return ruleDependenciesOfPossibilities(depth, node) } else if (isPossibilities2(node)) { return ruleDependenciesOfPossibilities2(depth, node) - } else if (isRecalculBroken(node)) { - return ruleDependenciesOfRecalculBroken(depth, node) } else if (isRecalculMech(node)) { return ruleDependenciesOfRecalculMech(depth, node) } else if (isEncadrementMech(node)) { @@ -1061,21 +1032,13 @@ export function ruleDependenciesOfNode( return ruleDependenciesOfDureeMech(depth, node) } - if (node.avec) { - // [XXX] - How come we meet this? Souldn't `mecanismRecalcul` (in `mecanisms.js`) build a `Recalcul` type node? - console.error( - `Visited a non-parsed recalcul node, to investigate: règle ${node.règle}` - ) - } else { - throw new Error( - `This node doesn't have a visitor method defined: ${JSON.stringify( - node, - null, - 4 - )}` - ) - } - return [] + throw new Error( + `This node doesn't have a visitor method defined: ${JSON.stringify( + node, + null, + 4 + )}` + ) } function ruleDependenciesOfRuleNode(