diff options
Diffstat (limited to 'llparse-frontend/test/fixtures/a-implementation/node')
12 files changed, 145 insertions, 0 deletions
diff --git a/llparse-frontend/test/fixtures/a-implementation/node/base.ts b/llparse-frontend/test/fixtures/a-implementation/node/base.ts new file mode 100644 index 0000000..04c8285 --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/base.ts @@ -0,0 +1,38 @@ +import { ContainerWrap, node } from '../../../../src/frontend'; + +export abstract class Node<T extends node.Node> { + private built: boolean = false; + + constructor(public readonly ref: T) { + } + + public build(out: string[]): void { + if (this.built) { + return; + } + + this.built = true; + this.doBuild(out); + + if (this.ref.otherwise !== undefined) { + const cwrap = this.ref.otherwise.node as ContainerWrap<T>; + const otherwise = cwrap.get<Node<T>>('a'); + otherwise.build(out); + } + } + + protected format(value: string): string { + let otherwise: string = ''; + if (this.ref.otherwise !== undefined) { + const otherwiseRef = this.ref.otherwise.node.ref; + otherwise = ' otherwise' + + `${this.ref.otherwise.noAdvance ? '-no_adv' : ''}=` + + `${otherwiseRef.id.name}`; + } + + return `<${this.constructor.name} name=${this.ref.id.name} ` + + `${value}${otherwise}/>`; + } + + protected abstract doBuild(out: string[]): void; +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/consume.ts b/llparse-frontend/test/fixtures/a-implementation/node/consume.ts new file mode 100644 index 0000000..cdc6cef --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/consume.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class Consume extends Node<node.Consume> { + protected doBuild(out: string[]): void { + out.push(this.format(`field=${this.ref.field}`)); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/empty.ts b/llparse-frontend/test/fixtures/a-implementation/node/empty.ts new file mode 100644 index 0000000..ef1499b --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/empty.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class Empty extends Node<node.Empty> { + protected doBuild(out: string[]): void { + out.push(this.format('')); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/error.ts b/llparse-frontend/test/fixtures/a-implementation/node/error.ts new file mode 100644 index 0000000..1a4f31d --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/error.ts @@ -0,0 +1,10 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +class ErrorNode extends Node<node.Error> { + protected doBuild(out: string[]): void { + out.push(this.format(`code=${this.ref.code} reason="${this.ref.reason}"`)); + } +} + +export { ErrorNode as Error }; diff --git a/llparse-frontend/test/fixtures/a-implementation/node/index.ts b/llparse-frontend/test/fixtures/a-implementation/node/index.ts new file mode 100644 index 0000000..31dbc5e --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/index.ts @@ -0,0 +1,15 @@ +import { Consume } from './consume'; +import { Empty } from './empty'; +import { Error } from './error'; +import { Invoke } from './invoke'; +import { Pause } from './pause'; +import { Sequence } from './sequence'; +import { Single } from './single'; +import { SpanEnd } from './span-end'; +import { SpanStart } from './span-start'; +import { TableLookup } from './table-lookup'; + +export default { + Consume, Empty, Error, Invoke, Pause, Sequence, Single, SpanEnd, + SpanStart, TableLookup, +}; diff --git a/llparse-frontend/test/fixtures/a-implementation/node/invoke.ts b/llparse-frontend/test/fixtures/a-implementation/node/invoke.ts new file mode 100644 index 0000000..674be5f --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/invoke.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class Invoke extends Node<node.Invoke> { + protected doBuild(out: string[]): void { + out.push(this.format('')); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/pause.ts b/llparse-frontend/test/fixtures/a-implementation/node/pause.ts new file mode 100644 index 0000000..94da63c --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/pause.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class Pause extends Node<node.Pause> { + protected doBuild(out: string[]): void { + out.push(this.format('')); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/sequence.ts b/llparse-frontend/test/fixtures/a-implementation/node/sequence.ts new file mode 100644 index 0000000..13fd336 --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/sequence.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class Sequence extends Node<node.Sequence> { + protected doBuild(out: string[]): void { + out.push(this.format(`select="${this.ref.select.toString('hex')}"`)); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/single.ts b/llparse-frontend/test/fixtures/a-implementation/node/single.ts new file mode 100644 index 0000000..d7bcc72 --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/single.ts @@ -0,0 +1,18 @@ +import { ContainerWrap, node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class Single extends Node<node.Single> { + protected doBuild(out: string[]): void { + const edges: string[] = []; + for (const edge of this.ref.edges) { + edges.push(`k${edge.key}${edge.noAdvance ? '-no_adv-' : ''}=` + + `${edge.node.ref.id.name}`); + } + out.push(this.format(edges.join(' '))); + + for (const edge of this.ref.edges) { + const edgeNode = edge.node as ContainerWrap<node.Node>; + edgeNode.get<Node<node.Node>>('a').build(out); + } + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/span-end.ts b/llparse-frontend/test/fixtures/a-implementation/node/span-end.ts new file mode 100644 index 0000000..dc79b81 --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/span-end.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class SpanEnd extends Node<node.SpanEnd> { + protected doBuild(out: string[]): void { + out.push(this.format('')); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/span-start.ts b/llparse-frontend/test/fixtures/a-implementation/node/span-start.ts new file mode 100644 index 0000000..32e373c --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/span-start.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class SpanStart extends Node<node.SpanStart> { + protected doBuild(out: string[]): void { + out.push(this.format('')); + } +} diff --git a/llparse-frontend/test/fixtures/a-implementation/node/table-lookup.ts b/llparse-frontend/test/fixtures/a-implementation/node/table-lookup.ts new file mode 100644 index 0000000..e6166d0 --- /dev/null +++ b/llparse-frontend/test/fixtures/a-implementation/node/table-lookup.ts @@ -0,0 +1,8 @@ +import { node } from '../../../../src/frontend'; +import { Node } from './base'; + +export class TableLookup extends Node<node.TableLookup> { + protected doBuild(out: string[]): void { + out.push(this.format('')); + } +} |