@tabnas/parser 0.2.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/LICENSE +20 -0
- package/README.md +75 -0
- package/dist/builtins.d.ts +4 -0
- package/dist/builtins.js +202 -0
- package/dist/builtins.js.map +1 -0
- package/dist/context.d.ts +64 -0
- package/dist/context.js +138 -0
- package/dist/context.js.map +1 -0
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.js +301 -0
- package/dist/defaults.js.map +1 -0
- package/dist/error.d.ts +51 -0
- package/dist/error.js +362 -0
- package/dist/error.js.map +1 -0
- package/dist/lexer.d.ts +85 -0
- package/dist/lexer.js +1202 -0
- package/dist/lexer.js.map +1 -0
- package/dist/parser.d.ts +15 -0
- package/dist/parser.js +141 -0
- package/dist/parser.js.map +1 -0
- package/dist/rules.d.ts +100 -0
- package/dist/rules.js +923 -0
- package/dist/rules.js.map +1 -0
- package/dist/tabnas.d.ts +103 -0
- package/dist/tabnas.js +387 -0
- package/dist/tabnas.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +527 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/dist/utility.d.ts +80 -0
- package/dist/utility.js +868 -0
- package/dist/utility.js.map +1 -0
- package/package.json +59 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
export declare const OPEN: RuleState;
|
|
2
|
+
export declare const CLOSE: RuleState;
|
|
3
|
+
export declare const BEFORE: RuleStep;
|
|
4
|
+
export declare const AFTER: RuleStep;
|
|
5
|
+
export declare const EMPTY = "";
|
|
6
|
+
export declare const INSPECT: unique symbol;
|
|
7
|
+
export declare const SKIP: unique symbol;
|
|
8
|
+
export declare const STRING = "string";
|
|
9
|
+
export type TabnasParse = (src: any, meta?: any, parent_ctx?: any) => any;
|
|
10
|
+
export type GrammarSetting = {
|
|
11
|
+
rule?: {
|
|
12
|
+
alt?: {
|
|
13
|
+
g?: string | string[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type TabnasInternal = {
|
|
18
|
+
parser: Parser;
|
|
19
|
+
config: Config;
|
|
20
|
+
plugins: Plugin[];
|
|
21
|
+
sub: {
|
|
22
|
+
lex?: LexSub[];
|
|
23
|
+
rule?: RuleSub[];
|
|
24
|
+
};
|
|
25
|
+
mark: number;
|
|
26
|
+
merged: Record<string, any>;
|
|
27
|
+
};
|
|
28
|
+
import type { Tabnas } from './tabnas';
|
|
29
|
+
export type { Tabnas };
|
|
30
|
+
export type Plugin = ((tabnas: Tabnas, // Instance to extend.
|
|
31
|
+
plugin_options?: any) => void | Tabnas) & {
|
|
32
|
+
defaults?: Record<string, any>;
|
|
33
|
+
options?: Record<string, any>;
|
|
34
|
+
};
|
|
35
|
+
export type TabnasOptions = {
|
|
36
|
+
plugins?: Plugin[];
|
|
37
|
+
safe?: {
|
|
38
|
+
key: boolean;
|
|
39
|
+
};
|
|
40
|
+
tag?: string;
|
|
41
|
+
fixed?: {
|
|
42
|
+
lex?: boolean;
|
|
43
|
+
token?: StrMap;
|
|
44
|
+
check?: LexCheck;
|
|
45
|
+
};
|
|
46
|
+
match?: {
|
|
47
|
+
lex?: boolean;
|
|
48
|
+
token?: {
|
|
49
|
+
[name: string]: RegExp | LexMatcher;
|
|
50
|
+
};
|
|
51
|
+
value?: {
|
|
52
|
+
[name: string]: {
|
|
53
|
+
match: RegExp | LexMatcher;
|
|
54
|
+
val?: any;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
check?: LexCheck;
|
|
58
|
+
};
|
|
59
|
+
tokenSet?: {
|
|
60
|
+
[name: string]: string[];
|
|
61
|
+
};
|
|
62
|
+
space?: {
|
|
63
|
+
lex?: boolean;
|
|
64
|
+
chars?: string;
|
|
65
|
+
check?: LexCheck;
|
|
66
|
+
};
|
|
67
|
+
line?: {
|
|
68
|
+
lex?: boolean;
|
|
69
|
+
chars?: string;
|
|
70
|
+
rowChars?: string;
|
|
71
|
+
single?: boolean;
|
|
72
|
+
check?: LexCheck;
|
|
73
|
+
};
|
|
74
|
+
text?: {
|
|
75
|
+
lex?: boolean;
|
|
76
|
+
modify?: ValModifier | ValModifier[];
|
|
77
|
+
check?: LexCheck;
|
|
78
|
+
};
|
|
79
|
+
number?: {
|
|
80
|
+
lex?: boolean;
|
|
81
|
+
hex?: boolean;
|
|
82
|
+
oct?: boolean;
|
|
83
|
+
bin?: boolean;
|
|
84
|
+
sep?: string | null;
|
|
85
|
+
exclude?: RegExp;
|
|
86
|
+
check?: LexCheck;
|
|
87
|
+
};
|
|
88
|
+
comment?: {
|
|
89
|
+
lex?: boolean;
|
|
90
|
+
def?: {
|
|
91
|
+
[name: string]: {
|
|
92
|
+
line?: boolean;
|
|
93
|
+
start?: string;
|
|
94
|
+
end?: string;
|
|
95
|
+
lex?: boolean;
|
|
96
|
+
suffix?: string | string[] | LexMatcher;
|
|
97
|
+
eatline: boolean;
|
|
98
|
+
} | null | undefined | false;
|
|
99
|
+
};
|
|
100
|
+
check?: LexCheck;
|
|
101
|
+
};
|
|
102
|
+
string?: {
|
|
103
|
+
lex?: boolean;
|
|
104
|
+
chars?: string;
|
|
105
|
+
multiChars?: string;
|
|
106
|
+
escapeChar?: string;
|
|
107
|
+
escape?: {
|
|
108
|
+
[char: string]: string | null;
|
|
109
|
+
};
|
|
110
|
+
allowUnknown?: boolean;
|
|
111
|
+
escapeStrict?: boolean;
|
|
112
|
+
replace?: {
|
|
113
|
+
[char: string]: string | null;
|
|
114
|
+
};
|
|
115
|
+
abandon?: boolean;
|
|
116
|
+
check?: LexCheck;
|
|
117
|
+
};
|
|
118
|
+
map?: {
|
|
119
|
+
extend?: boolean;
|
|
120
|
+
merge?: (prev: any, curr: any) => any;
|
|
121
|
+
child?: boolean;
|
|
122
|
+
};
|
|
123
|
+
list?: {
|
|
124
|
+
property: boolean;
|
|
125
|
+
pair: boolean;
|
|
126
|
+
child: boolean;
|
|
127
|
+
};
|
|
128
|
+
info?: {
|
|
129
|
+
map?: boolean;
|
|
130
|
+
list?: boolean;
|
|
131
|
+
text?: boolean;
|
|
132
|
+
marker?: string;
|
|
133
|
+
};
|
|
134
|
+
value?: {
|
|
135
|
+
lex?: boolean;
|
|
136
|
+
def?: {
|
|
137
|
+
[src: string]: undefined | null | false | {
|
|
138
|
+
val: any;
|
|
139
|
+
match?: RegExp;
|
|
140
|
+
consume?: boolean;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
ender?: string | string[];
|
|
145
|
+
plugin?: Record<string, any>;
|
|
146
|
+
debug?: {
|
|
147
|
+
get_console?: () => any;
|
|
148
|
+
maxlen?: number;
|
|
149
|
+
print?: {
|
|
150
|
+
config?: boolean;
|
|
151
|
+
src?: (x: any) => string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
error?: {
|
|
155
|
+
[code: string]: string;
|
|
156
|
+
};
|
|
157
|
+
errmsg?: {
|
|
158
|
+
name?: string;
|
|
159
|
+
suffix?: boolean | string | ((color?: any, spec?: any) => string);
|
|
160
|
+
link?: string;
|
|
161
|
+
};
|
|
162
|
+
hint?: any;
|
|
163
|
+
lex?: {
|
|
164
|
+
empty?: boolean;
|
|
165
|
+
emptyResult?: any;
|
|
166
|
+
match: {
|
|
167
|
+
[name: string]: {
|
|
168
|
+
order: number;
|
|
169
|
+
make: MakeLexMatcher;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
parse?: {
|
|
174
|
+
prepare?: {
|
|
175
|
+
[name: string]: ParsePrepare;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
rule?: {
|
|
179
|
+
start?: string;
|
|
180
|
+
finish?: boolean;
|
|
181
|
+
maxmul?: number;
|
|
182
|
+
include?: string;
|
|
183
|
+
exclude?: string;
|
|
184
|
+
};
|
|
185
|
+
result?: {
|
|
186
|
+
fail: any[];
|
|
187
|
+
};
|
|
188
|
+
rewind?: {
|
|
189
|
+
history?: number;
|
|
190
|
+
};
|
|
191
|
+
config?: {
|
|
192
|
+
modify?: {
|
|
193
|
+
[plugin_name: string]: (config: Config, options: TabnasOptions) => void;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
parser?: {
|
|
197
|
+
start?: (// Custom parse entry point.
|
|
198
|
+
lexer: any, src: string, tabnas: Tabnas, meta?: any, parent_ctx?: any) => any;
|
|
199
|
+
};
|
|
200
|
+
standard$?: boolean;
|
|
201
|
+
defaults$?: boolean;
|
|
202
|
+
grammar$?: boolean;
|
|
203
|
+
color?: {
|
|
204
|
+
active?: boolean;
|
|
205
|
+
reset?: string;
|
|
206
|
+
hi?: string;
|
|
207
|
+
lo?: string;
|
|
208
|
+
line?: string;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
import type { Rule, RuleSpec } from './rules';
|
|
212
|
+
export type { Rule, RuleSpec };
|
|
213
|
+
import type { Context } from './context';
|
|
214
|
+
export type { Context };
|
|
215
|
+
import type { Lex } from './lexer';
|
|
216
|
+
export type { Lex };
|
|
217
|
+
export type NextToken = (rule: Rule) => Token;
|
|
218
|
+
export type Config = {
|
|
219
|
+
safe: {
|
|
220
|
+
key: boolean;
|
|
221
|
+
};
|
|
222
|
+
lex: {
|
|
223
|
+
match: LexMatcher[];
|
|
224
|
+
empty: boolean;
|
|
225
|
+
emptyResult: any;
|
|
226
|
+
};
|
|
227
|
+
parse: {
|
|
228
|
+
prepare: ParsePrepare[];
|
|
229
|
+
};
|
|
230
|
+
rule: {
|
|
231
|
+
start: string;
|
|
232
|
+
maxmul: number;
|
|
233
|
+
finish: boolean;
|
|
234
|
+
include: string[];
|
|
235
|
+
exclude: string[];
|
|
236
|
+
};
|
|
237
|
+
fixed: {
|
|
238
|
+
lex: boolean;
|
|
239
|
+
token: TokenMap;
|
|
240
|
+
ref: Record<string | Tin, Tin | string>;
|
|
241
|
+
check?: LexCheck;
|
|
242
|
+
};
|
|
243
|
+
match: {
|
|
244
|
+
lex: boolean;
|
|
245
|
+
value: {
|
|
246
|
+
[name: string]: {
|
|
247
|
+
match: RegExp | LexMatcher;
|
|
248
|
+
val?: any;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
token: MatchMap;
|
|
252
|
+
check?: LexCheck;
|
|
253
|
+
};
|
|
254
|
+
tokenSet: TokenSetMap;
|
|
255
|
+
tokenSetTins: {
|
|
256
|
+
[name: string]: {
|
|
257
|
+
[tin: number]: boolean;
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
space: {
|
|
261
|
+
lex: boolean;
|
|
262
|
+
chars: Chars;
|
|
263
|
+
charsBitmap: Uint8Array;
|
|
264
|
+
check?: LexCheck;
|
|
265
|
+
};
|
|
266
|
+
line: {
|
|
267
|
+
lex: boolean;
|
|
268
|
+
chars: Chars;
|
|
269
|
+
charsBitmap: Uint8Array;
|
|
270
|
+
rowChars: Chars;
|
|
271
|
+
rowCharsBitmap: Uint8Array;
|
|
272
|
+
single: boolean;
|
|
273
|
+
check?: LexCheck;
|
|
274
|
+
};
|
|
275
|
+
text: {
|
|
276
|
+
lex: boolean;
|
|
277
|
+
modify: ValModifier[];
|
|
278
|
+
check?: LexCheck;
|
|
279
|
+
};
|
|
280
|
+
number: {
|
|
281
|
+
lex: boolean;
|
|
282
|
+
hex: boolean;
|
|
283
|
+
oct: boolean;
|
|
284
|
+
bin: boolean;
|
|
285
|
+
sep: boolean;
|
|
286
|
+
exclude?: RegExp;
|
|
287
|
+
sepChar?: string | null;
|
|
288
|
+
check?: LexCheck;
|
|
289
|
+
};
|
|
290
|
+
string: {
|
|
291
|
+
lex: boolean;
|
|
292
|
+
quoteMap: Chars;
|
|
293
|
+
quoteBitmap: Uint8Array;
|
|
294
|
+
escMap: Record<string, any>;
|
|
295
|
+
escBitmap: Uint8Array;
|
|
296
|
+
escChar?: string;
|
|
297
|
+
escCharCode?: number;
|
|
298
|
+
multiChars: Chars;
|
|
299
|
+
multiBitmap: Uint8Array;
|
|
300
|
+
allowUnknown: boolean;
|
|
301
|
+
escapeStrict: boolean;
|
|
302
|
+
replaceCodeMap: {
|
|
303
|
+
[charCode: number]: string;
|
|
304
|
+
};
|
|
305
|
+
hasReplace: boolean;
|
|
306
|
+
abandon: boolean;
|
|
307
|
+
check?: LexCheck;
|
|
308
|
+
};
|
|
309
|
+
value: {
|
|
310
|
+
lex: boolean;
|
|
311
|
+
def: {
|
|
312
|
+
[src: string]: {
|
|
313
|
+
val: any;
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
defre: {
|
|
317
|
+
name: string;
|
|
318
|
+
val: (res: any) => any;
|
|
319
|
+
match: RegExp;
|
|
320
|
+
consume: boolean;
|
|
321
|
+
}[];
|
|
322
|
+
};
|
|
323
|
+
comment: {
|
|
324
|
+
lex: boolean;
|
|
325
|
+
def: {
|
|
326
|
+
[name: string]: {
|
|
327
|
+
name: string;
|
|
328
|
+
line: boolean;
|
|
329
|
+
start: string;
|
|
330
|
+
end?: string;
|
|
331
|
+
lex: boolean;
|
|
332
|
+
eatline: boolean;
|
|
333
|
+
suffixes?: string[];
|
|
334
|
+
suffixFn?: LexMatcher;
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
check?: LexCheck;
|
|
338
|
+
};
|
|
339
|
+
map: {
|
|
340
|
+
extend: boolean;
|
|
341
|
+
merge?: (prev: any, curr: any, rule: Rule, ctx: Context) => any;
|
|
342
|
+
child: boolean;
|
|
343
|
+
};
|
|
344
|
+
list: {
|
|
345
|
+
property: boolean;
|
|
346
|
+
pair: boolean;
|
|
347
|
+
child: boolean;
|
|
348
|
+
};
|
|
349
|
+
info: {
|
|
350
|
+
map: boolean;
|
|
351
|
+
list: boolean;
|
|
352
|
+
text: boolean;
|
|
353
|
+
marker: string;
|
|
354
|
+
};
|
|
355
|
+
debug: {
|
|
356
|
+
get_console: () => any;
|
|
357
|
+
maxlen: number;
|
|
358
|
+
print: {
|
|
359
|
+
config: boolean;
|
|
360
|
+
src?: (x: any) => string;
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
result: {
|
|
364
|
+
fail: any[];
|
|
365
|
+
};
|
|
366
|
+
rewind: {
|
|
367
|
+
history: number;
|
|
368
|
+
};
|
|
369
|
+
error: {
|
|
370
|
+
[code: string]: string;
|
|
371
|
+
};
|
|
372
|
+
errmsg: {
|
|
373
|
+
name: string;
|
|
374
|
+
suffix: boolean | string | ((color?: any, spec?: any) => string);
|
|
375
|
+
link?: string;
|
|
376
|
+
};
|
|
377
|
+
hint: any;
|
|
378
|
+
rePart: any;
|
|
379
|
+
re: any;
|
|
380
|
+
tI: number;
|
|
381
|
+
t: Record<string, Tin>;
|
|
382
|
+
color: {
|
|
383
|
+
active: boolean;
|
|
384
|
+
reset: string;
|
|
385
|
+
hi: string;
|
|
386
|
+
lo: string;
|
|
387
|
+
line: string;
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
import type { Point, Token } from './lexer';
|
|
391
|
+
export type { Point, Token };
|
|
392
|
+
export interface AltSpec {
|
|
393
|
+
s?: (Tin | Tin[] | null | undefined | string)[] | null | string;
|
|
394
|
+
p?: string | AltNext | null | false | FuncRef;
|
|
395
|
+
r?: string | AltNext | null | false | FuncRef;
|
|
396
|
+
b?: number | AltBack | null | false | FuncRef;
|
|
397
|
+
c?: AltCond | null;
|
|
398
|
+
n?: Counters;
|
|
399
|
+
a?: AltAction | FuncRef | (AltAction | FuncRef)[] | null;
|
|
400
|
+
h?: AltModifier | null;
|
|
401
|
+
u?: Record<string, any>;
|
|
402
|
+
k?: Record<string, any>;
|
|
403
|
+
g?: string | string[];
|
|
404
|
+
e?: AltError | FuncRef | null;
|
|
405
|
+
}
|
|
406
|
+
export type AltSpecish = AltSpec | undefined | null | false | 0 | typeof NaN;
|
|
407
|
+
export type ListMods = {
|
|
408
|
+
append?: boolean;
|
|
409
|
+
clear?: boolean;
|
|
410
|
+
move?: number[];
|
|
411
|
+
delete?: number[];
|
|
412
|
+
custom?: (alts: AltSpec[]) => null | AltSpec[];
|
|
413
|
+
};
|
|
414
|
+
import type { AltMatch } from './rules';
|
|
415
|
+
export type { AltMatch };
|
|
416
|
+
export type FuncRef = `@${string}`;
|
|
417
|
+
export type FuncRefMap<FT> = Record<FuncRef, FT>;
|
|
418
|
+
export type Counters = {
|
|
419
|
+
[key: string]: number;
|
|
420
|
+
};
|
|
421
|
+
export type Tin = number & {
|
|
422
|
+
readonly __brand: 'Tin';
|
|
423
|
+
};
|
|
424
|
+
export declare const asTin: (n: number) => Tin;
|
|
425
|
+
export type TokenMap = {
|
|
426
|
+
[name: string]: Tin;
|
|
427
|
+
};
|
|
428
|
+
export type TokenSetMap = {
|
|
429
|
+
[name: string]: Tin[];
|
|
430
|
+
};
|
|
431
|
+
export type TinMap = {
|
|
432
|
+
[ref: number]: string;
|
|
433
|
+
};
|
|
434
|
+
export type TinSetMap = {
|
|
435
|
+
[ref: number]: string;
|
|
436
|
+
};
|
|
437
|
+
export type MatchMap = {
|
|
438
|
+
[name: string]: RegExp | LexMatcher;
|
|
439
|
+
};
|
|
440
|
+
export type Chars = {
|
|
441
|
+
[char: string]: number;
|
|
442
|
+
};
|
|
443
|
+
export type StrMap = {
|
|
444
|
+
[name: string]: string;
|
|
445
|
+
};
|
|
446
|
+
export type RuleState = 'o' | 'c';
|
|
447
|
+
export type RuleStep = 'b' | 'a';
|
|
448
|
+
export type LexMatcher = (lex: Lex, rule: Rule, tI?: number) => Token | undefined;
|
|
449
|
+
export type MakeLexMatcher = (cfg: Config, opts: TabnasOptions) => LexMatcher | null | undefined | false;
|
|
450
|
+
export type LexCheck = (lex: Lex) => void | undefined | {
|
|
451
|
+
done: boolean;
|
|
452
|
+
token: Token | undefined;
|
|
453
|
+
};
|
|
454
|
+
export type ParsePrepare = (tabnas: Tabnas, ctx: Context, meta?: any) => void;
|
|
455
|
+
export type RuleSpecMap = {
|
|
456
|
+
[name: string]: RuleSpec;
|
|
457
|
+
};
|
|
458
|
+
export type RuleDefiner = (rs: RuleSpec, p: Parser) => void | RuleSpec;
|
|
459
|
+
export interface NormAltSpec extends AltSpec {
|
|
460
|
+
s: (Tin | Tin[] | null | undefined)[];
|
|
461
|
+
p: string | AltNext | null | false;
|
|
462
|
+
r: string | AltNext | null | false;
|
|
463
|
+
b: number | AltBack | null | false;
|
|
464
|
+
S: (number[] | null)[] | null;
|
|
465
|
+
t: Tin[][];
|
|
466
|
+
sN: number;
|
|
467
|
+
c: NormAltCond | null | undefined;
|
|
468
|
+
g: string[];
|
|
469
|
+
a: AltAction | null | undefined;
|
|
470
|
+
e: AltError | null | undefined;
|
|
471
|
+
}
|
|
472
|
+
export type AltCond = ((rule: Rule, ctx: Context, alt: AltMatch) => boolean) | Record<string, any>;
|
|
473
|
+
export type NormAltCond = ((rule: Rule, ctx: Context, alt: AltMatch) => boolean);
|
|
474
|
+
export type AltModifier = (rule: Rule, ctx: Context, alt: AltMatch, next: Rule) => AltMatch;
|
|
475
|
+
export type AltAction = (rule: Rule, ctx: Context, alt: AltMatch) => any;
|
|
476
|
+
export type EagerRegExp = RegExp & {
|
|
477
|
+
tin$?: number;
|
|
478
|
+
eager$?: boolean;
|
|
479
|
+
};
|
|
480
|
+
export type AltNext = (rule: Rule, ctx: Context, alt: AltMatch) => string | null | false | 0;
|
|
481
|
+
export type AltBack = (rule: Rule, ctx: Context, alt: AltMatch) => number | null | false;
|
|
482
|
+
export type StateAction = (rule: Rule, ctx: Context, next: Rule, out?: Token | void) => Token | void;
|
|
483
|
+
export type AltError = (rule: Rule, ctx: Context, alt: AltMatch) => Token | undefined;
|
|
484
|
+
export type ValModifier = (val: any, lex: Lex, cfg: Config, opts: TabnasOptions) => string;
|
|
485
|
+
export type LexSub = (tkn: Token, rule: Rule, ctx: Context) => void;
|
|
486
|
+
export type RuleSub = (rule: Rule, ctx: Context) => void;
|
|
487
|
+
import type { Parser } from './parser';
|
|
488
|
+
export type { Parser };
|
|
489
|
+
export type GrammarSpec = {
|
|
490
|
+
ref?: Record<FuncRef, Function>;
|
|
491
|
+
v?: number;
|
|
492
|
+
options?: Record<string, any>;
|
|
493
|
+
rule?: Record<string, {
|
|
494
|
+
open?: GrammarAltSpec[] | // OPEN-state alternates (or alts + inject ops).
|
|
495
|
+
{
|
|
496
|
+
alts: GrammarAltSpec[];
|
|
497
|
+
inject: {
|
|
498
|
+
append?: boolean;
|
|
499
|
+
delete?: number[];
|
|
500
|
+
move?: number[];
|
|
501
|
+
};
|
|
502
|
+
};
|
|
503
|
+
close?: GrammarAltSpec[] | // CLOSE-state alternates (or alts + inject ops).
|
|
504
|
+
{
|
|
505
|
+
alts: GrammarAltSpec[];
|
|
506
|
+
inject: {
|
|
507
|
+
append?: boolean;
|
|
508
|
+
delete?: number[];
|
|
509
|
+
move?: number[];
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
}>;
|
|
513
|
+
};
|
|
514
|
+
export type GrammarAltSpec = {
|
|
515
|
+
s?: string | string[];
|
|
516
|
+
b?: FuncRef | number;
|
|
517
|
+
p?: FuncRef | string;
|
|
518
|
+
r?: FuncRef | string;
|
|
519
|
+
a?: FuncRef | FuncRef[];
|
|
520
|
+
e?: FuncRef;
|
|
521
|
+
h?: FuncRef;
|
|
522
|
+
c?: FuncRef | Record<string, any>;
|
|
523
|
+
n?: Record<string, number>;
|
|
524
|
+
u?: Record<string, any>;
|
|
525
|
+
k?: Record<string, any>;
|
|
526
|
+
g?: string | string[];
|
|
527
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2013-2026 Richard Rodger, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.asTin = exports.STRING = exports.SKIP = exports.INSPECT = exports.EMPTY = exports.AFTER = exports.BEFORE = exports.CLOSE = exports.OPEN = void 0;
|
|
5
|
+
/* types.ts
|
|
6
|
+
* Type and constant definitions.
|
|
7
|
+
*/
|
|
8
|
+
exports.OPEN = 'o';
|
|
9
|
+
exports.CLOSE = 'c';
|
|
10
|
+
exports.BEFORE = 'b';
|
|
11
|
+
exports.AFTER = 'a';
|
|
12
|
+
exports.EMPTY = '';
|
|
13
|
+
exports.INSPECT = Symbol.for('nodejs.util.inspect.custom');
|
|
14
|
+
// Sentinel value that acts as `undefined` in deep merge — the base value
|
|
15
|
+
// is preserved. Represented as "@SKIP" in grammar options.
|
|
16
|
+
exports.SKIP = Symbol.for('tabnas.SKIP');
|
|
17
|
+
// Empty rule used as a no-value placeholder.
|
|
18
|
+
// export const NONE = ({ name: 'none', state: OPEN } as Rule)
|
|
19
|
+
exports.STRING = 'string';
|
|
20
|
+
// Convenience cast for the few code paths that legitimately need to
|
|
21
|
+
// construct a Tin from a raw counter (tokenize, the test scaffold).
|
|
22
|
+
const asTin = (n) => n;
|
|
23
|
+
exports.asTin = asTin;
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAEzD;;GAEG;AAEU,QAAA,IAAI,GAAc,GAAG,CAAA;AACrB,QAAA,KAAK,GAAc,GAAG,CAAA;AACtB,QAAA,MAAM,GAAa,GAAG,CAAA;AACtB,QAAA,KAAK,GAAa,GAAG,CAAA;AACrB,QAAA,KAAK,GAAG,EAAE,CAAA;AACV,QAAA,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D,yEAAyE;AACzE,4DAA4D;AAC/C,QAAA,IAAI,GAAkB,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;AAE5D,6CAA6C;AAC7C,8DAA8D;AAEjD,QAAA,MAAM,GAAG,QAAQ,CAAA;AAsiB9B,oEAAoE;AACpE,oEAAoE;AAC7D,MAAM,KAAK,GAAG,CAAC,CAAS,EAAO,EAAE,CAAC,CAAQ,CAAA;AAApC,QAAA,KAAK,SAA+B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Tabnas, TabnasOptions, Chars, Config, Context, Lex, RuleSpec, Tin, ListMods } from './types';
|
|
2
|
+
declare const keys: (x: any) => string[];
|
|
3
|
+
declare const values: <T>(x: {
|
|
4
|
+
[key: string]: T;
|
|
5
|
+
} | undefined | null) => T[];
|
|
6
|
+
declare const entries: <T>(x: {
|
|
7
|
+
[key: string]: T;
|
|
8
|
+
} | undefined | null) => [string, T][];
|
|
9
|
+
declare const assign: (x: any, ...r: any[]) => any;
|
|
10
|
+
declare const isarr: (x: any) => x is any[];
|
|
11
|
+
declare const defprop: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
|
|
12
|
+
declare const omap: (o: any, f?: (e: any) => any) => any;
|
|
13
|
+
declare const S: {
|
|
14
|
+
indent: string;
|
|
15
|
+
logindent: string;
|
|
16
|
+
space: string;
|
|
17
|
+
gap: string;
|
|
18
|
+
Object: string;
|
|
19
|
+
Array: string;
|
|
20
|
+
object: string;
|
|
21
|
+
string: string;
|
|
22
|
+
function: string;
|
|
23
|
+
unexpected: string;
|
|
24
|
+
map: string;
|
|
25
|
+
list: string;
|
|
26
|
+
elem: string;
|
|
27
|
+
pair: string;
|
|
28
|
+
val: string;
|
|
29
|
+
node: string;
|
|
30
|
+
no_re_flags: string;
|
|
31
|
+
unprintable: string;
|
|
32
|
+
invalid_ascii: string;
|
|
33
|
+
invalid_unicode: string;
|
|
34
|
+
invalid_lex_state: string;
|
|
35
|
+
unterminated_string: string;
|
|
36
|
+
unterminated_comment: string;
|
|
37
|
+
lex: string;
|
|
38
|
+
parse: string;
|
|
39
|
+
error: string;
|
|
40
|
+
none: string;
|
|
41
|
+
imp_map: string;
|
|
42
|
+
imp_list: string;
|
|
43
|
+
imp_null: string;
|
|
44
|
+
end: string;
|
|
45
|
+
open: string;
|
|
46
|
+
close: string;
|
|
47
|
+
rule: string;
|
|
48
|
+
stack: string;
|
|
49
|
+
nUll: string;
|
|
50
|
+
name: string;
|
|
51
|
+
make: string;
|
|
52
|
+
colon: string;
|
|
53
|
+
step: string;
|
|
54
|
+
};
|
|
55
|
+
declare function configure(tabnas: Tabnas, incfg: Config | undefined, opts: TabnasOptions): Config;
|
|
56
|
+
declare function tokenize<R extends string | Tin, T extends R extends Tin ? string : Tin>(ref: R, cfg: Config, tabnas?: any): T;
|
|
57
|
+
declare function findTokenSet<R extends string | Tin, T extends R extends Tin ? string : Tin>(ref: R, cfg: Config): T;
|
|
58
|
+
declare function mesc(s: string, _?: any): any;
|
|
59
|
+
declare function regexp(flags: string | null, ...parts: (string | (String & {
|
|
60
|
+
esc?: boolean;
|
|
61
|
+
}))[]): RegExp;
|
|
62
|
+
declare function escre(s: string | undefined): string;
|
|
63
|
+
declare function deep(base?: any, ...rest: any): any;
|
|
64
|
+
declare function badlex(lex: Lex, BD: Tin, ctx: Context): Lex;
|
|
65
|
+
declare function makelog(ctx: Context, meta: any): ((...rest: any) => void) | undefined;
|
|
66
|
+
declare function srcfmt(config: Config): (s: any) => string;
|
|
67
|
+
declare function str(o: any, len?: number): string;
|
|
68
|
+
declare function snip(s: any, len?: number): string;
|
|
69
|
+
declare function clone(class_instance: any): any;
|
|
70
|
+
declare function charset(...parts: (string | object | boolean | undefined)[]): Chars;
|
|
71
|
+
declare function charsBitmap(...parts: (string | object | boolean | undefined)[]): Uint8Array;
|
|
72
|
+
declare function clean<T>(o: T): T;
|
|
73
|
+
declare function filterRules(rs: RuleSpec, cfg: Config): RuleSpec;
|
|
74
|
+
declare function modlist(list: any[], mods?: ListMods): any[];
|
|
75
|
+
declare function parserwrap(parser: any): {
|
|
76
|
+
start: (src: string, tabnas: Tabnas, meta?: any, parent_ctx?: any) => any;
|
|
77
|
+
};
|
|
78
|
+
declare function getpath(root: any, path: string | string[]): any;
|
|
79
|
+
declare function resolveFuncRefs(obj: any, ref?: Record<string, Function>): any;
|
|
80
|
+
export { S, assign, badlex, charset, charsBitmap, clean, clone, configure, deep, defprop, entries, escre, filterRules, getpath, isarr, makelog, mesc, regexp, snip, srcfmt, tokenize, parserwrap, str, omap, keys, values, findTokenSet, modlist, resolveFuncRefs, };
|