Files
NapCatQQ/.pnpm-store/v3/files/e9/65bde447ee0fead0446d6d029c6493ead0a5ccf286ea2c18cd70e5ef27b0c793068baad70ae82395a93efb87a30f8d8ad6272f69a3d3e308e6c6dbdff59fe5
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

60 lines
2.3 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplateLiteralSyntax = TemplateLiteralSyntax;
const index_1 = require("../literal/index");
const index_2 = require("../boolean/index");
const index_3 = require("../bigint/index");
const index_4 = require("../number/index");
const index_5 = require("../string/index");
const index_6 = require("../union/index");
const index_7 = require("../never/index");
// ------------------------------------------------------------------
// SyntaxParsers
// ------------------------------------------------------------------
// prettier-ignore
function* FromUnion(syntax) {
const trim = syntax.trim().replace(/"|'/g, '');
return (trim === 'boolean' ? yield (0, index_2.Boolean)() :
trim === 'number' ? yield (0, index_4.Number)() :
trim === 'bigint' ? yield (0, index_3.BigInt)() :
trim === 'string' ? yield (0, index_5.String)() :
yield (() => {
const literals = trim.split('|').map((literal) => (0, index_1.Literal)(literal.trim()));
return (literals.length === 0 ? (0, index_7.Never)() :
literals.length === 1 ? literals[0] :
(0, index_6.UnionEvaluated)(literals));
})());
}
// prettier-ignore
function* FromTerminal(syntax) {
if (syntax[1] !== '{') {
const L = (0, index_1.Literal)('$');
const R = FromSyntax(syntax.slice(1));
return yield* [L, ...R];
}
for (let i = 2; i < syntax.length; i++) {
if (syntax[i] === '}') {
const L = FromUnion(syntax.slice(2, i));
const R = FromSyntax(syntax.slice(i + 1));
return yield* [...L, ...R];
}
}
yield (0, index_1.Literal)(syntax);
}
// prettier-ignore
function* FromSyntax(syntax) {
for (let i = 0; i < syntax.length; i++) {
if (syntax[i] === '$') {
const L = (0, index_1.Literal)(syntax.slice(0, i));
const R = FromTerminal(syntax.slice(i));
return yield* [L, ...R];
}
}
yield (0, index_1.Literal)(syntax);
}
/** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
function TemplateLiteralSyntax(syntax) {
return [...FromSyntax(syntax)];
}