1
>
/*---------------------------------------------------------------------------------------------
richEditBrackets.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as strings from '../../../../base/common/strings.js';
7
>
import * as stringBuilder from '../../core/stringBuilder.js';
8
>
import { Range } from '../../core/range.js';
9
>
import { CharacterPair } from '../languageConfiguration.js';
10
>
11
>
interface InternalBracket {
12
>
open: string[];
13
>
close: string[];
14
>
}
15
>
16
>
/**
17
>
* Represents a grouping of colliding bracket pairs.
18
>
*
19
>
* Most of the times this contains a single bracket pair,
20
>
* but sometimes this contains multiple bracket pairs in cases
21
>
* where the same string appears as a closing bracket for multiple
22
>
* bracket pairs, or the same string appears an opening bracket for
23
>
* multiple bracket pairs.
24
>
*
25
>
* e.g. of a group containing a single pair:
26
>
* open: ['{'], close: ['}']
27
>
*
28
>
* e.g. of a group containing multiple pairs:
29
>
* open: ['if', 'for'], close: ['end', 'end']
30
>
*/
31
>
export class RichEditBracket {
32
>
_richEditBracketBrand: void = undefined;
33
>
34
>
readonly languageId: string;
35
>
/**
36
>
* A 0-based consecutive unique identifier for this bracket pair.
37
>
* If a language has 5 bracket pairs, out of which 2 are grouped together,
38
>
* it is expected that the `index` goes from 0 to 4.
39
>
*/
40
>
readonly index: number;
41
>
/**
42
>
* The open sequence for each bracket pair contained in this group.
43
>
*
44
>
* The open sequence at a specific index corresponds to the
45
>
* closing sequence at the same index.
46
>
*
47
>
* [ open[i], closed[i] ] represent a bracket pair.
48
>
*/
49
>
readonly open: string[];
50
>
/**
51
>
* The close sequence for each bracket pair contained in this group.
52
>
*
53
>
* The close sequence at a specific index corresponds to the
54
>
* opening sequence at the same index.
55
>
*
56
>
* [ open[i], closed[i] ] represent a bracket pair.
57
>
*/
58
>
readonly close: string[];
59
>
/**
60
>
* A regular expression that is useful to search for this bracket pair group in a string.
61
>
*
62
>
* This regular expression is built in a way that it is aware of the other bracket
63
>
* pairs defined for the language, so it might match brackets from other groups.
64
>
*
65
>
* See the fine details in `getRegexForBracketPair`.
66
>
*/
67
>
readonly forwardRegex: RegExp;
68
>
/**
69
>
* A regular expression that is useful to search for this bracket pair group in a string backwards.
70
>
*
71
>
* This regular expression is built in a way that it is aware of the other bracket
72
>
* pairs defined for the language, so it might match brackets from other groups.
73
>
*
74
>
* See the fine defails in `getReversedRegexForBracketPair`.
75
>
*/
76
>
readonly reversedRegex: RegExp;
77
>
private readonly _openSet: Set<string>;
78
>
private readonly _closeSet: Set<string>;
79
>
80
>
constructor(languageId: string, index: number, open: string[], close: string[], forwardRegex: RegExp, reversedRegex: RegExp) {
81
this.languageId = languageId;
82
this.index = index;