mambascript 0.5.4 → 2.0.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/README.md +509 -267
  3. package/bin/mamba +1 -258
  4. package/decision.js +1 -246
  5. package/docs/coverage.md +70 -0
  6. package/docs/features.md +3348 -0
  7. package/docs/perf.md +94 -0
  8. package/docs/reference.md +1295 -0
  9. package/docs/vs-coffeescript.md +1593 -0
  10. package/docs/vs-iced-coffeescript.md +626 -0
  11. package/docs/vs-typescript.md +107 -0
  12. package/esm.js +8 -0
  13. package/jest.js +33 -0
  14. package/lib/black.js +17 -13
  15. package/lib/browser.js +2 -4
  16. package/lib/cli.js +207 -136
  17. package/lib/compiler.js +1162 -93
  18. package/lib/decision.js +10 -10
  19. package/lib/diagnostics.js +219 -0
  20. package/lib/esm-hooks.js +60 -0
  21. package/lib/fast-parser.js +3469 -0
  22. package/lib/functional-helpers.js +26 -9
  23. package/lib/helpers.js +67 -50
  24. package/lib/js-nodes.js +151 -12
  25. package/lib/lexer.js +1499 -0
  26. package/lib/light-module.js +200 -63
  27. package/lib/mamba.js +372 -0
  28. package/lib/module.js +23 -172
  29. package/lib/nodes.js +84 -21
  30. package/lib/optimiser.js +29 -9
  31. package/lib/optparse.js +32 -15
  32. package/lib/parser.js +9433 -4840
  33. package/lib/preprocessor.js +3 -5
  34. package/lib/register.js +49 -56
  35. package/lib/repl.js +28 -9
  36. package/lib/reporter.js +106 -69
  37. package/lib/run.js +3 -5
  38. package/lib/string-scanner.js +94 -0
  39. package/lib/syntax-tables.js +480 -0
  40. package/lib/type-checker.js +258 -44
  41. package/lib/type-helpers.js +28 -10
  42. package/lib/type-resolver.js +256 -34
  43. package/lib/type-scope.js +10 -6
  44. package/lib/type-walker.js +664 -85
  45. package/lib/types.js +17 -7
  46. package/lib/underscore.js +170 -76
  47. package/lib/unicode-classes.js +122 -0
  48. package/mambaview.js +1 -0
  49. package/package.json +49 -46
  50. package/stdlib.js +1 -0
  51. package/vendor/README.md +40 -0
  52. package/vendor/escodegen/LICENSE.BSD +19 -0
  53. package/vendor/escodegen/escodegen.js +2289 -0
  54. package/vendor/estraverse/LICENSE.BSD +19 -0
  55. package/vendor/estraverse/estraverse.js +706 -0
  56. package/vendor/mambacodegen/LICENSE +24 -0
  57. package/vendor/mambacodegen/lib/mscodegen.js +620 -0
  58. package/vendor/patches/escodegen.diff +130 -0
  59. package/vendor/patches/estraverse.diff +51 -0
  60. package/vendor/patches/pegjs.diff +70 -0
  61. package/vendor/patches/source-map.diff +160 -0
  62. package/vendor/source-map/LICENSE +28 -0
  63. package/vendor/source-map/lib/source-map/array-set.js +92 -0
  64. package/vendor/source-map/lib/source-map/base64-vlq.js +140 -0
  65. package/vendor/source-map/lib/source-map/base64.js +38 -0
  66. package/vendor/source-map/lib/source-map/binary-search.js +77 -0
  67. package/vendor/source-map/lib/source-map/source-map-consumer.js +404 -0
  68. package/vendor/source-map/lib/source-map/source-map-generator.js +229 -0
  69. package/vendor/source-map/lib/source-map/source-node.js +201 -0
  70. package/vendor/source-map/lib/source-map/util.js +57 -0
  71. package/vendor/source-map/lib/source-map.js +8 -0
  72. package/bin/fix +0 -17
  73. package/bin/updateImports +0 -46
  74. package/build.js +0 -25
  75. package/lib/module-esm.js +0 -901
  76. package/lib/pegjs-kofu-plugin.js +0 -35
  77. package/lib/pegjs-mamba-plugin.js +0 -35
  78. package/lib/processor-esm.js +0 -507
  79. package/mamba +0 -259
  80. package/msast.js +0 -1
  81. package/utils/gulp-mamba.js +0 -29
  82. /package/{lib/esm.js → vendor/patches/mambacodegen.diff} +0 -0
