Implements flag "containsBalancedBrackets"

This commit is contained in:
Henning Dieterichs 2022-04-07 00:30:30 +02:00
Родитель 9ac3bb4801
Коммит 2d4d3c85d6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 771381EFFDB9EC06
7 изменённых файлов: 158 добавлений и 46 удалений

14
release/main.d.ts поставляемый
Просмотреть файл

@ -1,3 +1,4 @@
import { BalancedBracketSelectors } from './grammar';
import { IRawGrammar, IOnigLib } from './types';
export * from './types';
/**
@ -50,6 +51,8 @@ export declare const enum StandardTokenType {
export interface IGrammarConfiguration {
embeddedLanguages?: IEmbeddedLanguagesMap;
tokenTypes?: ITokenTypeMap;
balancedBracketSelectors?: string[];
unbalancedBracketSelectors?: string[];
}
/**
* The registry that will hold all grammars.
@ -92,7 +95,7 @@ export declare class Registry {
/**
* Get the grammar for `scopeName`. The grammar must first be created via `loadGrammar` or `addGrammar`.
*/
grammarForScopeName(scopeName: string, initialLanguage?: number, embeddedLanguages?: IEmbeddedLanguagesMap | null, tokenTypes?: ITokenTypeMap | null): Promise<IGrammar | null>;
grammarForScopeName(scopeName: string, initialLanguage?: number, embeddedLanguages?: IEmbeddedLanguagesMap | null, tokenTypes?: ITokenTypeMap | null, balancedBracketSelectors?: BalancedBracketSelectors | null): Promise<IGrammar | null>;
}
/**
* A grammar
@ -137,25 +140,28 @@ export interface ITokenizeLineResult {
* 1098 7654 3210 9876 5432 1098 7654 3210
* - -------------------------------------------
* xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
* bbbb bbbb bfff ffff ffFF FFTT LLLL LLLL
* mbbb bbbb bfff ffff ffFF FFTT LLLL LLLL
* - -------------------------------------------
* - L = LanguageId (8 bits)
* - T = StandardTokenType (2 bits)
* - F = FontStyle (4 bits)
* - f = foreground color (9 bits)
* - b = background color (9 bits)
* - m = is balanced bracket (1 bit)
*/
export declare const enum MetadataConsts {
LANGUAGEID_MASK = 255,
TOKEN_TYPE_MASK = 768,
FONT_STYLE_MASK = 15360,
FOREGROUND_MASK = 8372224,
BACKGROUND_MASK = 4286578688,
BACKGROUND_MASK = 2139095040,
BALANCED_BRACKETS_MASK = 2147483648,
LANGUAGEID_OFFSET = 0,
TOKEN_TYPE_OFFSET = 8,
FONT_STYLE_OFFSET = 10,
FOREGROUND_OFFSET = 14,
BACKGROUND_OFFSET = 23
BACKGROUND_OFFSET = 23,
BALANCED_BRACKETS = 31
}
export interface ITokenizeLineResult2 {
/**

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -30,8 +30,8 @@ export const enum OptionalStandardTokenType {
NotSet = 8
}
export function createGrammar(scopeName: string, grammar: IRawGrammar, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null, tokenTypes: ITokenTypeMap | null, grammarRepository: IGrammarRepository & IThemeProvider, onigLib: IOnigLib): Grammar {
return new Grammar(scopeName, grammar, initialLanguage, embeddedLanguages, tokenTypes, grammarRepository, onigLib);//TODO
export function createGrammar(scopeName: string, grammar: IRawGrammar, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null, tokenTypes: ITokenTypeMap | null, balancedBracketSelectors: BalancedBracketSelectors | null, grammarRepository: IGrammarRepository & IThemeProvider, onigLib: IOnigLib): Grammar {
return new Grammar(scopeName, grammar, initialLanguage, embeddedLanguages, tokenTypes, balancedBracketSelectors, grammarRepository, onigLib);//TODO
}
export interface IThemeProvider {
@ -460,7 +460,7 @@ export class Grammar implements IGrammar, IRuleFactoryHelper, IOnigLib {
private readonly _tokenTypeMatchers: TokenTypeMatcher[];
private readonly _onigLib: IOnigLib;
constructor(scopeName: string, grammar: IRawGrammar, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null, tokenTypes: ITokenTypeMap | null, grammarRepository: IGrammarRepository & IThemeProvider, onigLib: IOnigLib) {
constructor(scopeName: string, grammar: IRawGrammar, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null, tokenTypes: ITokenTypeMap | null, private readonly balancedBracketSelectors: BalancedBracketSelectors | null, grammarRepository: IGrammarRepository & IThemeProvider, onigLib: IOnigLib) {
this._scopeName = scopeName;
this._scopeMetadataProvider = new ScopeMetadataProvider(initialLanguage, grammarRepository, embeddedLanguages);
@ -635,7 +635,7 @@ export class Grammar implements IGrammar, IRuleFactoryHelper, IOnigLib {
isFirstLine = true;
const rawDefaultMetadata = this._scopeMetadataProvider.getDefaultMetadata();
const defaultTheme = rawDefaultMetadata.themeData![0];
const defaultMetadata = StackElementMetadata.set(0, rawDefaultMetadata.languageId, rawDefaultMetadata.tokenType, defaultTheme.fontStyle, defaultTheme.foreground, defaultTheme.background);
const defaultMetadata = StackElementMetadata.set(0, rawDefaultMetadata.languageId, rawDefaultMetadata.tokenType, defaultTheme.fontStyle, defaultTheme.foreground, defaultTheme.background, null);
const rootScopeName = this.getRule(this._rootId).getName(null, null);
const rawRootMetadata = this._scopeMetadataProvider.getMetadataForScope(rootScopeName);
@ -652,7 +652,7 @@ export class Grammar implements IGrammar, IRuleFactoryHelper, IOnigLib {
lineText = lineText + '\n';
const onigLineText = this.createOnigString(lineText);
const lineLength = onigLineText.content.length;
const lineTokens = new LineTokens(emitBinaryTokens, lineText, this._tokenTypeMatchers);
const lineTokens = new LineTokens(emitBinaryTokens, lineText, this._tokenTypeMatchers, this.balancedBracketSelectors);
const r = _tokenizeString(this, onigLineText, isFirstLine, 0, prevState, lineTokens, true, timeLimit);
disposeOnigString(onigLineText);
@ -1243,16 +1243,21 @@ 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.
*/
public static set(metadata: number, languageId: number, tokenType: OptionalStandardTokenType, fontStyle: FontStyle, foreground: number, background: number): number {
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 _fontStyle = StackElementMetadata.getFontStyle(metadata);
let _foreground = StackElementMetadata.getForeground(metadata);
let _background = StackElementMetadata.getBackground(metadata);
let _containsBalancedBrackets = StackElementMetadata.containsBalancedBrackets(metadata);
if (languageId !== 0) {
_languageId = languageId;
@ -1269,6 +1274,9 @@ export class StackElementMetadata {
if (background !== 0) {
_background = background;
}
if (containsBalancedBrackets !== null) {
_containsBalancedBrackets = containsBalancedBrackets;
}
return (
(_languageId << MetadataConsts.LANGUAGEID_OFFSET)
@ -1276,6 +1284,7 @@ export class StackElementMetadata {
| (_fontStyle << MetadataConsts.FONT_STYLE_OFFSET)
| (_foreground << MetadataConsts.FOREGROUND_OFFSET)
| (_background << MetadataConsts.BACKGROUND_OFFSET)
| (_containsBalancedBrackets ? MetadataConsts.BALANCED_BRACKETS_MASK : 0)
) >>> 0;
}
}
@ -1374,7 +1383,7 @@ export class ScopeListElement {
}
}
return StackElementMetadata.set(metadata, source.languageId, source.tokenType, fontStyle, foreground, background);
return StackElementMetadata.set(metadata, source.languageId, source.tokenType, fontStyle, foreground, background, null);
}
private static _push(target: ScopeListElement, grammar: Grammar, scopes: string[]): ScopeListElement {
@ -1626,8 +1635,54 @@ interface TokenTypeMatcher {
readonly type: StandardTokenType;
}
class LineTokens {
export class BalancedBracketSelectors {
private readonly balancedBracketScopes: Matcher<string[]>[];
private readonly unbalancedBracketScopes: Matcher<string[]>[];
private allowAny = false;
constructor(
balancedBracketScopes: string[],
unbalancedBracketScopes: string[],
) {
this.balancedBracketScopes = balancedBracketScopes.flatMap((selector) => {
if (selector === '*') {
this.allowAny = true;
return [];
}
return createMatchers(selector, nameMatcher).map((m) => m.matcher);
}
);
this.unbalancedBracketScopes = unbalancedBracketScopes.flatMap((selector) =>
createMatchers(selector, nameMatcher).map((m) => m.matcher)
);
}
public get matchesAlways(): boolean {
return this.allowAny && this.unbalancedBracketScopes.length === 0;
}
public get matchesNever(): boolean {
return this.balancedBracketScopes.length === 0 && !this.allowAny;
}
public match(scopes: string[]): boolean {
for (const excluder of this.unbalancedBracketScopes) {
if (excluder(scopes)) {
return false;
}
}
for (const includer of this.balancedBracketScopes) {
if (includer(scopes)) {
return true;
}
}
return this.allowAny;
}
}
class LineTokens {
private readonly _emitBinaryTokens: boolean;
/**
* defined only if `DebugFlags.InDebugMode`.
@ -1646,7 +1701,12 @@ class LineTokens {
private readonly _tokenTypeOverrides: TokenTypeMatcher[];
constructor(emitBinaryTokens: boolean, lineText: string, tokenTypeOverrides: TokenTypeMatcher[]) {
constructor(
emitBinaryTokens: boolean,
lineText: string,
tokenTypeOverrides: TokenTypeMatcher[],
private readonly balancedBracketSelectors: BalancedBracketSelectors | null,
) {
this._emitBinaryTokens = emitBinaryTokens;
this._tokenTypeOverrides = tokenTypeOverrides;
if (DebugFlags.InDebugMode) {
@ -1663,21 +1723,52 @@ class LineTokens {
this.produceFromScopes(stack.contentNameScopesList, endIndex);
}
public produceFromScopes(scopesList: ScopeListElement, endIndex: number): void {
public produceFromScopes(
scopesList: ScopeListElement,
endIndex: number
): void {
if (this._lastTokenEndIndex >= endIndex) {
return;
}
if (this._emitBinaryTokens) {
let metadata = scopesList.metadata;
let containsBalancedBrackets = false;
if (this.balancedBracketSelectors?.matchesAlways) {
containsBalancedBrackets = true;
}
if (this._tokenTypeOverrides.length > 0) {
if (this._tokenTypeOverrides.length > 0 || (this.balancedBracketSelectors && !this.balancedBracketSelectors.matchesAlways && !this.balancedBracketSelectors.matchesNever)) {
// Only generate scope array when required to improve performance
const scopes = scopesList.generateScopes();
for (const tokenType of this._tokenTypeOverrides) {
if (tokenType.matcher(scopes)) {
metadata = StackElementMetadata.set(metadata, 0, toOptionalTokenType(tokenType.type), FontStyle.NotSet, 0, 0);
metadata = StackElementMetadata.set(
metadata,
0,
toOptionalTokenType(tokenType.type),
FontStyle.NotSet,
0,
0,
null
);
}
}
if (this.balancedBracketSelectors) {
containsBalancedBrackets = this.balancedBracketSelectors.match(scopes);
}
}
if (containsBalancedBrackets) {
metadata = StackElementMetadata.set(
metadata,
0,
OptionalStandardTokenType.NotSet,
FontStyle.NotSet,
0,
0,
containsBalancedBrackets
);
}
if (this._binaryTokens.length > 0 && this._binaryTokens[this._binaryTokens.length - 1] === metadata) {

Просмотреть файл

@ -5,7 +5,7 @@
import { SyncRegistry } from './registry';
import * as grammarReader from './grammarReader';
import { Theme } from './theme';
import { StackElement as StackElementImpl, ScopeDependencyProcessor } from './grammar';
import { StackElement as StackElementImpl, ScopeDependencyProcessor, BalancedBracketSelectors } from './grammar';
import { IRawGrammar, IOnigLib } from './types';
export * from './types';
@ -66,6 +66,8 @@ export const enum StandardTokenType {
export interface IGrammarConfiguration {
embeddedLanguages?: IEmbeddedLanguagesMap;
tokenTypes?: ITokenTypeMap;
balancedBracketSelectors?: string[];
unbalancedBracketSelectors?: string[];
}
/**
@ -114,14 +116,23 @@ export class Registry {
* Please do not use language id 0.
*/
public loadGrammarWithConfiguration(initialScopeName: string, initialLanguage: number, configuration: IGrammarConfiguration): Promise<IGrammar | null> {
return this._loadGrammar(initialScopeName, initialLanguage, configuration.embeddedLanguages, configuration.tokenTypes);
return this._loadGrammar(
initialScopeName,
initialLanguage,
configuration.embeddedLanguages,
configuration.tokenTypes,
new BalancedBracketSelectors(
configuration.balancedBracketSelectors || [],
configuration.unbalancedBracketSelectors || []
)
);
}
/**
* Load the grammar for `scopeName` and all referenced included grammars asynchronously.
*/
public loadGrammar(initialScopeName: string): Promise<IGrammar | null> {
return this._loadGrammar(initialScopeName, 0, null, null);
return this._loadGrammar(initialScopeName, 0, null, null, null);
}
private async _doLoadSingleGrammar(scopeName: string): Promise<void> {
@ -139,7 +150,7 @@ export class Registry {
return this._ensureGrammarCache.get(scopeName);
}
private async _loadGrammar(initialScopeName: string, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null | undefined, tokenTypes: ITokenTypeMap | null | undefined): Promise<IGrammar | null> {
private async _loadGrammar(initialScopeName: string, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null | undefined, tokenTypes: ITokenTypeMap | null | undefined, balancedBracketSelectors: BalancedBracketSelectors | null): Promise<IGrammar | null> {
const dependencyProcessor = new ScopeDependencyProcessor(this._syncRegistry, initialScopeName);
while (dependencyProcessor.Q.length > 0) {
@ -147,7 +158,7 @@ export class Registry {
dependencyProcessor.processQueue();
}
return this.grammarForScopeName(initialScopeName, initialLanguage, embeddedLanguages, tokenTypes);
return this.grammarForScopeName(initialScopeName, initialLanguage, embeddedLanguages, tokenTypes, balancedBracketSelectors);
}
/**
@ -161,8 +172,8 @@ export class Registry {
/**
* Get the grammar for `scopeName`. The grammar must first be created via `loadGrammar` or `addGrammar`.
*/
public grammarForScopeName(scopeName: string, initialLanguage: number = 0, embeddedLanguages: IEmbeddedLanguagesMap | null = null, tokenTypes: ITokenTypeMap | null = null): Promise<IGrammar | null> {
return this._syncRegistry.grammarForScopeName(scopeName, initialLanguage, embeddedLanguages, tokenTypes);
public grammarForScopeName(scopeName: string, initialLanguage: number = 0, embeddedLanguages: IEmbeddedLanguagesMap | null = null, tokenTypes: ITokenTypeMap | null = null, balancedBracketSelectors: BalancedBracketSelectors | null = null): Promise<IGrammar | null> {
return this._syncRegistry.grammarForScopeName(scopeName, initialLanguage, embeddedLanguages, tokenTypes, balancedBracketSelectors);
}
}
@ -214,26 +225,30 @@ export interface ITokenizeLineResult {
* 1098 7654 3210 9876 5432 1098 7654 3210
* - -------------------------------------------
* xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
* bbbb bbbb bfff ffff ffFF FFTT LLLL LLLL
* mbbb bbbb bfff ffff ffFF FFTT LLLL LLLL
* - -------------------------------------------
* - L = LanguageId (8 bits)
* - T = StandardTokenType (2 bits)
* - 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 = 0b11111111100000000000000000000000,
BACKGROUND_MASK = 0b01111111100000000000000000000000,
BALANCED_BRACKETS_MASK = 0b10000000000000000000000000000000,
LANGUAGEID_OFFSET = 0,
TOKEN_TYPE_OFFSET = 8,
FONT_STYLE_OFFSET = 10,
FOREGROUND_OFFSET = 14,
BACKGROUND_OFFSET = 23
BACKGROUND_OFFSET = 23,
// Indicates that this token contains balanced brackets
BALANCED_BRACKETS = 31,
}
export interface ITokenizeLineResult2 {

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { createGrammar, Grammar, IGrammarRepository } from './grammar';
import { BalancedBracketSelectors, createGrammar, Grammar, IGrammarRepository } from './grammar';
import { IRawGrammar } from './types';
import { IGrammar, IEmbeddedLanguagesMap, ITokenTypeMap } from './main';
import { Theme, ThemeTrieElementRule } from './theme';
@ -86,13 +86,13 @@ export class SyncRegistry implements IGrammarRepository {
/**
* Lookup a grammar.
*/
public async grammarForScopeName(scopeName: string, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null, tokenTypes: ITokenTypeMap | null): Promise<IGrammar | null> {
public async grammarForScopeName(scopeName: string, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap | null, tokenTypes: ITokenTypeMap | null, balancedBracketSelectors: BalancedBracketSelectors | null): Promise<IGrammar | null> {
if (!this._grammars[scopeName]) {
let rawGrammar = this._rawGrammars[scopeName];
if (!rawGrammar) {
return null;
}
this._grammars[scopeName] = createGrammar(scopeName, rawGrammar, initialLanguage, embeddedLanguages, tokenTypes, this, await this._onigLibPromise);
this._grammars[scopeName] = createGrammar(scopeName, rawGrammar, initialLanguage, embeddedLanguages, tokenTypes, balancedBracketSelectors, this, await this._onigLibPromise);
}
return this._grammars[scopeName];
}

Просмотреть файл

@ -28,55 +28,55 @@ function assertEquals(metadata: number, languageId: number, tokenType: StandardT
}
test('StackElementMetadata works', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
});
test('StackElementMetadata can overwrite languageId', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 2, OptionalStandardTokenType.NotSet, FontStyle.NotSet, 0, 0);
value = StackElementMetadata.set(value, 2, OptionalStandardTokenType.NotSet, FontStyle.NotSet, 0, 0, false);
assertEquals(value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
});
test('StackElementMetadata can overwrite tokenType', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.Comment, FontStyle.NotSet, 0, 0);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.Comment, FontStyle.NotSet, 0, 0, false);
assertEquals(value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102);
});
test('StackElementMetadata can overwrite font style', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.None, 0, 0);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.None, 0, 0, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
});
test('StackElementMetadata can overwrite font style with strikethrough', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.None, 0, 0);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.None, 0, 0, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
});
test('StackElementMetadata can overwrite foreground', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.NotSet, 5, 0);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.NotSet, 5, 0, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102);
});
test('StackElementMetadata can overwrite background', () => {
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
let value = StackElementMetadata.set(0, 1, OptionalStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.NotSet, 0, 7);
value = StackElementMetadata.set(value, 0, OptionalStandardTokenType.NotSet, FontStyle.NotSet, 0, 7, false);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7);
});
@ -85,8 +85,8 @@ test('StackElementMetadata can work at max values', () => {
const maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx | StandardTokenType.String;
const maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline;
const maxForeground = 511;
const maxBackground = 511;
const maxBackground = 254;
let value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
let value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground, false);
assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
});