@mojir/lits 2.1.36 → 2.1.38

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.
@@ -0,0 +1,4 @@
1
+ import type { JsFunction } from '../../../src/Lits/Lits';
2
+ export declare const jsFunctions: {
3
+ [x: string]: JsFunction;
4
+ };
@@ -0,0 +1,3 @@
1
+ export declare function sys_cwd(): string;
2
+ export declare function sys_readFile(filePath: string): string;
3
+ export declare function sys_writeFile(filePath: string, content: string): void;
package/dist/cli/cli.js CHANGED
@@ -5,6 +5,7 @@ var fs = require('node:fs');
5
5
  var path = require('node:path');
6
6
  var readline = require('node:readline');
7
7
  var os = require('node:os');
8
+ var process$1 = require('node:process');
8
9
 
9
10
  /******************************************************************************
10
11
  Copyright (c) Microsoft Corporation.
@@ -92,7 +93,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
92
93
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
93
94
  };
94
95
 
95
- var version = "2.1.36";
96
+ var version = "2.1.38";
96
97
 
97
98
  function getCodeMarker(sourceCodeInfo) {
98
99
  if (!sourceCodeInfo.position || !sourceCodeInfo.code)
@@ -11805,7 +11806,6 @@ var lambdaSpecialExpression = {
11805
11806
  _b.arity = arity,
11806
11807
  _b.docString = docString,
11807
11808
  _b);
11808
- evaluatedFunction[2].self = { value: litsFunction };
11809
11809
  return litsFunction;
11810
11810
  },
11811
11811
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -12480,13 +12480,13 @@ var functionExecutors = {
12480
12480
  var args = evaluatedFunction[0];
12481
12481
  var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
12482
12482
  var newContextStack = contextStack.create(fn.evaluatedfunction[2]);
12483
- var newContext = {};
12483
+ var newContext = { self: { value: fn } };
12484
12484
  var rest = [];
12485
12485
  for (var i = 0; i < params.length; i += 1) {
12486
12486
  if (i < nbrOfNonRestArgs) {
12487
12487
  var param = toAny(params[i]);
12488
- var valueRecord = evalueateBindingNodeValues(args[i], param, function (Node) {
12489
- return evaluateNode(Node, newContextStack.create(newContext));
12488
+ var valueRecord = evalueateBindingNodeValues(args[i], param, function (node) {
12489
+ return evaluateNode(node, newContextStack.create(newContext));
12490
12490
  });
12491
12491
  Object.entries(valueRecord).forEach(function (_a) {
12492
12492
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -12500,8 +12500,8 @@ var functionExecutors = {
12500
12500
  for (var i = params.length; i < nbrOfNonRestArgs; i++) {
12501
12501
  var arg = args[i];
12502
12502
  var defaultValue = evaluateNode(arg[1][1], contextStack.create(newContext));
12503
- var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (Node) {
12504
- return evaluateNode(Node, contextStack.create(newContext));
12503
+ var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (node) {
12504
+ return evaluateNode(node, contextStack.create(newContext));
12505
12505
  });
12506
12506
  Object.entries(valueRecord).forEach(function (_a) {
12507
12507
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -12510,7 +12510,7 @@ var functionExecutors = {
12510
12510
  }
12511
12511
  var restArgument = args.find(function (arg) { return arg[0] === bindingTargetTypes.rest; });
12512
12512
  if (restArgument !== undefined) {
12513
- var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (Node) { return evaluateNode(Node, contextStack.create(newContext)); });
12513
+ var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (node) { return evaluateNode(node, contextStack.create(newContext)); });
12514
12514
  Object.entries(valueRecord).forEach(function (_a) {
12515
12515
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
12516
12516
  newContext[key] = { value: value };
@@ -13049,6 +13049,21 @@ var ContextStackImpl = /** @class */ (function () {
13049
13049
  };
13050
13050
  return ContextStackImpl;
13051
13051
  }());
