@samuelbines/nunjucks 0.0.3

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 (66) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +55 -0
  3. package/dist/scripts/smoke.d.ts +1 -0
  4. package/dist/scripts/smoke.js +95 -0
  5. package/dist/src/compiler.d.ts +12 -0
  6. package/dist/src/compiler.js +1050 -0
  7. package/dist/src/environment.d.ts +103 -0
  8. package/dist/src/environment.js +621 -0
  9. package/dist/src/express-app.d.ts +2 -0
  10. package/dist/src/express-app.js +33 -0
  11. package/dist/src/filters.d.ts +44 -0
  12. package/dist/src/filters.js +424 -0
  13. package/dist/src/globals.d.ts +14 -0
  14. package/dist/src/globals.js +342 -0
  15. package/dist/src/index.d.ts +28 -0
  16. package/dist/src/index.js +116 -0
  17. package/dist/src/interpreter.d.ts +16 -0
  18. package/dist/src/interpreter.js +489 -0
  19. package/dist/src/lexer.d.ts +72 -0
  20. package/dist/src/lexer.js +480 -0
  21. package/dist/src/lib.d.ts +74 -0
  22. package/dist/src/lib.js +237 -0
  23. package/dist/src/loader.d.ts +80 -0
  24. package/dist/src/loader.js +175 -0
  25. package/dist/src/nodes.d.ts +362 -0
  26. package/dist/src/nodes.js +894 -0
  27. package/dist/src/parser.d.ts +66 -0
  28. package/dist/src/parser.js +1068 -0
  29. package/dist/src/precompile.d.ts +15 -0
  30. package/dist/src/precompile.js +108 -0
  31. package/dist/src/runtime.d.ts +33 -0
  32. package/dist/src/runtime.js +314 -0
  33. package/dist/src/transformer.d.ts +3 -0
  34. package/dist/src/transformer.js +161 -0
  35. package/dist/src/types.d.ts +27 -0
  36. package/dist/src/types.js +2 -0
  37. package/dist/tests/compiler.test.d.ts +1 -0
  38. package/dist/tests/compiler.test.js +201 -0
  39. package/dist/tests/enviornment.test.d.ts +1 -0
  40. package/dist/tests/enviornment.test.js +279 -0
  41. package/dist/tests/express.test.d.ts +1 -0
  42. package/dist/tests/express.test.js +86 -0
  43. package/dist/tests/filters.test.d.ts +13 -0
  44. package/dist/tests/filters.test.js +286 -0
  45. package/dist/tests/globals.test.d.ts +1 -0
  46. package/dist/tests/globals.test.js +579 -0
  47. package/dist/tests/interpreter.test.d.ts +1 -0
  48. package/dist/tests/interpreter.test.js +208 -0
  49. package/dist/tests/lexer.test.d.ts +1 -0
  50. package/dist/tests/lexer.test.js +249 -0
  51. package/dist/tests/lib.test.d.ts +1 -0
  52. package/dist/tests/lib.test.js +236 -0
  53. package/dist/tests/loader.test.d.ts +1 -0
  54. package/dist/tests/loader.test.js +301 -0
  55. package/dist/tests/nodes.test.d.ts +1 -0
  56. package/dist/tests/nodes.test.js +137 -0
  57. package/dist/tests/parser.test.d.ts +1 -0
  58. package/dist/tests/parser.test.js +294 -0
  59. package/dist/tests/precompile.test.d.ts +1 -0
  60. package/dist/tests/precompile.test.js +224 -0
  61. package/dist/tests/runtime.test.d.ts +1 -0
  62. package/dist/tests/runtime.test.js +237 -0
  63. package/dist/tests/transformer.test.d.ts +1 -0
  64. package/dist/tests/transformer.test.js +125 -0
  65. package/dist/tsconfig.tsbuildinfo +1 -0
  66. package/package.json +59 -0
