Move the balanced bracket bit close to the token type bits
This commit is contained in:
Родитель
2d4d3c85d6
Коммит
0bc2addb0d
|
@ -1231,6 +1231,10 @@ export class StackElementMetadata {
|
|||
return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET;
|
||||
}
|
||||
|
||||
public static containsBalancedBrackets(metadata: number): boolean {
|
||||
return (metadata & MetadataConsts.BALANCED_BRACKETS_MASK) !== 0;
|
||||
}
|
||||
|
||||
public static getFontStyle(metadata: number): number {
|
||||
return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET;
|
||||
}
|
||||
|
@ -1243,10 +1247,6 @@ export class StackElementMetadata {
|
|||
return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET;
|
||||
}
|
||||
|
||||
public static containsBalancedBrackets(metadata: number): boolean {
|
||||
return (metadata & MetadataConsts.BALANCED_BRACKETS_MASK) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the fields in `metadata`.
|
||||
* A value of `0` or `NotSet` indicates that the corresponding field should be left as is.
|
||||
|
@ -1254,10 +1254,10 @@ export class StackElementMetadata {
|
|||
public static set(metadata: number, languageId: number, tokenType: OptionalStandardTokenType, fontStyle: FontStyle, foreground: number, background: number, containsBalancedBrackets: boolean | null): number {
|
||||
let _languageId = StackElementMetadata.getLanguageId(metadata);
|
||||
let _tokenType = StackElementMetadata.getTokenType(metadata);
|
||||
let _containsBalancedBracketsBit: 0 | 1 = StackElementMetadata.containsBalancedBrackets(metadata) ? 1 : 0;
|
||||
let _fontStyle = StackElementMetadata.getFontStyle(metadata);
|
||||
let _foreground = StackElementMetadata.getForeground(metadata);
|
||||
let _background = StackElementMetadata.getBackground(metadata);
|
||||
let _containsBalancedBrackets = StackElementMetadata.containsBalancedBrackets(metadata);
|
||||
|
||||
if (languageId !== 0) {
|
||||
_languageId = languageId;
|
||||
|
@ -1265,6 +1265,9 @@ export class StackElementMetadata {
|
|||
if (tokenType !== OptionalStandardTokenType.NotSet) {
|
||||
_tokenType = fromOptionalTokenType(tokenType);
|
||||
}
|
||||
if (containsBalancedBrackets !== null) {
|
||||
_containsBalancedBracketsBit = containsBalancedBrackets ? 1 : 0;
|
||||
}
|
||||
if (fontStyle !== FontStyle.NotSet) {
|
||||
_fontStyle = fontStyle;
|
||||
}
|
||||
|
@ -1274,17 +1277,14 @@ export class StackElementMetadata {
|
|||
if (background !== 0) {
|
||||
_background = background;
|
||||
}
|
||||
if (containsBalancedBrackets !== null) {
|
||||
_containsBalancedBrackets = containsBalancedBrackets;
|
||||
}
|
||||
|
||||
return (
|
||||
(_languageId << MetadataConsts.LANGUAGEID_OFFSET)
|
||||
| (_tokenType << MetadataConsts.TOKEN_TYPE_OFFSET)
|
||||
| (_containsBalancedBracketsBit << MetadataConsts.BALANCED_BRACKETS_OFFSET)
|
||||
| (_fontStyle << MetadataConsts.FONT_STYLE_OFFSET)
|
||||
| (_foreground << MetadataConsts.FOREGROUND_OFFSET)
|
||||
| (_background << MetadataConsts.BACKGROUND_OFFSET)
|
||||
| (_containsBalancedBrackets ? MetadataConsts.BALANCED_BRACKETS_MASK : 0)
|
||||
) >>> 0;
|
||||
}
|
||||
}
|
||||
|
|
21
src/main.ts
21
src/main.ts
|
@ -225,30 +225,29 @@ export interface ITokenizeLineResult {
|
|||
* 1098 7654 3210 9876 5432 1098 7654 3210
|
||||
* - -------------------------------------------
|
||||
* xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
|
||||
* mbbb bbbb bfff ffff ffFF FFTT LLLL LLLL
|
||||
* bbbb bbbb ffff ffff fFFF FBTT LLLL LLLL
|
||||
* - -------------------------------------------
|
||||
* - L = LanguageId (8 bits)
|
||||
* - T = StandardTokenType (2 bits)
|
||||
* - B = Balanced bracket (1 bit)
|
||||
* - F = FontStyle (4 bits)
|
||||
* - f = foreground color (9 bits)
|
||||
* - b = background color (9 bits)
|
||||
* - m = is balanced bracket (1 bit)
|
||||
*/
|
||||
export const enum MetadataConsts {
|
||||
LANGUAGEID_MASK = 0b00000000000000000000000011111111,
|
||||
TOKEN_TYPE_MASK = 0b00000000000000000000001100000000,
|
||||
FONT_STYLE_MASK = 0b00000000000000000011110000000000,
|
||||
FOREGROUND_MASK = 0b00000000011111111100000000000000,
|
||||
BACKGROUND_MASK = 0b01111111100000000000000000000000,
|
||||
BALANCED_BRACKETS_MASK = 0b10000000000000000000000000000000,
|
||||
BALANCED_BRACKETS_MASK = 0b00000000000000000000010000000000,
|
||||
FONT_STYLE_MASK = 0b00000000000000000111100000000000,
|
||||
FOREGROUND_MASK = 0b00000000111111111000000000000000,
|
||||
BACKGROUND_MASK = 0b11111111000000000000000000000000,
|
||||
|
||||
LANGUAGEID_OFFSET = 0,
|
||||
TOKEN_TYPE_OFFSET = 8,
|
||||
FONT_STYLE_OFFSET = 10,
|
||||
FOREGROUND_OFFSET = 14,
|
||||
BACKGROUND_OFFSET = 23,
|
||||
// Indicates that this token contains balanced brackets
|
||||
BALANCED_BRACKETS = 31,
|
||||
BALANCED_BRACKETS_OFFSET = 10,
|
||||
FONT_STYLE_OFFSET = 11,
|
||||
FOREGROUND_OFFSET = 15,
|
||||
BACKGROUND_OFFSET = 24
|
||||
}
|
||||
|
||||
export interface ITokenizeLineResult2 {
|
||||
|
|
Загрузка…
Ссылка в новой задаче