added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const reTag = /^@\S+/;
/**
* Creates configured `Parser`
* @param {Partial<Options>} options
*/
function getParser({
fence = '```'
} = {}) {
const fencer = getFencer(fence);
const toggleFence = (source, isFenced) => fencer(source) ? !isFenced : isFenced;
return function parseBlock(source) {
// start with description section
const sections = [[]];
let isFenced = false;
for (const line of source) {
if (reTag.test(line.tokens.description) && !isFenced) {
sections.push([line]);
} else {
sections[sections.length - 1].push(line);
}
isFenced = toggleFence(line.tokens.description, isFenced);
}
return sections;
};
}
exports.default = getParser;
function getFencer(fence) {
if (typeof fence === 'string') return source => source.split(fence).length % 2 === 0;
return fence;
}
//# sourceMappingURL=block-parser.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["block-parser.js"],"names":["Object","defineProperty","exports","value","reTag","getParser","fence","fencer","getFencer","toggleFence","source","isFenced","parseBlock","sections","line","test","tokens","description","push","length","default","split"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;AACA,MAAMC,KAAK,GAAG,OAAd;AACA;AACA;AACA;AACA;;AACA,SAASC,SAAT,CAAmB;AAAEC,EAAAA,KAAK,GAAG;AAAV,IAAqB,EAAxC,EAA4C;AACxC,QAAMC,MAAM,GAAGC,SAAS,CAACF,KAAD,CAAxB;;AACA,QAAMG,WAAW,GAAG,CAACC,MAAD,EAASC,QAAT,KAAsBJ,MAAM,CAACG,MAAD,CAAN,GAAiB,CAACC,QAAlB,GAA6BA,QAAvE;;AACA,SAAO,SAASC,UAAT,CAAoBF,MAApB,EAA4B;AAC/B;AACA,UAAMG,QAAQ,GAAG,CAAC,EAAD,CAAjB;AACA,QAAIF,QAAQ,GAAG,KAAf;;AACA,SAAK,MAAMG,IAAX,IAAmBJ,MAAnB,EAA2B;AACvB,UAAIN,KAAK,CAACW,IAAN,CAAWD,IAAI,CAACE,MAAL,CAAYC,WAAvB,KAAuC,CAACN,QAA5C,EAAsD;AAClDE,QAAAA,QAAQ,CAACK,IAAT,CAAc,CAACJ,IAAD,CAAd;AACH,OAFD,MAGK;AACDD,QAAAA,QAAQ,CAACA,QAAQ,CAACM,MAAT,GAAkB,CAAnB,CAAR,CAA8BD,IAA9B,CAAmCJ,IAAnC;AACH;;AACDH,MAAAA,QAAQ,GAAGF,WAAW,CAACK,IAAI,CAACE,MAAL,CAAYC,WAAb,EAA0BN,QAA1B,CAAtB;AACH;;AACD,WAAOE,QAAP;AACH,GAdD;AAeH;;AACDX,OAAO,CAACkB,OAAR,GAAkBf,SAAlB;;AACA,SAASG,SAAT,CAAmBF,KAAnB,EAA0B;AACtB,MAAI,OAAOA,KAAP,KAAiB,QAArB,EACI,OAAQI,MAAD,IAAYA,MAAM,CAACW,KAAP,CAAaf,KAAb,EAAoBa,MAApB,GAA6B,CAA7B,KAAmC,CAAtD;AACJ,SAAOb,KAAP;AACH","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst reTag = /^@\\S+/;\n/**\n * Creates configured `Parser`\n * @param {Partial<Options>} options\n */\nfunction getParser({ fence = '```', } = {}) {\n const fencer = getFencer(fence);\n const toggleFence = (source, isFenced) => fencer(source) ? !isFenced : isFenced;\n return function parseBlock(source) {\n // start with description section\n const sections = [[]];\n let isFenced = false;\n for (const line of source) {\n if (reTag.test(line.tokens.description) && !isFenced) {\n sections.push([line]);\n }\n else {\n sections[sections.length - 1].push(line);\n }\n isFenced = toggleFence(line.tokens.description, isFenced);\n }\n return sections;\n };\n}\nexports.default = getParser;\nfunction getFencer(fence) {\n if (typeof fence === 'string')\n return (source) => source.split(fence).length % 2 === 0;\n return fence;\n}\n"],"file":"block-parser.cjs"}
+24
View File
@@ -0,0 +1,24 @@
import { Line } from '../primitives';
/**
* Groups source lines in sections representing tags.
* First section is a block description if present. Last section captures lines starting with
* the last tag to the end of the block, including dangling closing marker.
* @param {Line[]} block souce lines making a single comment block
*/
export declare type Parser = (block: Line[]) => Line[][];
/**
* Predicate telling if string contains opening/closing escaping sequence
* @param {string} source raw source line
*/
export declare type Fencer = (source: string) => boolean;
/**
* `Parser` configuration options
*/
export interface Options {
fence: string | Fencer;
}
/**
* Creates configured `Parser`
* @param {Partial<Options>} options
*/
export default function getParser({ fence, }?: Partial<Options>): Parser;
+65
View File
@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const util_1 = require("../util.cjs");
const block_parser_1 = require("./block-parser.cjs");
const source_parser_1 = require("./source-parser.cjs");
const spec_parser_1 = require("./spec-parser.cjs");
const tag_1 = require("./tokenizers/tag.cjs");
const type_1 = require("./tokenizers/type.cjs");
const name_1 = require("./tokenizers/name.cjs");
const description_1 = require("./tokenizers/description.cjs");
function getParser({
startLine = 0,
fence = '```',
spacing = 'compact',
tokenizers = [tag_1.default(), type_1.default(spacing), name_1.default(), description_1.default(spacing)]
} = {}) {
if (startLine < 0 || startLine % 1 > 0) throw new Error('Invalid startLine');
const parseSource = source_parser_1.default({
startLine
});
const parseBlock = block_parser_1.default({
fence
});
const parseSpec = spec_parser_1.default({
tokenizers
});
const joinDescription = description_1.getJoiner(spacing);
const notEmpty = line => line.tokens.description.trim() != '';
return function (source) {
const blocks = [];
for (const line of util_1.splitLines(source)) {
const lines = parseSource(line);
if (lines === null) continue;
if (lines.find(notEmpty) === undefined) continue;
const sections = parseBlock(lines);
const specs = sections.slice(1).map(parseSpec);
blocks.push({
description: joinDescription(sections[0]),
tags: specs,
source: lines,
problems: specs.reduce((acc, spec) => acc.concat(spec.problems), [])
});
}
return blocks;
};
}
exports.default = getParser;
//# sourceMappingURL=index.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["index.js"],"names":["Object","defineProperty","exports","value","util_1","require","block_parser_1","source_parser_1","spec_parser_1","tag_1","type_1","name_1","description_1","getParser","startLine","fence","spacing","tokenizers","default","Error","parseSource","parseBlock","parseSpec","joinDescription","getJoiner","notEmpty","line","tokens","description","trim","source","blocks","splitLines","lines","find","undefined","sections","specs","slice","map","push","tags","problems","reduce","acc","spec","concat"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;;AACA,MAAMC,MAAM,GAAGC,OAAH,eAAZ;;AACA,MAAMC,cAAc,GAAGD,OAAH,sBAApB;;AACA,MAAME,eAAe,GAAGF,OAAH,uBAArB;;AACA,MAAMG,aAAa,GAAGH,OAAH,qBAAnB;;AACA,MAAMI,KAAK,GAAGJ,OAAH,wBAAX;;AACA,MAAMK,MAAM,GAAGL,OAAH,yBAAZ;;AACA,MAAMM,MAAM,GAAGN,OAAH,yBAAZ;;AACA,MAAMO,aAAa,GAAGP,OAAH,gCAAnB;;AACA,SAASQ,SAAT,CAAmB;AAAEC,EAAAA,SAAS,GAAG,CAAd;AAAiBC,EAAAA,KAAK,GAAG,KAAzB;AAAgCC,EAAAA,OAAO,GAAG,SAA1C;AAAqDC,EAAAA,UAAU,GAAG,CACjFR,KAAK,CAACS,OAAN,EADiF,EAEjFR,MAAM,CAACQ,OAAP,CAAeF,OAAf,CAFiF,EAGjFL,MAAM,CAACO,OAAP,EAHiF,EAIjFN,aAAa,CAACM,OAAd,CAAsBF,OAAtB,CAJiF;AAAlE,IAKZ,EALP,EAKW;AACP,MAAIF,SAAS,GAAG,CAAZ,IAAiBA,SAAS,GAAG,CAAZ,GAAgB,CAArC,EACI,MAAM,IAAIK,KAAJ,CAAU,mBAAV,CAAN;AACJ,QAAMC,WAAW,GAAGb,eAAe,CAACW,OAAhB,CAAwB;AAAEJ,IAAAA;AAAF,GAAxB,CAApB;AACA,QAAMO,UAAU,GAAGf,cAAc,CAACY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\nconst util_1 = require(\"../util\");\nconst block_parser_1 = require(\"./block-parser\");\nconst source_parser_1 = require(\"./source-parser\");\nconst spec_parser_1 = require(\"./spec-parser\");\nconst tag_1 = require(\"./tokenizers/tag\");\nconst type_1 = require(\"./tokenizers/type\");\nconst name_1 = require(\"./tokenizers/name\");\nconst description_1 = require(\"./tokenizers/description\");\nfunction getParser({ startLine = 0, fence = '```', spacing = 'compact', tokenizers = [\n tag_1.default(),\n type_1.default(spacing),\n name_1.default(),\n description_1.default(spacing),\n], } = {}) {\n if (startLine < 0 || startLine % 1 > 0)\n throw new Error('Invalid startLine');\n const parseSource = source_parser_1.default({ startLine });\n const parseBlock = block_parser_1.default({ fence });\n const parseSpec = spec_parser_1.default({ tokenizers });\n const joinDescription = description_1.getJoiner(spacing);\n const notEmpty = (line) => line.tokens.description.trim() != '';\n return function (source) {\n const blocks = [];\n for (const line of util_1.splitLines(source)) {\n const lines = parseSource(line);\n if (lines === null)\n continue;\n if (lines.find(notEmpty) === undefined)\n continue;\n const sections = parseBlock(lines);\n const specs = sections.slice(1).map(parseSpec);\n blocks.push({\n description: joinDescription(sections[0]),\n tags: specs,\n source: lines,\n problems: specs.reduce((acc, spec) => acc.concat(spec.problems), []),\n });\n }\n return blocks;\n };\n}\nexports.default = getParser;\n"],"file":"index.cjs"}
+10
View File
@@ -0,0 +1,10 @@
import { Block } from '../primitives';
import { Tokenizer } from './tokenizers/index';
export interface Options {
startLine: number;
fence: string;
spacing: 'compact' | 'preserve';
tokenizers: Tokenizer[];
}
export declare type Parser = (source: string) => Block[];
export default function getParser({ startLine, fence, spacing, tokenizers, }?: Partial<Options>): Parser;
+67
View File
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const primitives_1 = require("../primitives.cjs");
const util_1 = require("../util.cjs");
function getParser({
startLine = 0
} = {}) {
let block = null;
let num = startLine;
return function parseSource(source) {
let rest = source;
const tokens = util_1.seedTokens();
[tokens.lineEnd, rest] = util_1.splitCR(rest);
[tokens.start, rest] = util_1.splitSpace(rest);
if (block === null && rest.startsWith(primitives_1.Markers.start) && !rest.startsWith(primitives_1.Markers.nostart)) {
block = [];
tokens.delimiter = rest.slice(0, primitives_1.Markers.start.length);
rest = rest.slice(primitives_1.Markers.start.length);
[tokens.postDelimiter, rest] = util_1.splitSpace(rest);
}
if (block === null) {
num++;
return null;
}
const isClosed = rest.trimRight().endsWith(primitives_1.Markers.end);
if (tokens.delimiter === '' && rest.startsWith(primitives_1.Markers.delim) && !rest.startsWith(primitives_1.Markers.end)) {
tokens.delimiter = primitives_1.Markers.delim;
rest = rest.slice(primitives_1.Markers.delim.length);
[tokens.postDelimiter, rest] = util_1.splitSpace(rest);
}
if (isClosed) {
const trimmed = rest.trimRight();
tokens.end = rest.slice(trimmed.length - primitives_1.Markers.end.length);
rest = trimmed.slice(0, -primitives_1.Markers.end.length);
}
tokens.description = rest;
block.push({
number: num,
source,
tokens
});
num++;
if (isClosed) {
const result = block.slice();
block = null;
return result;
}
return null;
};
}
exports.default = getParser;
//# sourceMappingURL=source-parser.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["source-parser.js"],"names":["Object","defineProperty","exports","value","primitives_1","require","util_1","getParser","startLine","block","num","parseSource","source","rest","tokens","seedTokens","lineEnd","splitCR","start","splitSpace","startsWith","Markers","nostart","delimiter","slice","length","postDelimiter","isClosed","trimRight","endsWith","end","delim","trimmed","description","push","number","result","default"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;;AACA,MAAMC,YAAY,GAAGC,OAAH,qBAAlB;;AACA,MAAMC,MAAM,GAAGD,OAAH,eAAZ;;AACA,SAASE,SAAT,CAAmB;AAAEC,EAAAA,SAAS,GAAG;AAAd,IAAqB,EAAxC,EAA4C;AACxC,MAAIC,KAAK,GAAG,IAAZ;AACA,MAAIC,GAAG,GAAGF,SA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B,YAAY,CAACiB,OAAb,CAAqBS,GAArC,CAFL,EAEgD;AAC5ChB,MAAAA,MAAM,CAACS,SAAP,GAAmBnB,YAAY,CAACiB,OAAb,CAAqBU,KAAxC;AACAlB,MAAAA,IAAI,GAAGA,IAAI,CAACW,KAAL,CAAWpB,YAAY,CAACiB,OAAb,CAAqBU,KAArB,CAA2BN,MAAtC,CAAP;AACA,OAACX,MAAM,CAACY,aAAR,EAAuBb,IAAvB,IAA+BP,MAAM,CAACa,UAAP,CAAkBN,IAAlB,CAA/B;AACH;;AACD,QAAIc,QAAJ,EAAc;AACV,YAAMK,OAAO,GAAGnB,IAAI,CAACe,SAAL,EAAhB;AACAd,MAAAA,MAAM,CAACgB,GAAP,GAAajB,IAAI,CAACW,KAAL,CAAWQ,OAAO,CAACP,MAAR,GAAiBrB,YAAY,CAACiB,OAAb,CAAqBS,GAArB,CAAyBL,MAArD,CAAb;AACAZ,MAAAA,IAAI,GAAGmB,OAAO,CAACR,KAAR,CAAc,CAAd,EAAiB,CAACpB,YAAY,CAACiB,OAAb,CAAqBS,GAArB,CAAyBL,MAA3C,CAAP;AACH;;AACDX,IAAAA,MAAM,CAACmB,WAAP,GAAqBpB,IAArB;AACAJ,IAAAA,KAAK,CAACyB,IAAN,CAAW;AAAEC,MAAAA,MAAM,EAAEzB,GAAV;AAAeE,MAAAA,MAAf;AAAuBE,MAAAA;AAAvB,KAAX;AACAJ,IAAAA,GAAG;;AACH,QAAIiB,QAAJ,EAAc;AACV,YAAMS,MAAM,GAAG3B,KAAK,CAACe,KAAN,EAAf;AACAf,MAAAA,KAAK,GAAG,IAAR;AACA,aAAO2B,MAAP;AACH;;AACD,WAAO,IAAP;AACH,GAvCD;AAwCH;;AACDlC,OAAO,CAACmC,OAAR,GAAkB9B,SAAlB","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst primitives_1 = require(\"../primitives\");\nconst util_1 = require(\"../util\");\nfunction getParser({ startLine = 0, } = {}) {\n let block = null;\n let num = startLine;\n return function parseSource(source) {\n let rest = source;\n const tokens = util_1.seedTokens();\n [tokens.lineEnd, rest] = util_1.splitCR(rest);\n [tokens.start, rest] = util_1.splitSpace(rest);\n if (block === null &&\n rest.startsWith(primitives_1.Markers.start) &&\n !rest.startsWith(primitives_1.Markers.nostart)) {\n block = [];\n tokens.delimiter = rest.slice(0, primitives_1.Markers.start.length);\n rest = rest.slice(primitives_1.Markers.start.length);\n [tokens.postDelimiter, rest] = util_1.splitSpace(rest);\n }\n if (block === null) {\n num++;\n return null;\n }\n const isClosed = rest.trimRight().endsWith(primitives_1.Markers.end);\n if (tokens.delimiter === '' &&\n rest.startsWith(primitives_1.Markers.delim) &&\n !rest.startsWith(primitives_1.Markers.end)) {\n tokens.delimiter = primitives_1.Markers.delim;\n rest = rest.slice(primitives_1.Markers.delim.length);\n [tokens.postDelimiter, rest] = util_1.splitSpace(rest);\n }\n if (isClosed) {\n const trimmed = rest.trimRight();\n tokens.end = rest.slice(trimmed.length - primitives_1.Markers.end.length);\n rest = trimmed.slice(0, -primitives_1.Markers.end.length);\n }\n tokens.description = rest;\n block.push({ number: num, source, tokens });\n num++;\n if (isClosed) {\n const result = block.slice();\n block = null;\n return result;\n }\n return null;\n };\n}\nexports.default = getParser;\n"],"file":"source-parser.cjs"}
+6
View File
@@ -0,0 +1,6 @@
import { Line } from '../primitives';
export interface Options {
startLine: number;
}
export declare type Parser = (source: string) => Line[] | null;
export default function getParser({ startLine, }?: Partial<Options>): Parser;
+29
View File
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const util_1 = require("../util.cjs");
function getParser({
tokenizers
}) {
return function parseSpec(source) {
var _a;
let spec = util_1.seedSpec({
source
});
for (const tokenize of tokenizers) {
spec = tokenize(spec);
if ((_a = spec.problems[spec.problems.length - 1]) === null || _a === void 0 ? void 0 : _a.critical) break;
}
return spec;
};
}
exports.default = getParser;
//# sourceMappingURL=spec-parser.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["spec-parser.js"],"names":["Object","defineProperty","exports","value","util_1","require","getParser","tokenizers","parseSpec","source","_a","spec","seedSpec","tokenize","problems","length","critical","default"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;;AACA,MAAMC,MAAM,GAAGC,OAAH,eAAZ;;AACA,SAASC,SAAT,CAAmB;AAAEC,EAAAA;AAAF,CAAnB,EAAmC;AAC/B,SAAO,SAASC,SAAT,CAAmBC,MAAnB,EAA2B;AAC9B,QAAIC,EAAJ;;AACA,QAAIC,IAAI,GAAGP,MAAM,CAACQ,QAAP,CAAgB;AAAEH,MAAAA;AAAF,KAAhB,CAAX;;AACA,SAAK,MAAMI,QAAX,IAAuBN,UAAvB,EAAmC;AAC/BI,MAAAA,IAAI,GAAGE,QAAQ,CAACF,IAAD,CAAf;AACA,UAAI,CAACD,EAAE,GAAGC,IAAI,CAACG,QAAL,CAAcH,IAAI,CAACG,QAAL,CAAcC,MAAd,GAAuB,CAArC,CAAN,MAAmD,IAAnD,IAA2DL,EAAE,KAAK,KAAK,CAAvE,GAA2E,KAAK,CAAhF,GAAoFA,EAAE,CAACM,QAA3F,EACI;AACP;;AACD,WAAOL,IAAP;AACH,GATD;AAUH;;AACDT,OAAO,CAACe,OAAR,GAAkBX,SAAlB","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst util_1 = require(\"../util\");\nfunction getParser({ tokenizers }) {\n return function parseSpec(source) {\n var _a;\n let spec = util_1.seedSpec({ source });\n for (const tokenize of tokenizers) {\n spec = tokenize(spec);\n if ((_a = spec.problems[spec.problems.length - 1]) === null || _a === void 0 ? void 0 : _a.critical)\n break;\n }\n return spec;\n };\n}\nexports.default = getParser;\n"],"file":"spec-parser.cjs"}
+7
View File
@@ -0,0 +1,7 @@
import { Line, Spec } from '../primitives';
import { Tokenizer } from './tokenizers/index';
export declare type Parser = (source: Line[]) => Spec;
export interface Options {
tokenizers: Tokenizer[];
}
export default function getParser({ tokenizers }: Options): Parser;
+61
View File
@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getJoiner = void 0;
const primitives_1 = require("../../primitives.cjs");
/**
* Makes no changes to `spec.lines[].tokens` but joins them into `spec.description`
* following given spacing srtategy
* @param {Spacing} spacing tells how to handle the whitespace
*/
function descriptionTokenizer(spacing = 'compact') {
const join = getJoiner(spacing);
return spec => {
spec.description = join(spec.source);
return spec;
};
}
exports.default = descriptionTokenizer;
function getJoiner(spacing) {
if (spacing === 'compact') return compactJoiner;
if (spacing === 'preserve') return preserveJoiner;
return spacing;
}
exports.getJoiner = getJoiner;
function compactJoiner(lines) {
return lines.map(({
tokens: {
description
}
}) => description.trim()).filter(description => description !== '').join(' ');
}
const lineNo = (num, {
tokens
}, i) => tokens.type === '' ? num : i;
const getDescription = ({
tokens
}) => (tokens.delimiter === '' ? tokens.start : tokens.postDelimiter.slice(1)) + tokens.description;
function preserveJoiner(lines) {
if (lines.length === 0) return ''; // skip the opening line with no description
if (lines[0].tokens.description === '' && lines[0].tokens.delimiter === primitives_1.Markers.start) lines = lines.slice(1); // skip the closing line with no description
const lastLine = lines[lines.length - 1];
if (lastLine !== undefined && lastLine.tokens.description === '' && lastLine.tokens.end.endsWith(primitives_1.Markers.end)) lines = lines.slice(0, -1); // description starts at the last line of type definition
lines = lines.slice(lines.reduce(lineNo, 0));
return lines.map(getDescription).join('\n');
}
//# sourceMappingURL=description.cjs.map
@@ -0,0 +1 @@
{"version":3,"sources":["description.js"],"names":["Object","defineProperty","exports","value","getJoiner","primitives_1","require","descriptionTokenizer","spacing","join","spec","description","source","default","compactJoiner","preserveJoiner","lines","map","tokens","trim","filter","lineNo","num","i","type","getDescription","delimiter","start","postDelimiter","slice","length","Markers","lastLine","undefined","end","endsWith","reduce"],"mappings":"AAAA;;AACAA,MAAM,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,CAACS,KAAjC,GAAyCT,MAAM,CAACU,aAAP,CAAqBC,KAArB,CAA2B,CAA3B,CAA1C,IACnCX,MAAM,CAACP,WADX;;AAEA,SAASI,cAAT,CAAwBC,KAAxB,EAA+B;AAC3B,MAAIA,KAAK,CAACc,MAAN,KAAiB,CAArB,EACI,OAAO,EAAP,CAFuB,CAG3B;;AACA,MAAId,KAAK,CAAC,CAAD,CAAL,CAASE,MAAT,CAAgBP,WAAhB,KAAgC,EAAhC,IACAK,KAAK,CAAC,CAAD,CAAL,CAASE,MAAT,CAAgBQ,SAAhB,KAA8BrB,YAAY,CAAC0B,OAAb,CAAqBJ,KADvD,EAEIX,KAAK,GAAGA,KAAK,CAACa,KAAN,CAAY,CAAZ,CAAR,CANuB,CAO3B;;AACA,QAAMG,QAAQ,GAAGhB,KAAK,CAACA,KAAK,CAACc,MAAN,GAAe,CAAhB,CAAtB;AACA,MAAIE,QAAQ,KAAKC,SAAb,IACAD,QAAQ,CAACd,MAAT,CAAgBP,WAAhB,KAAgC,EADhC,IAEAqB,QAAQ,CAACd,MAAT,CAAgBgB,GAAhB,CAAoBC,QAApB,CAA6B9B,YAAY,CAAC0B,OAAb,CAAqBG,GAAlD,CAFJ,EAGIlB,KAAK,GAAGA,KAAK,CAACa,KAAN,CAAY,CAAZ,EAAe,CAAC,CAAhB,CAAR,CAZuB,CAa3B;;AACAb,EAAAA,KAAK,GAAGA,KAAK,CAACa,KAAN,CAAYb,KAAK,CAACoB,MAAN,CAAaf,MAAb,EAAqB,CAArB,CAAZ,CAAR;AACA,SAAOL,KAAK,CAACC,GAAN,CAAUQ,cAAV,EAA0BhB,IAA1B,CAA+B,IAA/B,CAAP;AACH","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getJoiner = void 0;\nconst primitives_1 = require(\"../../primitives\");\n/**\n * Makes no changes to `spec.lines[].tokens` but joins them into `spec.description`\n * following given spacing srtategy\n * @param {Spacing} spacing tells how to handle the whitespace\n */\nfunction descriptionTokenizer(spacing = 'compact') {\n const join = getJoiner(spacing);\n return (spec) => {\n spec.description = join(spec.source);\n return spec;\n };\n}\nexports.default = descriptionTokenizer;\nfunction getJoiner(spacing) {\n if (spacing === 'compact')\n return compactJoiner;\n if (spacing === 'preserve')\n return preserveJoiner;\n return spacing;\n}\nexports.getJoiner = getJoiner;\nfunction compactJoiner(lines) {\n return lines\n .map(({ tokens: { description } }) => description.trim())\n .filter((description) => description !== '')\n .join(' ');\n}\nconst lineNo = (num, { tokens }, i) => tokens.type === '' ? num : i;\nconst getDescription = ({ tokens }) => (tokens.delimiter === '' ? tokens.start : tokens.postDelimiter.slice(1)) +\n tokens.description;\nfunction preserveJoiner(lines) {\n if (lines.length === 0)\n return '';\n // skip the opening line with no description\n if (lines[0].tokens.description === '' &&\n lines[0].tokens.delimiter === primitives_1.Markers.start)\n lines = lines.slice(1);\n // skip the closing line with no description\n const lastLine = lines[lines.length - 1];\n if (lastLine !== undefined &&\n lastLine.tokens.description === '' &&\n lastLine.tokens.end.endsWith(primitives_1.Markers.end))\n lines = lines.slice(0, -1);\n // description starts at the last line of type definition\n lines = lines.slice(lines.reduce(lineNo, 0));\n return lines.map(getDescription).join('\\n');\n}\n"],"file":"description.cjs"}
+19
View File
@@ -0,0 +1,19 @@
import { Line } from '../../primitives';
import { Tokenizer } from './index';
/**
* Walks over provided lines joining description token into a single string.
* */
export declare type Joiner = (lines: Line[]) => string;
/**
* Shortcut for standard Joiners
* compact - strip surrounding whitespace and concat lines using a single string
* preserve - preserves original whitespace and line breaks as is
*/
export declare type Spacing = 'compact' | 'preserve' | Joiner;
/**
* Makes no changes to `spec.lines[].tokens` but joins them into `spec.description`
* following given spacing srtategy
* @param {Spacing} spacing tells how to handle the whitespace
*/
export default function descriptionTokenizer(spacing?: Spacing): Tokenizer;
export declare function getJoiner(spacing: Spacing): Joiner;
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=index.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["index.js"],"names":["Object","defineProperty","exports","value"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"file":"index.cjs"}
+7
View File
@@ -0,0 +1,7 @@
import { Spec } from '../../primitives';
/**
* Splits `spect.lines[].token.description` into other tokens,
* and populates the spec.{tag, name, type, description}. Invoked in a chaing
* with other tokens, operations listed above can be moved to separate tokenizers
*/
export declare type Tokenizer = (spec: Spec) => Spec;
+109
View File
@@ -0,0 +1,109 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const util_1 = require("../../util.cjs");
const isQuoted = s => s && s.startsWith('"') && s.endsWith('"');
/**
* Splits remaining `spec.lines[].tokens.description` into `name` and `descriptions` tokens,
* and populates the `spec.name`
*/
function nameTokenizer() {
const typeEnd = (num, {
tokens
}, i) => tokens.type === '' ? num : i;
return spec => {
// look for the name in the line where {type} ends
const {
tokens
} = spec.source[spec.source.reduce(typeEnd, 0)];
const source = tokens.description.trimLeft();
const quotedGroups = source.split('"'); // if it starts with quoted group, assume it is a literal
if (quotedGroups.length > 1 && quotedGroups[0] === '' && quotedGroups.length % 2 === 1) {
spec.name = quotedGroups[1];
tokens.name = `"${quotedGroups[1]}"`;
[tokens.postName, tokens.description] = util_1.splitSpace(source.slice(tokens.name.length));
return spec;
}
let brackets = 0;
let name = '';
let optional = false;
let defaultValue; // assume name is non-space string or anything wrapped into brackets
for (const ch of source) {
if (brackets === 0 && util_1.isSpace(ch)) break;
if (ch === '[') brackets++;
if (ch === ']') brackets--;
name += ch;
}
if (brackets !== 0) {
spec.problems.push({
code: 'spec:name:unpaired-brackets',
message: 'unpaired brackets',
line: spec.source[0].number,
critical: true
});
return spec;
}
const nameToken = name;
if (name[0] === '[' && name[name.length - 1] === ']') {
optional = true;
name = name.slice(1, -1);
const parts = name.split('=');
name = parts[0].trim();
if (parts[1] !== undefined) defaultValue = parts.slice(1).join('=').trim();
if (name === '') {
spec.problems.push({
code: 'spec:name:empty-name',
message: 'empty name',
line: spec.source[0].number,
critical: true
});
return spec;
}
if (defaultValue === '') {
spec.problems.push({
code: 'spec:name:empty-default',
message: 'empty default value',
line: spec.source[0].number,
critical: true
});
return spec;
} // has "=" and is not a string, except for "=>"
if (!isQuoted(defaultValue) && /=(?!>)/.test(defaultValue)) {
spec.problems.push({
code: 'spec:name:invalid-default',
message: 'invalid default value syntax',
line: spec.source[0].number,
critical: true
});
return spec;
}
}
spec.optional = optional;
spec.name = name;
tokens.name = nameToken;
if (defaultValue !== undefined) spec.default = defaultValue;
[tokens.postName, tokens.description] = util_1.splitSpace(source.slice(tokens.name.length));
return spec;
};
}
exports.default = nameTokenizer;
//# sourceMappingURL=name.cjs.map
File diff suppressed because one or more lines are too long
+6
View File
@@ -0,0 +1,6 @@
import { Tokenizer } from './index';
/**
* Splits remaining `spec.lines[].tokens.description` into `name` and `descriptions` tokens,
* and populates the `spec.name`
*/
export default function nameTokenizer(): Tokenizer;
+37
View File
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Splits the `@prefix` from remaining `Spec.lines[].token.descrioption` into the `tag` token,
* and populates `spec.tag`
*/
function tagTokenizer() {
return spec => {
const {
tokens
} = spec.source[0];
const match = tokens.description.match(/\s*(@(\S+))(\s*)/);
if (match === null) {
spec.problems.push({
code: 'spec:tag:prefix',
message: 'tag should start with "@" symbol',
line: spec.source[0].number,
critical: true
});
return spec;
}
tokens.tag = match[1];
tokens.postTag = match[3];
tokens.description = tokens.description.slice(match[0].length);
spec.tag = match[2];
return spec;
};
}
exports.default = tagTokenizer;
//# sourceMappingURL=tag.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["tag.js"],"names":["Object","defineProperty","exports","value","tagTokenizer","spec","tokens","source","match","description","problems","push","code","message","line","number","critical","tag","postTag","slice","length","default"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;AACA;AACA;AACA;AACA;;AACA,SAASC,YAAT,GAAwB;AACpB,SAAQC,IAAD,IAAU;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAaD,IAAI,CAACE,MAAL,CAAY,CAAZ,CAAnB;AACA,UAAMC,KAAK,GAAGF,MAAM,CAACG,WAAP,CAAmBD,KAAnB,CAAyB,kBAAzB,CAAd;;AACA,QAAIA,KAAK,KAAK,IAAd,EAAoB;AAChBH,MAAAA,IAAI,CAACK,QAAL,CAAcC,IAAd,CAAmB;AACfC,QAAAA,IAAI,EAAE,iBADS;AAEfC,QAAAA,OAAO,EAAE,kCAFM;AAGfC,QAAAA,IAAI,EAAET,IAAI,CAACE,MAAL,CAAY,CAAZ,EAAeQ,MAHN;AAIfC,QAAAA,QAAQ,EAAE;AAJK,OAAnB;AAMA,aAAOX,IAAP;AACH;;AACDC,IAAAA,MAAM,CAACW,GAAP,GAAaT,KAAK,CAAC,CAAD,CAAlB;AACAF,IAAAA,MAAM,CAACY,OAAP,GAAiBV,KAAK,CAAC,CAAD,CAAtB;AACAF,IAAAA,MAAM,CAACG,WAAP,GAAqBH,MAAM,CAACG,WAAP,CAAmBU,KAAnB,CAAyBX,KAAK,CAAC,CAAD,CAAL,CAASY,MAAlC,CAArB;AACAf,IAAAA,IAAI,CAACY,GAAL,GAAWT,KAAK,CAAC,CAAD,CAAhB;AACA,WAAOH,IAAP;AACH,GAjBD;AAkBH;;AACDH,OAAO,CAACmB,OAAR,GAAkBjB,YAAlB","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * Splits the `@prefix` from remaining `Spec.lines[].token.descrioption` into the `tag` token,\n * and populates `spec.tag`\n */\nfunction tagTokenizer() {\n return (spec) => {\n const { tokens } = spec.source[0];\n const match = tokens.description.match(/\\s*(@(\\S+))(\\s*)/);\n if (match === null) {\n spec.problems.push({\n code: 'spec:tag:prefix',\n message: 'tag should start with \"@\" symbol',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n tokens.tag = match[1];\n tokens.postTag = match[3];\n tokens.description = tokens.description.slice(match[0].length);\n spec.tag = match[2];\n return spec;\n };\n}\nexports.default = tagTokenizer;\n"],"file":"tag.cjs"}
+6
View File
@@ -0,0 +1,6 @@
import { Tokenizer } from './index';
/**
* Splits the `@prefix` from remaining `Spec.lines[].token.descrioption` into the `tag` token,
* and populates `spec.tag`
*/
export default function tagTokenizer(): Tokenizer;
+79
View File
@@ -0,0 +1,79 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const util_1 = require("../../util.cjs");
/**
* Sets splits remaining `Spec.lines[].tokes.description` into `type` and `description`
* tokens and populates Spec.type`
*
* @param {Spacing} spacing tells how to deal with a whitespace
* for type values going over multiple lines
*/
function typeTokenizer(spacing = 'compact') {
const join = getJoiner(spacing);
return spec => {
let curlies = 0;
let lines = [];
for (const [i, {
tokens
}] of spec.source.entries()) {
let type = '';
if (i === 0 && tokens.description[0] !== '{') return spec;
for (const ch of tokens.description) {
if (ch === '{') curlies++;
if (ch === '}') curlies--;
type += ch;
if (curlies === 0) break;
}
lines.push([tokens, type]);
if (curlies === 0) break;
}
if (curlies !== 0) {
spec.problems.push({
code: 'spec:type:unpaired-curlies',
message: 'unpaired curlies',
line: spec.source[0].number,
critical: true
});
return spec;
}
const parts = [];
const offset = lines[0][0].postDelimiter.length;
for (const [i, [tokens, type]] of lines.entries()) {
tokens.type = type;
if (i > 0) {
tokens.type = tokens.postDelimiter.slice(offset) + type;
tokens.postDelimiter = tokens.postDelimiter.slice(0, offset);
}
[tokens.postType, tokens.description] = util_1.splitSpace(tokens.description.slice(type.length));
parts.push(tokens.type);
}
parts[0] = parts[0].slice(1);
parts[parts.length - 1] = parts[parts.length - 1].slice(0, -1);
spec.type = join(parts);
return spec;
};
}
exports.default = typeTokenizer;
const trim = x => x.trim();
function getJoiner(spacing) {
if (spacing === 'compact') return t => t.map(trim).join('');else if (spacing === 'preserve') return t => t.join('\n');else return spacing;
}
//# sourceMappingURL=type.cjs.map
File diff suppressed because one or more lines are too long
+27
View File
@@ -0,0 +1,27 @@
import { Tokenizer } from './index';
/**
* Joiner is a function taking collected type token string parts,
* and joining them together. In most of the cases this will be
* a single piece like {type-name}, but type may go over multipe line
* ```
* @tag {function(
* number,
* string
* )}
* ```
*/
export declare type Joiner = (parts: string[]) => string;
/**
* Shortcut for standard Joiners
* compact - trim surrounding space, replace line breaks with a single space
* preserve - concat as is
*/
export declare type Spacing = 'compact' | 'preserve' | Joiner;
/**
* Sets splits remaining `Spec.lines[].tokes.description` into `type` and `description`
* tokens and populates Spec.type`
*
* @param {Spacing} spacing tells how to deal with a whitespace
* for type values going over multiple lines
*/
export default function typeTokenizer(spacing?: Spacing): Tokenizer;