@@ -1,9 +1,7 @@
1
- // Generated by MambaScript 0.5.2
2
- var present = console.log;
3
- // Generated by MambaScript 0.5.2
1
+ // Generated by MambaScript 2.0.0
4
2
  var DEDENT, INDENT, pointToErrorLocation, Preprocessor, reminder, StringScanner, TERM, ws;
5
3
  pointToErrorLocation = require('./helpers').pointToErrorLocation;
6
- StringScanner = require('StringScanner');
4
+ StringScanner = require('./string-scanner');
7
5
  reminder = 'no big deal take a look at your code. Are you sure you are following the KOFU principles of writing Unfancy Typed JavaScript';
8
6
  this.Preprocessor = Preprocessor = function () {
9
7
  ws = '\\t\\x0B\\f\\r \\xA0\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000\\uFEFF';
@@ -328,4 +326,4 @@ this.Preprocessor = Preprocessor = function () {
328
326
  return this.preprocessed;
329
327
  };
330
328
  return Preprocessor;
331
- }();
329
+ }();
package/lib/register.js CHANGED
@@ -1,89 +1,82 @@
1
- // Generated by MambaScript 0.5.2
2
- var present = console.log;
3
- // Generated by MambaScript 0.5.2
4
- var argv, child_process, coffeeBinary, compile, compileWithOriginalCoffee, fork, fs, MambaScript, path, runModule;
1
+ // Generated by MambaScript 2.0.0
2
+ var child_process, compile, ext, fork, fs, mambaBinary, MambaScript, path, runModule, typeCheckMode;
5
3
  child_process = require('child_process');
6
4
  fs = require('fs');
7
5
  path = require('path');
8
6
  MambaScript = require('./module');
9
7
  runModule = require('./run').runModule;
10
- module.exports = !(null != require.extensions['.coffee']);
11
- argv = require('kofu-optimist').boolean('self').argv;
8
+ module.exports = !(null != require.extensions['.mamba']);
9
+ typeCheckMode = function () {
10
+ return process.env.MAMBA_TYPECHECK || 'warn';
11
+ };
12
12
  compile = function (module, filename, opts) {
13
13
  var csAst, input, js, jsAst;
14
+ if (null == opts)
15
+ opts = {};
14
16
  input = fs.readFileSync(filename, 'utf8');
17
+ if (null != opts.raw)
18
+ opts.raw;
19
+ else
20
+ opts.raw = true;
21
+ if (null != opts.filename)
22
+ opts.filename;
23
+ else
24
+ opts.filename = filename;
25
+ if (null != opts.inputSource)
26
+ opts.inputSource;
27
+ else
28
+ opts.inputSource = filename;
29
+ if (null != opts.typeCheck)
30
+ opts.typeCheck;
31
+ else
32
+ opts.typeCheck = typeCheckMode();
15
33
  csAst = MambaScript.parse(input, opts);
16
- jsAst = MambaScript.compile(csAst);
34
+ jsAst = MambaScript.compile(csAst, { stdlibPath: MambaScript.stdlibPath });
17
35
  js = MambaScript.js(jsAst);
18
36
  return runModule(module, js, jsAst, filename);
19
37
  };
