Clean up /src/ structure
This commit is contained in:
Родитель
627e31caab
Коммит
7e30d059f6
|
@ -4,6 +4,7 @@
|
|||
/out/
|
||||
/src/
|
||||
/test-cases/
|
||||
/typings/
|
||||
/.npmignore
|
||||
/.travis.yml
|
||||
/gulpfile.js
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"name": "Microsoft Corporation"
|
||||
},
|
||||
"main": "./release/main.js",
|
||||
"typings": "./release/main.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Microsoft/vscode-textmate"
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
|
||||
import {clone} from './utils';
|
||||
import {IRawGrammar, IRawRepository, IRawRule} from './types';
|
||||
import {IRuleFactoryHelper, RuleFactory, Rule, CaptureRule, BeginEndRule, BeginWhileRule, MatchRule, ICompiledRule, createOnigString, getString} from './rule';
|
||||
import {IRuleRegistry, IRuleFactoryHelper, RuleFactory, Rule, CaptureRule, BeginEndRule, BeginWhileRule, MatchRule, ICompiledRule, createOnigString, getString} from './rule';
|
||||
import {IOnigCaptureIndex, IOnigNextMatchResult, OnigString} from 'oniguruma';
|
||||
import {createMatcher, Matcher} from './matcher';
|
||||
import {IGrammar, ITokenizeLineResult, IToken, StackElement as StackElementDef} from './main';
|
||||
|
||||
export function createGrammar(grammar:IRawGrammar, grammarRepository:IGrammarRepository): IGrammar {
|
||||
return new Grammar(grammar, grammarRepository);
|
||||
|
@ -18,21 +19,6 @@ export interface IGrammarRepository {
|
|||
injections(scopeName:string): string[];
|
||||
}
|
||||
|
||||
export interface IGrammar {
|
||||
tokenizeLine(lineText: string, prevState: StackElement): ITokenizeLineResult;
|
||||
}
|
||||
|
||||
export interface ITokenizeLineResult {
|
||||
tokens: IToken[];
|
||||
ruleStack: StackElement;
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
export interface IScopeNameSet {
|
||||
[scopeName:string]: boolean;
|
||||
}
|
||||
|
@ -597,10 +583,10 @@ function _tokenizeString(grammar: Grammar, lineText: OnigString, isFirstLine: bo
|
|||
/**
|
||||
* **IMPORTANT** - Immutable!
|
||||
*/
|
||||
export class StackElement {
|
||||
export class StackElement implements StackElementDef {
|
||||
public _stackElementBrand: void;
|
||||
|
||||
private _parent: StackElement;
|
||||
public _parent: StackElement;
|
||||
private _enterPos: number;
|
||||
private _ruleId: number;
|
||||
private _endRule: string;
|
||||
|
@ -668,7 +654,7 @@ export class StackElement {
|
|||
return this._enterPos;
|
||||
}
|
||||
|
||||
public getRule(grammar:Grammar): Rule {
|
||||
public getRule(grammar:IRuleRegistry): Rule {
|
||||
return grammar.getRule(this._ruleId);
|
||||
}
|
||||
|
||||
|
|
67
src/main.ts
67
src/main.ts
|
@ -4,23 +4,8 @@
|
|||
'use strict';
|
||||
|
||||
import {SyncRegistry as SyncRegistry} from './registry';
|
||||
import {IGrammar} from './grammar';
|
||||
import {readGrammar, readGrammarSync} from './grammarReader';
|
||||
import {IRawGrammar} from './types';
|
||||
import * as expressionMatcher from './matcher';
|
||||
export import createMatcher = expressionMatcher.createMatcher;
|
||||
|
||||
export interface IGrammarLocator {
|
||||
getFilePath(scopeName:string): string;
|
||||
getInjections?(scopeName:string): string[];
|
||||
}
|
||||
|
||||
export interface IGrammarInfo {
|
||||
fileTypes: string[];
|
||||
name: string;
|
||||
scopeName: string;
|
||||
firstLineMatch: string;
|
||||
}
|
||||
|
||||
interface IBarrier {
|
||||
(): void;
|
||||
|
@ -31,6 +16,17 @@ let DEFAULT_LOCATOR:IGrammarLocator = {
|
|||
getInjections: (scopeName:string) => null
|
||||
};
|
||||
|
||||
/**
|
||||
* A registry helper that can locate grammar file paths given scope names.
|
||||
*/
|
||||
export interface IGrammarLocator {
|
||||
getFilePath(scopeName:string): string;
|
||||
getInjections?(scopeName:string): string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The registry that will hold all grammars.
|
||||
*/
|
||||
export class Registry {
|
||||
|
||||
private _locator: IGrammarLocator;
|
||||
|
@ -97,3 +93,44 @@ export class Registry {
|
|||
return this._syncRegistry.grammarForScopeName(scopeName);
|
||||
}
|
||||
}
|
||||
|
||||
export interface IGrammarInfo {
|
||||
fileTypes: string[];
|
||||
name: string;
|
||||
scopeName: string;
|
||||
firstLineMatch: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A grammar
|
||||
*/
|
||||
export interface IGrammar {
|
||||
/**
|
||||
* Tokenize `lineText` using previous line state `prevState`.
|
||||
*/
|
||||
tokenizeLine(lineText: string, prevState: StackElement): ITokenizeLineResult;
|
||||
}
|
||||
|
||||
export interface ITokenizeLineResult {
|
||||
tokens: IToken[];
|
||||
/**
|
||||
* The `prevState` to be passed on to the next line tokenization.
|
||||
*/
|
||||
ruleStack: StackElement;
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* **IMPORTANT** - Immutable!
|
||||
*/
|
||||
export interface StackElement {
|
||||
_parent: StackElement;
|
||||
_stackElementBrand: void;
|
||||
|
||||
equals(other:StackElement): boolean;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {createGrammar, collectIncludedScopes, IGrammarRepository, IGrammar, IScopeNameSet} from './grammar';
|
||||
import {createGrammar, collectIncludedScopes, IGrammarRepository, IScopeNameSet} from './grammar';
|
||||
import {IRawGrammar} from './types';
|
||||
import {IGrammar} from './main';
|
||||
|
||||
export class SyncRegistry implements IGrammarRepository {
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as assert from 'assert';
|
||||
import {Registry, createMatcher, IGrammarLocator} from '../main';
|
||||
import {IToken, StackElement, IGrammar} from '../grammar';
|
||||
import {Registry, IToken, IGrammar, IGrammarLocator, StackElement} from '../main';
|
||||
import {createMatcher} from '../matcher';
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '../../');
|
||||
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* A registry helper that can locate grammar file paths given scope names.
|
||||
*/
|
||||
export interface IGrammarLocator {
|
||||
getFilePath(scopeName:string): string;
|
||||
getInjections?(scopeName:string): string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The registry that will hold all grammars.
|
||||
*/
|
||||
export class Registry {
|
||||
|
||||
constructor(locator?:IGrammarLocator);
|
||||
|
||||
/**
|
||||
* Load the grammar for `scopeName` and all referenced included grammars asynchronously.
|
||||
*/
|
||||
public loadGrammar(scopeName:string, callback:(err:any, grammar:IGrammar)=>void): void;
|
||||
|
||||
/**
|
||||
* Load the grammar at `path` synchronously.
|
||||
*/
|
||||
public loadGrammarFromPathSync(path:string): IGrammar;
|
||||
|
||||
/**
|
||||
* Get the grammar for `scopeName`. The grammar must first be created via `loadGrammar` or `loadGrammarFromPathSync`.
|
||||
*/
|
||||
public grammarForScopeName(scopeName:string): IGrammar;
|
||||
}
|
||||
|
||||
export interface IGrammarInfo {
|
||||
fileTypes: string[];
|
||||
name: string;
|
||||
scopeName: string;
|
||||
firstLineMatch: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A grammar
|
||||
*/
|
||||
export interface IGrammar {
|
||||
/**
|
||||
* Tokenize `lineText` using previous line state `prevState`.
|
||||
*/
|
||||
tokenizeLine(lineText: string, prevState: StackElement): ITokenizeLineResult;
|
||||
}
|
||||
|
||||
export interface ITokenizeLineResult {
|
||||
tokens: IToken[];
|
||||
/**
|
||||
* The `prevState` to be passed on to the next line tokenization.
|
||||
*/
|
||||
ruleStack: StackElement;
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* **IMPORTANT** - Immutable!
|
||||
*/
|
||||
export interface StackElement {
|
||||
_parent: StackElement;
|
||||
_stackElementBrand: void;
|
||||
|
||||
equals(other:StackElement): boolean;
|
||||
}
|
|
@ -4,7 +4,8 @@
|
|||
"module": "commonjs",
|
||||
"outDir": "out",
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true
|
||||
"sourceMap": true,
|
||||
"declaration": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
|
Загрузка…
Ссылка в новой задаче