summaryrefslogtreecommitdiffstats
path: root/llparse-frontend/src/node/base.ts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /llparse-frontend/src/node/base.ts
parentInitial commit. (diff)
downloadnode-undici-upstream.tar.xz
node-undici-upstream.zip
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--llparse-frontend/src/node/base.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/llparse-frontend/src/node/base.ts b/llparse-frontend/src/node/base.ts
new file mode 100644
index 0000000..1e93c49
--- /dev/null
+++ b/llparse-frontend/src/node/base.ts
@@ -0,0 +1,46 @@
+import { IUniqueName } from '../utils';
+import { IWrap } from '../wrap';
+import { Slot } from './slot';
+
+export interface IReadonlyOtherwiseEdge {
+ readonly node: IWrap<Node>;
+ readonly noAdvance: boolean;
+ readonly value: number | undefined;
+}
+
+interface IOtherwiseEdge {
+ node: IWrap<Node>;
+ readonly noAdvance: boolean;
+ readonly value: number | undefined;
+}
+
+export abstract class Node {
+ private privOtherwise: IOtherwiseEdge | undefined;
+ private privSlots: ReadonlyArray<Slot> | undefined;
+
+ constructor(public readonly id: IUniqueName) {
+ }
+
+ public setOtherwise(node: IWrap<Node>, noAdvance: boolean, value?: number) {
+ this.privOtherwise = { node, noAdvance, value };
+ }
+
+ public get otherwise(): IReadonlyOtherwiseEdge | undefined {
+ return this.privOtherwise;
+ }
+
+ public *getSlots() {
+ if (this.privSlots === undefined) {
+ this.privSlots = Array.from(this.buildSlots());
+ }
+
+ yield* this.privSlots;
+ }
+
+ protected *buildSlots() {
+ const otherwise = this.privOtherwise;
+ if (otherwise !== undefined) {
+ yield new Slot(otherwise.node, (value) => otherwise.node = value);
+ }
+ }
+}