20
- compileWithOriginalCoffee = function (module, filename, opts) {
21
- var input, js, OriginalCoffee;
22
- if (null == opts)
23
- opts = {};
24
- OriginalCoffee = require('coffeescript');
25
- input = fs.readFileSync(filename, 'utf8');
26
- js = OriginalCoffee.compile(input, opts);
27
- return runModule(module, js, null, filename);
28
- };
29
- require.extensions['.typed.coffee'] = function (module, filename) {
30
- return compile(module, filename, {
31
- raw: true,
32
- typeCheck: true
33
- });
34
- };
35
- require.extensions['.coffee'] = function (module, filename) {
36
- if (argv.self) {
37
- return compile(module, filename, { raw: true });
38
- } else {
39
- return compileWithOriginalCoffee(module, filename, {
40
- raw: true,
41
- bare: argv.bare
42
- });
43
- }
44
- };
38
+ for (var cache$ = [
39
+ '.mamba',
40
+ '.kofu',
41
+ '.coffee',
42
+ '.tcoffee',
43
+ '.typed.coffee'
44
+ ], i$ = 0, length$ = cache$.length; i$ < length$; ++i$) {
45
+ ext = cache$[i$];
46
+ (function (ext) {
47
+ return require.extensions[ext] = function (module, filename) {
48
+ return compile(module, filename);
49
+ };
50
+ }(ext));
51
+ }
45
52
  require.extensions['.litcoffee'] = function (module, filename) {
46
- return compile(module, filename, {
47
- raw: true,
48
- literate: true
49
- });
50
- };
51
- require.extensions['.tcoffee'] = function (module, filename) {
52
- return compile(module, filename, {
53
- raw: true,
54
- typeCheck: true
55
- });
56
- };
57
- require.extensions['.mamba'] = function (module, filename) {
58
- return compile(module, filename, {
59
- raw: true,
60
- typeCheck: true
61
- });
53
+ return compile(module, filename, { literate: true });
62
54
  };
63
55
  fork = child_process.fork;
