diff options
Diffstat (limited to 'llparse-frontend/src/node/sequence.ts')
-rw-r--r-- | llparse-frontend/src/node/sequence.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/llparse-frontend/src/node/sequence.ts b/llparse-frontend/src/node/sequence.ts new file mode 100644 index 0000000..c9105b3 --- /dev/null +++ b/llparse-frontend/src/node/sequence.ts @@ -0,0 +1,44 @@ +import * as assert from 'assert'; +import { Buffer } from 'buffer'; + +import { IUniqueName } from '../utils'; +import { IWrap } from '../wrap'; +import { Node } from './base'; +import { Match } from './match'; +import { Slot } from './slot'; + +interface ISequenceEdge { + node: IWrap<Node>; + readonly value: number | undefined; +} + +export interface IReadonlySequenceEdge { + readonly node: IWrap<Node>; + readonly value: number | undefined; +} + +export class Sequence extends Match { + private privEdge?: ISequenceEdge; + + constructor(id: IUniqueName, public readonly select: Buffer) { + super(id); + } + + public setEdge(node: IWrap<Node>, value?: number | undefined) { + assert.strictEqual(this.privEdge, undefined); + this.privEdge = { node, value }; + } + + public get edge(): IReadonlySequenceEdge | undefined { + return this.privEdge; + } + + protected *buildSlots() { + const edge = this.privEdge; + if (edge !== undefined) { + yield new Slot(edge.node, (value) => edge.node = value); + } + + yield* super.buildSlots(); + } +} |