@jondotsoy/don 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +72 -373
- package/lib/esm/don.d.ts +10 -0
- package/lib/esm/don.d.ts.map +1 -0
- package/lib/esm/don.js +27 -0
- package/lib/esm/don.js.map +1 -0
- package/lib/esm/index.d.ts +1 -2
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/v1/__utils__/key-syntax-kind.d.ts +2 -0
- package/lib/esm/v1/__utils__/key-syntax-kind.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/key-syntax-kind.js +23 -0
- package/lib/esm/v1/__utils__/key-syntax-kind.js.map +1 -0
- package/lib/esm/v1/__utils__/normalize.d.ts +3 -0
- package/lib/esm/v1/__utils__/normalize.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/normalize.js +10 -0
- package/lib/esm/v1/__utils__/normalize.js.map +1 -0
- package/lib/esm/v1/__utils__/t.d.ts +15 -0
- package/lib/esm/v1/__utils__/t.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/t.js +32 -0
- package/lib/esm/v1/__utils__/t.js.map +1 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.d.ts +7 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.js +162 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.js.map +1 -0
- package/lib/esm/v1/compiler/directive-node.d.ts +26 -0
- package/lib/esm/v1/compiler/directive-node.d.ts.map +1 -0
- package/lib/esm/v1/compiler/directive-node.js +48 -0
- package/lib/esm/v1/compiler/directive-node.js.map +1 -0
- package/lib/esm/v1/compiler/lexema-encode.d.ts +15 -0
- package/lib/esm/v1/compiler/lexema-encode.d.ts.map +1 -0
- package/lib/esm/v1/compiler/lexema-encode.js +22 -0
- package/lib/esm/v1/compiler/lexema-encode.js.map +1 -0
- package/lib/esm/v1/compiler/lexema.d.ts +10 -0
- package/lib/esm/v1/compiler/lexema.d.ts.map +1 -0
- package/lib/esm/v1/compiler/lexema.js +26 -0
- package/lib/esm/v1/compiler/lexema.js.map +1 -0
- package/lib/esm/v1/compiler/part-set-encode.d.ts +6 -0
- package/lib/esm/v1/compiler/part-set-encode.d.ts.map +1 -0
- package/lib/esm/v1/compiler/part-set-encode.js +15 -0
- package/lib/esm/v1/compiler/part-set-encode.js.map +1 -0
- package/lib/esm/v1/compiler/part-set.d.ts +6 -0
- package/lib/esm/v1/compiler/part-set.d.ts.map +1 -0
- package/lib/esm/v1/compiler/part-set.js +7 -0
- package/lib/esm/v1/compiler/part-set.js.map +1 -0
- package/lib/esm/v1/compiler/part.d.ts +31 -0
- package/lib/esm/v1/compiler/part.d.ts.map +1 -0
- package/lib/esm/v1/compiler/part.js +109 -0
- package/lib/esm/v1/compiler/part.js.map +1 -0
- package/lib/esm/v1/compiler/partial-span.d.ts +6 -0
- package/lib/esm/v1/compiler/partial-span.d.ts.map +1 -0
- package/lib/esm/v1/compiler/partial-span.js +9 -0
- package/lib/esm/v1/compiler/partial-span.js.map +1 -0
- package/lib/esm/v1/compiler/span.d.ts +9 -0
- package/lib/esm/v1/compiler/span.d.ts.map +1 -0
- package/lib/esm/v1/compiler/span.js +13 -0
- package/lib/esm/v1/compiler/span.js.map +1 -0
- package/lib/esm/v1/compiler/syntax-encode.d.ts +9 -0
- package/lib/esm/v1/compiler/syntax-encode.d.ts.map +1 -0
- package/lib/esm/v1/compiler/syntax-encode.js +160 -0
- package/lib/esm/v1/compiler/syntax-encode.js.map +1 -0
- package/lib/esm/v1/compiler/token.d.ts +59 -0
- package/lib/esm/v1/compiler/token.d.ts.map +1 -0
- package/lib/esm/v1/compiler/token.js +320 -0
- package/lib/esm/v1/compiler/token.js.map +1 -0
- package/lib/esm/v1/types/location.d.ts +6 -0
- package/lib/esm/v1/types/location.d.ts.map +1 -0
- package/lib/esm/v1/types/location.js +2 -0
- package/lib/esm/v1/types/location.js.map +1 -0
- package/lib/esm/v1/types/u8.d.ts +2 -0
- package/lib/esm/v1/types/u8.d.ts.map +1 -0
- package/lib/esm/v1/types/u8.js +2 -0
- package/lib/esm/v1/types/u8.js.map +1 -0
- package/lib/esm/v1/utils/build-logger.d.ts +11 -0
- package/lib/esm/v1/utils/build-logger.d.ts.map +1 -0
- package/lib/esm/v1/utils/build-logger.js +20 -0
- package/lib/esm/v1/utils/build-logger.js.map +1 -0
- package/lib/esm/v1/utils/charset-tools.d.ts +15 -0
- package/lib/esm/v1/utils/charset-tools.d.ts.map +1 -0
- package/lib/esm/v1/utils/charset-tools.js +37 -0
- package/lib/esm/v1/utils/charset-tools.js.map +1 -0
- package/lib/esm/v1/utils/charset.d.ts +34 -0
- package/lib/esm/v1/utils/charset.d.ts.map +1 -0
- package/lib/esm/v1/utils/charset.js +52 -0
- package/lib/esm/v1/utils/charset.js.map +1 -0
- package/lib/esm/v1/utils/parts-match.d.ts +12 -0
- package/lib/esm/v1/utils/parts-match.d.ts.map +1 -0
- package/lib/esm/v1/utils/parts-match.js +30 -0
- package/lib/esm/v1/utils/parts-match.js.map +1 -0
- package/lib/esm/v1/utils/syntax-kind.d.ts +22 -0
- package/lib/esm/v1/utils/syntax-kind.d.ts.map +1 -0
- package/lib/esm/v1/utils/syntax-kind.js +28 -0
- package/lib/esm/v1/utils/syntax-kind.js.map +1 -0
- package/lib/esm/v1/utils/take-while.d.ts +53 -0
- package/lib/esm/v1/utils/take-while.d.ts.map +1 -0
- package/lib/esm/v1/utils/take-while.js +69 -0
- package/lib/esm/v1/utils/take-while.js.map +1 -0
- package/package.json +5 -1
- package/lib/esm/chunk.d.ts +0 -28
- package/lib/esm/chunk.d.ts.map +0 -1
- package/lib/esm/chunk.js +0 -84
- package/lib/esm/chunk.js.map +0 -1
- package/lib/esm/document.d.ts +0 -20
- package/lib/esm/document.d.ts.map +0 -1
- package/lib/esm/document.js +0 -138
- package/lib/esm/document.js.map +0 -1
- package/lib/esm/lexer.d.ts +0 -38
- package/lib/esm/lexer.d.ts.map +0 -1
- package/lib/esm/lexer.js +0 -600
- package/lib/esm/lexer.js.map +0 -1
- package/lib/esm/utils/inspect.d.ts +0 -7
- package/lib/esm/utils/inspect.d.ts.map +0 -1
- package/lib/esm/utils/inspect.js +0 -39
- package/lib/esm/utils/inspect.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"u8.d.ts","sourceRoot":"","sources":["../../../../src/v1/types/u8.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"u8.js","sourceRoot":"","sources":["../../../../src/v1/types/u8.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type LOGGER = (...args: Parameters<typeof String.raw>) => void;
|
|
2
|
+
interface A {
|
|
3
|
+
test: (value: unknown) => boolean;
|
|
4
|
+
transform: (value: any) => any;
|
|
5
|
+
}
|
|
6
|
+
export declare const buildLogger: <T extends A[]>(options?: {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
tranformSubstitutions?: T;
|
|
9
|
+
}) => LOGGER;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=build-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-logger.d.ts","sourceRoot":"","sources":["../../../../src/v1/utils/build-logger.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;AAE/D,UAAU,CAAC;IACT,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAElC,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CAChC;AAOD,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,CAAC,EAAE,EAAE,UAAU;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,CAAC,CAAC;CAC3B,KAAG,MAiBH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const nothing = () => { };
|
|
2
|
+
const log = (...args) => {
|
|
3
|
+
console.log(String.raw(...args));
|
|
4
|
+
};
|
|
5
|
+
export const buildLogger = (options) => {
|
|
6
|
+
const enabled = options?.enabled ?? false;
|
|
7
|
+
if (!enabled)
|
|
8
|
+
return nothing;
|
|
9
|
+
return (template, ...substitutions) => {
|
|
10
|
+
log(template, ...substitutions.map((substitution) => {
|
|
11
|
+
for (const { test, transform } of options?.tranformSubstitutions ??
|
|
12
|
+
[]) {
|
|
13
|
+
if (test(substitution))
|
|
14
|
+
return transform(substitution);
|
|
15
|
+
}
|
|
16
|
+
return substitution;
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=build-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-logger.js","sourceRoot":"","sources":["../../../../src/v1/utils/build-logger.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,GAAW,GAAG,EAAE,GAAE,CAAC,CAAC;AACjC,MAAM,GAAG,GAAW,CAAC,GAAG,IAAI,EAAE,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAgB,OAG1C,EAAU,EAAE;IACX,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;IAE1C,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAE7B,OAAO,CAAC,QAAQ,EAAE,GAAG,aAAa,EAAE,EAAE;QACpC,GAAG,CACD,QAAQ,EACR,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,YAAiB,EAAE,EAAE;YACzC,KAAK,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,OAAO,EAAE,qBAAqB;gBAC9D,EAAE,EAAE,CAAC;gBACL,IAAI,IAAI,CAAC,YAAY,CAAC;oBAAE,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC;YACzD,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare namespace CharsetTools {
|
|
2
|
+
const charCode: (char: number | string) => number;
|
|
3
|
+
const range: (start: number | string, end: number | string) => number[];
|
|
4
|
+
const alphabetCharts: number[];
|
|
5
|
+
const numericCharts: number[];
|
|
6
|
+
const whitespaceCharts: number[];
|
|
7
|
+
const newlineCharts: number[];
|
|
8
|
+
const dotCharts: number[];
|
|
9
|
+
const underscoreCharts: number[];
|
|
10
|
+
const openCurlyBraceCharts: number[];
|
|
11
|
+
const closeCurlyBraceCharts: number[];
|
|
12
|
+
const doubleQuoteCharts: number[];
|
|
13
|
+
const singleQuoteCharts: number[];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=charset-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charset-tools.d.ts","sourceRoot":"","sources":["../../../../src/v1/utils/charset-tools.ts"],"names":[],"mappings":"AAAA,yBAAiB,YAAY,CAAC;IACrB,MAAM,QAAQ,GAAI,MAAM,MAAM,GAAG,MAAM,WACQ,CAAC;IAChD,MAAM,KAAK,GAAI,OAAO,MAAM,GAAG,MAAM,EAAE,KAAK,MAAM,GAAG,MAAM,aAKjE,CAAC;IAGK,MAAM,cAAc,UAG1B,CAAC;IAEK,MAAM,aAAa,UAAoC,CAAC;IAExD,MAAM,gBAAgB,UAG5B,CAAC;IAEK,MAAM,aAAa,UAAgC,CAAC;IAEpD,MAAM,SAAS,UAA+B,CAAC;IAE/C,MAAM,gBAAgB,UAA+B,CAAC;IAEtD,MAAM,oBAAoB,UAA+B,CAAC;IAE1D,MAAM,qBAAqB,UAA+B,CAAC;IAE3D,MAAM,iBAAiB,UAA+B,CAAC;IAEvD,MAAM,iBAAiB,UAA+B,CAAC;CAC/D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export var CharsetTools;
|
|
2
|
+
(function (CharsetTools) {
|
|
3
|
+
CharsetTools.charCode = (char) => typeof char === "string" ? char.charCodeAt(0) : char;
|
|
4
|
+
CharsetTools.range = (start, end) => {
|
|
5
|
+
const startCharCode = CharsetTools.charCode(start);
|
|
6
|
+
const endCharCode = CharsetTools.charCode(end);
|
|
7
|
+
const length = endCharCode - startCharCode + 1;
|
|
8
|
+
return Array.from({ length }, (_, i) => startCharCode + i);
|
|
9
|
+
};
|
|
10
|
+
// alphabet
|
|
11
|
+
CharsetTools.alphabetCharts = [
|
|
12
|
+
...CharsetTools.range("a", "z"),
|
|
13
|
+
...CharsetTools.range("A", "Z"),
|
|
14
|
+
];
|
|
15
|
+
// numeric
|
|
16
|
+
CharsetTools.numericCharts = [...CharsetTools.range("0", "9")];
|
|
17
|
+
// space & tab
|
|
18
|
+
CharsetTools.whitespaceCharts = [
|
|
19
|
+
CharsetTools.charCode(" "),
|
|
20
|
+
CharsetTools.charCode("\t"),
|
|
21
|
+
];
|
|
22
|
+
// \n: newline
|
|
23
|
+
CharsetTools.newlineCharts = [CharsetTools.charCode("\n")];
|
|
24
|
+
// .: dot
|
|
25
|
+
CharsetTools.dotCharts = [CharsetTools.charCode(".")];
|
|
26
|
+
// _: underscore
|
|
27
|
+
CharsetTools.underscoreCharts = [CharsetTools.charCode("_")];
|
|
28
|
+
// {: open curly brace
|
|
29
|
+
CharsetTools.openCurlyBraceCharts = [CharsetTools.charCode("{")];
|
|
30
|
+
// }: close curly brace
|
|
31
|
+
CharsetTools.closeCurlyBraceCharts = [CharsetTools.charCode("}")];
|
|
32
|
+
// Double Quote
|
|
33
|
+
CharsetTools.doubleQuoteCharts = [CharsetTools.charCode(`"`)];
|
|
34
|
+
// Single Quote
|
|
35
|
+
CharsetTools.singleQuoteCharts = [CharsetTools.charCode("'")];
|
|
36
|
+
})(CharsetTools || (CharsetTools = {}));
|
|
37
|
+
//# sourceMappingURL=charset-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charset-tools.js","sourceRoot":"","sources":["../../../../src/v1/utils/charset-tools.ts"],"names":[],"mappings":"AAAA,MAAM,KAAW,YAAY,CAoC5B;AApCD,WAAiB,YAAY;IACd,qBAAQ,GAAG,CAAC,IAAqB,EAAE,EAAE,CAChD,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1C,kBAAK,GAAG,CAAC,KAAsB,EAAE,GAAoB,EAAE,EAAE;QACpE,MAAM,aAAa,GAAG,aAAA,QAAQ,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,WAAW,GAAG,aAAA,QAAQ,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,WAAW,GAAG,aAAa,GAAG,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC;IAEF,WAAW;IACE,2BAAc,GAAG;QAC5B,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC;QAC/B,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC;KAChC,CAAC;IACF,UAAU;IACG,0BAAa,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/D,cAAc;IACD,6BAAgB,GAAG;QAC9B,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC1B,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;KAC5B,CAAC;IACF,cAAc;IACD,0BAAa,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,SAAS;IACI,sBAAS,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,gBAAgB;IACH,6BAAgB,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,sBAAsB;IACT,iCAAoB,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACjE,uBAAuB;IACV,kCAAqB,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,eAAe;IACF,8BAAiB,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9D,eAAe;IACF,8BAAiB,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAChE,CAAC,EApCgB,YAAY,KAAZ,YAAY,QAoC5B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PartialSpan } from "../compiler/partial-span.js";
|
|
2
|
+
import type { u8 } from "../types/u8.js";
|
|
3
|
+
export declare class Charset {
|
|
4
|
+
#private;
|
|
5
|
+
private readonly charset;
|
|
6
|
+
constructor(charset: u8);
|
|
7
|
+
get length(): number;
|
|
8
|
+
slice(start: number, end: number): number[];
|
|
9
|
+
/**
|
|
10
|
+
* Finds a continuous span of characters from the charset that match the whitelist.
|
|
11
|
+
* Returns a Span object representing the position and length of the matched sequence.
|
|
12
|
+
*
|
|
13
|
+
* @param {u8} whitelist - Array of allowed character codes to match
|
|
14
|
+
* @param {number} [fromIndex=0] - The index to start searching from (defaults to 0)
|
|
15
|
+
* @returns {Span | null} A Span object with the start position and length of the match,
|
|
16
|
+
* or null if no characters from the whitelist are found at the starting position
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const charset = new Charset([65, 66, 67, 68]); // "ABCD"
|
|
21
|
+
* const span = charset.span([65, 66]); // Match 'A' and 'B'
|
|
22
|
+
* // Returns: Span { start: 0, length: 2 }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const charset = new Charset([32, 32, 65, 66]); // " AB"
|
|
28
|
+
* const span = charset.span([32], 0); // Match spaces
|
|
29
|
+
* // Returns: Span { start: 0, length: 2 }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
span(whitelist: u8, fromIndex?: number, limit?: null | number): PartialSpan | null;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=charset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charset.d.ts","sourceRoot":"","sources":["../../../../src/v1/utils/charset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,OAAO;;IAGN,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,EAAE;IAIxC,IAAI,MAAM,WAET;IAED,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAIhC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CACF,SAAS,EAAE,EAAE,EACb,SAAS,GAAE,MAAU,EACrB,KAAK,GAAE,IAAI,GAAG,MAAa,GAC1B,WAAW,GAAG,IAAI;CAkBtB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PartialSpan } from "../compiler/partial-span.js";
|
|
2
|
+
export class Charset {
|
|
3
|
+
charset;
|
|
4
|
+
#length;
|
|
5
|
+
constructor(charset) {
|
|
6
|
+
this.charset = charset;
|
|
7
|
+
this.#length = charset.length;
|
|
8
|
+
}
|
|
9
|
+
get length() {
|
|
10
|
+
return this.#length;
|
|
11
|
+
}
|
|
12
|
+
slice(start, end) {
|
|
13
|
+
return this.charset.slice(start, end);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Finds a continuous span of characters from the charset that match the whitelist.
|
|
17
|
+
* Returns a Span object representing the position and length of the matched sequence.
|
|
18
|
+
*
|
|
19
|
+
* @param {u8} whitelist - Array of allowed character codes to match
|
|
20
|
+
* @param {number} [fromIndex=0] - The index to start searching from (defaults to 0)
|
|
21
|
+
* @returns {Span | null} A Span object with the start position and length of the match,
|
|
22
|
+
* or null if no characters from the whitelist are found at the starting position
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const charset = new Charset([65, 66, 67, 68]); // "ABCD"
|
|
27
|
+
* const span = charset.span([65, 66]); // Match 'A' and 'B'
|
|
28
|
+
* // Returns: Span { start: 0, length: 2 }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const charset = new Charset([32, 32, 65, 66]); // " AB"
|
|
34
|
+
* const span = charset.span([32], 0); // Match spaces
|
|
35
|
+
* // Returns: Span { start: 0, length: 2 }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
span(whitelist, fromIndex = 0, limit = null) {
|
|
39
|
+
let matchedPos = null;
|
|
40
|
+
let whitelistSet = new Set(whitelist);
|
|
41
|
+
for (let i = fromIndex, char = this.charset[i]; char && i < this.charset.length && whitelistSet.has(char); i++, char = this.charset[i]) {
|
|
42
|
+
matchedPos = i;
|
|
43
|
+
const length = matchedPos - fromIndex + 1;
|
|
44
|
+
if (limit !== null && length >= limit)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
if (matchedPos === null)
|
|
48
|
+
return null;
|
|
49
|
+
return new PartialSpan(fromIndex, matchedPos - fromIndex + 1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=charset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charset.js","sourceRoot":"","sources":["../../../../src/v1/utils/charset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,MAAM,OAAO,OAAO;IAGW;IAF7B,OAAO,CAAS;IAEhB,YAA6B,OAAW;QAAX,YAAO,GAAP,OAAO,CAAI;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAa,EAAE,GAAW;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CACF,SAAa,EACb,YAAoB,CAAC,EACrB,QAAuB,IAAI;QAE3B,IAAI,UAAU,GAAkB,IAAI,CAAC;QACrC,IAAI,YAAY,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAEtC,KACE,IAAI,CAAC,GAAG,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACzC,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EACzD,CAAC,EAAE,EAAE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAC3B,CAAC;YACD,UAAU,GAAG,CAAC,CAAC;YACf,MAAM,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,CAAC,CAAC;YAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK;gBAAE,MAAM;QAC/C,CAAC;QAED,IAAI,UAAU,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAErC,OAAO,IAAI,WAAW,CAAC,SAAS,EAAE,UAAU,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Part } from "../compiler/part.js";
|
|
2
|
+
import type { PartSet } from "../compiler/part-set.js";
|
|
3
|
+
import type { SyntaxKind } from "./syntax-kind.js";
|
|
4
|
+
type A<T extends string, V> = Record<T, {
|
|
5
|
+
eq: V;
|
|
6
|
+
}>;
|
|
7
|
+
type expressions = A<"type", SyntaxKind> | A<"buffer", number[]> | A<"type" | "buffer", SyntaxKind>;
|
|
8
|
+
export declare const partsMatch: (parts: PartSet | {
|
|
9
|
+
parts: Part[];
|
|
10
|
+
}, expressions: expressions[]) => boolean;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=parts-match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts-match.d.ts","sourceRoot":"","sources":["../../../../src/v1/utils/parts-match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,KAAK,CAAC,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE;IAAE,EAAE,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEnD,KAAK,WAAW,GACZ,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,GACrB,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,GACrB,CAAC,CAAC,MAAM,GAAG,QAAQ,EAAE,UAAU,CAAC,CAAC;AAErC,eAAO,MAAM,UAAU,GACrB,OAAO,OAAO,GAAG;IAAE,KAAK,EAAE,IAAI,EAAE,CAAA;CAAE,EAClC,aAAa,WAAW,EAAE,KACzB,OAiCF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const partsMatch = (parts, expressions) => {
|
|
2
|
+
if (parts.parts.length !== expressions.length) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
for (let i = 0; i < expressions.length; i++) {
|
|
6
|
+
const part = parts.parts[i];
|
|
7
|
+
const expr = expressions[i];
|
|
8
|
+
if (!part || !expr) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if ("type" in expr && expr.type) {
|
|
12
|
+
if (part.type !== expr.type.eq) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if ("buffer" in expr && expr.buffer && Array.isArray(expr.buffer.eq)) {
|
|
17
|
+
const expectedBuffer = expr.buffer.eq;
|
|
18
|
+
if (part.buffer.length !== expectedBuffer.length) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
for (let j = 0; j < expectedBuffer.length; j++) {
|
|
22
|
+
if (part.buffer[j] !== expectedBuffer[j]) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=parts-match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts-match.js","sourceRoot":"","sources":["../../../../src/v1/utils/parts-match.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAkC,EAClC,WAA0B,EACjB,EAAE;IACX,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAE5B,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;YACrE,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,EAAE,CAAC;gBACjD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;oBACzC,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum SyntaxKind {
|
|
2
|
+
unknown = 0,
|
|
3
|
+
alphabet = 1,
|
|
4
|
+
integer = 2,
|
|
5
|
+
whitespace = 3,
|
|
6
|
+
newline = 4,
|
|
7
|
+
dot = 5,
|
|
8
|
+
underscore = 6,
|
|
9
|
+
singleQuote = 7,
|
|
10
|
+
doubleQuote = 8,
|
|
11
|
+
openCurlyBrace = 9,
|
|
12
|
+
closeCurlyBrace = 10,
|
|
13
|
+
keyword = 11,
|
|
14
|
+
string = 12,
|
|
15
|
+
numeric = 13,
|
|
16
|
+
boolean = 14,
|
|
17
|
+
null = 15,
|
|
18
|
+
comment = 16,
|
|
19
|
+
indent = 17,
|
|
20
|
+
heredoc = 18
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=syntax-kind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-kind.d.ts","sourceRoot":"","sources":["../../../../src/v1/utils/syntax-kind.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,OAAO,IAAA;IACP,UAAU,IAAA;IACV,OAAO,IAAA;IACP,GAAG,IAAA;IACH,UAAU,IAAA;IACV,WAAW,IAAA;IACX,WAAW,IAAA;IAEX,cAAc,IAAA;IAEd,eAAe,KAAA;IAKf,OAAO,KAAA;IACP,MAAM,KAAA;IACN,OAAO,KAAA;IACP,OAAO,KAAA;IACP,IAAI,KAAA;IACJ,OAAO,KAAA;IACP,MAAM,KAAA;IACN,OAAO,KAAA;CACR"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export var SyntaxKind;
|
|
2
|
+
(function (SyntaxKind) {
|
|
3
|
+
SyntaxKind[SyntaxKind["unknown"] = 0] = "unknown";
|
|
4
|
+
SyntaxKind[SyntaxKind["alphabet"] = 1] = "alphabet";
|
|
5
|
+
SyntaxKind[SyntaxKind["integer"] = 2] = "integer";
|
|
6
|
+
SyntaxKind[SyntaxKind["whitespace"] = 3] = "whitespace";
|
|
7
|
+
SyntaxKind[SyntaxKind["newline"] = 4] = "newline";
|
|
8
|
+
SyntaxKind[SyntaxKind["dot"] = 5] = "dot";
|
|
9
|
+
SyntaxKind[SyntaxKind["underscore"] = 6] = "underscore";
|
|
10
|
+
SyntaxKind[SyntaxKind["singleQuote"] = 7] = "singleQuote";
|
|
11
|
+
SyntaxKind[SyntaxKind["doubleQuote"] = 8] = "doubleQuote";
|
|
12
|
+
// {
|
|
13
|
+
SyntaxKind[SyntaxKind["openCurlyBrace"] = 9] = "openCurlyBrace";
|
|
14
|
+
// }
|
|
15
|
+
SyntaxKind[SyntaxKind["closeCurlyBrace"] = 10] = "closeCurlyBrace";
|
|
16
|
+
////
|
|
17
|
+
// token types
|
|
18
|
+
////
|
|
19
|
+
SyntaxKind[SyntaxKind["keyword"] = 11] = "keyword";
|
|
20
|
+
SyntaxKind[SyntaxKind["string"] = 12] = "string";
|
|
21
|
+
SyntaxKind[SyntaxKind["numeric"] = 13] = "numeric";
|
|
22
|
+
SyntaxKind[SyntaxKind["boolean"] = 14] = "boolean";
|
|
23
|
+
SyntaxKind[SyntaxKind["null"] = 15] = "null";
|
|
24
|
+
SyntaxKind[SyntaxKind["comment"] = 16] = "comment";
|
|
25
|
+
SyntaxKind[SyntaxKind["indent"] = 17] = "indent";
|
|
26
|
+
SyntaxKind[SyntaxKind["heredoc"] = 18] = "heredoc";
|
|
27
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
28
|
+
//# sourceMappingURL=syntax-kind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-kind.js","sourceRoot":"","sources":["../../../../src/v1/utils/syntax-kind.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UA0BX;AA1BD,WAAY,UAAU;IACpB,iDAAO,CAAA;IACP,mDAAQ,CAAA;IACR,iDAAO,CAAA;IACP,uDAAU,CAAA;IACV,iDAAO,CAAA;IACP,yCAAG,CAAA;IACH,uDAAU,CAAA;IACV,yDAAW,CAAA;IACX,yDAAW,CAAA;IACX,IAAI;IACJ,+DAAc,CAAA;IACd,IAAI;IACJ,kEAAe,CAAA;IAEf,IAAI;IACJ,cAAc;IACd,IAAI;IACJ,kDAAO,CAAA;IACP,gDAAM,CAAA;IACN,kDAAO,CAAA;IACP,kDAAO,CAAA;IACP,4CAAI,CAAA;IACJ,kDAAO,CAAA;IACP,gDAAM,CAAA;IACN,kDAAO,CAAA;AACT,CAAC,EA1BW,UAAU,KAAV,UAAU,QA0BrB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generator function that yields elements from an array while a predicate condition is true.
|
|
3
|
+
* Stops iteration as soon as the predicate returns false.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array
|
|
6
|
+
* @param {T[]} array - The source array to iterate over
|
|
7
|
+
* @param {(value: T, index: number, array: T[]) => boolean} predicate - Function that tests each element.
|
|
8
|
+
* Returns true to continue yielding elements, false to stop iteration.
|
|
9
|
+
* @param {number} [fromIndex=0] - The index to start iteration from (defaults to 0)
|
|
10
|
+
* @yields {T} Elements from the array while the predicate returns true
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const numbers = [1, 2, 3, 4, 5, 6];
|
|
15
|
+
* const lessThanFour = [...takeWhile(numbers, n => n < 4)];
|
|
16
|
+
* // Result: [1, 2, 3]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const tokens = ['a', 'b', 'c', 'd'];
|
|
22
|
+
* const untilC = [...takeWhile(tokens, t => t !== 'c')];
|
|
23
|
+
* // Result: ['a', 'b']
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Starting from a specific index
|
|
29
|
+
* const items = [1, 2, 3, 4, 5];
|
|
30
|
+
* const fromIndex2 = [...takeWhile(items, n => n < 5, 2)];
|
|
31
|
+
* // Result: [3, 4]
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const takeWhile: <T>(array: T[], predicate: (value: T, index: number, array: T[]) => boolean, fromIndex?: number) => Generator<NonNullable<T>, void, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Finds the index of the first element in an array that satisfies the provided predicate function.
|
|
37
|
+
*
|
|
38
|
+
* @template T - The type of elements in the array
|
|
39
|
+
* @param array - The array to search
|
|
40
|
+
* @param predicate - Function to test each element. Returns truthy value for matching element
|
|
41
|
+
* @param fromIndex - The index to start searching from (default: 0)
|
|
42
|
+
* @returns The index of the first matching element, or -1 if no match is found
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
47
|
+
* findIndex(numbers, (n) => n > 3); // Returns 3
|
|
48
|
+
* findIndex(numbers, (n) => n > 3, 4); // Returns 4 (starts from index 4)
|
|
49
|
+
* findIndex(numbers, (n) => n > 10); // Returns -1
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const findIndex: <T>(array: T[], predicate: (value: T, index: number, obj: T[]) => unknown, fromIndex?: number) => number;
|
|
53
|
+
//# sourceMappingURL=take-while.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take-while.d.ts","sourceRoot":"","sources":["../../../../src/v1/utils/take-while.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,SAAS,GAAc,CAAC,EACnC,OAAO,CAAC,EAAE,EACV,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,OAAO,EAC3D,YAAW,MAAU,6CAWtB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,GAAa,CAAC,EAClC,OAAO,CAAC,EAAE,EACV,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,YAAW,MAAU,WAUtB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generator function that yields elements from an array while a predicate condition is true.
|
|
3
|
+
* Stops iteration as soon as the predicate returns false.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array
|
|
6
|
+
* @param {T[]} array - The source array to iterate over
|
|
7
|
+
* @param {(value: T, index: number, array: T[]) => boolean} predicate - Function that tests each element.
|
|
8
|
+
* Returns true to continue yielding elements, false to stop iteration.
|
|
9
|
+
* @param {number} [fromIndex=0] - The index to start iteration from (defaults to 0)
|
|
10
|
+
* @yields {T} Elements from the array while the predicate returns true
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const numbers = [1, 2, 3, 4, 5, 6];
|
|
15
|
+
* const lessThanFour = [...takeWhile(numbers, n => n < 4)];
|
|
16
|
+
* // Result: [1, 2, 3]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const tokens = ['a', 'b', 'c', 'd'];
|
|
22
|
+
* const untilC = [...takeWhile(tokens, t => t !== 'c')];
|
|
23
|
+
* // Result: ['a', 'b']
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Starting from a specific index
|
|
29
|
+
* const items = [1, 2, 3, 4, 5];
|
|
30
|
+
* const fromIndex2 = [...takeWhile(items, n => n < 5, 2)];
|
|
31
|
+
* // Result: [3, 4]
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const takeWhile = function* (array, predicate, fromIndex = 0) {
|
|
35
|
+
for (let index = fromIndex; index < array.length; index++) {
|
|
36
|
+
const item = array[index];
|
|
37
|
+
if (!predicate(item, index, array)) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
yield item;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Finds the index of the first element in an array that satisfies the provided predicate function.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The type of elements in the array
|
|
47
|
+
* @param array - The array to search
|
|
48
|
+
* @param predicate - Function to test each element. Returns truthy value for matching element
|
|
49
|
+
* @param fromIndex - The index to start searching from (default: 0)
|
|
50
|
+
* @returns The index of the first matching element, or -1 if no match is found
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
55
|
+
* findIndex(numbers, (n) => n > 3); // Returns 3
|
|
56
|
+
* findIndex(numbers, (n) => n > 3, 4); // Returns 4 (starts from index 4)
|
|
57
|
+
* findIndex(numbers, (n) => n > 10); // Returns -1
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export const findIndex = function (array, predicate, fromIndex = 0) {
|
|
61
|
+
for (let index = fromIndex; index < array.length; index++) {
|
|
62
|
+
const item = array[index];
|
|
63
|
+
if (predicate(item, index, array)) {
|
|
64
|
+
return index;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return -1;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=take-while.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take-while.js","sourceRoot":"","sources":["../../../../src/v1/utils/take-while.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC,EAChC,KAAU,EACV,SAA2D,EAC3D,YAAoB,CAAC;IAErB,KAAK,IAAI,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;QAE3B,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM;QACR,CAAC;QAED,MAAM,IAAI,CAAC;IACb,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UACvB,KAAU,EACV,SAAyD,EACzD,YAAoB,CAAC;IAErB,KAAK,IAAI,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;QAE3B,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jondotsoy/don",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "DON (Directive Object Notation) - A human-readable data serialization format based on directives and subdirectives for configuration files, infrastructure definitions, and structured data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"don",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./lib/esm/index.d.ts",
|
|
28
28
|
"import": "./lib/esm/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./utils": {
|
|
31
|
+
"types": "./lib/esm/utils/inspect.d.ts",
|
|
32
|
+
"import": "./lib/esm/utils/inspect.js"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"files": [
|
package/lib/esm/chunk.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare class Chunk {
|
|
2
|
-
readonly pos: number;
|
|
3
|
-
readonly length: number;
|
|
4
|
-
readonly value: Iterable<number>;
|
|
5
|
-
readonly debug_str: string;
|
|
6
|
-
constructor(pos: number, length: number, value: Iterable<number>, debug_str?: string);
|
|
7
|
-
}
|
|
8
|
-
export declare class ChunkList {
|
|
9
|
-
readonly length: number;
|
|
10
|
-
readonly chunks: Iterable<Chunk>;
|
|
11
|
-
constructor(length: number, chunks: Iterable<Chunk>);
|
|
12
|
-
}
|
|
13
|
-
export declare class Expression {
|
|
14
|
-
readonly m: number[];
|
|
15
|
-
constructor(m: number[]);
|
|
16
|
-
test(buff: number[], fromIndex: number): boolean;
|
|
17
|
-
exec(buff: number[], fromIndex: number): number[];
|
|
18
|
-
static keywordExpression: Expression;
|
|
19
|
-
static spaceExpression: Expression;
|
|
20
|
-
}
|
|
21
|
-
type LexerEncoderOptions = {};
|
|
22
|
-
export declare class ChunkEncoder {
|
|
23
|
-
private options?;
|
|
24
|
-
constructor(options?: LexerEncoderOptions | undefined);
|
|
25
|
-
encode(buff: string | Iterable<number>): ChunkList;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=chunk.d.ts.map
|
package/lib/esm/chunk.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/chunk.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IAEd,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS;gBAHT,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,SAAS,SAEjB;CAEJ;AAED,qBAAa,SAAS;IAElB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC;gBADvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC;CAEnC;AAKD,qBAAa,UAAU;IACT,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE;gBAAX,CAAC,EAAE,MAAM,EAAE;IAEhC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;IAMhD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAUjD,MAAM,CAAC,iBAAiB,aASrB;IAEH,MAAM,CAAC,eAAe,aAAwB;CAC/C;AAED,KAAK,mBAAmB,GAAG,EAAE,CAAC;AAE9B,qBAAa,YAAY;IACX,OAAO,CAAC,OAAO,CAAC;gBAAR,OAAO,CAAC,EAAE,mBAAmB,YAAA;IAEjD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS;CAiCnD"}
|
package/lib/esm/chunk.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export class Chunk {
|
|
2
|
-
pos;
|
|
3
|
-
length;
|
|
4
|
-
value;
|
|
5
|
-
debug_str;
|
|
6
|
-
constructor(pos, length, value, debug_str = JSON.stringify(new TextDecoder().decode(new Uint8Array(value)))) {
|
|
7
|
-
this.pos = pos;
|
|
8
|
-
this.length = length;
|
|
9
|
-
this.value = value;
|
|
10
|
-
this.debug_str = debug_str;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class ChunkList {
|
|
14
|
-
length;
|
|
15
|
-
chunks;
|
|
16
|
-
constructor(length, chunks) {
|
|
17
|
-
this.length = length;
|
|
18
|
-
this.chunks = chunks;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const range = (start, end) => Array.from({ length: -start + end + 1 }, (_, i) => i + start);
|
|
22
|
-
export class Expression {
|
|
23
|
-
m;
|
|
24
|
-
constructor(m) {
|
|
25
|
-
this.m = m;
|
|
26
|
-
}
|
|
27
|
-
test(buff, fromIndex) {
|
|
28
|
-
const charCode = buff[fromIndex];
|
|
29
|
-
if (charCode === undefined)
|
|
30
|
-
return false;
|
|
31
|
-
return this.m.includes(charCode);
|
|
32
|
-
}
|
|
33
|
-
exec(buff, fromIndex) {
|
|
34
|
-
let end = fromIndex;
|
|
35
|
-
while (end < buff.length && this.test(buff, end)) {
|
|
36
|
-
end++;
|
|
37
|
-
}
|
|
38
|
-
return buff.slice(fromIndex, end);
|
|
39
|
-
}
|
|
40
|
-
static keywordExpression = new Expression([
|
|
41
|
-
// a-z (97 ... 122)
|
|
42
|
-
...range(97, 122),
|
|
43
|
-
// A-Z (65 ... 90)
|
|
44
|
-
...range(65, 90),
|
|
45
|
-
// _ (95)
|
|
46
|
-
95,
|
|
47
|
-
// 0-9 (48 ... 57)
|
|
48
|
-
...range(48, 57),
|
|
49
|
-
]);
|
|
50
|
-
static spaceExpression = new Expression([32]);
|
|
51
|
-
}
|
|
52
|
-
export class ChunkEncoder {
|
|
53
|
-
options;
|
|
54
|
-
constructor(options) {
|
|
55
|
-
this.options = options;
|
|
56
|
-
}
|
|
57
|
-
encode(buff) {
|
|
58
|
-
const numberIterable = typeof buff === "string" ? new TextEncoder().encode(buff) : buff;
|
|
59
|
-
const bytes = Array.from(numberIterable);
|
|
60
|
-
const tokens = [];
|
|
61
|
-
let pos = 0;
|
|
62
|
-
const expressions = [
|
|
63
|
-
Expression.keywordExpression,
|
|
64
|
-
Expression.spaceExpression,
|
|
65
|
-
];
|
|
66
|
-
while (pos < bytes.length) {
|
|
67
|
-
const charCode = bytes[pos];
|
|
68
|
-
if (charCode === undefined)
|
|
69
|
-
break;
|
|
70
|
-
const expression = expressions.find((expression) => expression.test(bytes, pos));
|
|
71
|
-
if (expression) {
|
|
72
|
-
const value = expression.exec(bytes, pos);
|
|
73
|
-
tokens.push(new Chunk(pos, value.length, value));
|
|
74
|
-
pos += value.length;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
// Symbols
|
|
78
|
-
tokens.push(new Chunk(pos, 1, [charCode]));
|
|
79
|
-
pos++;
|
|
80
|
-
}
|
|
81
|
-
return new ChunkList(tokens.length, tokens);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=chunk.js.map
|
package/lib/esm/chunk.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/chunk.ts"],"names":[],"mappings":"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"}
|
package/lib/esm/document.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ChunkList } from "./chunk";
|
|
2
|
-
import { Lexema, Token } from "./lexer";
|
|
3
|
-
export declare class Directive {
|
|
4
|
-
readonly name: Token;
|
|
5
|
-
readonly args: Token[];
|
|
6
|
-
readonly children: Directive[];
|
|
7
|
-
constructor(name: Token, args: Token[], children: Directive[]);
|
|
8
|
-
static isDirective(doc: unknown): doc is Directive;
|
|
9
|
-
}
|
|
10
|
-
export declare class Document {
|
|
11
|
-
readonly children: Directive[];
|
|
12
|
-
constructor(children: Directive[]);
|
|
13
|
-
static isDocument(doc: unknown): doc is Document;
|
|
14
|
-
}
|
|
15
|
-
export declare class DocumentEncoder {
|
|
16
|
-
encode(input: string | Iterable<number> | ChunkList | Lexema): Document;
|
|
17
|
-
private segmentByBrackets;
|
|
18
|
-
private parseDirectives;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=document.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEtD,qBAAa,SAAS;IAElB,QAAQ,CAAC,IAAI,EAAE,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE;IACtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE;gBAFrB,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,KAAK,EAAE,EACb,QAAQ,EAAE,SAAS,EAAE;IAGhC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS;CAGnD;AAED,qBAAa,QAAQ;IACP,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE;gBAArB,QAAQ,EAAE,SAAS,EAAE;IAE1C,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,QAAQ;CAGjD;AAUD,qBAAa,eAAe;IAC1B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ;IAavE,OAAO,CAAC,iBAAiB;IAsCzB,OAAO,CAAC,eAAe;CAiGxB"}
|