64
- if (!fork.coffeePatched) {
65
- coffeeBinary = path.resolve('bin', 'mamba');
56
+ if (!fork.mambaPatched) {
57
+ mambaBinary = path.join(__dirname, '..', 'bin', 'mamba');
66
58
  child_process.fork = function (file, args, options) {
67
59
  if (null == args)
68
60
  args = [];
69
61
  if (null == options)
70
62
  options = {};
71
63
  if (in$(path.extname(file), [
64
+ '.mamba',
65
+ '.kofu',
72
66
  '.coffee',
73
67
  '.litcoffee',
74
68
  '.tcoffee',
75
- '.typed.coffee',
76
- '.mamba'
69
+ '.typed.coffee'
77
70
  ])) {
78
71
  if (!Array.isArray(args)) {
79
- args = [];
80
72
  options = args || {};
73
+ args = [];
81
74
  }
82
- options.execPath || (options.execPath = coffeeBinary);
75
+ options.execPath || (options.execPath = mambaBinary);
83
76
  }
84
77
  return fork(file, args, options);
85
78
  };
86
- child_process.fork.coffeePatched = true;
79
+ child_process.fork.mambaPatched = true;
87
80
  }
88
81
  delete require.cache[__filename];
89
82
  function in$(member, list) {
@@ -91,4 +84,4 @@ function in$(member, list) {
91
84
  if (i in list && list[i] === member)
92
85
  return true;
93
86
  return false;
94
- }
87
+ }
package/lib/repl.js CHANGED
@@ -1,6 +1,4 @@
1
- // Generated by MambaScript 0.5.2
2
- var present = console.log;
3
- // Generated by MambaScript 0.5.2
1
+ // Generated by MambaScript 2.0.0
4
2
  var addHistory, addMultilineHandler, fs, MambaScript, merge, MS, nodeREPL, path, reporter, vm;
5
3
  fs = require('fs');
6
4
  path = require('path');
@@ -11,12 +9,19 @@ MS = require('./nodes');
11
9
  merge = require('./helpers').merge;
12
10
  reporter = require('./reporter');
13
11
  addMultilineHandler = function (repl) {
14
- var buffer, cache$, enabled, inputStream, nodeLineListener, outputStream, rli;
12
+ var buffer, cache$, cache$1, continuationPrompt, enabled, initialPrompt, inputStream, nodeLineListener, outputStream, promptText, rli;
15
13
  cache$ = repl;
16
14
  inputStream = cache$.inputStream;
17
15
  outputStream = cache$.outputStream;
18
16
  rli = repl;
19
17
  enabled = false;
18
+ promptText = (cache$1 = 'function' === typeof repl.getPrompt ? repl.getPrompt() : void 0, null != cache$1 ? cache$1 : null != repl._prompt ? repl._prompt : '');
19
+ initialPrompt = promptText.replace(/^[^> ]*/, function (x) {
20
+ return x.replace(/./g, '-');
21
+ });
22
+ continuationPrompt = promptText.replace(/^[^> ]*>?/, function (x) {
23
+ return x.replace(/./g, '.');
24
+ });
20
25
  buffer = '';
21
26
  nodeLineListener = rli.listeners('line')[0];
22
27
  rli.removeListener('line', nodeLineListener);
@@ -35,7 +40,7 @@ addMultilineHandler = function (repl) {
35
40
  if (enabled) {
36
41
  if (!buffer.match(/\n/)) {
37
42
  enabled = !enabled;
38
- rli.setPrompt(repl.prompt);
43
+ rli.setPrompt(promptText);
39
44
  rli.prompt(true);
40
45
  return;
41
46
  }
@@ -86,13 +91,13 @@ addHistory = function (repl, filename, maxSize) {
86
91
  repl.on('exit', function () {
87
92
  return fs.closeSync(fd);
88
93
  });
89
- return repl.commands['.history'] = {
94
+ return repl.defineCommand('history', {
90
95
  help: 'Show command history',
91
96
  action: function () {
92
97
  repl.outputStream.write('' + repl.history.slice().reverse().join('\n') + '\n');
93
98
  return repl.displayPrompt();
94
99
  }
95
- };
100
+ });
96
101
  };
97
102
  module.exports = {
98
103
  start: function (opts) {
@@ -122,7 +127,9 @@ module.exports = {
122
127
  try {
123
128
  inputAst = MambaScript.parse(input, {
124
129
  filename: filename,
125
- raw: true
130
+ raw: true,
131
+ persistScope: true,
132
+ typeCheck: 'warn'
126
133
  });
127
134
  transformedAst = new MS.AssignOp(new MS.Identifier('_'), inputAst.body);
128
135
  jsAst = MambaScript.compile(transformedAst, {
@@ -138,6 +145,18 @@ module.exports = {
138
145
  }
139
146
  });
140
147
  repl = nodeREPL.start(opts);
148
+ if (null != repl.context['present'])
149
+ repl.context['present'];
150
+ else
151
+ repl.context['present'] = console.log;
152
+ if (null != repl.context['complain'])
153
+ repl.context['complain'];
154
+ else
155
+ repl.context['complain'] = console.warn;
156
+ if (null != repl.context.stdlib)
157
+ repl.context.stdlib;
158
+ else
159
+ repl.context.stdlib = require('./underscore');
141
160
  repl.on('exit', function () {
142
161
  return repl.outputStream.write('\n');
143
162
  });
@@ -146,4 +165,4 @@ module.exports = {
146
165
  addHistory(repl, opts.historyFile, opts.historyMaxInputSize);
147
166
  return repl;
148
167
  }
149
- };
168
+ };
package/lib/reporter.js CHANGED
@@ -1,90 +1,127 @@
1
- // Generated by MambaScript 0.5.2
2
- var present = console.log;
3
- // Generated by MambaScript 0.5.2
4
- var debug, pj, render, Reporter, TypeError;
5
- pj = function () {
6
- try {
7
- return require('prettyjson');
8
- } catch (e$) {
9
- return;
10
- }
11
- }.call(this);
12
- render = function (obj) {
13
- if (null != pj)
14
- return pj.render(obj);
15
- };
16
- TypeError = require('./type-helpers').TypeError;
17
- debug = require('./helpers').debug;
18
- require('colors');
1
+ // Generated by MambaScript 2.0.0
2
+ var Diagnostics, Reporter;
3
+ Diagnostics = require('./diagnostics');
19
4
  Reporter = function () {
20
5
  function Reporter() {
21
6
  var instance$;
22
7
  instance$ = this;
23
- this.add_warning = function (a, b) {
8
+ this.add_warning = function (a, b, c) {
24
9
  return Reporter.prototype.add_warning.apply(instance$, arguments);
25
10
  };
11
+ this.add_error = function (a, b, c) {
12
+ return Reporter.prototype.add_error.apply(instance$, arguments);
13
+ };
26
14
  this.clean = function () {
27
15
  return Reporter.prototype.clean.apply(instance$, arguments);
28
16
  };
29
- this.add_error = function (a, b) {
30
- return Reporter.prototype.add_error.apply(instance$, arguments);
31
- };
32
- this.errors = [];
33
- this.warnings = [];
17
+ this.clean();
34
18
  }
19
+ Reporter.prototype.clean = function () {
20
+ this.errors = [];
21
+ return this.warnings = [];
22
+ };
35
23
  Reporter.prototype.has_errors = function () {
36
- this.errors = this.errors.filter(function (param$) {
37
- var cache$, node, text;
38
- {
39
- cache$ = param$;
40
- node = cache$[0];
41
- text = cache$[1];
42
- }
43
- return node.raw === true;
44
- });
45
24
  return this.errors.length > 0;
46
25
  };
47
26
  Reporter.prototype.has_warnings = function () {
48
- this.warnings = this.warnings.filter(function (param$) {
49
- var cache$, node, text;
50
- {
51
- cache$ = param$;
52
- node = cache$[0];
53
- text = cache$[1];
54
- }
55
- return node.raw === true;
56
- });
57
27
  return this.warnings.length > 0;
58
28
  };
59
- Reporter.prototype.report = function () {
60
- var errors;
61
- errors = this.errors.map(function (param$) {
62
- var cache$, node, text;
63
- {
64
- cache$ = param$;
65
- node = cache$[0];
66
- text = cache$[1];
67
- }
68
- return 'L' + node.line + ' ' + node.raw.inverse + ' ' + text.red + ' If you think that you found a bug in the language this error is generated from src/reporter.mamba help me improve it... this reporter is exported and used around the whole language';
69
- });
70
- return '' + errors.join('\n') + '';
29
+ Reporter.prototype.add_error = function (node, text, extra) {
30
+ if (null == extra)
31
+ extra = {};
32
+ return this.errors.push(this.entry(node, text, extra));
71
33
  };
72
- Reporter.prototype.add_error = function (node, text) {
73
- return this.errors.push([
74
- node,
75
- text
76
- ]);
34
+ Reporter.prototype.add_warning = function (node, text, extra) {
35
+ if (null == extra)
36
+ extra = {};
37
+ return this.warnings.push(this.entry(node, text, extra));
77
38
  };
78
- Reporter.prototype.clean = function () {
79
- return this.errors = [];
39
+ Reporter.prototype.entry = function (node, text, extra) {
40
+ var endColumn;
41
+ if (null == extra)
42
+ extra = {};
43
+ endColumn = extra.endColumn;
44
+ if (!(null != endColumn) && null != (null != node ? node.column : void 0) && typeof node.raw === 'string' && node.raw.indexOf('\n') < 0)
45
+ endColumn = node.column + Math.max(1, node.raw.length);
46
+ return {
47
+ node: node,
48
+ text: text,
49
+ line: null != node ? node.line : void 0,
50
+ column: null != node ? node.column : void 0,
51
+ raw: null != node ? node.raw : void 0,
52
+ code: extra.code,
53
+ why: extra.why,
54
+ fix: extra.fix,
55
+ endColumn: endColumn
56
+ };
80
57
  };
81
- Reporter.prototype.add_warning = function (node) {
82
- var ws;
83
- ws = arguments.length > 1 ? [].slice.call(arguments, 1) : [];
84
- return this.warnings.push([
85
- node,
86
- ws.join('')
87
- ]);
58
+ Reporter.prototype.diagnostic = function (e, ctx, kind) {
59
+ var d, headline, lines, why;
60
+ if (null == ctx)
61
+ ctx = {};
62
+ if (null == kind)
63
+ kind = 'TypeError';
64
+ lines = e.text.trim().split('\n');
65
+ headline = lines[0];
66
+ why = null != e.why ? e.why : lines.length > 1 ? lines.slice(1).join('\n').trim() : void 0;
67
+ d = {
68
+ kind: kind,
69
+ code: e.code,
70
+ file: null != ctx.file ? ctx.file : '<input>',
71
+ line: e.line,
72
+ column: e.column,
73
+ endColumn: e.endColumn,
74
+ headline: headline,
75
+ why: why,
76
+ fix: e.fix,
77
+ source: ctx.source
78
+ };
79
+ if (!(null != d.why) && !(null != ctx.source) && null != e.raw)
80
+ d.why = '' + e.raw;
81
+ return d;
82
+ };
83
+ Reporter.prototype.format = function (e, ctx, kind) {
84
+ if (null == ctx)
85
+ ctx = {};
86
+ if (null == kind)
87
+ kind = 'TypeError';
88
+ return Diagnostics.render(this.diagnostic(e, ctx, kind));
89
+ };
90
+ Reporter.prototype.report = function (ctx) {
91
+ var e;
92
+ return function (accum$) {
93
+ for (var i$ = 0, length$ = this.errors.length; i$ < length$; ++i$) {
94
+ e = this.errors[i$];
95
+ accum$.push(this.format(e, ctx, 'TypeError'));
96
+ }
97
+ return accum$;
98
+ }.call(this, []).join('\n\n');
99
+ };
100
+ Reporter.prototype.reportWarnings = function (ctx) {
101
+ var w;
102
+ return function (accum$) {
103
+ for (var i$ = 0, length$ = this.warnings.length; i$ < length$; ++i$) {
104
+ w = this.warnings[i$];
105
+ accum$.push(this.format(w, ctx, 'TypeWarning'));
106
+ }
107
+ return accum$;
108
+ }.call(this, []).join('\n\n');
109
+ };
110
+ Reporter.prototype.toJSON = function (ctx) {
111
+ var e, w;
112
+ return function (accum$) {
113
+ for (var i$ = 0, length$ = this.errors.length; i$ < length$; ++i$) {
114
+ e = this.errors[i$];
115
+ accum$.push(Diagnostics.toJSON(this.diagnostic(e, ctx, 'TypeError')));
116
+ }
117
+ return accum$;
118
+ }.call(this, []).concat(function (accum$1) {
119
+ for (var i$1 = 0, length$1 = this.warnings.length; i$1 < length$1; ++i$1) {
120
+ w = this.warnings[i$1];
121
+ accum$1.push(Diagnostics.toJSON(this.diagnostic(w, ctx, 'TypeWarning')));
122
+ }
123
+ return accum$1;
124
+ }.call(this, []));
88
125
  };
89
126
  Reporter.prototype.dump = function (node, prefix) {
90
127
  var key, next, prop, type, val;
@@ -116,4 +153,4 @@ Reporter = function () {
116
153
  };
117
154
  return Reporter;
118
155
  }();
119
- module.exports = new Reporter;
156
+ module.exports = new Reporter;
package/lib/run.js CHANGED
@@ -1,11 +1,9 @@
1
- // Generated by MambaScript 0.5.2
2
- var present = console.log;
3
- // Generated by MambaScript 0.5.2
1
+ // Generated by MambaScript 2.0.0
4
2
  var formatSourcePosition, MambaScript, Module, patched, patchStackTrace, path, runMain, runModule, SourceMapConsumer;
5
3
  path = require('path');
6
4
  Module = require('module');
7
5
  MambaScript = require('./module');
8
- SourceMapConsumer = require('source-map').SourceMapConsumer;
6
+ SourceMapConsumer = require('../vendor/source-map/lib/source-map').SourceMapConsumer;
9
7
  patched = false;
10
8
  patchStackTrace = function () {
11
9
  if (patched)
@@ -105,4 +103,4 @@ runModule = function (module, jsSource, jsAst, filename) {
105
103
  module.exports = {
106
104
  runMain: runMain,
107
105
  runModule: runModule
108
- };
106
+ };
@@ -0,0 +1,94 @@
1
+ // Generated by MambaScript 2.0.0
2
+ var StringScanner;
3
+ StringScanner = function () {
4
+ function StringScanner(str) {
5
+ if (null == str)
6
+ str = '';
7
+ this.str = '' + str;
8
+ this.pos = 0;
9
+ this.lastMatch = {
10
+ str: null,
11
+ captures: []
12
+ };
13
+ }
14
+ StringScanner.prototype.bol = function () {
15
+ return this.pos <= 0 || this.str[this.pos - 1] === '\n';
16
+ };
17
+ StringScanner.prototype.captures = function () {
18
+ return this.lastMatch.captures;
19
+ };
20
+ StringScanner.prototype.check = function (pattern) {
21
+ var matches, rest;
22
+ rest = this.str.substr(this.pos);
23
+ if (!(rest.search(pattern) === 0)) {
24
+ this.lastMatch = {
25
+ str: null,
26
+ captures: []
27
+ };
28
+ return null;
29
+ }
30
+ matches = rest.match(pattern);
31
+ this.lastMatch = {
32
+ str: matches[0],
33
+ captures: matches.slice(1)
34
+ };
35
+ return this.lastMatch.str;
36
+ };
37
+ StringScanner.prototype.scan = function (pattern) {
38
+ var chk;
39
+ chk = this.check(pattern);
40
+ if (null != chk)
41
+ this.pos += chk.length;
42
+ return chk;
43
+ };
44
+ StringScanner.prototype.eos = function () {
45
+ return this.pos === this.str.length;
46
+ };
47
+ StringScanner.prototype.match = function () {
48
+ return this.lastMatch.str;
49
+ };
50
+ StringScanner.prototype.matched = function () {
51
+ return null != this.lastMatch.str;
52
+ };
53
+ StringScanner.prototype.peek = function (len) {
54
+ return this.str.substr(this.pos, len);
55
+ };
56
+ StringScanner.prototype.pointer = function () {
57
+ return this.pos;
58
+ };
59
+ StringScanner.prototype.position = function () {
60
+ return this.pos;
61
+ };
62
+ StringScanner.prototype.rest = function () {
63
+ return this.str.substr(this.pos);
64
+ };
65
+ StringScanner.prototype.string = function () {
66
+ return this.str;
67
+ };
68
+ StringScanner.prototype.setPointer = function (pos) {
69
+ pos = +pos;
70
+ if (pos < 0)
71
+ pos = 0;
72
+ if (pos > this.str.length)
73
+ pos = this.str.length;
74
+ return this.pos = pos;
75
+ };
76
+ StringScanner.prototype.reset = function () {
77
+ this.lastMatch = {
78
+ str: null,
79
+ captures: []
80
+ };
81
+ this.pos = 0;
82
+ return this;
83
+ };
84
+ StringScanner.prototype.terminate = function () {
85
+ this.pos = this.str.length;
86
+ this.lastMatch = {
87
+ str: null,
88
+ captures: []
89
+ };
90
+ return this;
91
+ };
92
+ return StringScanner;
93
+ }();
94
+ module.exports = StringScanner;