-
Notifications
You must be signed in to change notification settings - Fork 3
/
env.ts
36 lines (30 loc) · 1.01 KB
/
env.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { getMemorizedStringOffsetToPos, MatchFail, MatchContext, StringPos, BaseEnv } from "generic-parser/lib/core";
export interface Env extends BaseEnv<string, StringPos> {
currentIndentDepth: number;
state: {
parenthesesDepth: number;
maxOffsetMatchFail: MatchFail | null;
maxOffsetMatchContext: MatchContext | null;
};
}
export interface InitialEnvOptions {
options?: Record<string | number | symbol, unknown>,
baseOffset?: number,
}
export const initialEnv = (initialEnvOptions: InitialEnvOptions): Env => {
const { options = {}, baseOffset = 0 } = initialEnvOptions;
const offsetToPos = getMemorizedStringOffsetToPos();
const state = {
parenthesesDepth: 0,
maxOffsetMatchFail: null as null | MatchFail,
maxOffsetMatchContext: null as null | MatchContext,
};
return {
currentIndentDepth: 0,
offsetToPos,
registerCurrentRangeTarget: () => { /**/ },
options,
state,
baseOffset,
};
};