@codingame/monaco-vscode-editor-api 11.1.1 → 12.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 (35) hide show
  1. package/esm/vs/editor/browser/config/tabFocus.d.ts +1 -0
  2. package/esm/vs/editor/browser/coreCommands.d.ts +1 -0
  3. package/esm/vs/editor/common/commands/shiftCommand.d.ts +1 -0
  4. package/esm/vs/editor/contrib/bracketMatching/browser/bracketMatching.d.ts +1 -0
  5. package/esm/vs/editor/contrib/clipboard/browser/clipboard.d.ts +1 -0
  6. package/esm/vs/editor/contrib/contextmenu/browser/contextmenu.d.ts +1 -0
  7. package/esm/vs/editor/contrib/cursorUndo/browser/cursorUndo.d.ts +1 -0
  8. package/esm/vs/editor/contrib/find/browser/findController.d.ts +1 -0
  9. package/esm/vs/editor/contrib/format/browser/formatActions.d.ts +1 -0
  10. package/esm/vs/editor/contrib/hover/browser/hoverContribution.d.ts +1 -0
  11. package/esm/vs/editor/contrib/hover/browser/hoverContribution.js +1 -0
  12. package/esm/vs/editor/contrib/inlineCompletions/browser/inlineCompletions.contribution.d.ts +1 -0
  13. package/esm/vs/editor/editor.api.d.ts +7 -2
  14. package/esm/vs/editor/editor.api.js +4 -2311
  15. package/package.json +14 -9
  16. package/vscode/src/vs/editor/editor.api.d.ts +9338 -0
  17. package/vscode/src/vs/editor/editor.api.js +35 -0
  18. package/vscode/src/vs/editor/standalone/browser/colorizer.d.ts +17 -0
  19. package/vscode/src/vs/editor/standalone/browser/colorizer.js +178 -0
  20. package/vscode/src/vs/editor/standalone/browser/standalone-tokens.css.js +6 -0
  21. package/vscode/src/vs/editor/standalone/browser/standaloneEditor.d.ts +73 -0
  22. package/vscode/src/vs/editor/standalone/browser/standaloneEditor.js +347 -0
  23. package/vscode/src/vs/editor/standalone/browser/standaloneLanguages.d.ts +114 -0
  24. package/vscode/src/vs/editor/standalone/browser/standaloneLanguages.js +444 -0
  25. package/vscode/src/vs/editor/standalone/browser/standaloneWebWorker.d.ts +15 -0
  26. package/vscode/src/vs/editor/standalone/browser/standaloneWebWorker.js +66 -0
  27. package/vscode/src/vs/editor/standalone/common/monarch/monarchCommon.d.ts +72 -0
  28. package/vscode/src/vs/editor/standalone/common/monarch/monarchCommon.js +111 -0
  29. package/vscode/src/vs/editor/standalone/common/monarch/monarchCompile.d.ts +3 -0
  30. package/vscode/src/vs/editor/standalone/common/monarch/monarchCompile.js +476 -0
  31. package/vscode/src/vs/editor/standalone/common/monarch/monarchLexer.d.ts +33 -0
  32. package/vscode/src/vs/editor/standalone/common/monarch/monarchLexer.js +707 -0
  33. package/vscode/src/vs/editor/standalone/common/monarch/monarchTypes.d.ts +46 -0
  34. package/editor.api.d.ts +0 -7
  35. package/monaco.d.ts +0 -10
