limn-hl 0.1.1 → 0.2.1

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.
Files changed (73) hide show
  1. package/README.md +105 -174
  2. package/dist/detect.d.ts +7 -1
  3. package/dist/detect.js +657 -499
  4. package/dist/engine.js +45 -1
  5. package/dist/generated/detect.d.ts +8 -0
  6. package/dist/generated/detect.js +31 -0
  7. package/dist/generated/grammars.d.ts +119 -0
  8. package/dist/generated/grammars.js +628 -0
  9. package/dist/generated/lang.d.ts +6 -0
  10. package/dist/{lang/index.js → generated/lang.js} +82 -56
  11. package/dist/{theme/generated.d.ts → generated/themes.d.ts} +1 -1
  12. package/dist/lang.d.ts +1 -0
  13. package/dist/lang.js +1 -0
  14. package/dist/render/ansi.d.ts +1 -1
  15. package/dist/render/html.d.ts +1 -1
  16. package/dist/{theme/index.d.ts → theme.d.ts} +1 -1
  17. package/dist/theme.js +1 -0
  18. package/dist/vm/compile.d.ts +4 -0
  19. package/dist/vm/compile.js +393 -0
  20. package/dist/vm/exec.d.ts +3 -0
  21. package/dist/vm/exec.js +218 -0
  22. package/dist/vm/format.d.ts +260 -0
  23. package/dist/vm/format.js +251 -0
  24. package/dist/vm/index.d.ts +2 -0
  25. package/dist/vm/index.js +2 -0
  26. package/dist/vm/pat.d.ts +4 -0
  27. package/dist/vm/pat.js +816 -0
  28. package/dist/vm/quoted.d.ts +8 -0
  29. package/dist/vm/quoted.js +232 -0
  30. package/dist/vm/scan.d.ts +3 -0
  31. package/dist/vm/scan.js +499 -0
  32. package/dist/wordtable.d.ts +8 -4
  33. package/dist/wordtable.js +107 -30
  34. package/package.json +6 -6
  35. package/dist/lang/clike.d.ts +0 -15
  36. package/dist/lang/clike.js +0 -35
  37. package/dist/lang/clike_helpers.d.ts +0 -8
  38. package/dist/lang/clike_helpers.js +0 -220
  39. package/dist/lang/code.d.ts +0 -45
  40. package/dist/lang/code.js +0 -779
  41. package/dist/lang/config.d.ts +0 -5
  42. package/dist/lang/config.js +0 -164
  43. package/dist/lang/css.d.ts +0 -5
  44. package/dist/lang/css.js +0 -125
  45. package/dist/lang/docs.d.ts +0 -12
  46. package/dist/lang/docs.js +0 -462
  47. package/dist/lang/formats.d.ts +0 -10
  48. package/dist/lang/formats.js +0 -295
  49. package/dist/lang/html.d.ts +0 -11
  50. package/dist/lang/html.js +0 -298
  51. package/dist/lang/index.d.ts +0 -20
  52. package/dist/lang/js.d.ts +0 -9
  53. package/dist/lang/js.js +0 -532
  54. package/dist/lang/js_helpers.d.ts +0 -7
  55. package/dist/lang/js_helpers.js +0 -308
  56. package/dist/lang/json.d.ts +0 -3
  57. package/dist/lang/json.js +0 -136
  58. package/dist/lang/markdown.d.ts +0 -3
  59. package/dist/lang/markdown.js +0 -249
  60. package/dist/lang/python.d.ts +0 -3
  61. package/dist/lang/python.js +0 -335
  62. package/dist/lang/scripting.d.ts +0 -7
  63. package/dist/lang/scripting.js +0 -216
  64. package/dist/lang/shell.d.ts +0 -7
  65. package/dist/lang/shell.js +0 -404
  66. package/dist/lang/specs_gen.d.ts +0 -66
  67. package/dist/lang/specs_gen.js +0 -381
  68. package/dist/lang/terminal.d.ts +0 -9
  69. package/dist/lang/terminal.js +0 -550
  70. package/dist/lang/yaml.d.ts +0 -4
  71. package/dist/lang/yaml.js +0 -176
  72. package/dist/theme/index.js +0 -1
  73. /package/dist/{theme/generated.js → generated/themes.js} +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "limn-hl",