13052
+ function checkNotDefined(name) {
13053
+ if (specialExpressionKeys.includes(name)) {
13054
+ console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
13055
+ return false;
13056
+ }
13057
+ if (normalExpressionKeys.includes(name)) {
13058
+ console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
13059
+ return false;
13060
+ }
13061
+ if (name === 'self') {
13062
+ console.warn("Cannot shadow builtin value \"".concat(name, "\", ignoring."));
13063
+ return false;
13064
+ }
13065
+ return true;
13066
+ }
13052
13067
  function createContextStack(params) {
13053
13068
  var _a;
13054
13069
  if (params === void 0) { params = {}; }
@@ -13060,26 +13075,53 @@ function createContextStack(params) {
13060
13075
  values: params.values,
13061
13076
  nativeJsFunctions: params.jsFunctions
13062
13077
  && Object.entries(params.jsFunctions).reduce(function (acc, _a) {
13063
- var _b;
13064
- var _c, _d;
13065
- var _e = __read(_a, 2), name = _e[0], jsFunction = _e[1];
13066
- if (specialExpressionKeys.includes(name)) {
13067
- console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
13078
+ var e_5, _b, _c;
13079
+ var _d, _e;
13080
+ var _f = __read(_a, 2), identifier = _f[0], entry = _f[1];
13081
+ var identifierParts = identifier.split('.');
13082
+ var name = identifierParts.pop();
13083
+ if (/^[A-Z]/.test(name)) {
13084
+ console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, function name must not start with an uppercase letter"), undefined);
13068
13085
  return acc;
13069
13086
  }
13070
- if (normalExpressionKeys.includes(name)) {
13071
- console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
13072
- return acc;
13087
+ var scope = acc;
13088
+ try {
13089
+ for (var identifierParts_1 = __values(identifierParts), identifierParts_1_1 = identifierParts_1.next(); !identifierParts_1_1.done; identifierParts_1_1 = identifierParts_1.next()) {
13090
+ var part = identifierParts_1_1.value;
13091
+ if (part.length === 0) {
13092
+ console.warn("Invalid empty identifier \"".concat(identifier, "\" in nativeJsFunctions"), undefined);
13093
+ return acc;
13094
+ }
13095
+ if (!/^[A-Z]/.test(part)) {
13096
+ console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, namespace must start with an uppercase letter"), undefined);
13097
+ return acc;
13098
+ }
13099
+ if (!scope[part]) {
13100
+ scope[part] = {};
13101
+ }
13102
+ scope = scope[part];
13103
+ }
13104
+ }
13105
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
13106
+ finally {
13107
+ try {
13108
+ if (identifierParts_1_1 && !identifierParts_1_1.done && (_b = identifierParts_1.return)) _b.call(identifierParts_1);
13109
+ }
13110
+ finally { if (e_5) throw e_5.error; }
13073
13111
  }
13074
- acc[name] = (_b = {
13112
+ var natifeFn = (_c = {
13075
13113
  functionType: 'NativeJsFunction',
13076
- nativeFn: jsFunction,
13114
+ nativeFn: entry,
13077
13115
  name: name
13078
13116
  },
13079
- _b[FUNCTION_SYMBOL] = true,
13080
- _b.arity = (_c = jsFunction.arity) !== null && _c !== void 0 ? _c : {},
13081
- _b.docString = (_d = jsFunction.docString) !== null && _d !== void 0 ? _d : '',
13082
- _b);
13117
+ _c[FUNCTION_SYMBOL] = true,
13118
+ _c.arity = (_d = entry.arity) !== null && _d !== void 0 ? _d : {},
13119
+ _c.docString = (_e = entry.docString) !== null && _e !== void 0 ? _e : '',
13120
+ _c);
13121
+ if (scope === acc && !checkNotDefined(name)) {
13122
+ return acc;
13123
+ }
13124
+ scope[name] = natifeFn;
13083
13125
  return acc;
13084
13126
  }, {}),
13085
13127
  });
@@ -13495,10 +13537,10 @@ var tokenizeMultiLineComment = function (input, position) {
13495
13537
  }
13496
13538
  return NO_MATCH;
13497
13539
  };
13498
- var tokenizeSingleLineComment = function (input, position) {
13499
- if (input[position] === '/' && input[position + 1] === '/') {
13540
+ var tokenizeShebang = function (input, position) {
13541
+ if (input[position] === '#' && input[position + 1] === '!') {
13500
13542
  var length_3 = 2;
13501
- var value = '//';
13543
+ var value = '#!';
13502
13544
  while (input[position + length_3] !== '\n' && position + length_3 < input.length) {
13503
13545
  value += input[position + length_3];
13504
13546
  length_3 += 1;
@@ -13507,6 +13549,18 @@ var tokenizeSingleLineComment = function (input, position) {
13507
13549
  }
13508
13550
  return NO_MATCH;
13509
13551
  };
13552
+ var tokenizeSingleLineComment = function (input, position) {
13553
+ if (input[position] === '/' && input[position + 1] === '/') {
13554
+ var length_4 = 2;
13555
+ var value = '//';
13556
+ while (input[position + length_4] !== '\n' && position + length_4 < input.length) {
13557
+ value += input[position + length_4];
13558
+ length_4 += 1;
13559
+ }
13560
+ return [length_4, ['SingleLineComment', value]];
13561
+ }
13562
+ return NO_MATCH;
13563
+ };
13510
13564
  // All tokenizers, order matters!
13511
13565
  var tokenizers = [
13512
13566
  tokenizeWhitespace,
@@ -13572,10 +13626,17 @@ function createSourceCodeInfo(input, position, filePath) {
13572
13626
  function getCurrentToken(input, position) {
13573
13627
  var e_1, _a;
13574
13628
  var initialPosition = position;
13629
+ if (position === 0) {
13630
+ var _b = __read(tokenizeShebang(input, position), 2), nbrOfCharacters = _b[0], token = _b[1];
13631
+ position += nbrOfCharacters;
13632
+ if (nbrOfCharacters > 0) {
13633
+ return [position - initialPosition, token];
13634
+ }
13635
+ }
13575
13636
  try {
13576
13637
  for (var tokenizers_1 = __values(tokenizers), tokenizers_1_1 = tokenizers_1.next(); !tokenizers_1_1.done; tokenizers_1_1 = tokenizers_1.next()) {
13577
13638
  var tokenizer = tokenizers_1_1.value;
13578
- var _b = __read(tokenizer(input, position), 2), nbrOfCharacters = _b[0], token = _b[1];
13639
+ var _c = __read(tokenizer(input, position), 2), nbrOfCharacters = _c[0], token = _c[1];
13579
13640
  position += nbrOfCharacters;
13580
13641
  if (nbrOfCharacters === 0) {
13581
13642
  continue;
@@ -13629,6 +13690,9 @@ function asReservedSymbolToken(token, symbolName) {
13629
13690
  assertReservedSymbolToken(token, symbolName);
13630
13691
  return token;
13631
13692
  }
13693
+ function isShebangToken(token) {
13694
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'Shebang';
13695
+ }
13632
13696
  function isSingleLineCommentToken(token) {
13633
13697
  return (token === null || token === void 0 ? void 0 : token[0]) === 'SingleLineComment';
13634
13698
  }
@@ -13728,6 +13792,7 @@ function minifyTokenStream(tokenStream, _a) {
13728
13792
  .filter(function (token) {
13729
13793
  if (isSingleLineCommentToken(token)
13730
13794
  || isMultiLineCommentToken(token)
13795
+ || isShebangToken(token)
13731
13796
  || (removeWhiteSpace && isWhitespaceToken(token))) {
13732
13797
  return false;
13733
13798
  }
@@ -32081,15 +32146,42 @@ function createReadlineInterface(options) {
32081
32146
  return rl;
32082
32147
  }
32083
32148
 
32149
+ function sys_cwd() {
32150
+ return process$1.cwd();
32151
+ }
32152
+ function sys_readFile(filePath) {
32153
+ return fs.readFileSync(filePath, { encoding: 'utf8' });
32154
+ }
32155
+ function sys_writeFile(filePath, content) {
32156
+ fs.writeFileSync(content, filePath, { encoding: 'utf8' });
32157
+ }
32158
+
32159
+ var sysFunctions = {
32160
+ 'Sys.cwd': {
32161
+ fn: sys_cwd,
32162
+ docString: 'Returns the current working directory of the process.',
32163
+ arity: { min: 0, max: 0 },
32164
+ },
32165
+ 'Sys.read-file': {
32166
+ fn: sys_readFile,
32167
+ docString: 'Reads the content of a file at the specified path.',
32168
+ arity: { min: 1, max: 1 },
32169
+ },
32170
+ 'Sys.write-file': {
32171
+ fn: sys_writeFile,
32172
+ docString: 'Writes content to a file at the specified path.',
32173
+ arity: { min: 2, max: 2 },
32174
+ },
32175
+ };
32176
+ var jsFunctions = __assign({}, sysFunctions);
32177
+
32084
32178
  /* eslint-disable node/prefer-global/process */
32085
32179
  /* eslint-disable no-console */
32086
- var _a;
32087
32180
  var useColor = !process.env.NO_COLOR;
32088
32181
  var fmt = createColorizer(useColor);
32089
32182
  var HIST_SIZE = 1000;
32090
32183
  var PROMPT = fmt.bright.gray('> ');
32091
32184
  var historyResults = [];
32092
- var lits = new Lits({ debug: true });
32093
32185
  var formatValue = getInlineCodeFormatter(fmt);
32094
32186
  var commands = ['`help', '`quit', '`builtins', '`context'];
32095
32187
  var expressionRegExp = new RegExp("^(.*\\(\\s*)(".concat(polishSymbolFirstCharacterClass).concat(polishSymbolCharacterClass, "*)$"));
@@ -32097,20 +32189,44 @@ var nameRegExp = new RegExp("^(.*?)(".concat(polishSymbolFirstCharacterClass).co
32097
32189
  var helpRegExp = new RegExp("^`help\\s+(".concat(polishSymbolFirstCharacterClass).concat(polishSymbolCharacterClass, "+)\\s*$"));
32098
32190
  var expressions = __spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false);
32099
32191
  var config = processArguments(process.argv.slice(2));
32100
- if (config.eval) {
32101
- var success = execute(config.eval);
32102
- process.exit(success ? 0 : 1);
32103
- }
32104
- else if (config.evalFilename) {
32105
- var content = fs.readFileSync(config.evalFilename, { encoding: 'utf-8' });
32106
- var success = execute(content);
32107
- process.exit(success ? 0 : 1);
32192
+ var lits = (function () {
32193
+ var _lits = new Lits({ debug: true });
32194
+ return {
32195
+ run: function (program) {
32196
+ var _a;
32197
+ return _lits.run(program, {
32198
+ globalContext: (_a = config.context) !== null && _a !== void 0 ? _a : undefined,
32199
+ jsFunctions: jsFunctions,
32200
+ globalModuleScope: true,
32201
+ });
32202
+ },
32203
+ context: function (program) {
32204
+ var _a;
32205
+ return _lits.context(program, {
32206
+ globalContext: (_a = config.context) !== null && _a !== void 0 ? _a : undefined,
32207
+ jsFunctions: jsFunctions,
32208
+ globalModuleScope: true,
32209
+ });
32210
+ },
32211
+ };
32212
+ })();
32213
+ if (config.eval || config.evalFilename) {
32214
+ try {
32215
+ var program = config.eval || fs.readFileSync(config.evalFilename, { encoding: 'utf-8' });
32216
+ var result = lits.run(program);
32217
+ if (config.printResult) {
32218
+ console.log(result);
32219
+ }
32220
+ process.exit(0);
32221
+ }
32222
+ catch (error) {
32223
+ printErrorMessage("".concat(error));
32224
+ process.exit(1);
32225
+ }
32108
32226
  }
32109
32227
  else if (config.loadFilename) {
32110
32228
  var content = fs.readFileSync(config.loadFilename, { encoding: 'utf-8' });
32111
- config.context = lits.context(content, {
32112
- globalContext: (_a = config.context) !== null && _a !== void 0 ? _a : undefined,
32113
- });
32229
+ config.context = lits.context(content);
32114
32230
  runREPL();
32115
32231
  }
32116
32232
  else if (config.testFilename) {
@@ -32134,16 +32250,14 @@ function runLitsTest(testPath, testNamePattern) {
32134
32250
  process.exit(1);
32135
32251
  }
32136
32252
  function execute(expression) {
32137
- var _a;
32138
32253
  try {
32139
- var result = lits.run(expression, {
32140
- globalContext: (_a = config.context) !== null && _a !== void 0 ? _a : undefined,
32141
- });
32254
+ var result = lits.run(expression);
32142
32255
  historyResults.unshift(result);
32143
- if (historyResults.length > 9)
32256
+ if (historyResults.length > 9) {
32144
32257
  historyResults.length = 9;
32258
+ }
32145
32259
  setReplHistoryVariables();
32146
- console.log(formatValue(stringifyValue(result, false)));
32260
+ console.log(stringifyValue(result, false));
32147
32261
  return true;
32148
32262
  }
32149
32263
  catch (error) {
@@ -32173,6 +32287,9 @@ function setReplHistoryVariables() {
32173
32287
  }
32174
32288
  function parseOption(args, i) {
32175
32289
  var option = args[i];
32290
+ if (option === '-p') {
32291
+ return { option: option, argument: null, count: 1 };
32292
+ }
32176
32293
  if (/^-[a-z]$/i.test(option))
32177
32294
  return { option: option, argument: args[i + 1], count: 2 };
32178
32295
  var match = /^(--[a-z-]+)(?:=(.*))?$/i.exec(option);
@@ -32188,6 +32305,7 @@ function processArguments(args) {
32188
32305
  loadFilename: null,
32189
32306
  context: {},
32190
32307
  eval: null,
32308
+ printResult: false,
32191
32309
  };
32192
32310
  var i = 0;
32193
32311
  while (i < args.length) {
@@ -32199,7 +32317,6 @@ function processArguments(args) {
32199
32317
  var option = parsedOption.option, argument = parsedOption.argument, count = parsedOption.count;
32200
32318
  i += count;
32201
32319
  switch (option) {
32202
- case '-t':
32203
32320
  case '--test':
32204
32321
  if (!argument) {
32205
32322
  printErrorMessage("Missing filename after ".concat(option));
@@ -32207,7 +32324,6 @@ function processArguments(args) {
32207
32324
  }
32208
32325
  defaultConfig.testFilename = argument;
32209
32326
  break;
32210
- case '-p':
32211
32327
  case '--test-pattern':
32212
32328
  if (!argument) {
32213
32329
  printErrorMessage("Missing test name pattern after ".concat(option));
@@ -32266,6 +32382,10 @@ function processArguments(args) {
32266
32382
  process.exit(1);
32267
32383
  }
32268
32384
  break;
32385
+ case '-p':
32386
+ case '--print-result':
32387
+ defaultConfig.printResult = true;
32388
+ break;
32269
32389
  case '-e':
32270
32390
  case '--eval':
32271
32391
  if (!argument) {
@@ -32368,7 +32488,7 @@ function printHelp() {
32368
32488
  console.log("\n`builtins Print all builtin functions\n`context Print context\n`help Print this help message\n`help [builtin function] Print help for [builtin function]\n`quit Quit\n".trim());
32369
32489
  }
32370
32490
  function printUsage() {
32371
- console.log("\nUsage: lits [options]\n\nOptions:\n -c, --context=... Context as a JSON string\n -C, --context-file=... Context file (.json file)\n -e, --eval=... Evaluate Lits expression\n -f, --file=... Evaluate .lits file\n -p, --test-pattern=... Test name pattern, used together with --test\n -t, --test=... Test .test.lits file\n --help Show this help\n --version Print lits version\n".trim());
32491
+ console.log("\nUsage: lits [options]\n\nOptions:\n -c, --context=... Context as a JSON string\n -C, --context-file=... Context file (.json file)\n -e, --eval=... Evaluate Lits expression\n -f, --file=... Evaluate .lits file\n --test-pattern=... Test name pattern, used together with --test\n --test=... Test .test.lits file\n -p --print-result Test .test.lits file\n --help Show this help\n --version Print lits version\n".trim());
32372
32492
  }
32373
32493
  function printContext() {
32374
32494
  var context = config.context;
@@ -1,6 +1,6 @@
1
1
  import type { Any } from '../interface';
2
2
  import type { ContextParams } from '../Lits/Lits';
3
- import type { NativeJsFunction, SymbolNode, UserDefinedSymbolNode } from '../parser/types';
3
+ import type { NativeJsNamespace, SymbolNode, UserDefinedSymbolNode } from '../parser/types';
4
4
  import type { SourceCodeInfo } from '../tokenizer/token';
5
5
  import type { Context, LookUpResult } from './interface';
6
6
  export type ContextStack = ContextStackImpl;
@@ -12,7 +12,7 @@ export declare class ContextStackImpl {
12
12
  constructor({ contexts, values: hostValues, nativeJsFunctions, }: {
13
13
  contexts: Context[];
14
14
  values?: Record<string, unknown>;
15
- nativeJsFunctions?: Record<string, NativeJsFunction>;
15
+ nativeJsFunctions?: NativeJsNamespace;
16
16
  });
17
17
  create(context: Context): ContextStack;
18
18
  new(context: Context): ContextStack;
@@ -0,0 +1,4 @@
1
+ import type { JsFunction } from '../../../src/Lits/Lits';
2
+ export declare const jsFunctions: {
3
+ [x: string]: JsFunction;
4
+ };
@@ -0,0 +1,3 @@
1
+ export declare function sys_cwd(): string;
2
+ export declare function sys_readFile(filePath: string): string;
3
+ export declare function sys_writeFile(filePath: string, content: string): void;
@@ -30,6 +30,9 @@ export interface NativeJsFunction extends GenericLitsFunction {
30
30
  nativeFn: JsFunction;
31
31
  docString: string;
32
32
  }
33
+ export interface NativeJsNamespace {
34
+ [key: string]: NativeJsFunction | NativeJsNamespace;
35
+ }
33
36
  export interface UserDefinedFunction extends GenericLitsFunction {
34
37
  functionType: 'UserDefined';
35
38
  name: string | undefined;
@@ -1,6 +1,6 @@
1
1
  import type { ReservedSymbol } from './reservedNames';
2
2
  import { type SymbolicBinaryOperator, type SymbolicOperator } from './operators';
3
- export declare const tokenTypes: readonly ["LBrace", "LBracket", "RBrace", "RBracket", "LParen", "RParen", "BasePrefixedNumber", "DocString", "Error", "MultiLineComment", "Number", "Operator", "RegexpShorthand", "ReservedSymbol", "SingleLineComment", "String", "Symbol", "Whitespace"];
3
+ export declare const tokenTypes: readonly ["LBrace", "LBracket", "RBrace", "RBracket", "LParen", "RParen", "BasePrefixedNumber", "DocString", "Error", "MultiLineComment", "Number", "Operator", "RegexpShorthand", "ReservedSymbol", "SingleLineComment", "Shebang", "String", "Symbol", "Whitespace"];
4
4
  export type TokenType = typeof tokenTypes[number];
5
5
  declare const modifierNames: readonly ["&rest", "&let", "&when", "&while"];
6
6
  export type ModifierName = typeof modifierNames[number];
@@ -19,11 +19,12 @@ export type OperatorToken<T extends SymbolicOperator = SymbolicOperator> = Gener
19
19
  export type RegexpShorthandToken = GenericToken<'RegexpShorthand'>;
20
20
  export type ReservedSymbolToken<T extends ReservedSymbol = ReservedSymbol> = GenericToken<'ReservedSymbol', T>;
21
21
  export type SingleLineCommentToken = GenericToken<'SingleLineComment'>;
22
+ export type ShebangToken = GenericToken<'Shebang'>;
22
23
  export type StringToken = GenericToken<'String'>;
23
24
  export type DocStringToken = GenericToken<'DocString'>;
24
25
  export type SymbolToken<T extends string = string> = GenericToken<'Symbol', T>;
25
26
  export type WhitespaceToken = GenericToken<'Whitespace'>;
26
- export type Token = LBraceToken | LBracketToken | LParenToken | RBraceToken | RBracketToken | RParenToken | BasePrefixedNumberToken | DocStringToken | ErrorToken | MultiLineCommentToken | NumberToken | OperatorToken | RegexpShorthandToken | ReservedSymbolToken | SingleLineCommentToken | StringToken | SymbolToken | WhitespaceToken;
27
+ export type Token = LBraceToken | LBracketToken | LParenToken | RBraceToken | RBracketToken | RParenToken | BasePrefixedNumberToken | DocStringToken | ErrorToken | MultiLineCommentToken | NumberToken | OperatorToken | RegexpShorthandToken | ReservedSymbolToken | SingleLineCommentToken | ShebangToken | StringToken | SymbolToken | WhitespaceToken;
27
28
  export type TokenDescriptor<T extends Token> = [length: number, token?: T];
28
29
  export interface SourceCodeInfo {
29
30
  position: {
@@ -39,12 +40,9 @@ export declare function asSymbolToken<T extends string>(token: Token | undefined
39
40
  export declare function isReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): token is ReservedSymbolToken<T>;
40
41
  export declare function assertReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): asserts token is ReservedSymbolToken<T>;
41
42
  export declare function asReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): ReservedSymbolToken<T>;
43
+ export declare function isShebangToken(token: Token | undefined): token is SingleLineCommentToken;
42
44
  export declare function isSingleLineCommentToken(token: Token | undefined): token is SingleLineCommentToken;
43
- export declare function assertSingleLineCommentToken(token: Token | undefined): asserts token is SingleLineCommentToken;
44
- export declare function asSingleLineCommentToken(token: Token | undefined): SingleLineCommentToken;
45
45
  export declare function isMultiLineCommentToken(token: Token | undefined): token is MultiLineCommentToken;
46
- export declare function assertMultiLineCommentToken(token: Token | undefined): asserts token is MultiLineCommentToken;
47
- export declare function asMultiLineCommentToken(token: Token | undefined): MultiLineCommentToken;
48
46
  export declare function isOperatorToken<T extends SymbolicOperator>(token: Token | undefined | undefined, operatorName?: T): token is OperatorToken<T>;
49
47
  export declare function assertOperatorToken<T extends SymbolicOperator>(token: Token | undefined | undefined, operatorName?: T): asserts token is OperatorToken<T>;
50
48
  export declare function asOperatorToken<T extends SymbolicOperator>(token: Token | undefined | undefined, operatorName?: T): OperatorToken<T>;
@@ -9,5 +9,6 @@ export declare const tokenizeSymbol: Tokenizer<SymbolToken>;
9
9
  export declare const tokenizeReservedSymbolToken: Tokenizer<ReservedSymbolToken>;
10
10
  export declare const tokenizeOperator: Tokenizer<OperatorToken>;
11
11
  export declare const tokenizeMultiLineComment: Tokenizer<MultiLineCommentToken>;
12
+ export declare const tokenizeShebang: Tokenizer<SingleLineCommentToken>;
12
13
  export declare const tokenizeSingleLineComment: Tokenizer<SingleLineCommentToken>;
13
14
  export declare const tokenizers: [Tokenizer<WhitespaceToken>, Tokenizer<MultiLineCommentToken>, Tokenizer<SingleLineCommentToken>, Tokenizer<ReservedSymbolToken>, Tokenizer<LParenToken>, Tokenizer<RParenToken>, Tokenizer<LBracketToken>, Tokenizer<RBracketToken>, Tokenizer<LBraceToken>, Tokenizer<RBraceToken>, Tokenizer<DocStringToken>, Tokenizer<StringToken>, Tokenizer<RegexpShorthandToken>, Tokenizer<BasePrefixedNumberToken>, Tokenizer<NumberToken>, Tokenizer<OperatorToken>, Tokenizer<SymbolToken>];