Skip to content

Commit

Permalink
Rename "embedded input" to "inset"
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Jul 20, 2023
1 parent 7b57ae0 commit 7526080
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/compiler/deserialization/ucd-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export namespace UcdCompiler {
| UccFeature<UcdCompiler.Any>
| readonly UccFeature<UcdCompiler.Any>[]
| undefined;
readonly embed?: EsSnippet | undefined;
readonly inset?: EsSnippet | undefined;
readonly exportDefaults?: boolean | undefined;

createDeserializer?<T, TSchema extends UcSchema<T>>(
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/deserialization/ucd-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class UcdFunction<out T = unknown, out TSchema extends UcSchema<T> = UcSc
}

exportFn(externalName: string, mode: UcDeserializer.Mode): EsFunction<UcdExportSignature.Args> {
const { opaqueUcrx, defaultEntities, defaultFormats, onMeta, embed } = this.lib;
const { opaqueUcrx, defaultEntities, defaultFormats, onMeta, inset } = this.lib;
const stream = new EsSymbol('stream');
const options = (code: EsCode): void => {
code.multiLine(code => {
Expand All @@ -78,7 +78,7 @@ export class UcdFunction<out T = unknown, out TSchema extends UcSchema<T> = UcSc
'formats,',
'onMeta,',
opaqueUcrx ? esline`opaqueRx: ${opaqueUcrx.instantiate()},` : EsCode.none,
embed ? esline`embed: ${embed},` : EsCode.none,
inset ? esline`inset: ${inset},` : EsCode.none,
)
.write('}');
});
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/deserialization/ucd-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export class UcdLib<out TModels extends UcdModels = UcdModels> extends UcrxLib {
return this.#onMeta;
}

get embed(): EsSnippet | undefined {
return this.#options.embed;
get inset(): EsSnippet | undefined {
return this.#options.inset;
}

deserializerFor<T, TSchema extends UcSchema<T> = UcSchema<T>>(
Expand Down Expand Up @@ -152,7 +152,7 @@ export namespace UcdLib {
formats(this: void, exportNs?: EsNamespace): EsSnippet;
meta(this: void, exportNs?: EsNamespace): EsSnippet;
onMeta?: EsSnippet | undefined;
readonly embed?: EsSnippet | undefined;
readonly inset?: EsSnippet | undefined;
readonly exportDefaults?: boolean | undefined;

createDeserializer?<T, TSchema extends UcSchema<T>>(
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/deserialization/unknown.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class UnknownUcrxClass extends UcrxClass {
if (
!declared
&& member instanceof UcrxMethod
&& member !== UcrxCore.emb
&& member !== UcrxCore.ins
&& member !== UcrxCore.raw
) {
this.#declareMethod(member);
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/rx/ucrx-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export type UcrxCore = {
readonly att: UcrxMethod<UcrxAttrSetterSignature.Args>;
readonly bol: UcrxSetter;
readonly big: UcrxSetter;
readonly emb: UcrxMethod<{ emit: EsArg; cx: EsArg }>;
readonly ent: UcrxEntitySetter;
readonly fmt: UcrxFormattedSetter;
readonly ins: UcrxMethod<{ emit: EsArg; cx: EsArg }>;
readonly nls: UcrxMethod<{ cx: EsArg }>;
readonly nul: UcrxMethod<{ cx: EsArg }>;
readonly num: UcrxSetter;
Expand All @@ -36,12 +36,12 @@ export const UcrxCore: UcrxCore = {
att: /*#__PURE__*/ new UcrxAttrSetter('att'),
bol: /*#__PURE__*/ new UcrxSetter('bol', { typeName: 'boolean', stub: UcrxCore$stub }),
big: /*#__PURE__*/ new UcrxSetter('big', { typeName: 'bigint', stub: UcrxCore$stub }),
emb: /*#__PURE__*/ new UcrxMethod('emb', {
ent: /*#__PURE__*/ new UcrxEntitySetter('ent'),
fmt: /*#__PURE__*/ new UcrxFormattedSetter('fmt'),
ins: /*#__PURE__*/ new UcrxMethod('ins', {
args: { emit: {}, cx: {} },
stub: UcrxCore$stub,
}),
ent: /*#__PURE__*/ new UcrxEntitySetter('ent'),
fmt: /*#__PURE__*/ new UcrxFormattedSetter('fmt'),
nls: /*#__PURE__*/ new UcrxMethod<{ cx: EsArg }>('nls', {
args: { cx: {} },
stub: UcrxCore$stub,
Expand Down
6 changes: 3 additions & 3 deletions src/deserializer/async-ucd-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export class AsyncUcdReader extends UcdReader {
await ucdReadValue(this, new UcrxHandle(this, rx, [{}]), false);
}

override async readEmbeds(
override async readInset(
rx: Ucrx,
createLexer: (emit: (token: UcToken) => void) => UcInputLexer,
single: boolean,
): Promise<void> {
this.skip();

this.#reader.releaseLock();
this.#stream = this.#stream.pipeThrough(new UcEmbedsStream(createLexer));
this.#stream = this.#stream.pipeThrough(new UcInsetStream(createLexer));
this.#reader = this.#stream.getReader();

await ucdReadValue(this, new UcrxHandle(this, rx, [{}]), single);
Expand Down Expand Up @@ -150,7 +150,7 @@ export class AsyncUcdReader extends UcdReader {

}

export class UcEmbedsStream extends TransformStream<UcToken, UcToken> {
export class UcInsetStream extends TransformStream<UcToken, UcToken> {

constructor(createLexer: (emit: (token: UcToken) => void) => UcInputLexer) {
let lexer: UcInputLexer;
Expand Down
34 changes: 17 additions & 17 deletions src/deserializer/impl/ucd-read-value.sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
import { printUcTokens } from '../../syntax/print-uc-token.js';
import { trimUcTokensTail } from '../../syntax/trim-uc-tokens-tail.js';
import {
UC_TOKEN_KIND_BOUND,
UC_TOKEN_KIND_IS_WHITESPACE,
UC_TOKEN_KIND_NL,
isUcBoundToken,
isUcParenthesisToken,
isWhitespaceUcToken,
ucTokenKind,
UC_TOKEN_KIND_BOUND,
UC_TOKEN_KIND_IS_WHITESPACE,
UC_TOKEN_KIND_NL,
isUcBoundToken,
isUcParenthesisToken,
isWhitespaceUcToken,
ucTokenKind,
} from '../../syntax/uc-token-kind.js';
import {
UC_TOKEN_APOSTROPHE,
UC_TOKEN_CLOSING_PARENTHESIS,
UC_TOKEN_COMMA,
UC_TOKEN_DOLLAR_SIGN,
UC_TOKEN_EMBED,
UC_TOKEN_EXCLAMATION_MARK,
UC_TOKEN_OPENING_PARENTHESIS,
UcToken,
UC_TOKEN_APOSTROPHE,
UC_TOKEN_CLOSING_PARENTHESIS,
UC_TOKEN_COMMA,
UC_TOKEN_DOLLAR_SIGN,
UC_TOKEN_EXCLAMATION_MARK,
UC_TOKEN_INSET,
UC_TOKEN_OPENING_PARENTHESIS,
UcToken,
} from '../../syntax/uc-token.js';
import { SyncUcdReader } from '../sync-ucd-reader.js';
import { appendUcTokens } from './append-uc-token.js';
Expand Down Expand Up @@ -89,8 +89,8 @@ export function ucdReadValueSync(
}

hasValue = true;
} else if (firstToken === UC_TOKEN_EMBED) {
reader.readEmbeds(rx.rx, emit => rx.emb(emit), single);
} else if (firstToken === UC_TOKEN_INSET) {
reader.readInset(rx.rx, emit => rx.ins(emit), single);
ucdSkipWhitespaceSync(reader);

if (single) {
Expand Down
6 changes: 3 additions & 3 deletions src/deserializer/impl/ucd-read-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
UC_TOKEN_CLOSING_PARENTHESIS,
UC_TOKEN_COMMA,
UC_TOKEN_DOLLAR_SIGN,
UC_TOKEN_EMBED,
UC_TOKEN_EXCLAMATION_MARK,
UC_TOKEN_INSET,
UC_TOKEN_OPENING_PARENTHESIS,
UcToken,
} from '../../syntax/uc-token.js';
Expand Down Expand Up @@ -81,8 +81,8 @@ export async function ucdReadValue(
}

hasValue = true;
} else if (firstToken === UC_TOKEN_EMBED) {
await reader.readEmbeds(rx.rx, emit => rx.emb(emit), single);
} else if (firstToken === UC_TOKEN_INSET) {
await reader.readInset(rx.rx, emit => rx.ins(emit), single);
await ucdSkipWhitespace(reader);

if (single) {
Expand Down
30 changes: 15 additions & 15 deletions src/deserializer/impl/ucrx-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ export class UcrxHandle implements UcrxContext {
this.#rx.bol(value, this);
}

emb(emit: (token: UcToken) => void): UcInputLexer {
const lexer = this.#rx.emb(emit, this) ?? this.#reader.embed(this)?.(emit);

if (lexer) {
return lexer;
}

this.#reject({
code: 'unrecognizedInput',
message: 'Unrecognized embedded input',
});

return ucOpaqueLexer;
}

ent(entity: string): void {
if (!this.onEntity(entity)) {
// Process entity.
Expand All @@ -116,6 +101,21 @@ export class UcrxHandle implements UcrxContext {
}
}

ins(emit: (token: UcToken) => void): UcInputLexer {
const lexer = this.#rx.ins(emit, this) ?? this.#reader.inset(this)?.(emit);

if (lexer) {
return lexer;
}

this.#reject({
code: 'unexpectedInset',
message: 'Unrecognized inset',
});

return ucOpaqueLexer;
}

nls(beforeComma: boolean): UcrxHandle {
const isList = this.andBeforeNls(beforeComma);
let itemsRx: Ucrx | undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/deserializer/sync-ucd-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export class SyncUcdReader extends UcdReader {
ucdReadValueSync(this, new UcrxHandle(this, rx, [{}]), false);
}

override readEmbeds(
override readInset(
rx: Ucrx,
createLexer: (emit: (token: UcToken) => void) => UcInputLexer,
single: boolean,
): Promise<void> | void {
this.#unwrapEmbeds(createLexer);
this.#unwrapInset(createLexer);
ucdReadValueSync(this, new UcrxHandle(this, rx, [{}]), single);
}

#unwrapEmbeds(createLexer: (emit: (token: UcToken) => void) => UcInputLexer): void {
#unwrapInset(createLexer: (emit: (token: UcToken) => void) => UcInputLexer): void {
const tokens = this.#tokens;
const newTokens = [];
const lexer = createLexer(token => newTokens.push(token));
Expand All @@ -59,7 +59,7 @@ export class SyncUcdReader extends UcdReader {
const chunk = tokens[end++];

if (typeof chunk === 'number') {
// Embedded input expected to end with input bound.
// Inset expected to end with input bound.
break;
}

Expand Down
25 changes: 12 additions & 13 deletions src/deserializer/ucd-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class UcdReader {
readonly #entities: Exclude<UcdReader.Options['entities'], undefined>;
readonly #formats: Exclude<UcdReader.Options['formats'], undefined>;
readonly #onMeta: MetaUcrx;
readonly #embed: ((cx: UcrxContext) => UcInputLexerFactory | undefined) | undefined;
readonly #inset: ((cx: UcrxContext) => UcInputLexerFactory | undefined) | undefined;

constructor(options?: UcDeserializer.Options);

Expand All @@ -26,11 +26,11 @@ export abstract class UcdReader {
formats = {},
onMeta = UcdReader$noMeta,
opaqueRx = OPAQUE_UCRX,
embed,
inset,
}: UcdReader.Options = {}) {
this.#data = data;
this.#opaqueRx = opaqueRx;
this.#embed = embed;
this.#inset = inset;
this.#onError = onError;
this.#entities = entities;
this.#formats = formats;
Expand All @@ -45,8 +45,8 @@ export abstract class UcdReader {
return this.#opaqueRx;
}

embed(cx: UcrxContext): UcInputLexerFactory | undefined {
return this.#embed?.(cx);
inset(cx: UcrxContext): UcInputLexerFactory | undefined {
return this.#inset?.(cx);
}

abstract hasNext(): boolean;
Expand All @@ -63,7 +63,7 @@ export abstract class UcdReader {

abstract read(rx: Ucrx): Promise<void> | void;

abstract readEmbeds(
abstract readInset(
rx: Ucrx,
createLexer: (emit: (token: UcToken) => void) => UcInputLexer,
single: boolean,
Expand Down Expand Up @@ -103,18 +103,17 @@ export namespace UcdReader {
export interface Options extends UcDeserializer.Options {
readonly opaqueRx?: Ucrx | undefined;
/**
* Creates a lexer for _embedded input_. I.e. the input chunks enclosed into {@link churi!UC_TOKEN_EMBED embedded
* input bounds}.
* Creates a lexer for _inset_. I.e. the input chunks enclosed into {@link churi!UC_TOKEN_INSET inset bounds}.
*
* Once an embedded input is encountered, the deserializer would try to use the lexer defined by
* {@link churi!Ucrx#emb charge receiver}, and only if the latter is undefined - it will try to use the one created
* by this method. If that fails, an error will be thrown.
* Once an inset is encountered, the deserializer would try to use the lexer defined by {@link churi!Ucrx#ins
* charge receiver}. If the latter is not defined, it will try to use the one created by this method.
* If that fails, an error will be reported.
*
* @param cx - Charge processing context.
*
* @returns Either input lexer factory, or `undefined` if an embedded input is not expected.
* @returns Either input lexer factory, or `undefined` if an inset is not expected.
*/
readonly embed?: ((cx: UcrxContext) => UcInputLexerFactory | undefined) | undefined;
readonly inset?: ((cx: UcrxContext) => UcInputLexerFactory | undefined) | undefined;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rx/all.ucrx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export interface AllUcrx extends Ucrx {
att(attr: string): AllUcrx | undefined;
bol(value: boolean): 1;
big(value: bigint): 1;
emb(emit: (token: UcToken) => void): UcInputLexer;
ent(name: string): 1;
fmt(format: string, data: readonly UcToken[]): 1;
ins(emit: (token: UcToken) => void): UcInputLexer;
nls(): AllUcrx;
nul(): 1;
num(value: number): 1;
Expand Down
2 changes: 1 addition & 1 deletion src/rx/opaque.ucrx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('OpaqueUcrx', () => {

describe('emb', () => {
it('returns ucOpaqueLexer', () => {
expect(new OpaqueUcrx().emb(noop)).toBe(ucOpaqueLexer);
expect(new OpaqueUcrx().ins(noop)).toBe(ucOpaqueLexer);
});
});

Expand Down
12 changes: 6 additions & 6 deletions src/rx/opaque.ucrx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ export class OpaqueUcrx extends VoidUcrx implements AllUcrx {
// Ignore metadata.
}

override emb(emit: (token: UcToken) => void): UcInputLexer;
override emb(_emit: (token: UcToken) => void): UcInputLexer {
override ins(emit: (token: UcToken) => void): UcInputLexer;
override ins(_emit: (token: UcToken) => void): UcInputLexer {
return ucOpaqueLexer;
}

override nls(): this {
return this;
}

override raw(value: string): 1;
override raw(_value: string): 1 {
return 1;
}

override nls(): this {
return this;
}

override for(key: PropertyKey): this;
override for(_key: PropertyKey): this {
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/rx/token.ucrx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('TokenUcrx', () => {

describe('emb', () => {
it('returns ucOpaqueLexer', () => {
expect(new TokenUcrx(noop).emb(noop)).toBe(ucOpaqueLexer);
expect(new TokenUcrx(noop).ins(noop)).toBe(ucOpaqueLexer);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/rx/token.ucrx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class TokenUcrx implements AllUcrx {
return 1;
}

emb(emit: (token: UcToken) => void): UcInputLexer;
emb(_emit: (token: UcToken) => void): UcInputLexer {
ins(emit: (token: UcToken) => void): UcInputLexer;
ins(_emit: (token: UcToken) => void): UcInputLexer {
return ucOpaqueLexer;
}

Expand Down
Loading

0 comments on commit 7526080

Please sign in to comment.