From 14710493ec5659467656e8e5bd3644510f40fa0a Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Fri, 18 Aug 2023 05:56:20 +0800 Subject: [PATCH] move `formatEdge` to `edge/` --- TODO.md | 2 ++ src/lang/edge/formatEdge.ts | 13 +++++++++++++ src/lang/net/formatNet.ts | 14 +------------- 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 src/lang/edge/formatEdge.ts diff --git a/TODO.md b/TODO.md index 08cd91a0..17e0da42 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,5 @@ +remove `begin end` syntax + # books 反应网编程 diff --git a/src/lang/edge/formatEdge.ts b/src/lang/edge/formatEdge.ts new file mode 100644 index 00000000..455da53f --- /dev/null +++ b/src/lang/edge/formatEdge.ts @@ -0,0 +1,13 @@ +import { Edge } from "../edge" +import { formatNode } from "../node/formatNode" + +export function formatEdge(edge: Edge): string { + const first = formatNode(edge.first.node) + const second = formatNode(edge.second.node) + + if (edge.first.isPrincipal && edge.second.isPrincipal) { + return `(${first})-${edge.first.name}!${edge.second.name}-(${second})` + } else { + return `(${first})-${edge.first.name} ${edge.second.name}-(${second})` + } +} diff --git a/src/lang/net/formatNet.ts b/src/lang/net/formatNet.ts index db6805c3..a931c0a5 100644 --- a/src/lang/net/formatNet.ts +++ b/src/lang/net/formatNet.ts @@ -1,19 +1,7 @@ -import { Edge } from "../edge" -import { formatNode } from "../node/formatNode" +import { formatEdge } from "../edge/formatEdge" import { Net } from "./Net" import { allEdges } from "./allEdges" export function formatNet(net: Net): string { return allEdges(net).map(formatEdge).join("\n") } - -function formatEdge(edge: Edge): string { - const first = formatNode(edge.first.node) - const second = formatNode(edge.second.node) - - if (edge.first.isPrincipal && edge.second.isPrincipal) { - return `(${first})-${edge.first.name}!${edge.second.name}-(${second})` - } else { - return `(${first})-${edge.first.name} ${edge.second.name}-(${second})` - } -}