-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.d.ts
More file actions
545 lines (439 loc) · 12.8 KB
/
index.d.ts
File metadata and controls
545 lines (439 loc) · 12.8 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
// ============================================================
// Public API
export function parseText (input: string, options?: Options): Program
export function parseTokens (input: string, tokens: Token[], options?: Options): Program
export function tokenize (input: string, options?: Options): Token[]
export function startTokenization (input: string, options?: Options): Iterator<Token>
export const tokenTypes: TokenTypes
// ---------- Options
export const defaultOptions: Options
export interface Options {
defines?: { [key: string]: string | number | boolean }
tokens?: boolean // only for parser
preprocessor?: boolean
comments?: boolean
whitespace?: boolean
locations?: boolean
ranges?: boolean
raw?: boolean
rawIdentifiers?: boolean
rawLiterals?: boolean
sourceType?: SourceType
oldVersion?: boolean
sourceFile?: string
}
export type SourceType = 'object' | 'script' | 'dump'
// ============================================================
// Error Handling
export interface ParseWarning extends Error {
code: string
line: number
column: number
offset: number
length: number
source: string
}
export interface ParseError extends ParseWarning {
tokens?: Token[]
warnings: ParseWarning[]
}
// ============================================================
// Locations and Ranges
export interface SourceLocation {
start: Position
end: Position
source?: string | null
}
export interface Position {
line: number
column: number
}
export type Range = [number, number]
// ============================================================
// Lexer
export interface Token {
type: TokenType
value: null | boolean | number | string
line: number
lineStart: number
lastLine: number
lastLineStart: number
range: Range
hashQuote?: boolean // for identifiers
multiline?: boolean // for comments
directive?: string // for preprocessor directives
name?: string // for ifdef, ifndef, define and undef preprocessor directives
namedValue?: string // for ifdef, ifndef and define preprocessor directives
}
export type TokenType = 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | 1024 |
2048 | 8192 | 16384 | 32768
export interface TokenTypes {
EOF: 1
Whitespace: 2
Comment: 4
PreprocessorDirective: 8
PreprocessedAway: 16
Punctuator: 32
Keyword: 64
Identifier: 128
StringLiteral: 256
IntegerLiteral: 512
BooleanLiteral: 1024
UndefinedLiteral: 2048
RealLiteral: 4096
DateLiteral: 8192
ObjRef: 16384
LegacyAlias: 32768
// Combinations for matching multiple token types
KeywordOrIdentifier: 64 | 128
PunctuatorOrKeyword: 32 | 64
Literal: 256 | 512 | 1024 | 2048 | 4096 | 8182 | 16384
NoCode: 2 | 4 | 8 | 16
}
// ============================================================
// Parser
export interface Node {
type: string
loc?: SourceLocation
sourceFile?: string
range?: Range
}
export interface Program extends Node {
type: 'Program'
body: PackageDeclaration | ScriptSource | DumpSource
tokens?: Token[] // if tokens are enabled during parsing
warnings: ParseWarning[]
}
// ---------- Package
export interface PackageDeclaration extends Node {
type: 'PackageDeclaration'
name: ObjectName
object: ObjectDeclaration
}
export interface ObjectDeclaration extends Node {
type: 'ObjectDeclaration'
id: Identifier
modifier: Modifier
superObject?: ObjectName
body: MemberDeclaration[]
}
export type MemberDeclaration = FunctionDeclaration | ScriptDeclaration | FeatureDeclaration
export interface FeatureDeclaration extends Node {
type: 'FeatureDeclaration'
id: Identifier
featureType: Type
modifier?: Modifier
init?: Literal
}
export interface ObjectName extends Node {
type: 'ObjectName'
name: Array<Identifier | LegacyAlias>
}
// ---------- Script
export interface ScriptSource extends Node {
type: 'ScriptSource'
body: Array<FunctionDeclaration | Statement>
}
// ---------- Dump
export interface DumpSource extends Node {
type: 'DumpSource'
id: Identifier
parent: ObjRef
features: FeatureAddition[]
assignments: FeatureInitialization[]
scripts: ScriptDeclaration[]
}
export interface FeatureAddition extends Node {
type: 'FeatureAddition'
id: Identifier
}
export interface FeatureInitialization extends Node {
type: 'FeatureInitialization'
id: Identifier
value: Literal
}
// ---------- Scopes
export interface ScriptDeclaration extends Node {
type: 'ScriptDeclaration'
id: Identifier
modifier?: Modifier
body: Array<FunctionDeclaration | Statement>
}
export interface FunctionDeclaration extends Node {
type: 'FunctionDeclaration'
id: Identifier
functionType: Type
modifier?: Modifier
variadic: boolean
nodebug: boolean
params: Parameter[]
body: Statement[]
}
export interface Parameter extends Node {
type: 'Parameter'
id: Identifier
parameterType: Type
init?: Expression
}
// ---------- Statements
export type Statement = IfStatement | SwitchStatement | WhileStatement |
RepeatStatement | ForStatement | ForEachStatement | StructuredForStatement |
GotoStatement | ReturnStatement | BreakStatement | BreakIfStatement |
ContinueStatement | ContinueIfStatement | VariableDeclaration |
EmptyStatement | Expression
export interface IfStatement extends Node {
type: 'IfStatement'
test: Expression
consequent: Statement[]
otherClauses: ElseIfClause[]
alternate?: Statement[]
}
export interface ElseIfClause extends Node {
type: 'ElseIfClause'
test: Expression
consequent: Statement[]
}
export interface SwitchStatement extends Node {
type: 'SwitchStatement'
discriminant: Expression
cases: SwitchCase[]
}
export interface SwitchCase extends Node {
type: 'SwitchCase'
tests: Expression[]
consequent: Statement[]
}
export interface WhileStatement extends Node {
type: 'WhileStatement'
test: Expression
body: Statement[]
}
export interface RepeatStatement extends Node {
type: 'RepeatStatement'
test: Expression
body: Statement[]
}
export interface ForStatement extends Node {
type: 'ForStatement'
init?: Expression
test?: Expression
update?: Expression
body: Statement[]
}
export interface ForEachStatement extends Node {
type: 'ForEachStatement'
left: Identifier
right: Expression
body: Statement[]
}
export interface StructuredForStatement extends Node {
type: 'StructuredForStatement'
variable: Identifier
start: Expression
end: Expression
step?: Expression
down: boolean
body: Statement[]
}
export interface BreakStatement extends Node {
type: 'BreakStatement'
}
export interface ContinueStatement extends Node {
type: 'ContinueStatement'
}
export interface BreakIfStatement extends Node {
type: 'BreakIfStatement'
test: Expression
}
export interface ContinueIfStatement extends Node {
type: 'ContinueIfStatement'
test: Expression
}
export interface LabelStatement extends Node {
type: 'LabelStatement'
id: Identifier
}
export interface GotoStatement extends Node {
type: 'GotoStatement'
label: Identifier
}
export interface ReturnStatement extends Node {
type: 'ReturnStatement'
argument: Expression | undefined
}
export interface EmptyStatement extends Node {
type: 'EmptyStatement'
}
export interface VariableDeclaration extends Node {
type: 'VariableDeclaration'
variableType: Type
declarations: VariableDeclarator[]
}
export interface VariableDeclarator extends Node {
type: 'VariableDeclarator'
id: Identifier
init?: Expression
}
export type Modifier = 'override' | 'public' | 'private'
export type Type = 'Set' | 'List' | 'Date' | 'Long' | 'Real' | 'Void' |
'Assoc' | 'Bytes' | 'Frame' | 'String' | 'Record' | 'Object' |
'Boolean' | 'Integer' | 'Dynamic' | 'RecArray' | 'Error' | 'Regex' |
'Point' | 'HashMap' | 'ObjRef' | 'Script' | 'Socket' | 'File' | 'Dialog' |
'Vis' | 'CAPIERR' | 'CAPILOG' | 'PatFind' | 'WAPIMAP' |
'DOMAttr' | 'DOMNode' | 'DOMText' | 'OTQuery' | 'Compiler' | 'DAPINODE' |
'FileCopy' | 'UAPIUSER' | 'WAPIWORK' | 'OTSearch' | 'CacheTree' |
'CAPILOGIN' | 'FilePrefs' | 'PatChange' | 'SqlCursor' | 'DOMEntity' |
'DOMParser' | 'SAXParser' | 'DAPISTREAM' | 'JavaObject' | 'RestClient' |
'SslOptions' | 'DOMComment' | 'DOMElement' | 'CAPICONNECT' | 'DAPISESSION' |
'DAPIVERSION' | 'MailMessage' | 'POP3Session' | 'SMTPSession' |
'UAPISESSION' | 'WAPISESSION' | 'WAPIMAPTASK' | 'WAPISUBWORK' |
'DOMDocument' | 'DOMNodeList' | 'DOMNotation' | 'IPoolObject' |
'XSLProcessor' | 'SqlConnection' | 'DOMCdataSection' | 'DOMDocumentType' |
'DOMNamedNodeMap' | 'IPoolConnection' | 'DOMCharacterData' |
'IPoolTransaction' | 'DOMImplementation' | 'DOMEntityReference' |
'DOMDocumentFragment' | 'DOMProcessingInstruction'
// ---------- Expressions
export type Expression = BinaryExpression | ConditionalExpression
export interface ConditionalExpression extends Node {
type: 'ConditionalExpression'
test: BinaryExpression
consequent: Expression
alternate: Expression
}
export interface BinaryExpression extends Node {
type: 'BinaryExpression'
operator: BinaryOperator
left: UnaryExpression | MemberSliceCallExpression
right: UnaryExpression | MemberSliceCallExpression | BinaryExpression
}
export type BinaryOperator = ArithmeticOperator | BooleanOperator |
BitwiseOperator | LogicalOperator | AssignmentOperator
type ArithmeticOperator = '+' | '-' | '*' | '/' | '%'
type BooleanOperator =
'==' | '!=' | '<>' | '<' | '<=' | '>' | '>=' |
'in' | 'eq' | 'ne' | 'lt' | 'le' | 'gt' | 'ge'
type BitwiseOperator =
'<<' | '>>' | '|' | '^' | '&'
type LogicalOperator = '||' | '&&' | 'or' | 'and'
type AssignmentOperator =
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '|=' | '^=' | '&='
export interface UnaryExpression extends Node {
type: 'UnaryExpression'
operator: UnaryOperator
argument: UnaryExpression | MemberSliceCallExpression
}
export type UnaryOperator = '-' | '!' | '~' | 'not'
export type MemberSliceCallExpression = PrimaryExpression | MemberExpression |
SliceExpression | CallExpression
export type MemberExpression = SimpleMemberExpression | BoxedMemberExpression
export interface BaseMemberExpression extends Node {
type: 'MemberExpression'
object: MemberSliceCallExpression
}
export interface SimpleMemberExpression extends BaseMemberExpression {
property: Identifier | Literal
}
export interface BoxedMemberExpression extends BaseMemberExpression {
property: Expression
boxed: true
}
export interface SliceExpression extends Node {
type: 'SliceExpression'
object: MemberSliceCallExpression
start?: Expression
end?: Expression
}
export interface IndexExpression extends Node {
type: 'IndexExpression'
object: MemberSliceCallExpression
index: Expression
}
export interface CallExpression extends Node {
type: 'CallExpression'
callee: MemberSliceCallExpression
arguments: Expression[]
}
export type PrimaryExpression = XlateExpression | ParenthesisExpression |
ThisExpression | SuperExpression | AssocExpression | ListExpression |
ListComprehension | ObjectName | Identifier | Literal | ObjectExpression
export interface ThisExpression extends Node {
type: 'ThisExpression'
}
export interface SuperExpression extends Node {
type: 'SuperExpression'
}
export interface AssocExpression extends Node {
type: 'AssocExpression'
properties: Property[]
}
export type ObjectExpression = AssocExpression
export interface Property extends Node {
type: 'Property'
key: Expression
value: Expression
}
export interface ListExpression extends Node {
type: 'ListExpression'
elements: Expression[]
}
export interface ListComprehension extends Node {
type: 'ListComprehension'
expression: AtExpression | Expression
left: Identifier
right: Expression
test?: Expression
}
export interface AtExpression extends Node {
type: 'AtExpression'
expression: Expression
}
export interface ParenthesisExpression extends Node {
type: 'ParenthesisExpression'
expression: Expression
}
export interface XlateExpression extends Node {
type: 'XlateExpression'
ospace: Identifier
string: Identifier
}
// ---------- Identifiers
export interface Identifier extends Node {
type: 'Identifier'
value: string
raw?: string
}
export interface LegacyAlias extends Node {
type: 'LegacyAlias'
value: number
raw?: string
}
// ---------- Literals
export interface Literal extends Node {
type: 'Literal'
literalType: LiteralType
value: string | boolean | number | null
raw?: string
}
export type LiteralType = 'string' | 'integer' | 'real' | 'date' | 'objref' |
'boolean' | 'undefined'
export interface StringLiteral extends Literal {
literalType: 'string'
}
export interface IntegerLiteral extends Literal {
literalType: 'integer'
}
export interface RealLiteral extends Literal {
literalType: 'real'
}
export interface DateLiteral extends Literal {
literalType: 'date'
}
export interface ObjRef extends Literal {
literalType: 'objref'
}
export interface BooleanLiteral extends Literal {
literalType: 'boolean'
}
export interface UndefinedLiteral extends Literal {
literalType: 'undefined'
}