@@ -0,0 +1,707 @@
1
+
2
+ import { __decorate, __param } from 'vscode/external/tslib/tslib.es6';
3
+ import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
4
+ import { Token, TokenizationRegistry, TokenizationResult, EncodedTokenizationResult } from 'vscode/vscode/vs/editor/common/languages';
5
+ import { nullTokenize, nullTokenizeEncoded, NullState } from 'vscode/vscode/vs/editor/common/languages/nullTokenize';
6
+ import { findRules, createError, isIAction, isFuzzyAction, substituteMatches, log, isString, sanitize, fixCase, MonarchBracket } from './monarchCommon.js';
7
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
8
+ import { LanguageId, MetadataConsts } from 'vscode/vscode/vs/editor/common/encodedTokenAttributes';
9
+
10
+ var MonarchTokenizer_1;
11
+ const CACHE_STACK_DEPTH = 5;
12
+ class MonarchStackElementFactory {
13
+ static { this._INSTANCE = ( new MonarchStackElementFactory(CACHE_STACK_DEPTH)); }
14
+ static create(parent, state) {
15
+ return this._INSTANCE.create(parent, state);
16
+ }
17
+ constructor(maxCacheDepth) {
18
+ this._maxCacheDepth = maxCacheDepth;
19
+ this._entries = Object.create(null);
20
+ }
21
+ create(parent, state) {
22
+ if (parent !== null && parent.depth >= this._maxCacheDepth) {
23
+ return ( new MonarchStackElement(parent, state));
24
+ }
25
+ let stackElementId = MonarchStackElement.getStackElementId(parent);
26
+ if (stackElementId.length > 0) {
27
+ stackElementId += '|';
28
+ }
29
+ stackElementId += state;
30
+ let result = this._entries[stackElementId];
31
+ if (result) {
32
+ return result;
33
+ }
34
+ result = ( new MonarchStackElement(parent, state));
35
+ this._entries[stackElementId] = result;
36
+ return result;
37
+ }
38
+ }
39
+ class MonarchStackElement {
40
+ constructor(parent, state) {
41
+ this.parent = parent;
42
+ this.state = state;
43
+ this.depth = (this.parent ? this.parent.depth : 0) + 1;
44
+ }
45
+ static getStackElementId(element) {
46
+ let result = '';
47
+ while (element !== null) {
48
+ if (result.length > 0) {
49
+ result += '|';
50
+ }
51
+ result += element.state;
52
+ element = element.parent;
53
+ }
54
+ return result;
55
+ }
56
+ static _equals(a, b) {
57
+ while (a !== null && b !== null) {
58
+ if (a === b) {
59
+ return true;
60
+ }
61
+ if (a.state !== b.state) {
62
+ return false;
63
+ }
64
+ a = a.parent;
65
+ b = b.parent;
66
+ }
67
+ if (a === null && b === null) {
68
+ return true;
69
+ }
70
+ return false;
71
+ }
72
+ equals(other) {
73
+ return MonarchStackElement._equals(this, other);
74
+ }
75
+ push(state) {
76
+ return MonarchStackElementFactory.create(this, state);
77
+ }
78
+ pop() {
79
+ return this.parent;
80
+ }
81
+ popall() {
82
+ let result = this;
83
+ while (result.parent) {
84
+ result = result.parent;
85
+ }
86
+ return result;
87
+ }
88
+ switchTo(state) {
89
+ return MonarchStackElementFactory.create(this.parent, state);
90
+ }
91
+ }
92
+ class EmbeddedLanguageData {
93
+ constructor(languageId, state) {
94
+ this.languageId = languageId;
95
+ this.state = state;
96
+ }
97
+ equals(other) {
98
+ return (this.languageId === other.languageId
99
+ && this.state.equals(other.state));
100
+ }
101
+ clone() {
102
+ const stateClone = this.state.clone();
103
+ if (stateClone === this.state) {
104
+ return this;
105
+ }
106
+ return ( new EmbeddedLanguageData(this.languageId, this.state));
107
+ }
108
+ }
109
+ class MonarchLineStateFactory {
110
+ static { this._INSTANCE = ( new MonarchLineStateFactory(CACHE_STACK_DEPTH)); }
111
+ static create(stack, embeddedLanguageData) {
112
+ return this._INSTANCE.create(stack, embeddedLanguageData);
113
+ }
114
+ constructor(maxCacheDepth) {
115
+ this._maxCacheDepth = maxCacheDepth;
116
+ this._entries = Object.create(null);
117
+ }
118
+ create(stack, embeddedLanguageData) {
119
+ if (embeddedLanguageData !== null) {
120
+ return ( new MonarchLineState(stack, embeddedLanguageData));
121
+ }
122
+ if (stack !== null && stack.depth >= this._maxCacheDepth) {
123
+ return ( new MonarchLineState(stack, embeddedLanguageData));
124
+ }
125
+ const stackElementId = MonarchStackElement.getStackElementId(stack);
126
+ let result = this._entries[stackElementId];
127
+ if (result) {
128
+ return result;
129
+ }
130
+ result = ( new MonarchLineState(stack, null));
131
+ this._entries[stackElementId] = result;
132
+ return result;
133
+ }
134
+ }
135
+ class MonarchLineState {
136
+ constructor(stack, embeddedLanguageData) {
137
+ this.stack = stack;
138
+ this.embeddedLanguageData = embeddedLanguageData;
139
+ }
140
+ clone() {
141
+ const embeddedlanguageDataClone = this.embeddedLanguageData ? this.embeddedLanguageData.clone() : null;
142
+ if (embeddedlanguageDataClone === this.embeddedLanguageData) {
143
+ return this;
144
+ }
145
+ return MonarchLineStateFactory.create(this.stack, this.embeddedLanguageData);
146
+ }
147
+ equals(other) {
148
+ if (!(other instanceof MonarchLineState)) {
149
+ return false;
150
+ }
151
+ if (!this.stack.equals(other.stack)) {
152
+ return false;
153
+ }
154
+ if (this.embeddedLanguageData === null && other.embeddedLanguageData === null) {
155
+ return true;
156
+ }
157
+ if (this.embeddedLanguageData === null || other.embeddedLanguageData === null) {
158
+ return false;
159
+ }
160
+ return this.embeddedLanguageData.equals(other.embeddedLanguageData);
161
+ }
162
+ }
163
+ class MonarchClassicTokensCollector {
164
+ constructor() {
165
+ this._tokens = [];
166
+ this._languageId = null;
167
+ this._lastTokenType = null;
168
+ this._lastTokenLanguage = null;
169
+ }
170
+ enterLanguage(languageId) {
171
+ this._languageId = languageId;
172
+ }
173
+ emit(startOffset, type) {
174
+ if (this._lastTokenType === type && this._lastTokenLanguage === this._languageId) {
175
+ return;
176
+ }
177
+ this._lastTokenType = type;
178
+ this._lastTokenLanguage = this._languageId;
179
+ this._tokens.push(new Token(startOffset, type, this._languageId));
180
+ }
181
+ nestedLanguageTokenize(embeddedLanguageLine, hasEOL, embeddedLanguageData, offsetDelta) {
182
+ const nestedLanguageId = embeddedLanguageData.languageId;
183
+ const embeddedModeState = embeddedLanguageData.state;
184
+ const nestedLanguageTokenizationSupport = TokenizationRegistry.get(nestedLanguageId);
185
+ if (!nestedLanguageTokenizationSupport) {
186
+ this.enterLanguage(nestedLanguageId);
187
+ this.emit(offsetDelta, '');
188
+ return embeddedModeState;
189
+ }
190
+ const nestedResult = nestedLanguageTokenizationSupport.tokenize(embeddedLanguageLine, hasEOL, embeddedModeState);
191
+ if (offsetDelta !== 0) {
192
+ for (const token of nestedResult.tokens) {
193
+ this._tokens.push(new Token(token.offset + offsetDelta, token.type, token.language));
194
+ }
195
+ }
196
+ else {
197
+ this._tokens = this._tokens.concat(nestedResult.tokens);
198
+ }
199
+ this._lastTokenType = null;
200
+ this._lastTokenLanguage = null;
201
+ this._languageId = null;
202
+ return nestedResult.endState;
203
+ }
204
+ finalize(endState) {
205
+ return new TokenizationResult(this._tokens, endState);
206
+ }
207
+ }
208
+ class MonarchModernTokensCollector {
209
+ constructor(languageService, theme) {
210
+ this._languageService = languageService;
211
+ this._theme = theme;
212
+ this._prependTokens = null;
213
+ this._tokens = [];
214
+ this._currentLanguageId = LanguageId.Null;
215
+ this._lastTokenMetadata = 0;
216
+ }
217
+ enterLanguage(languageId) {
218
+ this._currentLanguageId = this._languageService.languageIdCodec.encodeLanguageId(languageId);
219
+ }
220
+ emit(startOffset, type) {
221
+ const metadata = this._theme.match(this._currentLanguageId, type) | MetadataConsts.BALANCED_BRACKETS_MASK;
222
+ if (this._lastTokenMetadata === metadata) {
223
+ return;
224
+ }
225
+ this._lastTokenMetadata = metadata;
226
+ this._tokens.push(startOffset);
227
+ this._tokens.push(metadata);
228
+ }
229
+ static _merge(a, b, c) {
230
+ const aLen = (a !== null ? a.length : 0);
231
+ const bLen = b.length;
232
+ const cLen = (c !== null ? c.length : 0);
233
+ if (aLen === 0 && bLen === 0 && cLen === 0) {
234
+ return ( new Uint32Array(0));
235
+ }
236
+ if (aLen === 0 && bLen === 0) {
237
+ return c;
238
+ }
239
+ if (bLen === 0 && cLen === 0) {
240
+ return a;
241
+ }
242
+ const result = ( new Uint32Array(aLen + bLen + cLen));
243
+ if (a !== null) {
244
+ result.set(a);
245
+ }
246
+ for (let i = 0; i < bLen; i++) {
247
+ result[aLen + i] = b[i];
248
+ }
249
+ if (c !== null) {
250
+ result.set(c, aLen + bLen);
251
+ }
252
+ return result;
253
+ }
254
+ nestedLanguageTokenize(embeddedLanguageLine, hasEOL, embeddedLanguageData, offsetDelta) {
255
+ const nestedLanguageId = embeddedLanguageData.languageId;
256
+ const embeddedModeState = embeddedLanguageData.state;
257
+ const nestedLanguageTokenizationSupport = TokenizationRegistry.get(nestedLanguageId);
258
+ if (!nestedLanguageTokenizationSupport) {
259
+ this.enterLanguage(nestedLanguageId);
260
+ this.emit(offsetDelta, '');
261
+ return embeddedModeState;
262
+ }
263
+ const nestedResult = nestedLanguageTokenizationSupport.tokenizeEncoded(embeddedLanguageLine, hasEOL, embeddedModeState);
264
+ if (offsetDelta !== 0) {
265
+ for (let i = 0, len = nestedResult.tokens.length; i < len; i += 2) {
266
+ nestedResult.tokens[i] += offsetDelta;
267
+ }
268
+ }
269
+ this._prependTokens = MonarchModernTokensCollector._merge(this._prependTokens, this._tokens, nestedResult.tokens);
270
+ this._tokens = [];
271
+ this._currentLanguageId = 0;
272
+ this._lastTokenMetadata = 0;
273
+ return nestedResult.endState;
274
+ }
275
+ finalize(endState) {
276
+ return new EncodedTokenizationResult(MonarchModernTokensCollector._merge(this._prependTokens, this._tokens, null), endState);
277
+ }
278
+ }
279
+ let MonarchTokenizer = MonarchTokenizer_1 = class MonarchTokenizer extends Disposable {
280
+ constructor(languageService, standaloneThemeService, languageId, lexer, _configurationService) {
281
+ super();
282
+ this._configurationService = _configurationService;
283
+ this._languageService = languageService;
284
+ this._standaloneThemeService = standaloneThemeService;
285
+ this._languageId = languageId;
286
+ this._lexer = lexer;
287
+ this._embeddedLanguages = Object.create(null);
288
+ this.embeddedLoaded = Promise.resolve(undefined);
289
+ let emitting = false;
290
+ this._register(TokenizationRegistry.onDidChange((e) => {
291
+ if (emitting) {
292
+ return;
293
+ }
294
+ let isOneOfMyEmbeddedModes = false;
295
+ for (let i = 0, len = e.changedLanguages.length; i < len; i++) {
296
+ const language = e.changedLanguages[i];
297
+ if (this._embeddedLanguages[language]) {
298
+ isOneOfMyEmbeddedModes = true;
299
+ break;
300
+ }
301
+ }
302
+ if (isOneOfMyEmbeddedModes) {
303
+ emitting = true;
304
+ TokenizationRegistry.handleChange([this._languageId]);
305
+ emitting = false;
306
+ }
307
+ }));
308
+ this._maxTokenizationLineLength = this._configurationService.getValue('editor.maxTokenizationLineLength', {
309
+ overrideIdentifier: this._languageId
310
+ });
311
+ this._register(this._configurationService.onDidChangeConfiguration(e => {
312
+ if (e.affectsConfiguration('editor.maxTokenizationLineLength')) {
313
+ this._maxTokenizationLineLength = this._configurationService.getValue('editor.maxTokenizationLineLength', {
314
+ overrideIdentifier: this._languageId
315
+ });
316
+ }
317
+ }));
318
+ }
319
+ getLoadStatus() {
320
+ const promises = [];
321
+ for (const nestedLanguageId in this._embeddedLanguages) {
322
+ const tokenizationSupport = TokenizationRegistry.get(nestedLanguageId);
323
+ if (tokenizationSupport) {
324
+ if (tokenizationSupport instanceof MonarchTokenizer_1) {
325
+ const nestedModeStatus = tokenizationSupport.getLoadStatus();
326
+ if (nestedModeStatus.loaded === false) {
327
+ promises.push(nestedModeStatus.promise);
328
+ }
329
+ }
330
+ continue;
331
+ }
332
+ if (!TokenizationRegistry.isResolved(nestedLanguageId)) {
333
+ promises.push(TokenizationRegistry.getOrCreate(nestedLanguageId));
334
+ }
335
+ }
336
+ if (promises.length === 0) {
337
+ return {
338
+ loaded: true
339
+ };
340
+ }
341
+ return {
342
+ loaded: false,
343
+ promise: Promise.all(promises).then(_ => undefined)
344
+ };
345
+ }
346
+ getInitialState() {
347
+ const rootState = MonarchStackElementFactory.create(null, this._lexer.start);
348
+ return MonarchLineStateFactory.create(rootState, null);
349
+ }
350
+ tokenize(line, hasEOL, lineState) {
351
+ if (line.length >= this._maxTokenizationLineLength) {
352
+ return nullTokenize(this._languageId, lineState);
353
+ }
354
+ const tokensCollector = ( new MonarchClassicTokensCollector());
355
+ const endLineState = this._tokenize(line, hasEOL, lineState, tokensCollector);
356
+ return tokensCollector.finalize(endLineState);
357
+ }
358
+ tokenizeEncoded(line, hasEOL, lineState) {
359
+ if (line.length >= this._maxTokenizationLineLength) {
360
+ return nullTokenizeEncoded(this._languageService.languageIdCodec.encodeLanguageId(this._languageId), lineState);
361
+ }
362
+ const tokensCollector = ( new MonarchModernTokensCollector(
363
+ this._languageService,
364
+ this._standaloneThemeService.getColorTheme().tokenTheme
365
+ ));
366
+ const endLineState = this._tokenize(line, hasEOL, lineState, tokensCollector);
367
+ return tokensCollector.finalize(endLineState);
368
+ }
369
+ _tokenize(line, hasEOL, lineState, collector) {
370
+ if (lineState.embeddedLanguageData) {
371
+ return this._nestedTokenize(line, hasEOL, lineState, 0, collector);
372
+ }
373
+ else {
374
+ return this._myTokenize(line, hasEOL, lineState, 0, collector);
375
+ }
376
+ }
377
+ _findLeavingNestedLanguageOffset(line, state) {
378
+ let rules = this._lexer.tokenizer[state.stack.state];
379
+ if (!rules) {
380
+ rules = findRules(this._lexer, state.stack.state);
381
+ if (!rules) {
382
+ throw createError(this._lexer, 'tokenizer state is not defined: ' + state.stack.state);
383
+ }
384
+ }
385
+ let popOffset = -1;
386
+ let hasEmbeddedPopRule = false;
387
+ for (const rule of rules) {
388
+ if (!isIAction(rule.action) || rule.action.nextEmbedded !== '@pop') {
389
+ continue;
390
+ }
391
+ hasEmbeddedPopRule = true;
392
+ let regex = rule.resolveRegex(state.stack.state);
393
+ const regexSource = regex.source;
394
+ if (regexSource.substr(0, 4) === '^(?:' && regexSource.substr(regexSource.length - 1, 1) === ')') {
395
+ const flags = (regex.ignoreCase ? 'i' : '') + (regex.unicode ? 'u' : '');
396
+ regex = ( new RegExp(regexSource.substr(4, regexSource.length - 5), flags));
397
+ }
398
+ const result = line.search(regex);
399
+ if (result === -1 || (result !== 0 && rule.matchOnlyAtLineStart)) {
400
+ continue;
401
+ }
402
+ if (popOffset === -1 || result < popOffset) {
403
+ popOffset = result;
404
+ }
405
+ }
406
+ if (!hasEmbeddedPopRule) {
407
+ throw createError(this._lexer, 'no rule containing nextEmbedded: "@pop" in tokenizer embedded state: ' + state.stack.state);
408
+ }
409
+ return popOffset;
410
+ }
411
+ _nestedTokenize(line, hasEOL, lineState, offsetDelta, tokensCollector) {
412
+ const popOffset = this._findLeavingNestedLanguageOffset(line, lineState);
413
+ if (popOffset === -1) {
414
+ const nestedEndState = tokensCollector.nestedLanguageTokenize(line, hasEOL, lineState.embeddedLanguageData, offsetDelta);
415
+ return MonarchLineStateFactory.create(lineState.stack, ( new EmbeddedLanguageData(lineState.embeddedLanguageData.languageId, nestedEndState)));
416
+ }
417
+ const nestedLanguageLine = line.substring(0, popOffset);
418
+ if (nestedLanguageLine.length > 0) {
419
+ tokensCollector.nestedLanguageTokenize(nestedLanguageLine, false, lineState.embeddedLanguageData, offsetDelta);
420
+ }
421
+ const restOfTheLine = line.substring(popOffset);
422
+ return this._myTokenize(restOfTheLine, hasEOL, lineState, offsetDelta + popOffset, tokensCollector);
423
+ }
424
+ _safeRuleName(rule) {
425
+ if (rule) {
426
+ return rule.name;
427
+ }
428
+ return '(unknown)';
429
+ }
430
+ _myTokenize(lineWithoutLF, hasEOL, lineState, offsetDelta, tokensCollector) {
431
+ tokensCollector.enterLanguage(this._languageId);
432
+ const lineWithoutLFLength = lineWithoutLF.length;
433
+ const line = (hasEOL && this._lexer.includeLF ? lineWithoutLF + '\n' : lineWithoutLF);
434
+ const lineLength = line.length;
435
+ let embeddedLanguageData = lineState.embeddedLanguageData;
436
+ let stack = lineState.stack;
437
+ let pos = 0;
438
+ let groupMatching = null;
439
+ let forceEvaluation = true;
440
+ while (forceEvaluation || pos < lineLength) {
441
+ const pos0 = pos;
442
+ const stackLen0 = stack.depth;
443
+ const groupLen0 = groupMatching ? groupMatching.groups.length : 0;
444
+ const state = stack.state;
445
+ let matches = null;
446
+ let matched = null;
447
+ let action = null;
448
+ let rule = null;
449
+ let enteringEmbeddedLanguage = null;
450
+ if (groupMatching) {
451
+ matches = groupMatching.matches;
452
+ const groupEntry = groupMatching.groups.shift();
453
+ matched = groupEntry.matched;
454
+ action = groupEntry.action;
455
+ rule = groupMatching.rule;
456
+ if (groupMatching.groups.length === 0) {
457
+ groupMatching = null;
458
+ }
459
+ }
460
+ else {
461
+ if (!forceEvaluation && pos >= lineLength) {
462
+ break;
463
+ }
464
+ forceEvaluation = false;
465
+ let rules = this._lexer.tokenizer[state];
466
+ if (!rules) {
467
+ rules = findRules(this._lexer, state);
468
+ if (!rules) {
469
+ throw createError(this._lexer, 'tokenizer state is not defined: ' + state);
470
+ }
471
+ }
472
+ const restOfLine = line.substr(pos);
473
+ for (const rule of rules) {
474
+ if (pos === 0 || !rule.matchOnlyAtLineStart) {
475
+ matches = restOfLine.match(rule.resolveRegex(state));
476
+ if (matches) {
477
+ matched = matches[0];
478
+ action = rule.action;
479
+ break;
480
+ }
481
+ }
482
+ }
483
+ }
484
+ if (!matches) {
485
+ matches = [''];
486
+ matched = '';
487
+ }
488
+ if (!action) {
489
+ if (pos < lineLength) {
490
+ matches = [line.charAt(pos)];
491
+ matched = matches[0];
492
+ }
493
+ action = this._lexer.defaultToken;
494
+ }
495
+ if (matched === null) {
496
+ break;
497
+ }
498
+ pos += matched.length;
499
+ while (isFuzzyAction(action) && isIAction(action) && action.test) {
500
+ action = action.test(matched, matches, state, pos === lineLength);
501
+ }
502
+ let result = null;
503
+ if (typeof action === 'string' || Array.isArray(action)) {
504
+ result = action;
505
+ }
506
+ else if (action.group) {
507
+ result = action.group;
508
+ }
509
+ else if (action.token !== null && action.token !== undefined) {
510
+ if (action.tokenSubst) {
511
+ result = substituteMatches(this._lexer, action.token, matched, matches, state);
512
+ }
513
+ else {
514
+ result = action.token;
515
+ }
516
+ if (action.nextEmbedded) {
517
+ if (action.nextEmbedded === '@pop') {
518
+ if (!embeddedLanguageData) {
519
+ throw createError(this._lexer, 'cannot pop embedded language if not inside one');
520
+ }
521
+ embeddedLanguageData = null;
522
+ }
523
+ else if (embeddedLanguageData) {
524
+ throw createError(this._lexer, 'cannot enter embedded language from within an embedded language');
525
+ }
526
+ else {
527
+ enteringEmbeddedLanguage = substituteMatches(this._lexer, action.nextEmbedded, matched, matches, state);
528
+ }
529
+ }
530
+ if (action.goBack) {
531
+ pos = Math.max(0, pos - action.goBack);
532
+ }
533
+ if (action.switchTo && typeof action.switchTo === 'string') {
534
+ let nextState = substituteMatches(this._lexer, action.switchTo, matched, matches, state);
535
+ if (nextState[0] === '@') {
536
+ nextState = nextState.substr(1);
537
+ }
538
+ if (!findRules(this._lexer, nextState)) {
539
+ throw createError(this._lexer, 'trying to switch to a state \'' + nextState + '\' that is undefined in rule: ' + this._safeRuleName(rule));
540
+ }
541
+ else {
542
+ stack = stack.switchTo(nextState);
543
+ }
544
+ }
545
+ else if (action.transform && typeof action.transform === 'function') {
546
+ throw createError(this._lexer, 'action.transform not supported');
547
+ }
548
+ else if (action.next) {
549
+ if (action.next === '@push') {
550
+ if (stack.depth >= this._lexer.maxStack) {
551
+ throw createError(this._lexer, 'maximum tokenizer stack size reached: [' +
552
+ stack.state + ',' + stack.parent.state + ',...]');
553
+ }
554
+ else {
555
+ stack = stack.push(state);
556
+ }
557
+ }
558
+ else if (action.next === '@pop') {
559
+ if (stack.depth <= 1) {
560
+ throw createError(this._lexer, 'trying to pop an empty stack in rule: ' + this._safeRuleName(rule));
561
+ }
562
+ else {
563
+ stack = stack.pop();
564
+ }
565
+ }
566
+ else if (action.next === '@popall') {
567
+ stack = stack.popall();
568
+ }
569
+ else {
570
+ let nextState = substituteMatches(this._lexer, action.next, matched, matches, state);
571
+ if (nextState[0] === '@') {
572
+ nextState = nextState.substr(1);
573
+ }
574
+ if (!findRules(this._lexer, nextState)) {
575
+ throw createError(this._lexer, 'trying to set a next state \'' + nextState + '\' that is undefined in rule: ' + this._safeRuleName(rule));
576
+ }
577
+ else {
578
+ stack = stack.push(nextState);
579
+ }
580
+ }
581
+ }
582
+ if (action.log && typeof (action.log) === 'string') {
583
+ log(this._lexer, this._lexer.languageId + ': ' + substituteMatches(this._lexer, action.log, matched, matches, state));
584
+ }
585
+ }
586
+ if (result === null) {
587
+ throw createError(this._lexer, 'lexer rule has no well-defined action in rule: ' + this._safeRuleName(rule));
588
+ }
589
+ const computeNewStateForEmbeddedLanguage = (enteringEmbeddedLanguage) => {
590
+ const languageId = (this._languageService.getLanguageIdByLanguageName(enteringEmbeddedLanguage)
591
+ || this._languageService.getLanguageIdByMimeType(enteringEmbeddedLanguage)
592
+ || enteringEmbeddedLanguage);
593
+ const embeddedLanguageData = this._getNestedEmbeddedLanguageData(languageId);
594
+ if (pos < lineLength) {
595
+ const restOfLine = lineWithoutLF.substr(pos);
596
+ return this._nestedTokenize(restOfLine, hasEOL, MonarchLineStateFactory.create(stack, embeddedLanguageData), offsetDelta + pos, tokensCollector);
597
+ }
598
+ else {
599
+ return MonarchLineStateFactory.create(stack, embeddedLanguageData);
600
+ }
601
+ };
602
+ if (Array.isArray(result)) {
603
+ if (groupMatching && groupMatching.groups.length > 0) {
604
+ throw createError(this._lexer, 'groups cannot be nested: ' + this._safeRuleName(rule));
605
+ }
606
+ if (matches.length !== result.length + 1) {
607
+ throw createError(this._lexer, 'matched number of groups does not match the number of actions in rule: ' + this._safeRuleName(rule));
608
+ }
609
+ let totalLen = 0;
610
+ for (let i = 1; i < matches.length; i++) {
611
+ totalLen += matches[i].length;
612
+ }
613
+ if (totalLen !== matched.length) {
614
+ throw createError(this._lexer, 'with groups, all characters should be matched in consecutive groups in rule: ' + this._safeRuleName(rule));
615
+ }
616
+ groupMatching = {
617
+ rule: rule,
618
+ matches: matches,
619
+ groups: []
620
+ };
621
+ for (let i = 0; i < result.length; i++) {
622
+ groupMatching.groups[i] = {
623
+ action: result[i],
624
+ matched: matches[i + 1]
625
+ };
626
+ }
627
+ pos -= matched.length;
628
+ continue;
629
+ }
630
+ else {
631
+ if (result === '@rematch') {
632
+ pos -= matched.length;
633
+ matched = '';
634
+ matches = null;
635
+ result = '';
636
+ if (enteringEmbeddedLanguage !== null) {
637
+ return computeNewStateForEmbeddedLanguage(enteringEmbeddedLanguage);
638
+ }
639
+ }
640
+ if (matched.length === 0) {
641
+ if (lineLength === 0 || stackLen0 !== stack.depth || state !== stack.state || (!groupMatching ? 0 : groupMatching.groups.length) !== groupLen0) {
642
+ continue;
643
+ }
644
+ else {
645
+ throw createError(this._lexer, 'no progress in tokenizer in rule: ' + this._safeRuleName(rule));
646
+ }
647
+ }
648
+ let tokenType = null;
649
+ if (isString(result) && result.indexOf('@brackets') === 0) {
650
+ const rest = result.substr('@brackets'.length);
651
+ const bracket = findBracket(this._lexer, matched);
652
+ if (!bracket) {
653
+ throw createError(this._lexer, '@brackets token returned but no bracket defined as: ' + matched);
654
+ }
655
+ tokenType = sanitize(bracket.token + rest);
656
+ }
657
+ else {
658
+ const token = (result === '' ? '' : result + this._lexer.tokenPostfix);
659
+ tokenType = sanitize(token);
660
+ }
661
+ if (pos0 < lineWithoutLFLength) {
662
+ tokensCollector.emit(pos0 + offsetDelta, tokenType);
663
+ }
664
+ }
665
+ if (enteringEmbeddedLanguage !== null) {
666
+ return computeNewStateForEmbeddedLanguage(enteringEmbeddedLanguage);
667
+ }
668
+ }
669
+ return MonarchLineStateFactory.create(stack, embeddedLanguageData);
670
+ }
671
+ _getNestedEmbeddedLanguageData(languageId) {
672
+ if (!this._languageService.isRegisteredLanguageId(languageId)) {
673
+ return ( new EmbeddedLanguageData(languageId, NullState));
674
+ }
675
+ if (languageId !== this._languageId) {
676
+ this._languageService.requestBasicLanguageFeatures(languageId);
677
+ TokenizationRegistry.getOrCreate(languageId);
678
+ this._embeddedLanguages[languageId] = true;
679
+ }
680
+ const tokenizationSupport = TokenizationRegistry.get(languageId);
681
+ if (tokenizationSupport) {
682
+ return ( new EmbeddedLanguageData(languageId, tokenizationSupport.getInitialState()));
683
+ }
684
+ return ( new EmbeddedLanguageData(languageId, NullState));
685
+ }
686
+ };
687
+ MonarchTokenizer = MonarchTokenizer_1 = ( __decorate([
688
+ ( __param(4, IConfigurationService))
689
+ ], MonarchTokenizer));
690
+ function findBracket(lexer, matched) {
691
+ if (!matched) {
692
+ return null;
693
+ }
694
+ matched = fixCase(lexer, matched);
695
+ const brackets = lexer.brackets;
696
+ for (const bracket of brackets) {
697
+ if (bracket.open === matched) {
698
+ return { token: bracket.token, bracketType: MonarchBracket.Open };
699
+ }
700
+ else if (bracket.close === matched) {
701
+ return { token: bracket.token, bracketType: MonarchBracket.Close };
702
+ }
703
+ }
704
+ return null;
705
+ }
706
+
707
+ export { MonarchTokenizer };