| @@ -1,17 +1,25 @@ |
|
|
| 1 |
1 |
import type { StateStackImpl } from '../vendor/vscode-textmate/src/grammar' |
| 2 |
2 |
import { ShikiError } from './error' |
| 3 |
3 |
import type { StateStack } from './textmate' |
|
4 |
+import { INITIAL } from './textmate' |
| 4 |
5 |
|
| 5 |
6 |
/** |
| 6 |
7 |
* GrammarState is a special reference object that holds the state of a grammar. |
| 7 |
8 |
* |
| 8 |
9 |
* It's used to highlight code snippets that are part of the target language. |
| 9 |
10 |
*/ |
| 10 |
11 |
export class GrammarState { |
|
12 |
+/** |
|
13 |
+ * Static method to create a initial grammar state. |
|
14 |
+ */ |
|
15 |
+static initial(lang: string, theme: string) { |
|
16 |
+return new GrammarState(INITIAL, lang, theme) |
|
17 |
+} |
|
18 |
+ |
| 11 |
19 |
constructor( |
| 12 |
|
-private _stack: StateStack, |
| 13 |
|
-public lang: string, |
| 14 |
|
-public theme: string, |
|
20 |
+private readonly _stack: StateStack, |
|
21 |
+public readonly lang: string, |
|
22 |
+public readonly theme: string, |
| 15 |
23 |
) {} |
| 16 |
24 |
|
| 17 |
25 |
get scopes() { |