-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
98 lines (82 loc) · 1.64 KB
/
index.d.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
export class ReadError extends Error {
reason: string
text: string
line: number
constructor(reason: string, text: string, line: number)
}
enum TokenType {
EOF = 1,
Whitespace = 2,
Comment = 4,
Punctuator = 8,
Name = 16,
Value = 32,
}
interface Token {
type: TokenType
value: string
raw?: string
line: number,
lineStart: number,
range: [tokenStart: number, offset: number]
}
interface Node {
type: string
}
interface Value extends Node {
type: 'Value'
value: string
}
interface Name extends Node {
type: 'Name'
value: string
raw?: string
}
interface Key extends Node {
type: 'Key'
name: Name
value: Value
}
interface Section extends Node {
type: 'Section'
name: Name
body: Key[]
}
interface File extends Node {
type: 'File'
body: (Key | Section)[]
tokens?: Token[]
}
interface Options {
tokens?: boolean
comments?: boolean
whitespace?: boolean
locations?: boolean
ranges?: boolean
raw?: boolean
sourceFile?: string
onCreateNode: (node: Node) => void
onCreateToken: (token: Token) => void
}
export const tokenTypes = {
EOF: 1,
Whitespace: 2,
Comment: 4,
Punctuator: 8,
Name: 16,
Value: 32,
NoData: 6
}
export const defaultOptions = {
tokens: false,
comments: false,
whitespace: false,
locations: false,
ranges: false,
raw: false,
sourceFile: 'ini'
}
export function parseText(input: string, options?: Options): File
export function parseTokens(input: string, tokens: Token[], options?: Options): File
export function tokenize(input: string, options?: Options): Token[]
export function startTokenization(input: string, options?: Options): Generator<Token>