parseman 0.19.0 → 0.20.0
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/README.md +3 -3
- package/dist/combinators/regex.d.ts +7 -7
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/compiler/scannable-run.d.ts +2 -10
- package/dist/compiler/scannable-run.d.ts.map +1 -1
- package/dist/index.cjs +313 -217
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +313 -207
- package/dist/index.js.map +4 -4
- package/dist/plugin/index.cjs +313 -207
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.js +313 -207
- package/dist/plugin/index.js.map +4 -4
- package/dist/regex/classes.d.ts +40 -0
- package/dist/regex/classes.d.ts.map +1 -0
- package/dist/regex/first-set.d.ts +35 -0
- package/dist/regex/first-set.d.ts.map +1 -0
- package/package.json +2 -3
- package/dist/combinators/regex-analyze.d.ts +0 -6
- package/dist/combinators/regex-analyze.d.ts.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level regex char-class primitives, shared by every hand-rolled regex
|
|
3
|
+
* analysis in the codebase — the interpreter's first-set walker
|
|
4
|
+
* (`./first-set.ts`), `regex()`'s short-scan fast path, and codegen's scannable
|
|
5
|
+
* lowering (`../compiler/scannable-run.ts`). Kept dependency-free (no combinator,
|
|
6
|
+
* no codegen imports) so it lands in even the leanest interpreter bundle.
|
|
7
|
+
*
|
|
8
|
+
* Everything here parses a regex STRUCTURE to code-point ranges; nothing encodes
|
|
9
|
+
* a specific byte meaning ("this is whitespace"). `\d`/`\w` lower to their ASCII
|
|
10
|
+
* ranges (correct for the default, non-`u` engine); `\s` uses the fixed
|
|
11
|
+
* `SPACE_RANGES` set (unaffected by the `u` flag).
|
|
12
|
+
*/
|
|
13
|
+
/** Single-char escapes whose code point is fixed regardless of context. */
|
|
14
|
+
export declare const CLASS_ESCAPES: Record<string, number>;
|
|
15
|
+
/**
|
|
16
|
+
* `\s`'s code-point set per the spec's `WhiteSpace` + `LineTerminator`
|
|
17
|
+
* productions — TAB/LF/VT/FF/CR, SPACE, NBSP, and the Unicode `Zs` space
|
|
18
|
+
* separators. Fixed regardless of the `u` flag, so always safe to lower.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SPACE_RANGES: Array<[number, number]>;
|
|
21
|
+
/**
|
|
22
|
+
* ASCII code-point ranges for the shorthand classes we lower. `\d`/`\w` are
|
|
23
|
+
* ASCII-only in the default (non-`u`) engine; `\s` maps to `SPACE_RANGES`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function shorthandRanges(ch: 'd' | 'w' | 's'): Array<[number, number]>;
|
|
26
|
+
/** `\uXXXX` at `body[i]` → its code point and the index past it, or null. */
|
|
27
|
+
export declare function readUnicodeEscape(body: string, i: number): {
|
|
28
|
+
cp: number;
|
|
29
|
+
next: number;
|
|
30
|
+
} | null;
|
|
31
|
+
/**
|
|
32
|
+
* Parse a regex char-class body (the chars BETWEEN `[` and `]`, negation `^`
|
|
33
|
+
* already stripped by the caller) to code-point ranges. `\d`/`\w`/`\s` expand to
|
|
34
|
+
* their ranges; `\uXXXX` and the fixed single-char escapes resolve to their code
|
|
35
|
+
* point; any other letter escape (`\D`, `\W`, `\S`, `\b`, …) returns null rather
|
|
36
|
+
* than being mis-read as a literal letter, so callers fall back to a safe
|
|
37
|
+
* over-approximation instead of a wrong set.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseClassRanges(body: string): Array<[number, number]> | null;
|
|
40
|
+
//# sourceMappingURL=classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../src/regex/classes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,2EAA2E;AAC3E,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAgD,CAAA;AAEjG;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAGhD,CAAA;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQ5E;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAK9F;AAID;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAyC7E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-rolled first-set analysis for `regex()` terminals — the interpreter's
|
|
3
|
+
* replacement for the old `regexp-tree`-backed analyzer (~264 KB). A `regex()`
|
|
4
|
+
* terminal's first-set is used ONLY to let `choice()` do first-char dispatch
|
|
5
|
+
* (see `choice.ts`); it is never consulted for whether a match succeeds. So this
|
|
6
|
+
* analyzer only has to be SOUND as an OVER-approximation: every char the pattern
|
|
7
|
+
* can actually start with must be in the returned set. Any construct it can't
|
|
8
|
+
* pin down widens to `any()` (— "could start with anything" —), which only
|
|
9
|
+
* disables a dispatch fast path, never changes a parse. Under-approximating
|
|
10
|
+
* (dropping a real start char) WOULD be a bug: dispatch would skip a matching
|
|
11
|
+
* arm. The soundness fuzz test (`test/unit/regex-first-set.test.ts`) checks this
|
|
12
|
+
* against the real `RegExp` engine as an oracle.
|
|
13
|
+
*
|
|
14
|
+
* It parses the regex into a tiny AST (single-char matchers, sequence,
|
|
15
|
+
* alternation, repetition, zero-width) reusing the shared char-class primitives
|
|
16
|
+
* in `./classes.ts`, then walks the AST unioning first-sets through the nullable
|
|
17
|
+
* prefix — the same shape the `regexp-tree` walker used.
|
|
18
|
+
*
|
|
19
|
+
* Note: flags are not consulted (matching the prior `regexp-tree` seam, which
|
|
20
|
+
* parsed `/${source}/` with no flags), so an `/i` pattern's first-set is its
|
|
21
|
+
* literal-case set. Sound for dispatch because the interpreter's `/i` regex arms
|
|
22
|
+
* are compared case-sensitively at the same seam.
|
|
23
|
+
*/
|
|
24
|
+
import type { FirstSet } from '../types.ts';
|
|
25
|
+
/**
|
|
26
|
+
* Compute a regex terminal's first-set and newline-start flag from its SOURCE
|
|
27
|
+
* (no delimiters, no flags). Over-approximates: an unparseable pattern degrades
|
|
28
|
+
* to `{ any, canMatchNewline: true }` — the same conservative value the prior
|
|
29
|
+
* `regexp-tree` seam returned on a parse failure.
|
|
30
|
+
*/
|
|
31
|
+
export declare function firstSetFromRegex(source: string): {
|
|
32
|
+
firstSet: FirstSet;
|
|
33
|
+
canMatchNewline: boolean;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=first-set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-set.d.ts","sourceRoot":"","sources":["../../src/regex/first-set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAqQ3C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CAalG"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parseman",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"packageManager": "pnpm@10.15.1",
|
|
5
|
-
"description": "Parser combinators that compile to optimized JavaScript
|
|
5
|
+
"description": "Parser combinators that compile to optimized JavaScript — use as a library or as a build-time macro",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Matthew Dean <matthew-dean@users.noreply.github.com>",
|
|
8
8
|
"repository": {
|
|
@@ -95,7 +95,6 @@
|
|
|
95
95
|
"magic-string": "~0.30.21",
|
|
96
96
|
"oxc-parser": "~0.137.0",
|
|
97
97
|
"oxc-resolver": "~11.23.0",
|
|
98
|
-
"regexp-tree": "~0.1.27",
|
|
99
98
|
"unplugin": "~3.0.0"
|
|
100
99
|
}
|
|
101
100
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex-analyze.d.ts","sourceRoot":"","sources":["../../src/combinators/regex-analyze.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG3C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CAOnG"}
|