Skip to content

Commit

Permalink
findTransition & findTransitionEntryOrFail
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Nov 16, 2023
1 parent 4d5b931 commit 652ccce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
findTransition & findTransitionEntryOrFail

connectTransitionToInputs & connectTransitionToOutputs

evaluateBlockStmt -- Connect
Expand Down
10 changes: 10 additions & 0 deletions src/lang/net/findTransitionEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { nodeKey } from "../node/nodeKey"
import { Transition } from "../transition"
import { Net, TransitionEntry } from "./Net"

export function findTransitionEntry(
net: Net,
transition: Transition,
): TransitionEntry | undefined {
return net.transitionEntries.get(nodeKey(transition))
}
22 changes: 22 additions & 0 deletions src/lang/net/findTransitionEntryOrFail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { formatNode } from "../node"
import { Transition } from "../transition"
import { Net, TransitionEntry } from "./Net"
import { findTransitionEntry } from "./findTransitionEntry"

export function findTransitionEntryOrFail(
net: Net,
transition: Transition,
): TransitionEntry {
const transitionEntry = findTransitionEntry(net, transition)
if (transitionEntry === undefined) {
throw new Error(
[
`[findTransitionEntryOrFail] I can not find nodeEntry for node.`,
``,
` transition: [${formatNode(net, transition)}]`,
].join("\n"),
)
}

return transitionEntry
}
2 changes: 2 additions & 0 deletions src/lang/net/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export * from "./addPlace"
export * from "./addTransition"
export * from "./findPlaceEntry"
export * from "./findPlaceEntryOrFail"
export * from "./findTransitionEntry"
export * from "./findTransitionEntryOrFail"

0 comments on commit 652ccce

Please sign in to comment.