3
- "version": "0.1.1",
4
- "description": "Fast, lightweight, zero-dependency, synchronous syntax highlighter",
3
+ "version": "0.2.1",
4
+ "description": "Fast, lightweight, zero-dependency, native multi-target syntax highlighter compiled from one shared grammar spec, with built-in language detection",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -26,16 +26,16 @@
26
26
  "default": "./dist/detect.js"
27
27
  },
28
28
  "./lang": {
29
- "types": "./dist/lang/index.d.ts",
30
- "default": "./dist/lang/index.js"
29
+ "types": "./dist/lang.d.ts",
30
+ "default": "./dist/lang.js"
31
31
  },
32
32
  "./render": {
33
33
  "types": "./dist/render/index.d.ts",
34
34
  "default": "./dist/render/index.js"
35
35
  },
36
36
  "./theme": {
37
- "types": "./dist/theme/index.d.ts",
38
- "default": "./dist/theme/index.js"
37
+ "types": "./dist/theme.d.ts",
38
+ "default": "./dist/theme.js"
39
39
  }
40
40
  },
41
41
  "files": [
@@ -1,15 +0,0 @@
1
- import type { Grammar } from "../engine.js";
2
- /** Returns the C grammar. */
3
- export declare const c: () => Grammar;
4
- /** Returns the C++ grammar. */
5
- export declare const cpp: () => Grammar;
6
- /** Returns the C# grammar. */
7
- export declare const cs: () => Grammar;
8
- /** Returns the GLSL shader grammar. */
9
- export declare const glsl: () => Grammar;
10
- /** Returns the Rust grammar. */
11
- export declare const rs: () => Grammar;
12
- /** Returns the Zig grammar. */
13
- export declare const zig: () => Grammar;
14
- /** Returns the PHP grammar. */
15
- export declare const php: () => Grammar;
@@ -1,35 +0,0 @@
1
- import {
2
- scanCPreprocessor,
3
- scanRustLifetimeOrChar,
4
- tryCPPRawString,
5
- tryPHPTag,
6
- tryRustCustom,
7
- tryRustString,
8
- tryZigCustom
9
- } from "./clike_helpers.js";
10
- import { buildCodeGrammar, onceGrammar } from "./code.js";
11
- import {
12
- specC,
13
- specCpp,
14
- specCs,
15
- specGlsl,
16
- specPhp,
17
- specRs,
18
- specZig
19
- } from "./specs_gen.js";
20
- function cPreprocessorHook(self) {
21
- return {
22
- leadBytes: "#",
23
- scan: (src, pos, lineStart, e) => lineStart ? scanCPreprocessor(src, pos, self(), e) : 0
24
- };
25
- }
26
- export const c = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specC, cPreprocessorHook(c)));
27
- export const cpp = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specCpp, cPreprocessorHook(cpp), {
28
- leadBytes: "R",
29
- scan: tryCPPRawString
30
- }));
31
- export const cs = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specCs, cPreprocessorHook(cs)));
32
- export const glsl = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specGlsl, cPreprocessorHook(glsl)));
33
- export const rs = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specRs, { leadBytes: "#", scan: tryRustCustom }, { leadBytes: "rbc", scan: tryRustString }, { leadBytes: "'", scan: scanRustLifetimeOrChar }));
34
- export const zig = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specZig, { leadBytes: "\\@", scan: tryZigCustom }));
35
- export const php = /* @__PURE__ */ onceGrammar(() => buildCodeGrammar(specPhp, { leadBytes: "<?", scan: tryPHPTag }));
@@ -1,8 +0,0 @@
1
- import type { Emitter, Grammar } from "../engine.js";
2
- export declare function scanCPreprocessor(src: string, pos: number, self: Grammar, e: Emitter): number;
3
- export declare function tryCPPRawString(src: string, pos: number, _ls: boolean, e: Emitter): number;
4
- export declare function tryRustString(src: string, pos: number, _ls: boolean, e: Emitter): number;
5
- export declare function scanRustLifetimeOrChar(src: string, pos: number, _ls: boolean, e: Emitter): number;
6
- export declare function tryRustCustom(src: string, pos: number, _ls: boolean, e: Emitter): number;
7
- export declare function tryZigCustom(src: string, pos: number, _ls: boolean, e: Emitter): number;
8
- export declare function tryPHPTag(src: string, pos: number, _ls: boolean, e: Emitter): number;
@@ -1,220 +0,0 @@
1
- import { Cursor, isIdentCont, isIdentStart, scanEscape } from "../cursor.js";
2
- import { TokenKind } from "../token.js";
3
- import { scanStringDelim } from "./code.js";
4
- export function scanCPreprocessor(src, pos, self, e) {
5
- const n = src.length;
6
- const nl = src.indexOf(`
7
- `, pos + 1);
8
- let end = nl >= 0 ? nl : n;
9
- while (end < n && end > pos && src.charCodeAt(end - 1) === 92) {
10
- const nextNL = src.indexOf(`
11
- `, end + 1);
12
- if (nextNL < 0) {
13
- end = n;
14
- break;
15
- }
16
- end = nextNL;
17
- }
18
- let cur = pos + 1;
19
- while (cur < end && (src.charCodeAt(cur) === 32 || src.charCodeAt(cur) === 9)) {
20
- cur++;
21
- }
22
- const kwStart = cur;
23
- while (cur < end && isIdentCont(src.charCodeAt(cur))) {
24
- cur++;
25
- }
26
- if (cur > kwStart) {
27
- e.emit(pos, cur, TokenKind.Keyword);
28
- if (src.slice(kwStart, cur) === "include") {
29
- let rest = cur;
30
- while (rest < end && (src.charCodeAt(rest) === 32 || src.charCodeAt(rest) === 9)) {
31
- rest++;
32
- }
33
- if (rest < end && src.charCodeAt(rest) === 60) {
34
- const closeIdx = src.indexOf(">", rest);
35
- if (closeIdx >= 0 && closeIdx < end) {
36
- e.emit(rest, closeIdx + 1, TokenKind.String);
37
- return end;
38
- }
39
- }
40
- }
41
- } else {
42
- e.emit(pos, pos + 1, TokenKind.Keyword);
43
- }
44
- if (cur < end) {
45
- e.embed(src, cur, end, self, TokenKind.Plain);
46
- }
47
- return end;
48
- }
49
- export function tryCPPRawString(src, pos, _ls, e) {
50
- const n = src.length;
51
- if (src.charCodeAt(pos) !== 82 || pos + 1 >= n || src.charCodeAt(pos + 1) !== 34) {
52
- return 0;
53
- }
54
- const paren = src.indexOf("(", pos + 2);
55
- if (paren < 0 || paren - (pos + 2) > 16) {
56
- return 0;
57
- }
58
- const delim = src.slice(pos + 2, paren);
59
- for (let i = 0;i < delim.length; i++) {
60
- const c = delim.charCodeAt(i);
61
- if (c === 32 || c === 9 || c === 10 || c === 13 || c === 92 || c === 41) {
62
- return 0;
63
- }
64
- }
65
- const closeSeq = ")" + delim + '"';
66
- const bodyStart = paren + 1;
67
- const idx = src.indexOf(closeSeq, bodyStart);
68
- if (idx >= 0) {
69
- const end = idx + closeSeq.length;
70
- e.emit(pos, end, TokenKind.String);
71
- return end;
72
- }
73
- e.emit(pos, n, TokenKind.String);
74
- return n;
75
- }
76
- export function tryRustString(src, pos, _ls, e) {
77
- const n = src.length;
78
- let p = pos;
79
- const ch = src.charCodeAt(p);
80
- if (ch === 98 || ch === 99) {
81
- p++;
82
- if (p < n && src.charCodeAt(p) === 114) {
83
- p++;
84
- }
85
- } else if (ch === 114) {
86
- p++;
87
- }
88
- if (p >= n) {
89
- return 0;
90
- }
91
- if (src.charCodeAt(pos) !== 114 && p === pos + 1 && src.charCodeAt(p) === 34) {
92
- return scanStringDelim(src, pos, p + 1, '"', true, false, true, e);
93
- }
94
- if (src.charCodeAt(p) === 34) {
95
- return scanStringDelim(src, pos, p + 1, '"', true, true, false, e);
96
- }
97
- if (src.charCodeAt(p) === 35) {
98
- let hashes = 0;
99
- while (p < n && src.charCodeAt(p) === 35) {
100
- hashes++;
101
- p++;
102
- }
103
- if (p < n && src.charCodeAt(p) === 34) {
104
- let i = p + 1;
105
- while (i < n) {
106
- const idx = src.indexOf('"', i);
107
- if (idx >= 0) {
108
- const qPos = idx + 1;
109
- if (qPos + hashes <= n) {
110
- let match = true;
111
- for (let k = 0;k < hashes; k++) {
112
- if (src.charCodeAt(qPos + k) !== 35) {
113
- match = false;
114
- break;
115
- }
116
- }
117
- if (match) {
118
- const end = qPos + hashes;
119
- e.emit(pos, end, TokenKind.String);
120
- return end;
121
- }
122
- }
123
- i = qPos;
124
- continue;
125
- }
126
- break;
127
- }
128
- e.emit(pos, n, TokenKind.String);
129
- return n;
130
- }
131
- }
132
- return 0;
133
- }
134
- export function scanRustLifetimeOrChar(src, pos, _ls, e) {
135
- const n = src.length;
136
- if (pos + 1 >= n) {
137
- e.emit(pos, n, TokenKind.Punctuation);
138
- return n;
139
- }
140
- const next = src.charCodeAt(pos + 1);
141
- if (next === 92) {
142
- const escEnd = scanEscape(src, pos + 1);
143
- if (escEnd < n && src.charCodeAt(escEnd) === 39) {
144
- const end = escEnd + 1;
145
- e.emit(pos, pos + 1, TokenKind.String);
146
- e.emit(pos + 1, escEnd, TokenKind.Escape);
147
- e.emit(escEnd, end, TokenKind.String);
148
- return end;
149
- }
150
- return scanStringDelim(src, pos, pos + 1, "'", false, false, true, e);
151
- }
152
- for (let k = 1;k <= 4 && pos + 1 + k < n; k++) {
153
- const c = src.charCodeAt(pos + 1 + k);
154
- if (c === 10)
155
- break;
156
- if (c === 39) {
157
- const end = pos + 2 + k;
158
- e.emit(pos, end, TokenKind.String);
159
- return end;
160
- }
161
- }
162
- if (isIdentStart(next)) {
163
- let end = pos + 2;
164
- while (end < n && isIdentCont(src.charCodeAt(end))) {
165
- end++;
166
- }
167
- e.emit(pos, end, src.slice(pos + 1, end) === "static" ? TokenKind.Keyword : TokenKind.Type);
168
- return end;
169
- }
170
- e.emit(pos, pos + 1, TokenKind.Punctuation);
171
- return pos + 1;
172
- }
173
- export function tryRustCustom(src, pos, _ls, e) {
174
- const n = src.length;
175
- if (src.charCodeAt(pos) === 35 && pos + 1 < n && (src.charCodeAt(pos + 1) === 91 || src.charCodeAt(pos + 1) === 33 && pos + 2 < n && src.charCodeAt(pos + 2) === 91)) {
176
- const cur = new Cursor(src, pos + 1);
177
- if (cur.peek() === 33) {
178
- cur.pos++;
179
- }
180
- cur.pos++;
181
- cur.scanBalanced(91, 93, true);
182
- e.emit(pos, cur.pos, TokenKind.Variable);
183
- return cur.pos;
184
- }
185
- return 0;
186
- }
187
- export function tryZigCustom(src, pos, _ls, e) {
188
- const n = src.length;
189
- if (src.charCodeAt(pos) === 92 && pos + 1 < n && src.charCodeAt(pos + 1) === 92) {
190
- const nl = src.indexOf(`
191
- `, pos + 2);
192
- const end = nl >= 0 ? nl : n;
193
- e.emit(pos, end, TokenKind.String);
194
- return end;
195
- }
196
- if (src.charCodeAt(pos) === 64 && pos + 1 < n && isIdentStart(src.charCodeAt(pos + 1))) {
197
- let end = pos + 2;
198
- while (end < n && isIdentCont(src.charCodeAt(end))) {
199
- end++;
200
- }
201
- e.emit(pos, end, TokenKind.Func);
202
- return end;
203
- }
204
- return 0;
205
- }
206
- export function tryPHPTag(src, pos, _ls, e) {
207
- if (src.startsWith("<?php", pos)) {
208
- e.emit(pos, pos + 5, TokenKind.Keyword);
209
- return pos + 5;
210
- }
211
- if (src.startsWith("<?=", pos)) {
212
- e.emit(pos, pos + 3, TokenKind.Keyword);
213
- return pos + 3;
214
- }
215
- if (src.startsWith("?>", pos)) {
216
- e.emit(pos, pos + 2, TokenKind.Keyword);
217
- return pos + 2;
218
- }
219
- return 0;
220
- }
@@ -1,45 +0,0 @@
1
- import { type Emitter, Grammar } from "../engine.js";
2
- import { TokenKind, type WordTable } from "../index.js";
3
- /** Creates a lazily initialized singleton getter for a Grammar. */
4
- export declare function onceGrammar(build: () => Grammar): () => Grammar;
5
- export type InterpolationKind = "dollarBrace" | "hashBrace" | "backslashParen";
6
- export interface StringInterpolation {
7
- readonly kind: InterpolationKind;
8
- readonly quotes: string;
9
- }
10
- export interface PrefixIdentSpec {
11
- readonly prefixes: string;
12
- readonly contExtra?: string;
13
- }
14
- export interface CustomHook {
15
- readonly leadBytes: string;
16
- readonly scan: (src: string, pos: number, lineStart: boolean, e: Emitter) => number;
17
- }
18
- export interface CodeConfig {
19
- readonly name: string;
20
- readonly aliases?: readonly string[];
21
- readonly keywords?: string;
22
- readonly types?: string;
23
- readonly constants?: string;
24
- readonly typeAfterKeywords?: string;
25
- readonly caseInsensitive?: boolean;
26
- readonly lineComments?: readonly string[];
27
- readonly blockComment?: readonly [string, string];
28
- readonly nestedBlockComments?: boolean;
29
- readonly quotes?: string;
30
- readonly multilineQuotes?: string;
31
- readonly rawQuotes?: string;
32
- readonly tripleQuotes?: boolean;
33
- readonly stringEscapes?: boolean;
34
- readonly interpolation?: StringInterpolation;
35
- readonly typeAfterArrow?: boolean;
36
- readonly bangMacros?: boolean;
37
- readonly identStartExtra?: string;
38
- readonly identContExtra?: string;
39
- readonly prefixIdent?: PrefixIdentSpec;
40
- }
41
- export declare function buildWordTable(keywords: string, types: string, constants: string, caseInsensitive: boolean): WordTable;
42
- export declare function scanStringDelim(src: string, start: number, bodyPos: number, closeDelim: string, multiline: boolean, raw: boolean, escapes: boolean, e: Emitter): number;
43
- export declare function tryPrefixIdent(src: string, pos: number, extra: Uint8Array | undefined, kind: TokenKind, e: Emitter): number;
44
- /** Builds an immutable Grammar from a declarative CodeConfig and optional custom hooks. */
45
- export declare function buildCodeGrammar(cfg: CodeConfig, ...hooks: readonly CustomHook[]): Grammar;