@@ -0,0 +1,489 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderRootToString = renderRootToString;
4
+ exports.renderAST = renderAST;
5
+ //TODO: Sun 4th Jan 2026 [Expand and write tests for each type.]
6
+ const environment_1 = require("./environment");
7
+ const lib_1 = require("./lib");
8
+ const nodes_1 = require("./nodes");
9
+ const transformer_1 = require("./transformer");
10
+ const runtime_1 = require("./runtime");
11
+ const parser_1 = require("./parser");
12
+ async function evalBinOp(node, st, fn) {
13
+ const left = await evalExpr(node.left, st);
14
+ const right = await evalExpr(node.right, st);
15
+ return fn(left, right);
16
+ }
17
+ function makeBlockFn(block, env, runtime) {
18
+ return async (context, frame) => {
19
+ const st = { env, context, frame: frame.push(true), runtime, buffer: [] };
20
+ await evalNode(block.body, st);
21
+ return st.buffer.join('');
22
+ };
23
+ }
24
+ async function registerBlocksFromAst(root, st) {
25
+ const blocks = (0, transformer_1.collectBlocks)(root);
26
+ for (const b of blocks) {
27
+ const name = b.name.value; // Block.name is Symbol in your AST
28
+ st.context.addBlock(name, makeBlockFn(b, st.env, st.runtime));
29
+ }
30
+ }
31
+ async function evalExtends(node, st) {
32
+ const parentStr = String(await evalExpr(node.template, st));
33
+ await registerBlocksFromAst(st.rootAst, st);
34
+ const info = await new Promise((resolve, reject) => {
35
+ st.env.getTemplateInfo(parentStr, { parentName: null }, (err, out) => err ? reject(err) : resolve(out));
36
+ });
37
+ const parentAst = (0, transformer_1.transform)((0, parser_1.parse)(info.src, [], st.env), []);
38
+ // const parentTpl = await st.env.getTemplate(parentStr,undefined, {eagerCompile:true});
39
+ // p.err('Parent string is: ',parentStr, parentTpl.ast, parentTpl.root)
40
+ // const parentAst: Root = parentTpl.ast ?? parentTpl.root;
41
+ // if (!parentAst) {
42
+ // throw st.runtime.handleError(
43
+ // new Error(`Parent template "${parentStr}" has no AST loaded`),
44
+ // node.lineno,
45
+ // node.colno
46
+ // );
47
+ // }
48
+ // const rendered = await new Promise<string>((resolve, reject) => {
49
+ // parentTpl.render(st.context.getVariables?.() ?? st.context, (err: any, res: string) =>
50
+ // err ? reject(err) : resolve(res)
51
+ // );
52
+ // });
53
+ const parentState = {
54
+ ...st,
55
+ rootAst: parentAst,
56
+ buffer: [],
57
+ didExtend: false,
58
+ };
59
+ await evalNode(parentAst, parentState);
60
+ write(st, parentState.buffer.join(""));
61
+ // write(st, rendered);
62
+ st.didExtend = true;
63
+ }
64
+ async function evalNodeListStmt(node, st) {
65
+ for (const child of node.children) {
66
+ await evalNode(child, st);
67
+ if (st.didExtend)
68
+ return;
69
+ }
70
+ }
71
+ async function evalRoot(node, st) {
72
+ await registerBlocksFromAst(node, st);
73
+ await evalNodeListStmt(node, st);
74
+ }
75
+ async function evalBlock(node, st) {
76
+ const name = node.name.value;
77
+ const fn = st.context.getBlock(name); // whatever your API is
78
+ if (!fn)
79
+ return;
80
+ const rendered = await fn(st.context, st.frame);
81
+ write(st, rendered);
82
+ }
83
+ async function evalBinOpHp(node, st, op) {
84
+ switch (op) {
85
+ case '||': {
86
+ const left = await evalExpr(node.left, st);
87
+ return left ? left : await evalExpr(node.right, st);
88
+ }
89
+ case '&&': {
90
+ const left = await evalExpr(node.left, st);
91
+ return left ? await evalExpr(node.right, st) : left;
92
+ }
93
+ case '+': {
94
+ return evalBinOp(node, st, (l, r) => l + r);
95
+ }
96
+ case 'concat': {
97
+ return evalBinOp(node, st, (l, r) => l + '' + r);
98
+ }
99
+ case '-': {
100
+ return evalBinOp(node, st, (l, r) => l - r);
101
+ }
102
+ case '*': {
103
+ return evalBinOp(node, st, (l, r) => l * r);
104
+ }
105
+ case '/': {
106
+ return evalBinOp(node, st, (l, r) => l / r);
107
+ }
108
+ case '%': {
109
+ return evalBinOp(node, st, (l, r) => l % r);
110
+ }
111
+ default:
112
+ throw st.runtime.handleError(new Error(`Unknown binop ${op}`), node.lineno, node.colno);
113
+ }
114
+ }
115
+ async function evalUnaryOp(node, st, op) {
116
+ switch (op) {
117
+ case '!': {
118
+ const v = await evalExpr(node.target, st);
119
+ return !v;
120
+ }
121
+ case '+': {
122
+ const v = await evalExpr(node.target, st);
123
+ return +v;
124
+ }
125
+ case '-': {
126
+ const v = await evalExpr(node.target, st);
127
+ return -v;
128
+ }
129
+ default:
130
+ throw st.runtime.handleError(new Error(`Unknown unary ${op}`), node.lineno, node.colno);
131
+ }
132
+ }
133
+ async function evalNodeList(node, st) {
134
+ const out = [];
135
+ for (const child of node.children)
136
+ out.push(await evalExpr(child, st));
137
+ return out;
138
+ }
139
+ async function evalGroup(node, st) {
140
+ let last = undefined;
141
+ for (const child of node.children)
142
+ last = await evalExpr(child, st);
143
+ return last;
144
+ }
145
+ async function evalArrayNode(node, st) {
146
+ const arr = [];
147
+ for (const child of node.children)
148
+ arr.push(await evalExpr(child, st));
149
+ return arr;
150
+ }
151
+ async function evalDict(node, st) {
152
+ const obj = {};
153
+ for (const child of node.children) {
154
+ const pair = child;
155
+ const keyNode = pair.key;
156
+ let key;
157
+ if (keyNode instanceof nodes_1.Symbol)
158
+ key = keyNode.value;
159
+ else
160
+ key = await evalExpr(keyNode, st);
161
+ obj[String(key)] = await evalExpr(pair.value, st);
162
+ }
163
+ return obj;
164
+ }
165
+ async function evalKeywordArgs(node, st) {
166
+ const dict = await evalDict(node, st);
167
+ return st.runtime.makeKeywordArgs(dict);
168
+ }
169
+ function jsCompare(op, a, b) {
170
+ switch (op) {
171
+ case '==':
172
+ return a == b;
173
+ case '===':
174
+ return a === b;
175
+ case '!=':
176
+ return a != b;
177
+ case '!==':
178
+ return a !== b;
179
+ case '<':
180
+ return a < b;
181
+ case '>':
182
+ return a > b;
183
+ case '<=':
184
+ return a <= b;
185
+ case '>=':
186
+ return a >= b;
187
+ default:
188
+ throw new Error(`Unknown compare op: ${op}`);
189
+ }
190
+ }
191
+ async function evalCompare(node, st) {
192
+ let left = await evalExpr(node.expr, st);
193
+ for (const op of node.ops) {
194
+ const right = await evalExpr(op.expr, st);
195
+ if (!jsCompare(op.type, left, right))
196
+ return false;
197
+ left = right;
198
+ }
199
+ return true;
200
+ }
201
+ // Conditional
202
+ async function evalIf(node, st) {
203
+ const cond = await evalExpr(node.cond, st);
204
+ if (cond)
205
+ return evalNode(node.body, st);
206
+ if (node.else_)
207
+ return evalNode(node.else_, st);
208
+ }
209
+ async function evalIfAsync(node, st) {
210
+ return evalIf(node, st);
211
+ }
212
+ async function evalSet(node, st) {
213
+ const targets = node.targets; // array of Symbol
214
+ let value;
215
+ if (node.value)
216
+ value = await evalExpr(node.value, st);
217
+ else {
218
+ const cap = { ...st, frame: st.frame.push(true), buffer: [] };
219
+ await evalNode(node.body, cap);
220
+ value = cap.buffer.join('');
221
+ }
222
+ for (const t of targets) {
223
+ const name = t.value;
224
+ st.frame.set(name, value, true);
225
+ if (st.frame.topLevel) {
226
+ st.context.setVariable(name, value);
227
+ if (!name.startsWith('_'))
228
+ st.context.addExport(name);
229
+ }
230
+ }
231
+ }
232
+ async function evalFor(node, st) {
233
+ const frame = st.frame.push();
234
+ const inner = { ...st, frame };
235
+ const iterVal = await evalExpr(node.arr, inner);
236
+ const arr = iterVal ? st.runtime.fromIterator(iterVal) : null;
237
+ let didIterate = false;
238
+ if (arr) {
239
+ if (node.name instanceof nodes_1.ArrayNode) {
240
+ const names = node.name.children.map((c) => c.value);
241
+ if (Array.isArray(arr)) {
242
+ for (let i = 0; i < arr.length; i++) {
243
+ didIterate = true;
244
+ const row = arr[i];
245
+ const loopFrame = frame.push();
246
+ const loopSt = { ...inner, frame: loopFrame };
247
+ for (let u = 0; u < names.length; u++) {
248
+ loopFrame.set(names[u], row?.[u]);
249
+ }
250
+ await evalNode(node.body, loopSt);
251
+ }
252
+ }
253
+ else {
254
+ let i = -1;
255
+ for (const key of Object.keys(arr)) {
256
+ i++;
257
+ didIterate = true;
258
+ const loopFrame = frame.push();
259
+ const loopSt = { ...inner, frame: loopFrame };
260
+ const [keyName, valName] = names;
261
+ loopFrame.set(keyName, key);
262
+ loopFrame.set(valName, arr[key]);
263
+ await evalNode(node.body, loopSt);
264
+ }
265
+ }
266
+ }
267
+ else {
268
+ const name = node.name.value; // Symbol
269
+ if (Array.isArray(arr)) {
270
+ for (let i = 0; i < arr.length; i++) {
271
+ didIterate = true;
272
+ const loopFrame = frame.push();
273
+ const loopSt = { ...inner, frame: loopFrame };
274
+ loopFrame.set(name, arr[i]);
275
+ await evalNode(node.body, loopSt);
276
+ }
277
+ }
278
+ else {
279
+ // for (const k in arr) {
280
+ // didIterate = true;
281
+ // const loopFrame = frame.push();
282
+ // const loopSt: EvalState = { ...inner, frame: loopFrame };
283
+ // loopFrame.set(name, arr[k]);
284
+ // await evalNode(node.body, loopSt);
285
+ // }
286
+ }
287
+ }
288
+ }
289
+ if (!didIterate && node.else_) {
290
+ await evalNode(node.else_, inner);
291
+ }
292
+ }
293
+ async function evalCallExtension(node, st) {
294
+ const ext = st.env.getExtension(node.extname);
295
+ const fn = ext?.[node.prop];
296
+ if (typeof fn !== 'function') {
297
+ throw st.runtime.handleError(new Error(`Extension "${node.extname}" has no method "${node.prop}"`), node.lineno, node.colno);
298
+ }
299
+ const args = [];
300
+ if (node.args) {
301
+ for (const child of node.args.children)
302
+ args.push(await evalExpr(child, st));
303
+ }
304
+ const contentFns = [];
305
+ if (node.contentArgs?.length) {
306
+ for (const contentNode of node.contentArgs) {
307
+ if (!contentNode) {
308
+ contentFns.push(null);
309
+ continue;
310
+ }
311
+ contentFns.push(async () => {
312
+ const inner = {
313
+ ...st,
314
+ frame: st.frame.push(true),
315
+ buffer: [],
316
+ };
317
+ await evalNode(contentNode, inner); // contentNode is likely NodeList/Output
318
+ return inner.buffer.join('');
319
+ });
320
+ }
321
+ }
322
+ const res = fn.call(ext, st.context, ...args, ...contentFns);
323
+ if (node instanceof nodes_1.CallExtensionAsync) {
324
+ return await new Promise((resolve, reject) => {
325
+ if (res && typeof res.then === 'function')
326
+ res.then(resolve, reject);
327
+ else
328
+ resolve(res);
329
+ });
330
+ }
331
+ return res;
332
+ }
333
+ async function evalExpr(node, st) {
334
+ // BinOp
335
+ if (node instanceof nodes_1.Or)
336
+ return evalBinOpHp(node, st, '||');
337
+ if (node instanceof nodes_1.And)
338
+ return evalBinOpHp(node, st, '&&');
339
+ if (node instanceof nodes_1.Concat)
340
+ return evalBinOpHp(node, st, 'concat');
341
+ if (node instanceof nodes_1.Add)
342
+ return evalBinOpHp(node, st, '+');
343
+ if (node instanceof nodes_1.Sub)
344
+ return evalBinOpHp(node, st, '-');
345
+ if (node instanceof nodes_1.Mul)
346
+ return evalBinOpHp(node, st, '*');
347
+ if (node instanceof nodes_1.Div)
348
+ return evalBinOpHp(node, st, '/');
349
+ if (node instanceof nodes_1.Mod)
350
+ return evalBinOpHp(node, st, '%');
351
+ // UnaryOp
352
+ if (node instanceof nodes_1.Pos)
353
+ return evalUnaryOp(node, st, '+');
354
+ if (node instanceof nodes_1.Neg)
355
+ return evalUnaryOp(node, st, '-');
356
+ if (node instanceof nodes_1.Not)
357
+ return evalUnaryOp(node, st, '!');
358
+ // List types
359
+ if (node instanceof nodes_1.NodeList)
360
+ return evalNodeList(node, st);
361
+ if (node instanceof nodes_1.Group)
362
+ return evalGroup(node, st);
363
+ if (node instanceof nodes_1.ArrayNode)
364
+ return evalArrayNode(node, st);
365
+ if (node instanceof nodes_1.Dict)
366
+ return evalDict(node, st);
367
+ if (node instanceof nodes_1.KeywordArgs)
368
+ return evalKeywordArgs(node, st);
369
+ if (node instanceof nodes_1.Compare)
370
+ return evalCompare(node, st);
371
+ if (node instanceof nodes_1.CallExtension)
372
+ return evalCallExtension(node, st);
373
+ if (node instanceof nodes_1.CallExtensionAsync)
374
+ return evalCallExtension(node, st);
375
+ if (node instanceof nodes_1.Literal)
376
+ return node.value;
377
+ if (node instanceof nodes_1.Symbol) {
378
+ const v = st.runtime.contextOrFrameLookup(st.context, st.frame, node.value);
379
+ lib_1.p.debug('LOOKUP', node.value, '=>', v);
380
+ return v;
381
+ }
382
+ if (node instanceof nodes_1.LookupVal) {
383
+ const target = await evalExpr(node.target, st);
384
+ const key = await evalExpr(node.val, st);
385
+ return st.runtime.memberLookup(target, key);
386
+ }
387
+ if (node instanceof nodes_1.Filter) {
388
+ const name = node.name.value; // your AST uses Symbol node for filter name
389
+ const fn = st.env.getFilter(name);
390
+ const args = [];
391
+ for (const child of node.args.children) {
392
+ args.push(await evalExpr(child, st));
393
+ }
394
+ return fn.call(st.context, ...args);
395
+ }
396
+ if (node instanceof nodes_1.FunCall) {
397
+ const callee = await evalExpr(node.name, st);
398
+ const args = [];
399
+ for (const child of node.args.children)
400
+ args.push(await evalExpr(child, st));
401
+ return st.runtime.callWrap(callee,
402
+ /*friendlyName*/ '...', st.context, args);
403
+ }
404
+ if (node instanceof nodes_1.InlineIf) {
405
+ const cond = await evalExpr(node.cond, st);
406
+ if (cond)
407
+ return evalExpr(node.body, st);
408
+ return node.else_ ? evalExpr(node.else_, st) : '';
409
+ }
410
+ throw st.runtime.handleError(new Error(`evalExpr: unsupported node ${node.typename}`), node.lineno, node.colno);
411
+ }
412
+ function write(st, s) {
413
+ st.buffer.push(s);
414
+ }
415
+ async function evalOutput(node, st) {
416
+ for (const child of node.children) {
417
+ if (child instanceof nodes_1.TemplateData) {
418
+ if (child.value)
419
+ write(st, child.value);
420
+ continue;
421
+ }
422
+ const val = await evalExpr(child, st);
423
+ const safe = st.runtime.suppressValue(st.env.throwOnUndefined
424
+ ? st.runtime.ensureDefined(val, node.lineno, node.colno)
425
+ : val, st.env.autoescape);
426
+ write(st, safe);
427
+ }
428
+ }
429
+ async function evalNode(node, st) {
430
+ switch (node.typename) {
431
+ case 'Output':
432
+ return evalOutput(node, st);
433
+ case 'NodeList':
434
+ return evalNodeListStmt(node, st);
435
+ case 'If':
436
+ return evalIf(node, st);
437
+ case 'IfAsync':
438
+ return evalIfAsync(node, st);
439
+ case 'For':
440
+ return evalFor(node, st);
441
+ case 'Set':
442
+ return evalSet(node, st);
443
+ case 'Extends':
444
+ return evalExtends(node, st);
445
+ case 'Root':
446
+ return evalRoot(node, st);
447
+ case 'Block':
448
+ return evalBlock(node, st);
449
+ default:
450
+ throw st.runtime.handleError('Unknown evaluation: ' + node.typename);
451
+ }
452
+ }
453
+ async function renderRootToString(ast, st) {
454
+ const inner = { ...st, frame: st.frame, buffer: [] };
455
+ await evalNode(ast, inner);
456
+ return inner.buffer.join('');
457
+ }
458
+ async function renderAST(env, ast, ctx, runtime) {
459
+ lib_1.p.debug('ctx: ', ctx);
460
+ const context = new environment_1.Context(ctx || {}, /*blocks*/ {}, env);
461
+ const frame = new runtime_1.Frame();
462
+ frame.topLevel = true;
463
+ const st = { env, context, frame, runtime, buffer: [], rootAst: ast };
464
+ await evalNode(ast, st);
465
+ return st.buffer.join('');
466
+ }
467
+ // async function renderTemplate(tpl: Template, ctx: any) {
468
+ // const context = new Context(ctx, /*blocks*/ {}, tpl.env);
469
+ // const frame = new Frame(); frame.topLevel = true;
470
+ // // register our blocks first
471
+ // for (const [name, blockNode] of tpl.blocks) {
472
+ // context.addBlock(name, makeBlockFn(blockNode, tpl.env));
473
+ // }
474
+ // // if extends, load parent and render parent root
475
+ // if (tpl.parentName) {
476
+ // const parent = await tpl.env.getTemplate(tpl.parentName, /*eager*/ true, tpl.path, /*ignoreMissing*/ false);
477
+ // // parent will call context.getBlock("name") and it’ll resolve to overridden blocks
478
+ // return await renderRoot(parent, context, frame);
479
+ // }
480
+ // // otherwise render our root
481
+ // return await renderRoot(tpl, context, frame);
482
+ // }
483
+ // function makeBlockFn(blockBody: NodeList, env: Environment) {
484
+ // return async (context: Context, frame: Frame, runtime: Runtime) => {
485
+ // const st: EvalState = { env, context, frame: frame.push(true), runtime, buffer: [] };
486
+ // await evalNode(blockBody, st);
487
+ // return st.buffer.join("");
488
+ // };
489
+ // }
@@ -0,0 +1,72 @@
1
+ import { Token } from './types';
2
+ export declare const whitespaceChars = " \n\t\r\u00A0";
3
+ export declare const delimChars = "()[]{}%*-+~/#,:|.<>=!";
4
+ export declare const intChars = "0123456789";
5
+ export declare const BLOCK_START = "{%";
6
+ export declare const BLOCK_END = "%}";
7
+ export declare const VARIABLE_START = "{{";
8
+ export declare const VARIABLE_END = "}}";
9
+ export declare const COMMENT_START = "{#";
10
+ export declare const COMMENT_END = "#}";
11
+ export declare const TOKEN_STRING = "string";
12
+ export declare const TOKEN_WHITESPACE = "whitespace";
13
+ export declare const TOKEN_DATA = "data";
14
+ export declare const TOKEN_BLOCK_START = "block-start";
15
+ export declare const TOKEN_BLOCK_END = "block-end";
16
+ export declare const TOKEN_VARIABLE_START = "variable-start";
17
+ export declare const TOKEN_VARIABLE_END = "variable-end";
18
+ export declare const TOKEN_COMMENT = "comment";
19
+ export declare const TOKEN_LEFT_PAREN = "left-paren";
20
+ export declare const TOKEN_RIGHT_PAREN = "right-paren";
21
+ export declare const TOKEN_LEFT_BRACKET = "left-bracket";
22
+ export declare const TOKEN_RIGHT_BRACKET = "right-bracket";
23
+ export declare const TOKEN_LEFT_CURLY = "left-curly";
24
+ export declare const TOKEN_RIGHT_CURLY = "right-curly";
25
+ export declare const TOKEN_OPERATOR = "operator";
26
+ export declare const TOKEN_COMMA = "comma";
27
+ export declare const TOKEN_COLON = "colon";
28
+ export declare const TOKEN_TILDE = "tilde";
29
+ export declare const TOKEN_PIPE = "pipe";
30
+ export declare const TOKEN_INT = "int";
31
+ export declare const TOKEN_FLOAT = "float";
32
+ export declare const TOKEN_BOOLEAN = "boolean";
33
+ export declare const TOKEN_NONE = "none";
34
+ export declare const TOKEN_SYMBOL = "symbol";
35
+ export declare const TOKEN_SPECIAL = "special";
36
+ export declare const TOKEN_REGEX = "regex";
37
+ interface ITokenizerOpts {
38
+ trimBlocks?: boolean;
39
+ lstripBlocks?: boolean;
40
+ tags?: Record<string, any>;
41
+ }
42
+ export declare class Tokenizer {
43
+ str: string;
44
+ index: number;
45
+ len: number;
46
+ lineno: number;
47
+ colno: number;
48
+ inCode: boolean;
49
+ trimBlocks: boolean;
50
+ lstripBlocks: boolean;
51
+ tags: Record<string, any>;
52
+ src: any;
53
+ constructor(str: string, opts: ITokenizerOpts);
54
+ nextToken(): Token;
55
+ _parseString(delimiter: string): string;
56
+ _matches(str: string): boolean;
57
+ _extractString(str: string): string;
58
+ _extractUntil(charString: string): string;
59
+ _extract(charString: string): string;
60
+ _extractMatching(breakOnMatch: boolean, charString: string): string;
61
+ _extractRegex(regex: RegExp): RegExpMatchArray;
62
+ isFinished(): boolean;
63
+ forwardN(n: number): void;
64
+ forward(): void;
65
+ backN(n: number): void;
66
+ back(): void;
67
+ current(): string;
68
+ currentStr(): string;
69
+ previous(): string;
70
+ }
71
+ export declare const lex: (str: string, opts: ITokenizerOpts) => Tokenizer;
72
+ export {};