vba-interpreter 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +96 -2
- package/dist/contract-CBGNXslV.d.ts +226 -0
- package/dist/exec/index.d.ts +12 -0
- package/dist/exec/index.js +1 -0
- package/dist/exec-DYWJe-eU.js +306 -0
- package/dist/exec-DYWJe-eU.js.map +1 -0
- package/dist/index-DnrotnmB.d.ts +2015 -0
- package/dist/index-DtaSNo0V.d.ts +111 -0
- package/dist/index-DyoT9JOJ.d.ts +4 -0
- package/dist/index-gM7FYTaq.d.ts +1353 -0
- package/dist/index-zKYgEJdV.d.ts +900 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +3 -0
- package/dist/interp/index.d.ts +10 -0
- package/dist/interp/index.js +1 -0
- package/dist/interp-ChrsgBCf.js +3433 -0
- package/dist/interp-ChrsgBCf.js.map +1 -0
- package/dist/lang/index.d.ts +10 -0
- package/dist/lang/index.js +1 -0
- package/dist/lang-Bo63dJb9.js +4740 -0
- package/dist/lang-Bo63dJb9.js.map +1 -0
- package/dist/runtime/index.d.ts +33 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime-C8-PPxmH.js +8284 -0
- package/dist/runtime-C8-PPxmH.js.map +1 -0
- package/dist/semantic/index.d.ts +12 -0
- package/dist/semantic/index.js +1 -0
- package/dist/semantic-CAVxm72C.js +2877 -0
- package/dist/semantic-CAVxm72C.js.map +1 -0
- package/package.json +91 -5
|
@@ -0,0 +1,1353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A point in the source text. `offset` counts UTF-16 code units from the start of the source;
|
|
3
|
+
* `line` and `column` are 1-based (column in UTF-16 code units), as the VBA editor shows them.
|
|
4
|
+
*/
|
|
5
|
+
interface SourcePosition {
|
|
6
|
+
/** UTF-16 code units from the start of the source, 0-based. */
|
|
7
|
+
readonly offset: number;
|
|
8
|
+
/** The 1-based line number. */
|
|
9
|
+
readonly line: number;
|
|
10
|
+
/** The 1-based column, in UTF-16 code units. */
|
|
11
|
+
readonly column: number;
|
|
12
|
+
}
|
|
13
|
+
/** The half-open range `[start, end)` a token or node covers. */
|
|
14
|
+
interface Span {
|
|
15
|
+
/** The first position covered. */
|
|
16
|
+
readonly start: SourcePosition;
|
|
17
|
+
/** The position just past the last one covered. */
|
|
18
|
+
readonly end: SourcePosition;
|
|
19
|
+
}
|
|
20
|
+
/** The name of a built-in VBA data type, in its canonical spelling. */
|
|
21
|
+
type BuiltinTypeName = 'Boolean' | 'Byte' | 'Currency' | 'Date' | 'Decimal' | 'Double' | 'Integer' | 'Long' | 'LongLong' | 'LongPtr' | 'Object' | 'Single' | 'String' | 'Variant' | 'Any';
|
|
22
|
+
/** A type-declaration character after a name or number literal ([MS-VBAL] 3.3.5.3). */
|
|
23
|
+
type TypeSuffix = '%' | '&' | '^' | '!' | '#' | '@' | '$';
|
|
24
|
+
/** The declared type of a number literal ([MS-VBAL] 3.3.2). */
|
|
25
|
+
type NumberLiteralType = 'Integer' | 'Long' | 'LongLong' | 'Single' | 'Double' | 'Currency';
|
|
26
|
+
/** Punctuation and operators. `=<`, `=>` and `><` are lexed as `<=`, `>=` and `<>`. */
|
|
27
|
+
type Punctuator = '(' | ')' | ',' | ';' | ':' | ':=' | '.' | '!' | '#' | '=' | '<>' | '<' | '>' | '<=' | '>=' | '+' | '-' | '*' | '/' | '\\' | '^' | '&';
|
|
28
|
+
/**
|
|
29
|
+
* An exact decimal value, `mantissa` x 10^-`scale`. The mantissa is an integer in decimal text
|
|
30
|
+
* (a string keeps the tree JSON-serialisable); `BigInt(mantissa)` gives it exactly.
|
|
31
|
+
*/
|
|
32
|
+
interface ExactDecimal {
|
|
33
|
+
/** The integer mantissa, in decimal text. */
|
|
34
|
+
readonly mantissa: string;
|
|
35
|
+
/** The number of decimal places: the value is `mantissa` divided by 10 to this power. */
|
|
36
|
+
readonly scale: number;
|
|
37
|
+
}
|
|
38
|
+
/** The parts of a date literal, before conversion to a serial. */
|
|
39
|
+
interface DateParts {
|
|
40
|
+
/** The four-digit year: 1899 when the literal has only a time. */
|
|
41
|
+
readonly year: number;
|
|
42
|
+
/** The month, 1 to 12: 12 when the literal has only a time. */
|
|
43
|
+
readonly month: number;
|
|
44
|
+
/** The day of the month: 30 when the literal has only a time. */
|
|
45
|
+
readonly day: number;
|
|
46
|
+
/** The hour, 0 to 23: 0 when the literal has only a date. */
|
|
47
|
+
readonly hour: number;
|
|
48
|
+
/** The minute: 0 when the literal has only a date. */
|
|
49
|
+
readonly minute: number;
|
|
50
|
+
/** The second: 0 when the literal has only a date. */
|
|
51
|
+
readonly second: number;
|
|
52
|
+
/** Whether the literal names a date, a time, or both. */
|
|
53
|
+
readonly hasDate: boolean;
|
|
54
|
+
/** Whether the literal has a time part. */
|
|
55
|
+
readonly hasTime: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface TokenBase {
|
|
58
|
+
/** The exact source text of the token. */
|
|
59
|
+
readonly text: string;
|
|
60
|
+
readonly span: Span;
|
|
61
|
+
/** Whether whitespace (or a line continuation) separates it from the previous token. */
|
|
62
|
+
readonly spaceBefore: boolean;
|
|
63
|
+
/** Whether a line continuation is part of that whitespace. */
|
|
64
|
+
readonly afterContinuation: boolean;
|
|
65
|
+
/** Whether it is the first token of a logical line. */
|
|
66
|
+
readonly lineStart: boolean;
|
|
67
|
+
}
|
|
68
|
+
interface WordToken extends TokenBase {
|
|
69
|
+
readonly kind: 'word';
|
|
70
|
+
/** The name without brackets or type suffix, as written. */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** `name` lower-cased, for case-insensitive comparison. */
|
|
73
|
+
readonly lower: string;
|
|
74
|
+
readonly suffix: TypeSuffix | null;
|
|
75
|
+
/** A foreign name written in brackets, `[My Name]`: never a keyword. */
|
|
76
|
+
readonly bracketed: boolean;
|
|
77
|
+
/** The reserved word it is (lower-cased), unless bracketed or suffixed. */
|
|
78
|
+
readonly keyword: string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Set on the `Next` the parser reads in place of the comma of `Next i, j`. It is never in the
|
|
81
|
+
* token list: the parser's cursor holds it for one read.
|
|
82
|
+
*/
|
|
83
|
+
readonly synthetic?: true;
|
|
84
|
+
}
|
|
85
|
+
interface NumberToken extends TokenBase {
|
|
86
|
+
readonly kind: 'number';
|
|
87
|
+
readonly value: number;
|
|
88
|
+
/** The exact value of a LongLong literal outside the safe integer range, in decimal. */
|
|
89
|
+
readonly bigValue: string | null;
|
|
90
|
+
/** The exact value of a Currency literal: ten-thousandths, `scale` 4. Null for other types. */
|
|
91
|
+
readonly exact: ExactDecimal | null;
|
|
92
|
+
readonly literalType: NumberLiteralType;
|
|
93
|
+
readonly radix: 8 | 10 | 16;
|
|
94
|
+
readonly suffix: TypeSuffix | null;
|
|
95
|
+
/** Whether it is written as a whole number (no point, no exponent). */
|
|
96
|
+
readonly integral: boolean;
|
|
97
|
+
}
|
|
98
|
+
interface StringToken extends TokenBase {
|
|
99
|
+
readonly kind: 'string';
|
|
100
|
+
readonly value: string;
|
|
101
|
+
}
|
|
102
|
+
interface DateToken extends TokenBase {
|
|
103
|
+
readonly kind: 'date';
|
|
104
|
+
/** The OLE Automation date serial (days since 1899-12-30, time as the fraction). */
|
|
105
|
+
readonly value: number;
|
|
106
|
+
readonly parts: DateParts;
|
|
107
|
+
}
|
|
108
|
+
interface PunctToken extends TokenBase {
|
|
109
|
+
readonly kind: 'punct';
|
|
110
|
+
readonly value: Punctuator;
|
|
111
|
+
}
|
|
112
|
+
/** The end of a logical line. Continued lines do not produce one. */
|
|
113
|
+
interface NewlineToken extends TokenBase {
|
|
114
|
+
readonly kind: 'newline';
|
|
115
|
+
}
|
|
116
|
+
/** `#If`, `#ElseIf`, `#Else`, `#End` (of `#End If`), `#EndIf`, `#Const` at the start of a line. */
|
|
117
|
+
interface DirectiveToken extends TokenBase {
|
|
118
|
+
readonly kind: 'directive';
|
|
119
|
+
readonly directive: 'if' | 'elseif' | 'else' | 'end' | 'endif' | 'const';
|
|
120
|
+
}
|
|
121
|
+
interface InvalidToken extends TokenBase {
|
|
122
|
+
readonly kind: 'invalid';
|
|
123
|
+
}
|
|
124
|
+
interface EofToken extends TokenBase {
|
|
125
|
+
readonly kind: 'eof';
|
|
126
|
+
}
|
|
127
|
+
/** A token of VBA source, told apart by its `kind`. */
|
|
128
|
+
type Token = WordToken | NumberToken | StringToken | DateToken | PunctToken | NewlineToken | DirectiveToken | InvalidToken | EofToken;
|
|
129
|
+
/** Source text the parser skips but an editor shows: comments and line continuations. */
|
|
130
|
+
interface Trivia {
|
|
131
|
+
/** A `'` comment, a `Rem` comment, or a line continuation (` _` at the end of a line). */
|
|
132
|
+
readonly kind: 'comment' | 'rem' | 'continuation';
|
|
133
|
+
/** The exact source text. */
|
|
134
|
+
readonly text: string;
|
|
135
|
+
/** Where it is in the source. */
|
|
136
|
+
readonly span: Span;
|
|
137
|
+
}
|
|
138
|
+
/** A name as written: `Foo`, `s$`, `[My Name]`. Compare names case-insensitively. */
|
|
139
|
+
interface NameRef {
|
|
140
|
+
readonly kind: 'NameRef';
|
|
141
|
+
readonly span: Span;
|
|
142
|
+
/** The name as written, without brackets or type suffix. */
|
|
143
|
+
readonly name: string;
|
|
144
|
+
/** The type-declaration character written after the name (`s$`), if any. */
|
|
145
|
+
readonly suffix: TypeSuffix | null;
|
|
146
|
+
/** Whether the name is written in brackets (`[My Name]`), so never a keyword. */
|
|
147
|
+
readonly bracketed: boolean;
|
|
148
|
+
}
|
|
149
|
+
/** A type in an `As` clause, `New`, `TypeOf ... Is` or `Implements`: `Long`, `Excel.Range`. */
|
|
150
|
+
interface TypeRef {
|
|
151
|
+
readonly kind: 'TypeRef';
|
|
152
|
+
readonly span: Span;
|
|
153
|
+
/** The dotted name as written, `Excel.Range`. */
|
|
154
|
+
readonly name: string;
|
|
155
|
+
/** Each dotted part of the name, in order. */
|
|
156
|
+
readonly parts: readonly NameRef[];
|
|
157
|
+
/** The built-in type it names, when it is a single reserved type name. */
|
|
158
|
+
readonly builtin: BuiltinTypeName | null;
|
|
159
|
+
}
|
|
160
|
+
/** A number literal: `42`, `3.5!`, `&HFF`, `1E3`, `12.5@` ([MS-VBAL] 3.3.2). */
|
|
161
|
+
interface NumberLiteral {
|
|
162
|
+
readonly kind: 'NumberLiteral';
|
|
163
|
+
readonly span: Span;
|
|
164
|
+
/** The value as a JavaScript number; a Single is already rounded to single precision. */
|
|
165
|
+
readonly value: number;
|
|
166
|
+
/** The exact decimal value of a LongLong literal beyond the safe integer range, else null. */
|
|
167
|
+
readonly bigValue: string | null;
|
|
168
|
+
/**
|
|
169
|
+
* The exact value of a Currency literal (`922337203685477.5807@`), in ten-thousandths
|
|
170
|
+
* (`scale` 4), rounded half to even as VBA does; null for other types.
|
|
171
|
+
*/
|
|
172
|
+
readonly exact: ExactDecimal | null;
|
|
173
|
+
/** The literal's declared type, from its value, suffix and form. */
|
|
174
|
+
readonly literalType: NumberLiteralType;
|
|
175
|
+
/** 16 for `&H`, 8 for `&O` or `&`, 10 otherwise. */
|
|
176
|
+
readonly radix: 8 | 10 | 16;
|
|
177
|
+
/** The type-declaration character written after it, if any. */
|
|
178
|
+
readonly suffix: TypeSuffix | null;
|
|
179
|
+
/** The source text as written. */
|
|
180
|
+
readonly text: string;
|
|
181
|
+
}
|
|
182
|
+
/** A string literal: `"text"`. */
|
|
183
|
+
interface StringLiteral {
|
|
184
|
+
readonly kind: 'StringLiteral';
|
|
185
|
+
readonly span: Span;
|
|
186
|
+
/** The text, with doubled quotes (`""`) already undone. */
|
|
187
|
+
readonly value: string;
|
|
188
|
+
}
|
|
189
|
+
/** A date literal: `#1/2/2003#`, `#10:30 PM#` ([MS-VBAL] 3.3.3). */
|
|
190
|
+
interface DateLiteral {
|
|
191
|
+
readonly kind: 'DateLiteral';
|
|
192
|
+
readonly span: Span;
|
|
193
|
+
/** OLE Automation date serial. */
|
|
194
|
+
readonly value: number;
|
|
195
|
+
/** The date and time fields as read. */
|
|
196
|
+
readonly parts: DateParts;
|
|
197
|
+
}
|
|
198
|
+
/** `True` or `False`. */
|
|
199
|
+
interface BooleanLiteral {
|
|
200
|
+
readonly kind: 'BooleanLiteral';
|
|
201
|
+
readonly span: Span;
|
|
202
|
+
/** True for `True`. */
|
|
203
|
+
readonly value: boolean;
|
|
204
|
+
}
|
|
205
|
+
/** `Nothing`, `Empty` or `Null`. */
|
|
206
|
+
interface SpecialLiteral {
|
|
207
|
+
readonly kind: 'NothingLiteral' | 'EmptyLiteral' | 'NullLiteral';
|
|
208
|
+
readonly span: Span;
|
|
209
|
+
}
|
|
210
|
+
/** A simple name in an expression: a variable, constant, procedure or object. */
|
|
211
|
+
interface NameExpression {
|
|
212
|
+
readonly kind: 'Name';
|
|
213
|
+
readonly span: Span;
|
|
214
|
+
/** The name. */
|
|
215
|
+
readonly name: NameRef;
|
|
216
|
+
}
|
|
217
|
+
/** `Me`: the current object in a class, form or document module. */
|
|
218
|
+
interface MeExpression {
|
|
219
|
+
readonly kind: 'Me';
|
|
220
|
+
readonly span: Span;
|
|
221
|
+
}
|
|
222
|
+
/** `object.member`, or `.member` inside a `With` block when `object` is null. */
|
|
223
|
+
interface MemberAccess {
|
|
224
|
+
readonly kind: 'MemberAccess';
|
|
225
|
+
readonly span: Span;
|
|
226
|
+
/** The object expression; null inside a `With` block (`.member`). */
|
|
227
|
+
readonly object: Expression | null;
|
|
228
|
+
/** The member name. */
|
|
229
|
+
readonly member: NameRef;
|
|
230
|
+
}
|
|
231
|
+
/** `object!key` (the default member called with the string "key"), or `!key` inside `With`. */
|
|
232
|
+
interface DictionaryAccess {
|
|
233
|
+
readonly kind: 'DictionaryAccess';
|
|
234
|
+
readonly span: Span;
|
|
235
|
+
/** The object expression; null inside a `With` block (`!key`). */
|
|
236
|
+
readonly object: Expression | null;
|
|
237
|
+
/** The key, as a name; it is passed as the string of its text. */
|
|
238
|
+
readonly key: NameRef;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* `target(arguments)`: a call, an array index or a default-member access. VBA cannot tell them
|
|
242
|
+
* apart without knowing what `target` is, so the executor resolves it.
|
|
243
|
+
*/
|
|
244
|
+
interface CallOrIndex {
|
|
245
|
+
readonly kind: 'CallOrIndex';
|
|
246
|
+
readonly span: Span;
|
|
247
|
+
/** The expression before the parentheses. */
|
|
248
|
+
readonly target: Expression;
|
|
249
|
+
/** The arguments, in order, omitted ones included. */
|
|
250
|
+
readonly args: readonly Argument[];
|
|
251
|
+
}
|
|
252
|
+
/** One argument of a call: positional, named (`name:=value`) or omitted (`f(1, , 3)`). */
|
|
253
|
+
interface Argument {
|
|
254
|
+
readonly kind: 'Argument';
|
|
255
|
+
readonly span: Span;
|
|
256
|
+
/** Null when the argument is omitted. */
|
|
257
|
+
readonly value: Expression | null;
|
|
258
|
+
/** The parameter name of a named argument (`name:=value`), else null. */
|
|
259
|
+
readonly name: NameRef | null;
|
|
260
|
+
/** `ByVal x` passed to a `Declare`d procedure. */
|
|
261
|
+
readonly byVal: boolean;
|
|
262
|
+
}
|
|
263
|
+
/** A parenthesised expression. Kept because `Foo (x)` passes `x` by value. */
|
|
264
|
+
interface ParenExpression {
|
|
265
|
+
readonly kind: 'Paren';
|
|
266
|
+
readonly span: Span;
|
|
267
|
+
/** The expression inside the parentheses. */
|
|
268
|
+
readonly expression: Expression;
|
|
269
|
+
}
|
|
270
|
+
/** A unary operator: negation, unary plus, or `Not`. */
|
|
271
|
+
type UnaryOperator = '-' | '+' | 'Not';
|
|
272
|
+
/** A unary operation: `-x`, `+x`, `Not x`. */
|
|
273
|
+
interface UnaryExpression {
|
|
274
|
+
readonly kind: 'Unary';
|
|
275
|
+
readonly span: Span;
|
|
276
|
+
/** The operator. */
|
|
277
|
+
readonly operator: UnaryOperator;
|
|
278
|
+
/** The expression it applies to. */
|
|
279
|
+
readonly operand: Expression;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* A binary operator. Precedence follows [MS-VBAL] 5.6.9, and every one is left-associative, `^`
|
|
283
|
+
* included.
|
|
284
|
+
*/
|
|
285
|
+
type BinaryOperator = '^' | '*' | '/' | '\\' | 'Mod' | '+' | '-' | '&' | '=' | '<>' | '<' | '>' | '<=' | '>=' | 'Like' | 'Is' | 'And' | 'Or' | 'Xor' | 'Eqv' | 'Imp';
|
|
286
|
+
/** A binary operation: `a + b`, `s Like "A*"`, `x Is Nothing`. */
|
|
287
|
+
interface BinaryExpression {
|
|
288
|
+
readonly kind: 'Binary';
|
|
289
|
+
readonly span: Span;
|
|
290
|
+
/** The operator. */
|
|
291
|
+
readonly operator: BinaryOperator;
|
|
292
|
+
/** The left operand. */
|
|
293
|
+
readonly left: Expression;
|
|
294
|
+
/** The right operand. */
|
|
295
|
+
readonly right: Expression;
|
|
296
|
+
}
|
|
297
|
+
/** `TypeOf expression Is Type`. */
|
|
298
|
+
interface TypeOfExpression {
|
|
299
|
+
readonly kind: 'TypeOf';
|
|
300
|
+
readonly span: Span;
|
|
301
|
+
/** The object tested. */
|
|
302
|
+
readonly expression: Expression;
|
|
303
|
+
/** The type it is tested against. */
|
|
304
|
+
readonly type: TypeRef;
|
|
305
|
+
}
|
|
306
|
+
/** `New Type`. */
|
|
307
|
+
interface NewExpression {
|
|
308
|
+
readonly kind: 'New';
|
|
309
|
+
readonly span: Span;
|
|
310
|
+
/** The class to create. */
|
|
311
|
+
readonly type: TypeRef;
|
|
312
|
+
}
|
|
313
|
+
/** `AddressOf procedure`. */
|
|
314
|
+
interface AddressOfExpression {
|
|
315
|
+
readonly kind: 'AddressOf';
|
|
316
|
+
readonly span: Span;
|
|
317
|
+
/** The procedure named. */
|
|
318
|
+
readonly procedure: Expression;
|
|
319
|
+
}
|
|
320
|
+
/** `#n`: a file number in a file statement or in `Input(n, #f)`. */
|
|
321
|
+
interface FileNumberExpression {
|
|
322
|
+
readonly kind: 'FileNumber';
|
|
323
|
+
readonly span: Span;
|
|
324
|
+
/** The file number, without the `#`. */
|
|
325
|
+
readonly expression: Expression;
|
|
326
|
+
}
|
|
327
|
+
/** What could not be parsed; a diagnostic covers the same span. */
|
|
328
|
+
interface InvalidExpression {
|
|
329
|
+
readonly kind: 'InvalidExpression';
|
|
330
|
+
readonly span: Span;
|
|
331
|
+
}
|
|
332
|
+
/** Any literal expression. */
|
|
333
|
+
type Literal = NumberLiteral | StringLiteral | DateLiteral | BooleanLiteral | SpecialLiteral;
|
|
334
|
+
/**
|
|
335
|
+
* Any expression node. Like every node of the tree, each has a `kind` discriminant and a `span`,
|
|
336
|
+
* the source range it covers.
|
|
337
|
+
*/
|
|
338
|
+
type Expression = Literal | NameExpression | MeExpression | MemberAccess | DictionaryAccess | CallOrIndex | ParenExpression | UnaryExpression | BinaryExpression | TypeOfExpression | NewExpression | AddressOfExpression | FileNumberExpression | InvalidExpression;
|
|
339
|
+
/** One item of a `Print` or `Debug.Print` list, with the separator that follows it. */
|
|
340
|
+
interface OutputItem {
|
|
341
|
+
readonly kind: 'OutputItem';
|
|
342
|
+
readonly span: Span;
|
|
343
|
+
/** `Spc(n)`, `Tab(n)`, bare `Tab`, or a value. */
|
|
344
|
+
readonly form: 'value' | 'spc' | 'tab';
|
|
345
|
+
/** The value, or the count of `Spc(n)`/`Tab(n)`; null for bare `Tab` or an empty item. */
|
|
346
|
+
readonly value: Expression | null;
|
|
347
|
+
/** `;` keeps the position, `,` moves to the next print zone; null at the end. */
|
|
348
|
+
readonly separator: ';' | ',' | null;
|
|
349
|
+
}
|
|
350
|
+
/** `Debug.Print items` or `Print #n, items`. */
|
|
351
|
+
interface PrintStatement {
|
|
352
|
+
readonly kind: 'Print';
|
|
353
|
+
readonly span: Span;
|
|
354
|
+
/** `debug` for `Debug.Print`, `file` for `Print #n`. */
|
|
355
|
+
readonly channel: 'debug' | 'file';
|
|
356
|
+
/** The file number of `Print #n`, without the `#`; null for `Debug.Print`. */
|
|
357
|
+
readonly fileNumber: Expression | null;
|
|
358
|
+
/** The items printed, in order. */
|
|
359
|
+
readonly items: readonly OutputItem[];
|
|
360
|
+
}
|
|
361
|
+
/** `Open path For mode [Access a] [lock] As [#]n [Len = r]`. */
|
|
362
|
+
interface OpenStatement {
|
|
363
|
+
readonly kind: 'Open';
|
|
364
|
+
readonly span: Span;
|
|
365
|
+
/** The file path. */
|
|
366
|
+
readonly path: Expression;
|
|
367
|
+
/** Null when `For mode` is omitted (Random). */
|
|
368
|
+
readonly mode: 'Append' | 'Binary' | 'Input' | 'Output' | 'Random' | null;
|
|
369
|
+
/** The `Access` clause, or null when omitted. */
|
|
370
|
+
readonly access: 'Read' | 'Write' | 'ReadWrite' | null;
|
|
371
|
+
/** The lock clause, or null when omitted. */
|
|
372
|
+
readonly lock: 'Shared' | 'LockRead' | 'LockWrite' | 'LockReadWrite' | null;
|
|
373
|
+
/** The file number after `As`, without the `#`. */
|
|
374
|
+
readonly fileNumber: Expression;
|
|
375
|
+
/** The `Len =` record length, or null when omitted. */
|
|
376
|
+
readonly recordLength: Expression | null;
|
|
377
|
+
}
|
|
378
|
+
/** `Close [#a, #b]`, or `Reset`-like `Close` with no list. */
|
|
379
|
+
interface CloseStatement {
|
|
380
|
+
readonly kind: 'Close';
|
|
381
|
+
readonly span: Span;
|
|
382
|
+
/** The file numbers to close, without `#`; empty to close every open file. */
|
|
383
|
+
readonly fileNumbers: readonly Expression[];
|
|
384
|
+
}
|
|
385
|
+
/** `Input #n, a, b`. */
|
|
386
|
+
interface InputStatement {
|
|
387
|
+
readonly kind: 'Input';
|
|
388
|
+
readonly span: Span;
|
|
389
|
+
/** The file number, without the `#`. */
|
|
390
|
+
readonly fileNumber: Expression;
|
|
391
|
+
/** The variables read into, in order. */
|
|
392
|
+
readonly targets: readonly Expression[];
|
|
393
|
+
}
|
|
394
|
+
/** `Line Input #n, s`. */
|
|
395
|
+
interface LineInputStatement {
|
|
396
|
+
readonly kind: 'LineInput';
|
|
397
|
+
readonly span: Span;
|
|
398
|
+
/** The file number, without the `#`. */
|
|
399
|
+
readonly fileNumber: Expression;
|
|
400
|
+
/** The string variable that receives the line. */
|
|
401
|
+
readonly target: Expression;
|
|
402
|
+
}
|
|
403
|
+
/** `Write #n, a, b`. */
|
|
404
|
+
interface WriteStatement {
|
|
405
|
+
readonly kind: 'Write';
|
|
406
|
+
readonly span: Span;
|
|
407
|
+
/** The file number, without the `#`. */
|
|
408
|
+
readonly fileNumber: Expression;
|
|
409
|
+
/** The items written, in order. */
|
|
410
|
+
readonly items: readonly OutputItem[];
|
|
411
|
+
}
|
|
412
|
+
/** `Get #n, [record], target` or `Put #n, [record], value`. */
|
|
413
|
+
interface GetPutStatement {
|
|
414
|
+
readonly kind: 'Get' | 'Put';
|
|
415
|
+
readonly span: Span;
|
|
416
|
+
/** The file number, without the `#`. */
|
|
417
|
+
readonly fileNumber: Expression;
|
|
418
|
+
/** The record number or byte position, or null when omitted (the current position). */
|
|
419
|
+
readonly recordNumber: Expression | null;
|
|
420
|
+
/** The variable read into (`Get`) or written from (`Put`). */
|
|
421
|
+
readonly target: Expression;
|
|
422
|
+
}
|
|
423
|
+
/** `Seek #n, position`. */
|
|
424
|
+
interface SeekStatement {
|
|
425
|
+
readonly kind: 'Seek';
|
|
426
|
+
readonly span: Span;
|
|
427
|
+
/** The file number, without the `#`. */
|
|
428
|
+
readonly fileNumber: Expression;
|
|
429
|
+
/** The new record number or byte position. */
|
|
430
|
+
readonly position: Expression;
|
|
431
|
+
}
|
|
432
|
+
/** `Lock #n[, from [To to]]` or `Unlock`. */
|
|
433
|
+
interface LockStatement {
|
|
434
|
+
readonly kind: 'Lock' | 'Unlock';
|
|
435
|
+
readonly span: Span;
|
|
436
|
+
/** The file number, without the `#`. */
|
|
437
|
+
readonly fileNumber: Expression;
|
|
438
|
+
/** The first record or byte, or null when omitted. */
|
|
439
|
+
readonly from: Expression | null;
|
|
440
|
+
/** The last record or byte (after `To`), or null when omitted. */
|
|
441
|
+
readonly to: Expression | null;
|
|
442
|
+
}
|
|
443
|
+
/** `Width #n, width`. */
|
|
444
|
+
interface WidthStatement {
|
|
445
|
+
readonly kind: 'Width';
|
|
446
|
+
readonly span: Span;
|
|
447
|
+
/** The file number, without the `#`. */
|
|
448
|
+
readonly fileNumber: Expression;
|
|
449
|
+
/** The line width. */
|
|
450
|
+
readonly width: Expression;
|
|
451
|
+
}
|
|
452
|
+
/** A statement that reads, writes or manages a file opened with `Open`, or `Debug.Print`. */
|
|
453
|
+
type FileStatement = PrintStatement | OpenStatement | CloseStatement | InputStatement | LineInputStatement | WriteStatement | GetPutStatement | SeekStatement | LockStatement | WidthStatement;
|
|
454
|
+
/** A label (`Retry:`) or line number (`100`) that `GoTo`, `GoSub`, `Resume` and `On` name. */
|
|
455
|
+
interface LabelRef {
|
|
456
|
+
readonly kind: 'LabelRef';
|
|
457
|
+
readonly span: Span;
|
|
458
|
+
/** The label name, or the line number's digits. */
|
|
459
|
+
readonly name: string;
|
|
460
|
+
/** Whether it is a line number (`100`) rather than a name (`Retry`). */
|
|
461
|
+
readonly isLineNumber: boolean;
|
|
462
|
+
}
|
|
463
|
+
/** A label definition at the start of a line. Statements after it on the line follow it. */
|
|
464
|
+
interface LabelStatement {
|
|
465
|
+
readonly kind: 'Label';
|
|
466
|
+
readonly span: Span;
|
|
467
|
+
/** The label or line number defined. */
|
|
468
|
+
readonly label: LabelRef;
|
|
469
|
+
}
|
|
470
|
+
/** `[Let] target = value` or `Set target = value`. */
|
|
471
|
+
interface AssignmentStatement {
|
|
472
|
+
readonly kind: 'Assignment';
|
|
473
|
+
readonly span: Span;
|
|
474
|
+
/** `Set` for an object assignment, else `Let`. */
|
|
475
|
+
readonly assignment: 'Let' | 'Set';
|
|
476
|
+
/** Whether `Let` is written. */
|
|
477
|
+
readonly explicitLet: boolean;
|
|
478
|
+
/** What is assigned to: a variable, element, field or property. */
|
|
479
|
+
readonly target: Expression;
|
|
480
|
+
/** The value assigned. */
|
|
481
|
+
readonly value: Expression;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* A call statement: `Call Foo(a)`, `Foo a, b`, `obj.Method`, `Foo (x)`. Without `Call`, a single
|
|
485
|
+
* parenthesised argument stays a `Paren` expression (it is passed by value).
|
|
486
|
+
*/
|
|
487
|
+
interface CallStatement {
|
|
488
|
+
readonly kind: 'Call';
|
|
489
|
+
readonly span: Span;
|
|
490
|
+
/** What is called, without its argument list: a name or a member access. */
|
|
491
|
+
readonly callee: Expression;
|
|
492
|
+
/** The arguments, in order. */
|
|
493
|
+
readonly args: readonly Argument[];
|
|
494
|
+
/** Whether the `Call` keyword is written. */
|
|
495
|
+
readonly explicitCall: boolean;
|
|
496
|
+
}
|
|
497
|
+
/** One `If`/`ElseIf` condition with its statements. */
|
|
498
|
+
interface IfBranch {
|
|
499
|
+
readonly kind: 'IfBranch';
|
|
500
|
+
readonly span: Span;
|
|
501
|
+
/** The condition. */
|
|
502
|
+
readonly condition: Expression;
|
|
503
|
+
/** The statements that run when the condition is true. */
|
|
504
|
+
readonly body: readonly Statement[];
|
|
505
|
+
}
|
|
506
|
+
/** A block `If ... End If` or a single-line `If c Then a: b Else c`. */
|
|
507
|
+
interface IfStatement {
|
|
508
|
+
readonly kind: 'If';
|
|
509
|
+
readonly span: Span;
|
|
510
|
+
/** Whether it is written as a block or on one line. */
|
|
511
|
+
readonly form: 'block' | 'singleLine';
|
|
512
|
+
/** The `If` branch, then each `ElseIf`, in order. */
|
|
513
|
+
readonly branches: readonly IfBranch[];
|
|
514
|
+
/** The `Else` statements, or null when there is no `Else`. */
|
|
515
|
+
readonly elseBody: readonly Statement[] | null;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* One test of a `Case` clause: a value (`Case 1`), a range (`Case 1 To 5`, `from` and `to`) or a
|
|
519
|
+
* comparison (`Case Is >= 10`, `operator` and `value`).
|
|
520
|
+
*/
|
|
521
|
+
type CaseTest = {
|
|
522
|
+
readonly kind: 'CaseValue';
|
|
523
|
+
readonly span: Span;
|
|
524
|
+
readonly value: Expression;
|
|
525
|
+
} | {
|
|
526
|
+
readonly kind: 'CaseRange';
|
|
527
|
+
readonly span: Span;
|
|
528
|
+
/** The lower end of the range. */
|
|
529
|
+
readonly from: Expression;
|
|
530
|
+
/** The upper end of the range. */
|
|
531
|
+
readonly to: Expression;
|
|
532
|
+
} | {
|
|
533
|
+
readonly kind: 'CaseIs';
|
|
534
|
+
readonly span: Span;
|
|
535
|
+
/** The comparison operator after `Is`. */
|
|
536
|
+
readonly operator: '=' | '<>' | '<' | '>' | '<=' | '>=';
|
|
537
|
+
/** The value the subject is compared with. */
|
|
538
|
+
readonly value: Expression;
|
|
539
|
+
};
|
|
540
|
+
/** One `Case` clause of a `Select Case`, with its tests and statements. */
|
|
541
|
+
interface CaseClause {
|
|
542
|
+
readonly kind: 'CaseClause';
|
|
543
|
+
readonly span: Span;
|
|
544
|
+
/** The comma-separated tests; the clause runs when any of them matches. */
|
|
545
|
+
readonly tests: readonly CaseTest[];
|
|
546
|
+
/** The statements of the clause. */
|
|
547
|
+
readonly body: readonly Statement[];
|
|
548
|
+
}
|
|
549
|
+
/** A `Select Case subject ... End Select` block. */
|
|
550
|
+
interface SelectCaseStatement {
|
|
551
|
+
readonly kind: 'SelectCase';
|
|
552
|
+
readonly span: Span;
|
|
553
|
+
/** The expression the cases test. */
|
|
554
|
+
readonly subject: Expression;
|
|
555
|
+
/** The `Case` clauses, in order (`Case Else` excluded). */
|
|
556
|
+
readonly cases: readonly CaseClause[];
|
|
557
|
+
/** The `Case Else` statements, or null when there is none. */
|
|
558
|
+
readonly elseBody: readonly Statement[] | null;
|
|
559
|
+
}
|
|
560
|
+
/** A `For counter = start To end [Step step] ... Next` loop. */
|
|
561
|
+
interface ForStatement {
|
|
562
|
+
readonly kind: 'For';
|
|
563
|
+
readonly span: Span;
|
|
564
|
+
/** The loop variable. */
|
|
565
|
+
readonly counter: Expression;
|
|
566
|
+
/** The initial value. */
|
|
567
|
+
readonly start: Expression;
|
|
568
|
+
/** The final value. */
|
|
569
|
+
readonly end: Expression;
|
|
570
|
+
/** The `Step` value, or null (1). */
|
|
571
|
+
readonly step: Expression | null;
|
|
572
|
+
/** The loop body. */
|
|
573
|
+
readonly body: readonly Statement[];
|
|
574
|
+
/** The variable named after `Next`, if any. */
|
|
575
|
+
readonly nextCounter: Expression | null;
|
|
576
|
+
/** Whether this loop's `Next` is shared with an inner loop (`Next j, i`). */
|
|
577
|
+
readonly sharedNext: boolean;
|
|
578
|
+
}
|
|
579
|
+
/** A `For Each element In collection ... Next` loop. */
|
|
580
|
+
interface ForEachStatement {
|
|
581
|
+
readonly kind: 'ForEach';
|
|
582
|
+
readonly span: Span;
|
|
583
|
+
/** The variable that takes each element. */
|
|
584
|
+
readonly element: Expression;
|
|
585
|
+
/** The array or collection iterated. */
|
|
586
|
+
readonly collection: Expression;
|
|
587
|
+
/** The loop body. */
|
|
588
|
+
readonly body: readonly Statement[];
|
|
589
|
+
/** The variable named after `Next`, if any. */
|
|
590
|
+
readonly nextCounter: Expression | null;
|
|
591
|
+
/** Whether this loop's `Next` is shared with an inner loop (`Next j, i`). */
|
|
592
|
+
readonly sharedNext: boolean;
|
|
593
|
+
}
|
|
594
|
+
/** The `While` or `Until` condition of a `Do` loop. */
|
|
595
|
+
interface LoopCondition {
|
|
596
|
+
readonly kind: 'LoopCondition';
|
|
597
|
+
readonly span: Span;
|
|
598
|
+
/** `While` loops while the condition is true, `Until` while it is false. */
|
|
599
|
+
readonly mode: 'While' | 'Until';
|
|
600
|
+
/** Tested before each pass (`Do While`) or after it (`Loop While`). */
|
|
601
|
+
readonly position: 'pre' | 'post';
|
|
602
|
+
/** The condition. */
|
|
603
|
+
readonly expression: Expression;
|
|
604
|
+
}
|
|
605
|
+
/** A `Do ... Loop` loop, with its condition at the top, the bottom or nowhere. */
|
|
606
|
+
interface DoLoopStatement {
|
|
607
|
+
readonly kind: 'DoLoop';
|
|
608
|
+
readonly span: Span;
|
|
609
|
+
/** The condition, or null for an endless `Do ... Loop`. */
|
|
610
|
+
readonly condition: LoopCondition | null;
|
|
611
|
+
/** The loop body. */
|
|
612
|
+
readonly body: readonly Statement[];
|
|
613
|
+
}
|
|
614
|
+
/** A `While condition ... Wend` loop. */
|
|
615
|
+
interface WhileStatement {
|
|
616
|
+
readonly kind: 'While';
|
|
617
|
+
readonly span: Span;
|
|
618
|
+
/** The condition tested before each pass. */
|
|
619
|
+
readonly condition: Expression;
|
|
620
|
+
/** The loop body. */
|
|
621
|
+
readonly body: readonly Statement[];
|
|
622
|
+
}
|
|
623
|
+
/** A `With object ... End With` block. */
|
|
624
|
+
interface WithStatement {
|
|
625
|
+
readonly kind: 'With';
|
|
626
|
+
readonly span: Span;
|
|
627
|
+
/** The object that `.member` and `!key` inside the block refer to. */
|
|
628
|
+
readonly object: Expression;
|
|
629
|
+
/** The statements of the block. */
|
|
630
|
+
readonly body: readonly Statement[];
|
|
631
|
+
}
|
|
632
|
+
/** An `Exit Do`, `Exit For`, `Exit Function`, `Exit Property` or `Exit Sub` statement. */
|
|
633
|
+
interface ExitStatement {
|
|
634
|
+
readonly kind: 'Exit';
|
|
635
|
+
readonly span: Span;
|
|
636
|
+
/** What it exits. */
|
|
637
|
+
readonly target: 'Do' | 'For' | 'Function' | 'Property' | 'Sub';
|
|
638
|
+
}
|
|
639
|
+
/** A `GoTo label` or `GoSub label` statement. */
|
|
640
|
+
interface GoToStatement {
|
|
641
|
+
readonly kind: 'GoTo' | 'GoSub';
|
|
642
|
+
readonly span: Span;
|
|
643
|
+
/** The label jumped to. */
|
|
644
|
+
readonly label: LabelRef;
|
|
645
|
+
}
|
|
646
|
+
/** A `Return` (from `GoSub`), `Stop` or `End` statement. */
|
|
647
|
+
interface SimpleStatement {
|
|
648
|
+
readonly kind: 'Return' | 'Stop' | 'End';
|
|
649
|
+
readonly span: Span;
|
|
650
|
+
}
|
|
651
|
+
/** `On [Local] Error GoTo label | GoTo 0 | GoTo -1 | Resume Next`. */
|
|
652
|
+
interface OnErrorStatement {
|
|
653
|
+
readonly kind: 'OnError';
|
|
654
|
+
readonly span: Span;
|
|
655
|
+
/** Whether `Local` is written (`On Local Error`). */
|
|
656
|
+
readonly local: boolean;
|
|
657
|
+
/** `goto`: jump to `label`; `resumeNext`; `disable` is `GoTo 0`; `clear` is `GoTo -1`. */
|
|
658
|
+
readonly action: 'goto' | 'resumeNext' | 'disable' | 'clear';
|
|
659
|
+
/** The handler label for `goto`, else null. */
|
|
660
|
+
readonly label: LabelRef | null;
|
|
661
|
+
}
|
|
662
|
+
/** `Resume`, `Resume 0` (retry), `Resume Next`, `Resume label`. */
|
|
663
|
+
interface ResumeStatement {
|
|
664
|
+
readonly kind: 'Resume';
|
|
665
|
+
readonly span: Span;
|
|
666
|
+
/**
|
|
667
|
+
* `retry` runs the failing statement again, `next` the one after it, `label` jumps to `label`.
|
|
668
|
+
*/
|
|
669
|
+
readonly action: 'retry' | 'next' | 'label';
|
|
670
|
+
/** The label for `label`, else null. */
|
|
671
|
+
readonly label: LabelRef | null;
|
|
672
|
+
}
|
|
673
|
+
/** `On n GoTo a, b` or `On n GoSub a, b`. */
|
|
674
|
+
interface OnGoToStatement {
|
|
675
|
+
readonly kind: 'OnGoTo';
|
|
676
|
+
readonly span: Span;
|
|
677
|
+
/** The 1-based index of the label to jump to. */
|
|
678
|
+
readonly selector: Expression;
|
|
679
|
+
/** Whether it is `On ... GoSub` rather than `On ... GoTo`. */
|
|
680
|
+
readonly gosub: boolean;
|
|
681
|
+
/** The labels, in order. */
|
|
682
|
+
readonly labels: readonly LabelRef[];
|
|
683
|
+
}
|
|
684
|
+
/** One array of a `ReDim` statement: `a(1 To n) As Long`. */
|
|
685
|
+
interface ReDimClause {
|
|
686
|
+
readonly kind: 'ReDimClause';
|
|
687
|
+
readonly span: Span;
|
|
688
|
+
/** The array resized. */
|
|
689
|
+
readonly target: Expression;
|
|
690
|
+
/** The new bounds, one per dimension. */
|
|
691
|
+
readonly bounds: readonly ArrayBound[];
|
|
692
|
+
/** The `As` clause, or null. */
|
|
693
|
+
readonly asClause: AsClause | null;
|
|
694
|
+
}
|
|
695
|
+
/** A `ReDim [Preserve] a(...), ...` statement. */
|
|
696
|
+
interface ReDimStatement {
|
|
697
|
+
readonly kind: 'ReDim';
|
|
698
|
+
readonly span: Span;
|
|
699
|
+
/** Whether `Preserve` is written: existing elements are kept. */
|
|
700
|
+
readonly preserve: boolean;
|
|
701
|
+
/** Each array resized, in order. */
|
|
702
|
+
readonly clauses: readonly ReDimClause[];
|
|
703
|
+
}
|
|
704
|
+
/** An `Erase a, b` statement. */
|
|
705
|
+
interface EraseStatement {
|
|
706
|
+
readonly kind: 'Erase';
|
|
707
|
+
readonly span: Span;
|
|
708
|
+
/** The arrays erased. */
|
|
709
|
+
readonly targets: readonly Expression[];
|
|
710
|
+
}
|
|
711
|
+
/** A `RaiseEvent Name(args)` statement. */
|
|
712
|
+
interface RaiseEventStatement {
|
|
713
|
+
readonly kind: 'RaiseEvent';
|
|
714
|
+
readonly span: Span;
|
|
715
|
+
/** The event raised. */
|
|
716
|
+
readonly name: NameRef;
|
|
717
|
+
/** The arguments, in order. */
|
|
718
|
+
readonly args: readonly Argument[];
|
|
719
|
+
}
|
|
720
|
+
/** `Mid[B][$](target, start[, length]) = value`. */
|
|
721
|
+
interface MidAssignmentStatement {
|
|
722
|
+
readonly kind: 'MidAssignment';
|
|
723
|
+
readonly span: Span;
|
|
724
|
+
/** `Mid` counts characters, `MidB` bytes. */
|
|
725
|
+
readonly function: 'Mid' | 'MidB';
|
|
726
|
+
/** The string variable changed. */
|
|
727
|
+
readonly target: Expression;
|
|
728
|
+
/** The 1-based start position. */
|
|
729
|
+
readonly start: Expression;
|
|
730
|
+
/** How much to replace, or null for as much as `value` holds. */
|
|
731
|
+
readonly length: Expression | null;
|
|
732
|
+
/** The replacement text. */
|
|
733
|
+
readonly value: Expression;
|
|
734
|
+
}
|
|
735
|
+
/** `LSet a = b` or `RSet a = b`. */
|
|
736
|
+
interface LSetStatement {
|
|
737
|
+
readonly kind: 'LSet' | 'RSet';
|
|
738
|
+
readonly span: Span;
|
|
739
|
+
/** The variable assigned. */
|
|
740
|
+
readonly target: Expression;
|
|
741
|
+
/** The value assigned. */
|
|
742
|
+
readonly value: Expression;
|
|
743
|
+
}
|
|
744
|
+
/** `Name old As new`. */
|
|
745
|
+
interface NameStatement {
|
|
746
|
+
readonly kind: 'Name';
|
|
747
|
+
readonly span: Span;
|
|
748
|
+
/** The current path. */
|
|
749
|
+
readonly oldPath: Expression;
|
|
750
|
+
/** The new path. */
|
|
751
|
+
readonly newPath: Expression;
|
|
752
|
+
}
|
|
753
|
+
/** `Error n`. */
|
|
754
|
+
interface ErrorStatement {
|
|
755
|
+
readonly kind: 'Error';
|
|
756
|
+
readonly span: Span;
|
|
757
|
+
/** The error number raised. */
|
|
758
|
+
readonly number: Expression;
|
|
759
|
+
}
|
|
760
|
+
/** What could not be parsed; a diagnostic covers the same span. */
|
|
761
|
+
interface InvalidStatement {
|
|
762
|
+
readonly kind: 'InvalidStatement';
|
|
763
|
+
readonly span: Span;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Any statement node. Like every node of the tree, each has a `kind` discriminant and a `span`, the
|
|
767
|
+
* source range it covers.
|
|
768
|
+
*/
|
|
769
|
+
type Statement = LabelStatement | AssignmentStatement | CallStatement | IfStatement | SelectCaseStatement | ForStatement | ForEachStatement | DoLoopStatement | WhileStatement | WithStatement | ExitStatement | GoToStatement | SimpleStatement | OnErrorStatement | ResumeStatement | OnGoToStatement | ReDimStatement | EraseStatement | RaiseEventStatement | MidAssignmentStatement | LSetStatement | NameStatement | ErrorStatement | FileStatement | VariableDeclaration | ConstDeclaration | AttributeStatement | InvalidStatement;
|
|
770
|
+
/** `As [New] Type [* length]`, with `()` for an array return type. */
|
|
771
|
+
interface AsClause {
|
|
772
|
+
readonly kind: 'AsClause';
|
|
773
|
+
readonly span: Span;
|
|
774
|
+
/** The type named. */
|
|
775
|
+
readonly type: TypeRef;
|
|
776
|
+
/** `As New Class`: the object is created on first use. */
|
|
777
|
+
readonly isNew: boolean;
|
|
778
|
+
/** `String * n`: a fixed-length string. */
|
|
779
|
+
readonly fixedLength: Expression | null;
|
|
780
|
+
/** `Function F() As Long()`: the procedure returns an array. */
|
|
781
|
+
readonly isArray: boolean;
|
|
782
|
+
}
|
|
783
|
+
/** One dimension of an array: `[lower To] upper`. */
|
|
784
|
+
interface ArrayBound {
|
|
785
|
+
readonly kind: 'ArrayBound';
|
|
786
|
+
readonly span: Span;
|
|
787
|
+
/** The lower bound; null when omitted (the module's `Option Base` applies). */
|
|
788
|
+
readonly lower: Expression | null;
|
|
789
|
+
/** The upper bound. */
|
|
790
|
+
readonly upper: Expression;
|
|
791
|
+
}
|
|
792
|
+
/** The parenthesised dimensions after a name. An empty list is a dynamic array `a()`. */
|
|
793
|
+
interface ArrayDimensions {
|
|
794
|
+
readonly kind: 'ArrayDimensions';
|
|
795
|
+
readonly span: Span;
|
|
796
|
+
/** One bound per dimension; empty for a dynamic array. */
|
|
797
|
+
readonly bounds: readonly ArrayBound[];
|
|
798
|
+
}
|
|
799
|
+
/** An access modifier as written. `Global` is the old spelling of `Public`. */
|
|
800
|
+
type Scope = 'Public' | 'Private' | 'Global' | 'Friend';
|
|
801
|
+
/** One name of a `Dim`, `Private`, `Public`, `Global` or `Static` statement. */
|
|
802
|
+
interface VariableDeclarator {
|
|
803
|
+
readonly kind: 'VariableDeclarator';
|
|
804
|
+
readonly span: Span;
|
|
805
|
+
/** The variable name. */
|
|
806
|
+
readonly name: NameRef;
|
|
807
|
+
/** Declared `WithEvents`, so `name_Event` Subs handle the object's events. */
|
|
808
|
+
readonly withEvents: boolean;
|
|
809
|
+
/** The parenthesised array dimensions (`a(1 To 3)`, `a()`), or null when it is not an array. */
|
|
810
|
+
readonly dimensions: ArrayDimensions | null;
|
|
811
|
+
/** The `As` clause, or null (Variant, or the type a suffix or `DefType` gives). */
|
|
812
|
+
readonly asClause: AsClause | null;
|
|
813
|
+
}
|
|
814
|
+
/** `Dim`, `Static`, or a module-level `Private`/`Public`/`Global` variable declaration. */
|
|
815
|
+
interface VariableDeclaration {
|
|
816
|
+
readonly kind: 'VariableDeclaration';
|
|
817
|
+
readonly span: Span;
|
|
818
|
+
/** The keyword that starts the statement. */
|
|
819
|
+
readonly keyword: 'Dim' | 'Static' | 'Private' | 'Public' | 'Global';
|
|
820
|
+
/** Each variable declared, in order. */
|
|
821
|
+
readonly declarators: readonly VariableDeclarator[];
|
|
822
|
+
}
|
|
823
|
+
/** One name of a `Const` statement: `Pi As Double = 3.14159`. */
|
|
824
|
+
interface ConstantDeclarator {
|
|
825
|
+
readonly kind: 'ConstantDeclarator';
|
|
826
|
+
readonly span: Span;
|
|
827
|
+
/** The constant name. */
|
|
828
|
+
readonly name: NameRef;
|
|
829
|
+
/** The `As` clause, or null when the type comes from the value. */
|
|
830
|
+
readonly asClause: AsClause | null;
|
|
831
|
+
/** The value, a constant expression. */
|
|
832
|
+
readonly value: Expression;
|
|
833
|
+
}
|
|
834
|
+
/** `[scope] Const a [As T] = value, ...`. */
|
|
835
|
+
interface ConstDeclaration {
|
|
836
|
+
readonly kind: 'ConstDeclaration';
|
|
837
|
+
readonly span: Span;
|
|
838
|
+
/** The scope keyword, or null when none is written. */
|
|
839
|
+
readonly scope: Scope | null;
|
|
840
|
+
/** Each constant declared, in order. */
|
|
841
|
+
readonly declarators: readonly ConstantDeclarator[];
|
|
842
|
+
}
|
|
843
|
+
/** One field of a user-defined type: `Name As String` or `Values(1 To 3) As Long`. */
|
|
844
|
+
interface TypeMember {
|
|
845
|
+
readonly kind: 'TypeMember';
|
|
846
|
+
readonly span: Span;
|
|
847
|
+
/** The field name. */
|
|
848
|
+
readonly name: NameRef;
|
|
849
|
+
/** The array dimensions of an array field, or null. */
|
|
850
|
+
readonly dimensions: ArrayDimensions | null;
|
|
851
|
+
/** The field's `As` clause, or null (Variant). */
|
|
852
|
+
readonly asClause: AsClause | null;
|
|
853
|
+
}
|
|
854
|
+
/** A user-defined type: `[scope] Type Name ... End Type`. */
|
|
855
|
+
interface TypeDeclaration {
|
|
856
|
+
readonly kind: 'TypeDeclaration';
|
|
857
|
+
readonly span: Span;
|
|
858
|
+
/** The scope keyword, or null (Public). */
|
|
859
|
+
readonly scope: Scope | null;
|
|
860
|
+
/** The type name. */
|
|
861
|
+
readonly name: NameRef;
|
|
862
|
+
/** The fields, in order. */
|
|
863
|
+
readonly members: readonly TypeMember[];
|
|
864
|
+
}
|
|
865
|
+
/** One member of an `Enum`: `Red` or `Red = 1`. */
|
|
866
|
+
interface EnumMember {
|
|
867
|
+
readonly kind: 'EnumMember';
|
|
868
|
+
readonly span: Span;
|
|
869
|
+
/** The member name. */
|
|
870
|
+
readonly name: NameRef;
|
|
871
|
+
/** The value expression; null means one more than the previous member (0 for the first). */
|
|
872
|
+
readonly value: Expression | null;
|
|
873
|
+
}
|
|
874
|
+
/** `[scope] Enum Name ... End Enum`. */
|
|
875
|
+
interface EnumDeclaration {
|
|
876
|
+
readonly kind: 'EnumDeclaration';
|
|
877
|
+
readonly span: Span;
|
|
878
|
+
/** The scope keyword, or null (Public). */
|
|
879
|
+
readonly scope: Scope | null;
|
|
880
|
+
/** The enum name. */
|
|
881
|
+
readonly name: NameRef;
|
|
882
|
+
/** The members, in order. */
|
|
883
|
+
readonly members: readonly EnumMember[];
|
|
884
|
+
}
|
|
885
|
+
/** One parameter of a procedure, event or `Declare`. */
|
|
886
|
+
interface Parameter {
|
|
887
|
+
readonly kind: 'Parameter';
|
|
888
|
+
readonly span: Span;
|
|
889
|
+
/** The parameter name. */
|
|
890
|
+
readonly name: NameRef;
|
|
891
|
+
/** Declared `Optional`. */
|
|
892
|
+
readonly optional: boolean;
|
|
893
|
+
/** The passing mode as written; null means the default, ByRef. */
|
|
894
|
+
readonly passing: 'ByVal' | 'ByRef' | null;
|
|
895
|
+
/** Declared `ParamArray`: it takes the remaining arguments as an array. */
|
|
896
|
+
readonly paramArray: boolean;
|
|
897
|
+
/** `name()`: the parameter is an array. */
|
|
898
|
+
readonly isArray: boolean;
|
|
899
|
+
/** The `As` clause, or null (Variant). */
|
|
900
|
+
readonly asClause: AsClause | null;
|
|
901
|
+
/** The default of an `Optional` parameter (`Optional n = 1`), or null. */
|
|
902
|
+
readonly defaultValue: Expression | null;
|
|
903
|
+
}
|
|
904
|
+
/** `[scope] Declare [PtrSafe] Sub|Function name [CDecl] Lib "lib" [Alias "alias"] (...)`. */
|
|
905
|
+
interface DeclareStatement {
|
|
906
|
+
readonly kind: 'DeclareStatement';
|
|
907
|
+
readonly span: Span;
|
|
908
|
+
/** The scope keyword, or null (Public). */
|
|
909
|
+
readonly scope: Scope | null;
|
|
910
|
+
/** Whether `PtrSafe` is written. */
|
|
911
|
+
readonly ptrSafe: boolean;
|
|
912
|
+
/** Whether `CDecl` is written. */
|
|
913
|
+
readonly cdecl: boolean;
|
|
914
|
+
/** Whether it declares a `Sub` or a `Function`. */
|
|
915
|
+
readonly procedureKind: 'Sub' | 'Function';
|
|
916
|
+
/** The name VBA code calls it by. */
|
|
917
|
+
readonly name: NameRef;
|
|
918
|
+
/** The library name after `Lib`, without quotes. */
|
|
919
|
+
readonly lib: string;
|
|
920
|
+
/** The entry point name after `Alias`, without quotes, or null. */
|
|
921
|
+
readonly alias: string | null;
|
|
922
|
+
/** The parameters, in order. */
|
|
923
|
+
readonly parameters: readonly Parameter[];
|
|
924
|
+
/** The return type of a `Function`, or null. */
|
|
925
|
+
readonly returnType: AsClause | null;
|
|
926
|
+
}
|
|
927
|
+
/** `[Public] Event Name(params)`. */
|
|
928
|
+
interface EventDeclaration {
|
|
929
|
+
readonly kind: 'EventDeclaration';
|
|
930
|
+
readonly span: Span;
|
|
931
|
+
/** The scope keyword, or null (Public). */
|
|
932
|
+
readonly scope: Scope | null;
|
|
933
|
+
/** The event name. */
|
|
934
|
+
readonly name: NameRef;
|
|
935
|
+
/** The parameters, in order. */
|
|
936
|
+
readonly parameters: readonly Parameter[];
|
|
937
|
+
}
|
|
938
|
+
/** `Implements Interface`. */
|
|
939
|
+
interface ImplementsStatement {
|
|
940
|
+
readonly kind: 'ImplementsStatement';
|
|
941
|
+
readonly span: Span;
|
|
942
|
+
/** The interface (a class) named. */
|
|
943
|
+
readonly type: TypeRef;
|
|
944
|
+
}
|
|
945
|
+
/** A letter range of a `DefType` statement: `A-Z` or `S`. */
|
|
946
|
+
interface LetterRange {
|
|
947
|
+
readonly kind: 'LetterRange';
|
|
948
|
+
readonly span: Span;
|
|
949
|
+
/** The first letter, upper-cased. */
|
|
950
|
+
readonly from: string;
|
|
951
|
+
/** The last letter, upper-cased; equal to `from` for a single letter. */
|
|
952
|
+
readonly to: string;
|
|
953
|
+
}
|
|
954
|
+
/** `DefInt A-Z` and the other `DefType` statements. */
|
|
955
|
+
interface DefTypeStatement {
|
|
956
|
+
readonly kind: 'DefTypeStatement';
|
|
957
|
+
readonly span: Span;
|
|
958
|
+
/** The type the statement gives: `Integer` for `DefInt`, and so on. */
|
|
959
|
+
readonly type: 'Boolean' | 'Byte' | 'Currency' | 'Date' | 'Double' | 'Integer' | 'Long' | 'LongLong' | 'LongPtr' | 'Object' | 'Single' | 'String' | 'Variant' | 'Decimal';
|
|
960
|
+
/** The letter ranges, in order. */
|
|
961
|
+
readonly ranges: readonly LetterRange[];
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* An `Option` statement: `Option Explicit`, `Option Base 0|1` (`base`), `Option Compare
|
|
965
|
+
* Binary|Text|Database` (`mode`) or `Option Private Module`.
|
|
966
|
+
*/
|
|
967
|
+
type OptionStatement = {
|
|
968
|
+
readonly kind: 'OptionExplicit';
|
|
969
|
+
readonly span: Span;
|
|
970
|
+
} | {
|
|
971
|
+
readonly kind: 'OptionBase';
|
|
972
|
+
readonly span: Span;
|
|
973
|
+
readonly base: 0 | 1;
|
|
974
|
+
} | {
|
|
975
|
+
readonly kind: 'OptionCompare';
|
|
976
|
+
readonly span: Span;
|
|
977
|
+
/** How strings compare: `Binary` by code, `Text` without regard to case. */
|
|
978
|
+
readonly mode: 'Binary' | 'Text' | 'Database';
|
|
979
|
+
} | {
|
|
980
|
+
readonly kind: 'OptionPrivateModule';
|
|
981
|
+
readonly span: Span;
|
|
982
|
+
};
|
|
983
|
+
/** `Attribute VB_Name = "Module1"` or `Attribute Proc.VB_UserMemId = 0`. */
|
|
984
|
+
interface AttributeStatement {
|
|
985
|
+
readonly kind: 'AttributeStatement';
|
|
986
|
+
readonly span: Span;
|
|
987
|
+
/** The dotted name as written, `VB_Name` or `Value.VB_UserMemId`. */
|
|
988
|
+
readonly name: string;
|
|
989
|
+
/** The values after `=`, in order (most attributes have one). */
|
|
990
|
+
readonly values: readonly Expression[];
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* The kind of a procedure. The three `Property` kinds are written `Property Get`, `Property Let`
|
|
994
|
+
* and `Property Set` in source.
|
|
995
|
+
*/
|
|
996
|
+
type ProcedureKind = 'Sub' | 'Function' | 'PropertyGet' | 'PropertyLet' | 'PropertySet';
|
|
997
|
+
/** A `Sub`, `Function` or `Property Get/Let/Set` with its body. */
|
|
998
|
+
interface ProcedureDeclaration {
|
|
999
|
+
readonly kind: 'ProcedureDeclaration';
|
|
1000
|
+
readonly span: Span;
|
|
1001
|
+
/** Which kind of procedure it is. */
|
|
1002
|
+
readonly procedureKind: ProcedureKind;
|
|
1003
|
+
/** The scope as written; null means Public. */
|
|
1004
|
+
readonly scope: 'Public' | 'Private' | 'Friend' | null;
|
|
1005
|
+
/** Declared `Static`: every local keeps its value between calls. */
|
|
1006
|
+
readonly isStatic: boolean;
|
|
1007
|
+
/** The procedure name. */
|
|
1008
|
+
readonly name: NameRef;
|
|
1009
|
+
/** The parameters, in order. */
|
|
1010
|
+
readonly parameters: readonly Parameter[];
|
|
1011
|
+
/** The `As` clause of a `Function` or `Property Get`, or null. */
|
|
1012
|
+
readonly returnType: AsClause | null;
|
|
1013
|
+
/** The statements between the declaration line and `End`, in source order. */
|
|
1014
|
+
readonly body: readonly Statement[];
|
|
1015
|
+
/** `Attribute Name.VB_*` lines inside the procedure. */
|
|
1016
|
+
readonly attributes: readonly AttributeStatement[];
|
|
1017
|
+
/** The `End Sub` line, or null when it is missing (a diagnostic says so). */
|
|
1018
|
+
readonly endSpan: Span | null;
|
|
1019
|
+
}
|
|
1020
|
+
/** What may appear at module level, in source order. */
|
|
1021
|
+
type ModuleMember = OptionStatement | AttributeStatement | VariableDeclaration | ConstDeclaration | TypeDeclaration | EnumDeclaration | DeclareStatement | EventDeclaration | ImplementsStatement | DefTypeStatement | ProcedureDeclaration;
|
|
1022
|
+
/** `Name = value` inside a header `BEGIN ... END` block, value kept as written. */
|
|
1023
|
+
interface HeaderProperty {
|
|
1024
|
+
readonly kind: 'HeaderProperty';
|
|
1025
|
+
readonly span: Span;
|
|
1026
|
+
/** The property name. */
|
|
1027
|
+
readonly name: string;
|
|
1028
|
+
/** The raw value text, without a trailing comment: `-1`, `"UserForm1"`, `"Form.frx":0000`. */
|
|
1029
|
+
readonly value: string;
|
|
1030
|
+
}
|
|
1031
|
+
/** A `BEGIN ... END` block of an exported class or form, possibly nested (form controls). */
|
|
1032
|
+
interface HeaderBlock {
|
|
1033
|
+
readonly kind: 'HeaderBlock';
|
|
1034
|
+
readonly span: Span;
|
|
1035
|
+
/** The class id or type after `Begin` (`{C62A69F0-...}`, `Forms.CommandButton.1`), if any. */
|
|
1036
|
+
readonly type: string | null;
|
|
1037
|
+
/** The object name after it, if any. */
|
|
1038
|
+
readonly name: string | null;
|
|
1039
|
+
/** The `Name = value` lines of the block, in order. */
|
|
1040
|
+
readonly properties: readonly HeaderProperty[];
|
|
1041
|
+
/** Nested `BEGIN ... END` blocks (form controls), in order. */
|
|
1042
|
+
readonly children: readonly HeaderBlock[];
|
|
1043
|
+
}
|
|
1044
|
+
/** The `VERSION` line and `BEGIN` block that exported `.cls` and `.frm` files start with. */
|
|
1045
|
+
interface ModuleHeader {
|
|
1046
|
+
readonly kind: 'ModuleHeader';
|
|
1047
|
+
readonly span: Span;
|
|
1048
|
+
/** `1.0`, `5.00`. */
|
|
1049
|
+
readonly version: string;
|
|
1050
|
+
/** `VERSION 1.0 CLASS`. */
|
|
1051
|
+
readonly isClass: boolean;
|
|
1052
|
+
/** `Object = ...` lines between the `VERSION` line and the block. */
|
|
1053
|
+
readonly properties: readonly HeaderProperty[];
|
|
1054
|
+
/** The `BEGIN ... END` block, or null when there is none. */
|
|
1055
|
+
readonly block: HeaderBlock | null;
|
|
1056
|
+
}
|
|
1057
|
+
/** A `#If`, `#ElseIf`, `#Else`, `#End If` or `#Const` line and what it evaluated to. */
|
|
1058
|
+
interface ConditionalDirective {
|
|
1059
|
+
readonly kind: 'ConditionalDirective';
|
|
1060
|
+
readonly span: Span;
|
|
1061
|
+
/** Which directive it is; `#End If` and `#EndIf` are both `EndIf`. */
|
|
1062
|
+
readonly directive: 'If' | 'ElseIf' | 'Else' | 'EndIf' | 'Const';
|
|
1063
|
+
/** The constant a `#Const` defines. */
|
|
1064
|
+
readonly name: string | null;
|
|
1065
|
+
/**
|
|
1066
|
+
* The condition of `#If`/`#ElseIf` or the value of `#Const`; null for `#Else` and `#End If`.
|
|
1067
|
+
*/
|
|
1068
|
+
readonly expression: Expression | null;
|
|
1069
|
+
/** The value of the `#Const` or condition; null when not evaluated (an inactive branch). */
|
|
1070
|
+
readonly value: ConditionalValue | null;
|
|
1071
|
+
}
|
|
1072
|
+
/** A conditional compilation value: VBA's `True` is the number -1. */
|
|
1073
|
+
type ConditionalValue = number | string;
|
|
1074
|
+
/**
|
|
1075
|
+
* What kind of module the source is. `document` modules belong to a workbook, sheet or document
|
|
1076
|
+
* (`ThisWorkbook`, `Sheet1`, `ThisDocument`); `form` modules sit behind a UserForm.
|
|
1077
|
+
*/
|
|
1078
|
+
type ModuleKind = 'standard' | 'class' | 'document' | 'form';
|
|
1079
|
+
/** A parsed module. */
|
|
1080
|
+
interface ModuleNode {
|
|
1081
|
+
readonly kind: 'Module';
|
|
1082
|
+
readonly span: Span;
|
|
1083
|
+
/**
|
|
1084
|
+
* The kind given in the parse options, else the kind inferred from the header and attributes.
|
|
1085
|
+
*/
|
|
1086
|
+
readonly moduleKind: ModuleKind;
|
|
1087
|
+
/** The `VB_Name` attribute, when present. */
|
|
1088
|
+
readonly name: string | null;
|
|
1089
|
+
/** The header of an exported `.cls` or `.frm` file, or null. */
|
|
1090
|
+
readonly header: ModuleHeader | null;
|
|
1091
|
+
/** Declarations, options, attributes and procedures in source order. */
|
|
1092
|
+
readonly members: readonly ModuleMember[];
|
|
1093
|
+
/** Comments, `Rem` lines and line continuations, in source order. */
|
|
1094
|
+
readonly trivia: readonly Trivia[];
|
|
1095
|
+
/** Every conditional compilation directive, in source order. */
|
|
1096
|
+
readonly directives: readonly ConditionalDirective[];
|
|
1097
|
+
/** Source excluded by conditional compilation. */
|
|
1098
|
+
readonly inactiveRanges: readonly Span[];
|
|
1099
|
+
}
|
|
1100
|
+
/** The kinds of problem the front end reports. */
|
|
1101
|
+
type VbaDiagnosticCode = 'invalid-character' | 'unterminated-string' | 'unterminated-identifier' | 'invalid-number' | 'overflow' | 'invalid-date' | 'too-many-line-continuations' | 'expected' | 'unexpected' | 'block-mismatch' | 'invalid-outside-procedure' | 'invalid-inside-procedure' | 'conditional-compilation' | 'too-complex' | 'invalid-header' | 'too-many-diagnostics';
|
|
1102
|
+
/** A problem found in the source, with where it is. The front end never throws for these. */
|
|
1103
|
+
interface VbaDiagnostic {
|
|
1104
|
+
/** What kind of problem it is. */
|
|
1105
|
+
readonly code: VbaDiagnosticCode;
|
|
1106
|
+
/** A human-readable description. */
|
|
1107
|
+
readonly message: string;
|
|
1108
|
+
/** An error stops the module from running; a warning does not. */
|
|
1109
|
+
readonly severity: 'error' | 'warning';
|
|
1110
|
+
/** The source the problem covers. Empty for something missing. */
|
|
1111
|
+
readonly span: Span;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Bounds on what the front end accepts. VBA source is untrusted input: every resource the lexer
|
|
1115
|
+
* and parser use grows with one of these, and going over a hard limit throws
|
|
1116
|
+
* {@link VbaLangLimitError} instead of using unbounded time, memory or stack.
|
|
1117
|
+
*/
|
|
1118
|
+
interface VbaLangLimits {
|
|
1119
|
+
/** Longest source accepted, in UTF-16 code units (hard limit). */
|
|
1120
|
+
readonly maxSourceLength: number;
|
|
1121
|
+
/** Most tokens one source may produce (hard limit). */
|
|
1122
|
+
readonly maxTokens: number;
|
|
1123
|
+
/**
|
|
1124
|
+
* Deepest nesting of blocks and expressions together: each block, parenthesis, unary operator,
|
|
1125
|
+
* operator of a chain (`a & b & c` counts 2) and `.member`/`(args)` link counts one. Deeper
|
|
1126
|
+
* code is reported as "Expression too complex" and skipped to the end of its statement, so the
|
|
1127
|
+
* parser's stack stays bounded, and so does the depth of every tree it returns (executors may
|
|
1128
|
+
* walk it recursively).
|
|
1129
|
+
*/
|
|
1130
|
+
readonly maxNestingDepth: number;
|
|
1131
|
+
/**
|
|
1132
|
+
* Line continuations allowed in one logical line before a diagnostic. VBA itself refuses more
|
|
1133
|
+
* than 24 ("Too many line continuations"); the code still parses.
|
|
1134
|
+
*/
|
|
1135
|
+
readonly maxLineContinuations: number;
|
|
1136
|
+
/** Most diagnostics kept; the rest are counted in one final diagnostic. */
|
|
1137
|
+
readonly maxDiagnostics: number;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* The limits used for every field a caller leaves out: 4 MiB of source, a million tokens, a
|
|
1141
|
+
* nesting depth of 256, 24 line continuations and 1000 diagnostics.
|
|
1142
|
+
*/
|
|
1143
|
+
declare const DEFAULT_VBA_LANG_LIMITS: VbaLangLimits;
|
|
1144
|
+
/** Thrown when a source exceeds a hard limit of {@link VbaLangLimits}. */
|
|
1145
|
+
declare class VbaLangLimitError extends Error {
|
|
1146
|
+
/** The limit that was exceeded. */
|
|
1147
|
+
readonly limit: 'maxSourceLength' | 'maxTokens';
|
|
1148
|
+
/** The source length, or for `maxTokens` the token count reached (one over the limit). */
|
|
1149
|
+
readonly value: number;
|
|
1150
|
+
constructor(limit: 'maxSourceLength' | 'maxTokens', value: number, max: number);
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* The conditional compilation constants VBA predefines, as 64-bit Office for Windows sets them
|
|
1154
|
+
* (`True` is -1). Override any of them with `ParseOptions.constants`, for example
|
|
1155
|
+
* `{ Win64: false }` for 32-bit Office or `{ Mac: true, Win32: false, Win64: false }`.
|
|
1156
|
+
*/
|
|
1157
|
+
declare const DEFAULT_CONDITIONAL_CONSTANTS: Readonly<Record<string, ConditionalValue>>;
|
|
1158
|
+
/** How a date literal of three numbers is read: month/day/year, year/month/day or day/month/year. */
|
|
1159
|
+
type DateFieldOrder = 'mdy' | 'ymd' | 'dmy';
|
|
1160
|
+
/** How date literals (`#1/2/03#`) are read. Every field is explicit: the lexer reads no clock. */
|
|
1161
|
+
interface DateLiteralOptions {
|
|
1162
|
+
/** The year a literal without one (`#1/2#`, `#Jan 2#`) falls in. */
|
|
1163
|
+
readonly currentYear: number;
|
|
1164
|
+
/** The last year a one- or two-digit year can mean: 2049 reads `49` as 2049 and `50` as 1950. */
|
|
1165
|
+
readonly twoDigitYearMax: number;
|
|
1166
|
+
/** The readings tried in turn for three numbers; the first that names a real date wins. */
|
|
1167
|
+
readonly dateOrder: readonly DateFieldOrder[];
|
|
1168
|
+
}
|
|
1169
|
+
/** The two-digit year window the VBA editor used on the reference machine (1950 to 2049). */
|
|
1170
|
+
declare const DEFAULT_TWO_DIGIT_YEAR_MAX = 2049;
|
|
1171
|
+
/**
|
|
1172
|
+
* The date reading order observed in the VBA editor on a machine whose short date is
|
|
1173
|
+
* `yyyy-MM-dd`: month/day/year, then year/month/day, then day/month/year. Other locales may try
|
|
1174
|
+
* their own order second; pass it explicitly for them.
|
|
1175
|
+
*/
|
|
1176
|
+
declare const DEFAULT_DATE_ORDER: readonly DateFieldOrder[];
|
|
1177
|
+
/** Options every entry point that reads tokens takes. */
|
|
1178
|
+
interface LexicalOptions {
|
|
1179
|
+
/**
|
|
1180
|
+
* Overrides of {@link DEFAULT_VBA_LANG_LIMITS}. Values that are not positive integers are
|
|
1181
|
+
* ignored.
|
|
1182
|
+
*/
|
|
1183
|
+
readonly limits?: Partial<VbaLangLimits>;
|
|
1184
|
+
/** See {@link DateLiteralOptions.currentYear}; defaults to the system clock's year at the call. */
|
|
1185
|
+
readonly currentYear?: number;
|
|
1186
|
+
/** See {@link DateLiteralOptions.twoDigitYearMax}; defaults to {@link DEFAULT_TWO_DIGIT_YEAR_MAX}. */
|
|
1187
|
+
readonly twoDigitYearMax?: number;
|
|
1188
|
+
/** See {@link DateLiteralOptions.dateOrder}; defaults to {@link DEFAULT_DATE_ORDER}. */
|
|
1189
|
+
readonly dateOrder?: readonly DateFieldOrder[];
|
|
1190
|
+
}
|
|
1191
|
+
/** Options of `parseModule` and the other entry points that parse. */
|
|
1192
|
+
interface ParseOptions extends LexicalOptions {
|
|
1193
|
+
/**
|
|
1194
|
+
* Conditional compilation constants, merged over {@link DEFAULT_CONDITIONAL_CONSTANTS}
|
|
1195
|
+
* (names are case-insensitive; `true` is -1).
|
|
1196
|
+
*/
|
|
1197
|
+
readonly constants?: Readonly<Record<string, ConditionalValue | boolean>>;
|
|
1198
|
+
/** The module kind when the caller knows it (from the project's `dir` stream); else inferred. */
|
|
1199
|
+
readonly moduleKind?: ModuleKind;
|
|
1200
|
+
}
|
|
1201
|
+
/** What `parseModule` returns. */
|
|
1202
|
+
interface ParseResult {
|
|
1203
|
+
/** The module's tree. Partial when the source has errors. */
|
|
1204
|
+
readonly module: ModuleNode;
|
|
1205
|
+
/** Problems found, except those inside inactive `#If` branches. */
|
|
1206
|
+
readonly diagnostics: readonly VbaDiagnostic[];
|
|
1207
|
+
}
|
|
1208
|
+
/** What `tokenize` returns. */
|
|
1209
|
+
interface TokenizeResult {
|
|
1210
|
+
/** The tokens in source order, ending with an `eof` token. */
|
|
1211
|
+
readonly tokens: readonly Token[];
|
|
1212
|
+
/** Comments and line continuations, in source order. */
|
|
1213
|
+
readonly trivia: readonly Trivia[];
|
|
1214
|
+
/** Lexical problems found. */
|
|
1215
|
+
readonly diagnostics: readonly VbaDiagnostic[];
|
|
1216
|
+
}
|
|
1217
|
+
/** Splits source into tokens without the header or conditional compilation, tolerating errors. */
|
|
1218
|
+
declare function tokenize(source: string, options?: LexicalOptions): TokenizeResult;
|
|
1219
|
+
/**
|
|
1220
|
+
* Parses a VBA module: an exported `.bas`/`.cls`/`.frm` text or a decompressed module stream.
|
|
1221
|
+
* Never throws for bad code: problems come back as diagnostics with a partial tree. Throws
|
|
1222
|
+
* {@link VbaLangLimitError} only when the source exceeds a hard limit.
|
|
1223
|
+
*/
|
|
1224
|
+
declare function parseModule(source: string, options?: ParseOptions): ParseResult;
|
|
1225
|
+
/**
|
|
1226
|
+
* Parses a single expression (a watch, the Immediate window, a form control's formula). Returns
|
|
1227
|
+
* the expression and the problems found; text after the expression is reported as an error.
|
|
1228
|
+
*/
|
|
1229
|
+
declare function parseExpression(source: string, options?: LexicalOptions): {
|
|
1230
|
+
expression: Expression;
|
|
1231
|
+
diagnostics: readonly VbaDiagnostic[];
|
|
1232
|
+
};
|
|
1233
|
+
/**
|
|
1234
|
+
* What a highlighted range is. `type` is a type keyword (`Long`, `String`); `identifier` covers
|
|
1235
|
+
* names and the reserved words that act as names in expressions (`Len`, `CStr`); `header` is the
|
|
1236
|
+
* header block of an exported file (the `VERSION` and `BEGIN` lines).
|
|
1237
|
+
*/
|
|
1238
|
+
type HighlightKind = 'keyword' | 'type' | 'identifier' | 'number' | 'string' | 'date' | 'comment' | 'operator' | 'punctuation' | 'directive' | 'continuation' | 'header' | 'invalid';
|
|
1239
|
+
/** One range of the source and how to colour it. */
|
|
1240
|
+
interface HighlightToken {
|
|
1241
|
+
/** How to colour the range. */
|
|
1242
|
+
readonly kind: HighlightKind;
|
|
1243
|
+
/** The range of source it covers. */
|
|
1244
|
+
readonly span: Span;
|
|
1245
|
+
}
|
|
1246
|
+
/** The lexical options: limits and how date literals are read. */
|
|
1247
|
+
type HighlightOptions = LexicalOptions;
|
|
1248
|
+
/**
|
|
1249
|
+
* Classifies the source for syntax highlighting, in source order. It never fails on bad code
|
|
1250
|
+
* (bad characters come back as `invalid`); only a source over a hard limit throws
|
|
1251
|
+
* {@link VbaLangLimitError}. Conditional compilation is not applied: every branch is coloured.
|
|
1252
|
+
*/
|
|
1253
|
+
declare function tokenizeForHighlight(source: string, options?: HighlightOptions): HighlightToken[];
|
|
1254
|
+
/**
|
|
1255
|
+
* The Office application whose Macros dialog rules apply. `generic` lists document-module Subs
|
|
1256
|
+
* by their bare name, as Word and Visio do.
|
|
1257
|
+
*/
|
|
1258
|
+
type MacroHost = 'excel' | 'word' | 'powerpoint' | 'visio' | 'generic';
|
|
1259
|
+
/** Why a procedure runs without the user starting it. */
|
|
1260
|
+
interface AutoExecInfo {
|
|
1261
|
+
/**
|
|
1262
|
+
* `auto-macro`: a name the host runs on open, close, new or exit (`Auto_Open`, `AutoOpen`, a
|
|
1263
|
+
* `Main` in an `AutoExec` module). `document-event`: an event handler of a document module
|
|
1264
|
+
* (`Workbook_Open`, `Worksheet_Change`, `Document_Open`). `withevents-handler`: a handler of a
|
|
1265
|
+
* `WithEvents` variable (`App_WorkbookOpen`), which runs once the variable is connected.
|
|
1266
|
+
* `control-event`: a handler of an ActiveX control on the document for an event that can fire
|
|
1267
|
+
* as the document opens and draws (`Frame1_Layout`, `InkPicture1_Painted`, `TextBox1_Change`).
|
|
1268
|
+
*/
|
|
1269
|
+
readonly kind: 'auto-macro' | 'document-event' | 'withevents-handler' | 'control-event';
|
|
1270
|
+
/** The object (`Workbook`, `Document`, `App`, a control, or the module name) and its event. */
|
|
1271
|
+
readonly object: string;
|
|
1272
|
+
/** The event (`Open`, `Change`), or the name of an auto macro (`Auto_Open`, `Main`). */
|
|
1273
|
+
readonly event: string;
|
|
1274
|
+
/**
|
|
1275
|
+
* False when the host is known not to run it: Excel ignores `Auto_Open` and the other
|
|
1276
|
+
* `Auto_` macros in a document module. True otherwise, also when the host is not known.
|
|
1277
|
+
*/
|
|
1278
|
+
readonly runs: boolean;
|
|
1279
|
+
}
|
|
1280
|
+
/** One parameter of a listed procedure. */
|
|
1281
|
+
interface ParameterInfo {
|
|
1282
|
+
/** The parameter name, as written. */
|
|
1283
|
+
readonly name: string;
|
|
1284
|
+
/** Whether it is declared `Optional`. */
|
|
1285
|
+
readonly optional: boolean;
|
|
1286
|
+
/** How it is passed: `ByRef` when the declaration says neither. */
|
|
1287
|
+
readonly passing: 'ByVal' | 'ByRef';
|
|
1288
|
+
/** Whether it is declared `ParamArray`. */
|
|
1289
|
+
readonly paramArray: boolean;
|
|
1290
|
+
/** Whether it is declared with parentheses (`x() As Long`), so it takes an array. */
|
|
1291
|
+
readonly isArray: boolean;
|
|
1292
|
+
/** The declared type as written, or null (Variant). */
|
|
1293
|
+
readonly type: string | null;
|
|
1294
|
+
/** Whether an `Optional` parameter has a default value (`Optional n As Long = 1`). */
|
|
1295
|
+
readonly hasDefault: boolean;
|
|
1296
|
+
}
|
|
1297
|
+
/** One procedure of a module, as `listProcedures` reports it. */
|
|
1298
|
+
interface ProcedureInfo {
|
|
1299
|
+
/** The procedure name, as written. */
|
|
1300
|
+
readonly name: string;
|
|
1301
|
+
/** `Sub`, `Function`, `PropertyGet`, `PropertyLet` or `PropertySet`. */
|
|
1302
|
+
readonly kind: ProcedureKind;
|
|
1303
|
+
/** The effective scope: a procedure without one is Public. */
|
|
1304
|
+
readonly scope: 'Public' | 'Private' | 'Friend';
|
|
1305
|
+
/** Whether it is declared `Static`: its local variables keep their values between calls. */
|
|
1306
|
+
readonly isStatic: boolean;
|
|
1307
|
+
/** The whole declaration, from its first keyword to its `End` line. */
|
|
1308
|
+
readonly span: Span;
|
|
1309
|
+
/** The procedure name in the declaration line, for go-to-definition. */
|
|
1310
|
+
readonly nameSpan: Span;
|
|
1311
|
+
/** The parameters, in order. */
|
|
1312
|
+
readonly parameters: readonly ParameterInfo[];
|
|
1313
|
+
/** The declared return type as written (`As Long`), or null when there is none. */
|
|
1314
|
+
readonly returnType: string | null;
|
|
1315
|
+
/** Whether the host's Macros dialog lists it (see the README for the rules). */
|
|
1316
|
+
readonly isMacro: boolean;
|
|
1317
|
+
/**
|
|
1318
|
+
* The name the host's Macros dialog shows (`ThisWorkbook.Foo` for a document module in Excel,
|
|
1319
|
+
* `Foo` otherwise), or null when it is not a macro.
|
|
1320
|
+
*/
|
|
1321
|
+
readonly macroName: string | null;
|
|
1322
|
+
/** How the procedure can run without a click (on open, as an event handler), or null. */
|
|
1323
|
+
readonly autoExec: AutoExecInfo | null;
|
|
1324
|
+
}
|
|
1325
|
+
/** Options of `listProcedures`. */
|
|
1326
|
+
interface ListProceduresOptions {
|
|
1327
|
+
/** Parse options when `input` is source text. */
|
|
1328
|
+
readonly parse?: ParseOptions;
|
|
1329
|
+
/** Overrides the module's kind (from the project's `dir` stream). */
|
|
1330
|
+
readonly moduleKind?: ModuleKind;
|
|
1331
|
+
/** Overrides the module's name (its `VB_Name` attribute otherwise). */
|
|
1332
|
+
readonly moduleName?: string;
|
|
1333
|
+
/** The host whose Macros dialog rules apply; `generic` by default. */
|
|
1334
|
+
readonly host?: MacroHost;
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Lists the procedures of a module with what the Macros dialog and the trust UI need: which are
|
|
1338
|
+
* macros under the host's rules, the name the dialog shows, and which run without a click.
|
|
1339
|
+
*/
|
|
1340
|
+
declare function listProcedures(input: string | ModuleNode, options?: ListProceduresOptions): ProcedureInfo[];
|
|
1341
|
+
/** The OLE Automation serial of a date and time. Dates before 1899-12-30 count the time back. */
|
|
1342
|
+
declare function dateSerial(parts: Omit<DateParts, 'hasDate' | 'hasTime'>): number;
|
|
1343
|
+
/** Any node of the tree: everything with a `kind` and a `span`. */
|
|
1344
|
+
interface AnyNode {
|
|
1345
|
+
readonly kind: string;
|
|
1346
|
+
readonly span: Span;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Calls `visit` for each direct child node of `node` (sub-expressions, statements, declarators,
|
|
1350
|
+
* names), in property order. Iterative callers use it to walk the tree without recursion.
|
|
1351
|
+
*/
|
|
1352
|
+
declare function forEachChild(node: AnyNode, visit: (child: AnyNode) => void): void;
|
|
1353
|
+
export { ProcedureDeclaration as $, BooleanLiteral as $t, ConditionalDirective as A, ReDimStatement as At, AttributeStatement as B, InputStatement as Bt, ParseOptions as C, Punctuator as Cn, LoopCondition as Ct, VbaLangLimits as D, BuiltinTypeName as Dn, OnGoToStatement as Dt, VbaLangLimitError as E, TypeSuffix as En, OnErrorStatement as Et, ModuleKind as F, WhileStatement as Ft, EnumDeclaration as G, PrintStatement as Gt, ConstantDeclarator as H, LockStatement as Ht, ModuleNode as I, WithStatement as It, ImplementsStatement as J, WriteStatement as Jt, EnumMember as K, SeekStatement as Kt, ArrayBound as L, CloseStatement as Lt, HeaderBlock as M, SelectCaseStatement as Mt, HeaderProperty as N, SimpleStatement as Nt, VbaDiagnostic as O, SourcePosition as On, RaiseEventStatement as Ot, ModuleHeader as P, Statement as Pt, Parameter as Q, BinaryOperator as Qt, ArrayDimensions as R, FileStatement as Rt, LexicalOptions as S, NumberLiteralType as Sn, LabelStatement as St, DEFAULT_VBA_LANG_LIMITS as T, Trivia as Tn, NameStatement as Tt, DeclareStatement as U, OpenStatement as Ut, ConstDeclaration as V, LineInputStatement as Vt, DefTypeStatement as W, OutputItem as Wt, ModuleMember as X, Argument as Xt, LetterRange as Y, AddressOfExpression as Yt, OptionStatement as Z, BinaryExpression as Zt, tokenize as _, TypeRef as _n, IfBranch as _t, ProcedureInfo as a, InvalidExpression as an, VariableDeclarator as at, DateFieldOrder as b, DateParts as bn, LSetStatement as bt, MacroHost as c, MemberAccess as cn, CaseClause as ct, HighlightToken as d, NewExpression as dn, EraseStatement as dt, CallOrIndex as en, ProcedureKind as et, tokenizeForHighlight as f, NumberLiteral as fn, ErrorStatement as ft, parseModule as g, TypeOfExpression as gn, GoToStatement as gt, parseExpression as h, StringLiteral as hn, ForStatement as ht, ParameterInfo as i, FileNumberExpression as in, VariableDeclaration as it, ConditionalValue as j, ResumeStatement as jt, VbaDiagnosticCode as k, Span as kn, ReDimClause as kt, HighlightKind as l, NameExpression as ln, CaseTest as lt, TokenizeResult as m, SpecialLiteral as mn, ForEachStatement as mt, dateSerial as n, DictionaryAccess as nn, TypeDeclaration as nt, listProcedures as o, Literal as on, AssignmentStatement as ot, ParseResult as p, ParenExpression as pn, ExitStatement as pt, EventDeclaration as q, WidthStatement as qt, ListProceduresOptions as r, Expression as rn, TypeMember as rt, AutoExecInfo as s, MeExpression as sn, CallStatement as st, forEachChild as t, DateLiteral as tn, Scope as tt, HighlightOptions as u, NameRef as un, DoLoopStatement as ut, DEFAULT_DATE_ORDER as v, UnaryExpression as vn, IfStatement as vt, DEFAULT_CONDITIONAL_CONSTANTS as w, Token as wn, MidAssignmentStatement as wt, DateLiteralOptions as x, ExactDecimal as xn, LabelRef as xt, DEFAULT_TWO_DIGIT_YEAR_MAX as y, UnaryOperator as yn, InvalidStatement as yt, AsClause as z, GetPutStatement as zt };
|