37 lines
1,006 B
TypeScript
37 lines
1,006 B
TypeScript
import {IRawGrammar} from 'vscode-textmate';
|
|
import {type Overwrite} from './util.mts';
|
|
|
|
// vscode-textmate doesn't expose anything else so fine we'll do it ourselves
|
|
|
|
type AllOptionalWritable<T> = { -readonly [K in keyof T]?: T[K] };
|
|
type RemoveLocation<T> = Omit<T, '$vscodeTextmateLocation'>;
|
|
|
|
type Cleanup<T, Overrides = unknown> = AllOptionalWritable<
|
|
RemoveLocation<Overwrite<T, Overrides>>
|
|
>;
|
|
|
|
type IRawRepository = IRawGrammar['repository'];
|
|
type IRawRule = IRawRepository[string];
|
|
type IRawCaptures = NonNullable<IRawRule['captures']>;
|
|
|
|
export type Captures = Cleanup<IRawCaptures>;
|
|
export type Rule = Cleanup<IRawRule, {
|
|
captures: Captures;
|
|
beginCaptures: Captures;
|
|
endCaptures: Captures;
|
|
whileCaptures: Captures;
|
|
repository: Repository;
|
|
}>;
|
|
export type Repository = Cleanup<IRawRepository, {
|
|
[name: string]: Rule;
|
|
$self: Rule;
|
|
$base: Rule;
|
|
}>;
|
|
export type Grammar = Cleanup<IRawGrammar, {
|
|
repository: Repository;
|
|
patterns: Rule[];
|
|
injections: {
|
|
[expression: string]: Rule;
|
|
};
|
|
}>;
|