Adopt TS's readonly
This commit is contained in:
Родитель
394a4bb23b
Коммит
a33377e93d
|
@ -9,8 +9,8 @@ export interface IGrammarLocator {
|
|||
* The registry that will hold all grammars.
|
||||
*/
|
||||
export declare class Registry {
|
||||
private _locator;
|
||||
private _syncRegistry;
|
||||
private readonly _locator;
|
||||
private readonly _syncRegistry;
|
||||
constructor(locator?: IGrammarLocator);
|
||||
/**
|
||||
* Load the grammar for `scopeName` and all referenced included grammars asynchronously.
|
||||
|
@ -26,10 +26,10 @@ export declare class Registry {
|
|||
grammarForScopeName(scopeName: string): IGrammar;
|
||||
}
|
||||
export interface IGrammarInfo {
|
||||
fileTypes: string[];
|
||||
name: string;
|
||||
scopeName: string;
|
||||
firstLineMatch: string;
|
||||
readonly fileTypes: string[];
|
||||
readonly name: string;
|
||||
readonly scopeName: string;
|
||||
readonly firstLineMatch: string;
|
||||
}
|
||||
/**
|
||||
* A grammar
|
||||
|
@ -41,22 +41,22 @@ export interface IGrammar {
|
|||
tokenizeLine(lineText: string, prevState: StackElement): ITokenizeLineResult;
|
||||
}
|
||||
export interface ITokenizeLineResult {
|
||||
tokens: IToken[];
|
||||
readonly tokens: IToken[];
|
||||
/**
|
||||
* The `prevState` to be passed on to the next line tokenization.
|
||||
*/
|
||||
ruleStack: StackElement;
|
||||
readonly ruleStack: StackElement;
|
||||
}
|
||||
export interface IToken {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
scopes: string[];
|
||||
readonly endIndex: number;
|
||||
readonly scopes: string[];
|
||||
}
|
||||
/**
|
||||
* **IMPORTANT** - Immutable!
|
||||
*/
|
||||
export interface StackElement {
|
||||
_parent: StackElement;
|
||||
_stackElementBrand: void;
|
||||
readonly _parent: StackElement;
|
||||
equals(other: StackElement): boolean;
|
||||
}
|
||||
|
|
|
@ -93,10 +93,10 @@ export function collectIncludedScopes(result: IScopeNameSet, grammar:IRawGrammar
|
|||
}
|
||||
|
||||
interface Injection {
|
||||
matcher: Matcher<StackElement>;
|
||||
priorityMatch: boolean,
|
||||
ruleId:number;
|
||||
grammar: IRawGrammar;
|
||||
readonly matcher: Matcher<StackElement>;
|
||||
readonly priorityMatch: boolean,
|
||||
readonly ruleId:number;
|
||||
readonly grammar: IRawGrammar;
|
||||
}
|
||||
|
||||
function collectInjections(result: Injection[], selector: string, rule: IRawRule, ruleFactoryHelper: IRuleFactoryHelper, grammar: IRawGrammar) : void {
|
||||
|
@ -142,10 +142,10 @@ class Grammar implements IGrammar, IRuleFactoryHelper {
|
|||
|
||||
private _rootId: number;
|
||||
private _lastRuleId: number;
|
||||
private _ruleId2desc: Rule[];
|
||||
private _includedGrammars: { [scopeName:string]:IRawGrammar; };
|
||||
private _grammarRepository: IGrammarRepository;
|
||||
private _grammar: IRawGrammar;
|
||||
private readonly _ruleId2desc: Rule[];
|
||||
private readonly _includedGrammars: { [scopeName:string]:IRawGrammar; };
|
||||
private readonly _grammarRepository: IGrammarRepository;
|
||||
private readonly _grammar: IRawGrammar;
|
||||
private _injections : Injection[];
|
||||
|
||||
constructor(grammar:IRawGrammar, grammarRepository:IGrammarRepository) {
|
||||
|
@ -322,9 +322,9 @@ function handleCaptures(grammar: Grammar, lineText: OnigString, isFirstLine: boo
|
|||
}
|
||||
|
||||
interface IMatchInjectionsResult {
|
||||
priorityMatch: boolean;
|
||||
captureIndices: IOnigCaptureIndex[];
|
||||
matchedRuleId: number;
|
||||
readonly priorityMatch: boolean;
|
||||
readonly captureIndices: IOnigCaptureIndex[];
|
||||
readonly matchedRuleId: number;
|
||||
}
|
||||
|
||||
function debugCompiledRuleToString(ruleScanner:ICompiledRule): string {
|
||||
|
@ -384,8 +384,8 @@ function matchInjections(injections:Injection[], grammar: Grammar, lineText: Oni
|
|||
}
|
||||
|
||||
interface IMatchResult {
|
||||
captureIndices: IOnigCaptureIndex[];
|
||||
matchedRuleId: number;
|
||||
readonly captureIndices: IOnigCaptureIndex[];
|
||||
readonly matchedRuleId: number;
|
||||
}
|
||||
|
||||
function matchRule(grammar: Grammar, lineText: OnigString, isFirstLine: boolean, linePos: number, stack: StackElement, anchorPosition:number): IMatchResult {
|
||||
|
@ -440,15 +440,15 @@ function matchRuleOrInjections(grammar: Grammar, lineText: OnigString, isFirstLi
|
|||
}
|
||||
|
||||
interface IWhileStack {
|
||||
stack: StackElement;
|
||||
rule: BeginWhileRule;
|
||||
readonly stack: StackElement;
|
||||
readonly rule: BeginWhileRule;
|
||||
}
|
||||
|
||||
interface IWhileCheckResult {
|
||||
stack: StackElement;
|
||||
linePos: number;
|
||||
anchorPosition: number;
|
||||
isFirstLine: boolean;
|
||||
readonly stack: StackElement;
|
||||
readonly linePos: number;
|
||||
readonly anchorPosition: number;
|
||||
readonly isFirstLine: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -664,12 +664,12 @@ function _tokenizeString(grammar: Grammar, lineText: OnigString, isFirstLine: bo
|
|||
export class StackElement implements StackElementDef {
|
||||
public _stackElementBrand: void;
|
||||
|
||||
public _parent: StackElement;
|
||||
public readonly _parent: StackElement;
|
||||
private _enterPos: number;
|
||||
private _ruleId: number;
|
||||
private _endRule: string;
|
||||
private _scopeName: string;
|
||||
private _contentName: string;
|
||||
private readonly _ruleId: number;
|
||||
private readonly _endRule: string;
|
||||
private readonly _scopeName: string;
|
||||
private readonly _contentName: string;
|
||||
|
||||
constructor(parent:StackElement, ruleId:number, enterPos:number, endRule:string, scopeName:string, contentName: string) {
|
||||
this._parent = parent;
|
||||
|
@ -801,8 +801,8 @@ export class StackElement implements StackElementDef {
|
|||
}
|
||||
|
||||
class LocalStackElement {
|
||||
public scopeName: string;
|
||||
public endPos: number;
|
||||
public readonly scopeName: string;
|
||||
public readonly endPos: number;
|
||||
|
||||
constructor (scopeName: string, endPos: number) {
|
||||
if (typeof scopeName !== 'string') {
|
||||
|
@ -815,8 +815,8 @@ class LocalStackElement {
|
|||
|
||||
class LineTokens {
|
||||
|
||||
private _lineText: string;
|
||||
private _tokens: IToken[];
|
||||
private readonly _lineText: string;
|
||||
private readonly _tokens: IToken[];
|
||||
private _lastTokenEndIndex: number;
|
||||
|
||||
constructor(lineText:string) {
|
||||
|
|
|
@ -29,8 +29,8 @@ interface IGrammarParser {
|
|||
}
|
||||
|
||||
class AsyncGrammarReader {
|
||||
private _filePath: string;
|
||||
private _parser: IGrammarParser;
|
||||
private readonly _filePath: string;
|
||||
private readonly _parser: IGrammarParser;
|
||||
|
||||
constructor(filePath:string, parser:IGrammarParser) {
|
||||
this._filePath = filePath;
|
||||
|
@ -56,8 +56,8 @@ class AsyncGrammarReader {
|
|||
}
|
||||
|
||||
class SyncGrammarReader {
|
||||
private _filePath: string;
|
||||
private _parser: IGrammarParser;
|
||||
private readonly _filePath: string;
|
||||
private readonly _parser: IGrammarParser;
|
||||
|
||||
constructor(filePath:string, parser:IGrammarParser) {
|
||||
this._filePath = filePath;
|
||||
|
|
|
@ -9,9 +9,9 @@ function doFail(streamState:JSONStreamState, msg:string): void {
|
|||
}
|
||||
|
||||
export interface ILocation {
|
||||
filename: string;
|
||||
line: number;
|
||||
char: number;
|
||||
readonly filename: string;
|
||||
readonly line: number;
|
||||
readonly char: number;
|
||||
}
|
||||
|
||||
export function parse(source:string, filename:string, withMetadata:boolean): any {
|
||||
|
|
22
src/main.ts
22
src/main.ts
|
@ -25,8 +25,8 @@ export interface IGrammarLocator {
|
|||
*/
|
||||
export class Registry {
|
||||
|
||||
private _locator: IGrammarLocator;
|
||||
private _syncRegistry: SyncRegistry;
|
||||
private readonly _locator: IGrammarLocator;
|
||||
private readonly _syncRegistry: SyncRegistry;
|
||||
|
||||
constructor(locator:IGrammarLocator = DEFAULT_LOCATOR) {
|
||||
this._locator = locator;
|
||||
|
@ -100,10 +100,10 @@ export class Registry {
|
|||
}
|
||||
|
||||
export interface IGrammarInfo {
|
||||
fileTypes: string[];
|
||||
name: string;
|
||||
scopeName: string;
|
||||
firstLineMatch: string;
|
||||
readonly fileTypes: string[];
|
||||
readonly name: string;
|
||||
readonly scopeName: string;
|
||||
readonly firstLineMatch: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,25 +117,25 @@ export interface IGrammar {
|
|||
}
|
||||
|
||||
export interface ITokenizeLineResult {
|
||||
tokens: IToken[];
|
||||
readonly tokens: IToken[];
|
||||
/**
|
||||
* The `prevState` to be passed on to the next line tokenization.
|
||||
*/
|
||||
ruleStack: StackElement;
|
||||
readonly ruleStack: StackElement;
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
scopes: string[];
|
||||
readonly endIndex: number;
|
||||
readonly scopes: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* **IMPORTANT** - Immutable!
|
||||
*/
|
||||
export interface StackElement {
|
||||
_parent: StackElement;
|
||||
_stackElementBrand: void;
|
||||
readonly _parent: StackElement;
|
||||
|
||||
equals(other:StackElement): boolean;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ import {IGrammar} from './main';
|
|||
|
||||
export class SyncRegistry implements IGrammarRepository {
|
||||
|
||||
private _grammars: {[scopeName:string]:IGrammar;};
|
||||
private _rawGrammars: {[scopeName:string]:IRawGrammar;};
|
||||
private _injectionGrammars: {[scopeName:string]:string[];};
|
||||
private readonly _grammars: {[scopeName:string]:IGrammar;};
|
||||
private readonly _rawGrammars: {[scopeName:string]:IRawGrammar;};
|
||||
private readonly _injectionGrammars: {[scopeName:string]:string[];};
|
||||
|
||||
constructor() {
|
||||
this._grammars = {};
|
||||
|
|
78
src/rule.ts
78
src/rule.ts
|
@ -24,21 +24,21 @@ export interface IRuleFactoryHelper extends IRuleRegistry, IGrammarRegistry {
|
|||
}
|
||||
|
||||
export interface ICompiledRule {
|
||||
scanner: OnigScanner;
|
||||
rules: number[];
|
||||
debugRegExps: string[]
|
||||
readonly scanner: OnigScanner;
|
||||
readonly rules: number[];
|
||||
readonly debugRegExps: string[]
|
||||
}
|
||||
|
||||
export abstract class Rule {
|
||||
|
||||
public $location:ILocation;
|
||||
public id:number;
|
||||
public readonly $location:ILocation;
|
||||
public readonly id:number;
|
||||
|
||||
private _nameIsCapturing: boolean;
|
||||
private _name: string;
|
||||
private readonly _nameIsCapturing: boolean;
|
||||
private readonly _name: string;
|
||||
|
||||
private _contentNameIsCapturing: boolean;
|
||||
private _contentName: string;
|
||||
private readonly _contentNameIsCapturing: boolean;
|
||||
private readonly _contentName: string;
|
||||
|
||||
constructor($location:ILocation, id:number, name:string, contentName:string) {
|
||||
this.$location = $location;
|
||||
|
@ -77,13 +77,13 @@ export abstract class Rule {
|
|||
}
|
||||
|
||||
export interface ICompilePatternsResult {
|
||||
patterns: number[];
|
||||
hasMissingPatterns: boolean;
|
||||
readonly patterns: number[];
|
||||
readonly hasMissingPatterns: boolean;
|
||||
}
|
||||
|
||||
export class CaptureRule extends Rule {
|
||||
|
||||
public retokenizeCapturedWithRuleId: number;
|
||||
public readonly retokenizeCapturedWithRuleId: number;
|
||||
|
||||
constructor($location:ILocation, id:number, name:string, contentName:string, retokenizeCapturedWithRuleId:number) {
|
||||
super($location, id, name, contentName);
|
||||
|
@ -92,18 +92,18 @@ export class CaptureRule extends Rule {
|
|||
}
|
||||
|
||||
interface IRegExpSourceAnchorCache {
|
||||
A0_G0: string;
|
||||
A0_G1: string;
|
||||
A1_G0: string;
|
||||
A1_G1: string;
|
||||
readonly A0_G0: string;
|
||||
readonly A0_G1: string;
|
||||
readonly A1_G0: string;
|
||||
readonly A1_G1: string;
|
||||
}
|
||||
|
||||
export class RegExpSource {
|
||||
|
||||
public source: string;
|
||||
public ruleId: number;
|
||||
public readonly ruleId: number;
|
||||
public hasAnchor: boolean;
|
||||
public hasBackReferences: boolean;
|
||||
public readonly hasBackReferences: boolean;
|
||||
private _anchorCache: IRegExpSourceAnchorCache;
|
||||
|
||||
constructor(regExpSource:string, ruleId:number, handleAnchors:boolean = true) {
|
||||
|
@ -297,11 +297,11 @@ export function getString(str:OnigString): string {
|
|||
|
||||
export class RegExpSourceList {
|
||||
|
||||
private _items: RegExpSource[];
|
||||
private readonly _items: RegExpSource[];
|
||||
private _hasAnchors: boolean;
|
||||
private _cached: ICompiledRule;
|
||||
private _anchorCache: IRegExpSourceListAnchorCache;
|
||||
private _cachedSources: string[];
|
||||
private readonly _cachedSources: string[];
|
||||
|
||||
constructor() {
|
||||
this._items = [];
|
||||
|
@ -388,8 +388,8 @@ export class RegExpSourceList {
|
|||
}
|
||||
|
||||
export class MatchRule extends Rule {
|
||||
private _match: RegExpSource;
|
||||
public captures: CaptureRule[];
|
||||
private readonly _match: RegExpSource;
|
||||
public readonly captures: CaptureRule[];
|
||||
private _cachedCompiledPatterns: RegExpSourceList;
|
||||
|
||||
constructor($location:ILocation, id: number, name: string, match: string, captures: CaptureRule[]) {
|
||||
|
@ -417,8 +417,8 @@ export class MatchRule extends Rule {
|
|||
}
|
||||
|
||||
export class IncludeOnlyRule extends Rule {
|
||||
public hasMissingPatterns: boolean;
|
||||
public patterns: number[];
|
||||
public readonly hasMissingPatterns: boolean;
|
||||
public readonly patterns: number[];
|
||||
private _cachedCompiledPatterns: RegExpSourceList;
|
||||
|
||||
constructor($location:ILocation, id: number, name: string, contentName: string, patterns: ICompilePatternsResult) {
|
||||
|
@ -453,14 +453,14 @@ function escapeRegExpCharacters(value: string): string {
|
|||
}
|
||||
|
||||
export class BeginEndRule extends Rule {
|
||||
private _begin: RegExpSource;
|
||||
public beginCaptures: CaptureRule[];
|
||||
private _end: RegExpSource;
|
||||
public endHasBackReferences:boolean;
|
||||
public endCaptures: CaptureRule[];
|
||||
public applyEndPatternLast: boolean;
|
||||
public hasMissingPatterns: boolean;
|
||||
public patterns: number[];
|
||||
private readonly _begin: RegExpSource;
|
||||
public readonly beginCaptures: CaptureRule[];
|
||||
private readonly _end: RegExpSource;
|
||||
public readonly endHasBackReferences:boolean;
|
||||
public readonly endCaptures: CaptureRule[];
|
||||
public readonly applyEndPatternLast: boolean;
|
||||
public readonly hasMissingPatterns: boolean;
|
||||
public readonly patterns: number[];
|
||||
private _cachedCompiledPatterns: RegExpSourceList;
|
||||
|
||||
constructor($location:ILocation, id: number, name: string, contentName: string, begin: string, beginCaptures: CaptureRule[], end: string, endCaptures: CaptureRule[], applyEndPatternLast: boolean, patterns: ICompilePatternsResult) {
|
||||
|
@ -533,13 +533,13 @@ export class BeginEndRule extends Rule {
|
|||
}
|
||||
|
||||
export class BeginWhileRule extends Rule {
|
||||
private _begin: RegExpSource;
|
||||
public beginCaptures: CaptureRule[];
|
||||
public whileCaptures: CaptureRule[];
|
||||
private _while: RegExpSource;
|
||||
public whileHasBackReferences: boolean;
|
||||
public hasMissingPatterns: boolean;
|
||||
public patterns: number[];
|
||||
private readonly _begin: RegExpSource;
|
||||
public readonly beginCaptures: CaptureRule[];
|
||||
public readonly whileCaptures: CaptureRule[];
|
||||
private readonly _while: RegExpSource;
|
||||
public readonly whileHasBackReferences: boolean;
|
||||
public readonly hasMissingPatterns: boolean;
|
||||
public readonly patterns: number[];
|
||||
private _cachedCompiledPatterns: RegExpSourceList;
|
||||
private _cachedCompiledWhilePatterns: RegExpSourceList;
|
||||
|
||||
|
|
50
src/types.ts
50
src/types.ts
|
@ -6,25 +6,25 @@
|
|||
// -- raw grammar typings
|
||||
|
||||
export interface ILocation {
|
||||
filename: string;
|
||||
line: number;
|
||||
char: number;
|
||||
readonly filename: string;
|
||||
readonly line: number;
|
||||
readonly char: number;
|
||||
}
|
||||
|
||||
export interface ILocatable {
|
||||
$vscodeTextmateLocation?:ILocation;
|
||||
readonly $vscodeTextmateLocation?:ILocation;
|
||||
}
|
||||
|
||||
export interface IRawGrammar extends ILocatable {
|
||||
repository: IRawRepository;
|
||||
scopeName: string;
|
||||
patterns: IRawRule[];
|
||||
injections?: { [expression:string]: IRawRule };
|
||||
injectionSelector?: string;
|
||||
readonly scopeName: string;
|
||||
readonly patterns: IRawRule[];
|
||||
readonly injections?: { [expression:string]: IRawRule };
|
||||
readonly injectionSelector?: string;
|
||||
|
||||
fileTypes?: string[];
|
||||
name?: string;
|
||||
firstLineMatch?: string;
|
||||
readonly fileTypes?: string[];
|
||||
readonly name?: string;
|
||||
readonly firstLineMatch?: string;
|
||||
}
|
||||
|
||||
export interface IRawRepository extends ILocatable {
|
||||
|
@ -36,24 +36,24 @@ export interface IRawRepository extends ILocatable {
|
|||
export interface IRawRule extends ILocatable {
|
||||
id?: number;
|
||||
|
||||
include?: string;
|
||||
readonly include?: string;
|
||||
|
||||
name?: string;
|
||||
contentName?: string;
|
||||
readonly name?: string;
|
||||
readonly contentName?: string;
|
||||
|
||||
match?:string;
|
||||
captures?: IRawCaptures;
|
||||
begin?:string;
|
||||
beginCaptures?: IRawCaptures;
|
||||
end?:string;
|
||||
endCaptures?: IRawCaptures;
|
||||
while?:string;
|
||||
whileCaptures?: IRawCaptures;
|
||||
patterns?: IRawRule[];
|
||||
readonly match?:string;
|
||||
readonly captures?: IRawCaptures;
|
||||
readonly begin?:string;
|
||||
readonly beginCaptures?: IRawCaptures;
|
||||
readonly end?:string;
|
||||
readonly endCaptures?: IRawCaptures;
|
||||
readonly while?:string;
|
||||
readonly whileCaptures?: IRawCaptures;
|
||||
readonly patterns?: IRawRule[];
|
||||
|
||||
repository?: IRawRepository;
|
||||
readonly repository?: IRawRepository;
|
||||
|
||||
applyEndPatternLast?:boolean;
|
||||
readonly applyEndPatternLast?:boolean;
|
||||
}
|
||||
|
||||
export interface IRawCaptures extends ILocatable {
|
||||
|
|
Загрузка…
Ссылка в новой задаче