diff --git a/TODO.md b/TODO.md index 9e454af..577c46d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,3 @@ -findTransition & findTransitionEntryOrFail - connectTransitionToInputs & connectTransitionToOutputs evaluateBlockStmt -- Connect diff --git a/src/lang/net/findTransitionEntry.ts b/src/lang/net/findTransitionEntry.ts new file mode 100644 index 0000000..7296ed5 --- /dev/null +++ b/src/lang/net/findTransitionEntry.ts @@ -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)) +} diff --git a/src/lang/net/findTransitionEntryOrFail.ts b/src/lang/net/findTransitionEntryOrFail.ts new file mode 100644 index 0000000..835c347 --- /dev/null +++ b/src/lang/net/findTransitionEntryOrFail.ts @@ -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 +} diff --git a/src/lang/net/index.ts b/src/lang/net/index.ts index 3d4b799..1fa8f0e 100644 --- a/src/lang/net/index.ts +++ b/src/lang/net/index.ts @@ -4,3 +4,5 @@ export * from "./addPlace" export * from "./addTransition" export * from "./findPlaceEntry" export * from "./findPlaceEntryOrFail" +export * from "./findTransitionEntry" +export * from "./findTransitionEntryOrFail"