Skip to content

Commit

Permalink
move formatEdge to edge/
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 17, 2023
1 parent f12232e commit 1471049
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
remove `begin end` syntax

# books

反应网编程
Expand Down
13 changes: 13 additions & 0 deletions src/lang/edge/formatEdge.ts
Original file line number Diff line number Diff line change
@@ -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})`
}
}
14 changes: 1 addition & 13 deletions src/lang/net/formatNet.ts
Original file line number Diff line number Diff line change
@@ -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})`
}
}

0 comments on commit 1471049

Please sign in to comment.