Skip to content

Commit

Permalink
feat: add static initial method for GrammarState, #715
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 26, 2024
1 parent 1349bb4 commit be07da8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/core/src/grammar-state.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import type { StateStackImpl } from '../vendor/vscode-textmate/src/grammar'
import { ShikiError } from './error'
import type { StateStack } from './textmate'
import { INITIAL } from './textmate'

/**
* GrammarState is a special reference object that holds the state of a grammar.
*
* It's used to highlight code snippets that are part of the target language.
*/
export class GrammarState {
/**
* Static method to create a initial grammar state.
*/
static initial(lang: string, theme: string) {
return new GrammarState(INITIAL, lang, theme)
}

constructor(
private _stack: StateStack,
public lang: string,
public theme: string,
private readonly _stack: StateStack,
public readonly lang: string,
public readonly theme: string,
) {}

get scopes() {
Expand Down

0 comments on commit be07da8

Please sign in to comment.