-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathast_types.yml
More file actions
581 lines (503 loc) · 17 KB
/
Copy pathast_types.yml
File metadata and controls
581 lines (503 loc) · 17 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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
supertypes:
expr:
- name_expr
- int_literal
- float_literal
- boolean_literal
- string_literal
- regex_literal
- builtin_expr
- binary_expr
- unary_expr
- call_expr
- member_access_expr
- super_expr
- function_expr
- array_literal
- map_literal
- key_value_pair
- tuple_expr
- type_cast_expr
- type_test_expr
- if_expr
- assign_expr
- compound_assign_expr
- pattern_guard_expr
- empty_expr
- block
- break_expr
- continue_expr
- return_expr
- throw_expr
- try_expr
- switch_expr
- unsupported_node
expr_or_pattern:
- expr
- pattern
expr_or_type:
- expr
- type_expr
pattern:
- name_pattern
- tuple_pattern
- constructor_pattern
- or_pattern
- ignore_pattern
- expr_equality_pattern
- bulk_importing_pattern
- unsupported_node
# A statement is anything that can appear in a block.
# This type contains all of 'expr' and has partial overlap with 'member'.
# For example, type_alias_declaration can appear either as a stmt or member.
# constructor_declaration and destructor_declaration appear here because
# tree-sitter-swift's error recovery for #if/#endif in class bodies can place
# init/deinit declarations at the wrong (statement) level.
stmt:
- expr
- variable_declaration
- type_alias_declaration
- function_declaration
- import_declaration
- operator_syntax_declaration
- class_like_declaration
- accessor_declaration
- constructor_declaration
- destructor_declaration
- guard_if_stmt
- for_each_stmt
- while_stmt
- do_while_stmt
- labeled_stmt
# A member is anything that can appear in the body of a class-like declaration
member:
- constructor_declaration
- destructor_declaration
- function_declaration
- variable_declaration
- accessor_declaration
- initializer_declaration
- class_like_declaration
- type_alias_declaration
- associated_type_declaration
- unsupported_node
type_expr:
- named_type_expr
- generic_type_expr
- tuple_type_expr
- function_type_expr
- inferred_type_expr
- unsupported_node
type_constraint:
- equality_type_constraint
- bound_type_constraint
operator:
- infix_operator
- prefix_operator
- postfix_operator
named:
# Top-level is the root node, containing a single block of statements
# (which are themselves expressions or declarations).
top_level:
body: block
# An identifier used in the context of an expression
name_expr:
identifier: identifier
# An integer literal
int_literal:
# A floating-point literal
float_literal:
# A boolean literal
boolean_literal:
# A literal backed by a keyword such as `nil`, `null`, or `nullptr`.
#
# Although nil/null are keyword literals in many languages there should be
# no attempt to normalize "null-like" named entities, like Python's `None`.
builtin_expr:
# A string literal
string_literal:
# A regex literal
regex_literal:
# Application of a binary operator, such as `a + b`
binary_expr:
left: expr
operator: infix_operator
right: expr
# Application of a unary operator, such as `!x`
unary_expr:
operand: expr
operator: operator
# Plain assignment
assign_expr:
target: expr_or_pattern
value: expr
# Compound assignment
compound_assign_expr:
target: expr
operator: infix_operator
value: expr
# A function or method call, such as `f(x)` or `obj.m(x)`.
#
# Method calls are represented as a call whose `function` is a `member_access_expr`.
#
# Constructor calls are marked by a language-specific modifier, and the target may be
# a `type_expr` if the parser can deduce that the target is a type.
call_expr:
modifier*: modifier
callee: expr_or_type
argument*: argument
argument:
modifier*: modifier
name?: identifier
value: expr
# Member access, such as `obj.member`.
#
# The base may be a type expression when it is a static member access like `Array<Int>.method`.
# In ambiguous cases where the parser cannot distinguish static and instance member access, the base
# will be typically be an expression.
#
# For `super.x` the base will be an instance of `super_expr`.
member_access_expr:
base: expr_or_type
member: identifier
# A type expression that refers to a type inferred from the contextual type.
# This is used to translate Swift's leading-dot syntax, `.foo`, which means `T.foo` where
# `T` is the contextual type of some enclosing expression. This is translated to a member_access
# with an inferred_type_expr as the base.
inferred_type_expr:
# A `super` token, which can usually only appear as the base of member access.
super_expr:
function_expr:
modifier*: modifier
capture_declaration*: variable_declaration
parameter*: parameter
return_type?: type_expr
body: block
array_literal:
element*: expr
map_literal:
element*: expr
# A key-value pair, usually appearing as a named argument or as part of a map literal.
#
# For some languages, the key-value pair is a first class value and this type of expression
# may thus appear anywhere in the general case.
key_value_pair:
key: expr
value: expr
# A tuple expression, such as `(a, b, c)`.
tuple_expr:
element*: expr
# A parameter.
#
# `type` is its declared type annotation (if any)
#
# `pattern` binds the parameter's internal name(s). For a simple parameter this is a
# `name_pattern`, but may be an arbitrary pattern for languages where patterns may appear
# in the parameter list.
#
# `external_name` is the name by which to call sites refer to the parameter, if the parameter
# can be passed as a named parameter. For example, the Swift function `func greet(person id: String)`
# would have `person` as the external name and a `name_pattern` wrapping `id` is the parameter's pattern.
parameter:
modifier*: modifier
external_name?: identifier
type?: type_expr
pattern?: pattern
default?: expr
# An expression that does nothing. Used where the grammar permits an
# empty statement (e.g. a stray `;`).
empty_expr:
# A brace-delimited sequence of statements (`{ ... }`). Blocks are the
# only nodes that can directly contain statements; every other body-like
# field holds a single `block`.
block:
stmt*: stmt
if_expr:
condition: expr
then?: expr
else?: expr
# A variable declaration or destructuring assignment that introduces new variables.
#
# Any occurrence of `var_patterns` in 'pattern' result in fresh bindings that are
# in scope for the rest of the enclosing block.
#
# The initializer is optional (but typically cannot be omitted if combined with a non-trivial pattern).
#
# Modifiers should include 'var', 'let', 'const', etc, if they are significant.
# A grouped declaration like `let x = 1, y = 2` is emitted as a sequence of
# `variable_declaration`s directly into the enclosing stmt/member slot; every
# declaration after the first in such a group is tagged with a synthetic
# `chained_declaration` modifier so the grouping can be recovered downstream.
variable_declaration:
modifier*: modifier
pattern: pattern
type?: type_expr
value?: expr
# Evaluate 'condition', and if false, execute 'else' which must break from the enclosing block scope (return, break, etc).
# Any variables bound by 'condition' will be in scope for the remainder of the enclosing block scope
# (which differs from how if_expr works).
guard_if_stmt:
condition: expr
else: block
# `break` (with optional label)
break_expr:
label?: identifier
# `continue` (with optional label)
continue_expr:
label?: identifier
# A labeled statement, such as `outer: for ... { ... }`. The labeled
# statement appears as the `stmt` field; `break`/`continue` may target
# the label.
labeled_stmt:
label: identifier
stmt: stmt
# `return value` or bare `return`
return_expr:
value?: expr
# `throw value`
throw_expr:
value?: expr
# An import declaration.
#
# The semantics of an import are generally:
# - Evaluate the 'imported_expr' to a value (possibly a compile-time value, such as namespace)
# - Filter away possible values based on modifiers (e.g. type-only imports only accept types)
# - Assign the value to the pattern, binding variables and/or type names in scope
#
import_declaration:
modifier*: modifier
imported_expr: expr # Qualified names are encoded as a chain of member_access_expr ending with a name_expr
pattern?: pattern # Binds local names in scope (possibly via bulk_importing_pattern)
# `typealias Name = Type`
type_alias_declaration:
modifier*: modifier
name: identifier
type_parameter*: type_parameter
type_constraint*: type_constraint
type: type_expr
# A top-level function declaration.
function_declaration:
modifier*: modifier
name: identifier
type_parameter*: type_parameter
type_constraint*: type_constraint
parameter*: parameter
return_type?: type_expr
body?: block
# `for pattern in iterable [where guard] { body }`.
for_each_stmt:
modifier*: modifier
pattern: pattern
iterable: expr
guard?: expr
body?: block
# `while condition { body }`.
while_stmt:
modifier*: modifier
condition: expr
body?: block
# `repeat { body } while condition`.
do_while_stmt:
modifier*: modifier
body?: block
condition: expr
# `do { body } catch pattern { ... } catch ...`. Swift uses `do`/`catch`
# for error handling; for languages with `try`/`catch`, this is the same shape.
try_expr:
modifier*: modifier
body: block
catch_clause*: catch_clause
catch_clause:
modifier*: modifier
pattern?: pattern
guard?: expr
body: block
# `switch value { case pattern: body case ...: default: body }`
switch_expr:
modifier*: modifier
value: expr
case*: switch_case
# A single `case ...:` (or `default:`) entry in a switch.
# An entry with multiple `case p1, p2:` patterns uses an `or_pattern`.
# A `default:` entry has no pattern.
# An optional `guard` corresponds to a `where`-clause on the case.
switch_case:
modifier*: modifier
pattern?: pattern
guard?: expr
body: block
# Evaluate 'expr' and match its result against 'pattern', and return true if it matches.
# Variables bound by the pattern will be in scope within the 'true' branch controlled by this expression.
#
# In Swift, `if case let PATTERN = EXPR` maps to this node
#
# Java: 'if (x instanceof Foo y && w ...) { ... }'
pattern_guard_expr:
pattern: pattern
value: expr
# A type cast expression, such as `x as T`, `x as? T`, or `x as! T`. The
# operator distinguishes between the variants.
type_cast_expr:
expr: expr
operator: infix_operator
type: type_expr
# A type-test expression, such as `x is T`. Yields a boolean indicating
# whether `expr` is an instance of `type`.
type_test_expr:
expr: expr
operator: infix_operator
type: type_expr
# An identifier that introduces a variable.
#
# When used as a pattern, the pattern matches anything and binds its incoming value to the variable
name_pattern:
modifier*: modifier
identifier: identifier
# A pattern matching anything, binding no variables, usually using the syntax "_"
ignore_pattern:
# A pattern that matches if the incoming value is equal to the value of the given expression.
# Used for literal patterns in switch (e.g. `case 1:`).
expr_equality_pattern:
expr: expr
# A tuple pattern such as `(a, b)` in `let (a, b) = pair`.
#
# Elements of the tuple pattern can have names, such as Swift's `let (foo: x, bar: y) = tuple`.
tuple_pattern:
modifier*: modifier
element*: pattern_element
# A pattern such as `Some(x)` where `Some` is the constructor and `x` is an element.
# The element names are interpreted as argument labels and/or field names.
constructor_pattern:
modifier*: modifier
constructor: expr_or_type
element*: pattern_element
# A disjunction pattern that matches if any of its sub-patterns match.
or_pattern:
modifier*: modifier
pattern*: pattern
# A pattern with an optional associated name.
pattern_element:
modifier*: modifier
key?: identifier
pattern: pattern
# A pattern that checks if the incoming value has the given type, and if so, the
# value is matched against the given nested pattern (and succeeds iff the nested match succeeds).
#
# In Swift: `if let y = x as? Foo` is a pattern_guard_expr containing a type_test_pattern
# In Java: `x instanceof Foo y` is a type_test_pattern wrapping a name_pattern
type_test_pattern:
pattern: pattern
type: type_expr
# A '*' pattern that imports all members of the incoming value into the local scope
# Currently this can only appear in import declarations.
bulk_importing_pattern:
modifier*: modifier
# An simple unqualified identifier token
identifier:
# A node that we don't yet translate
unsupported_node:
infix_operator:
prefix_operator:
postfix_operator:
# The fixity of a custom operator declaration (e.g. "prefix", "infix",
# "postfix"). The value is the keyword string.
fixity:
type_parameter:
modifier*: modifier
name: identifier
bound?: type_expr
# A generic constraint of the form `T == U`, requiring two types to be
# equal. Appears in `where` clauses on generic declarations
# (e.g. Swift `func foo<T, U>() where T == U`).
equality_type_constraint:
left: type_expr
right: type_expr
# A generic constraint of the form `T: Bound`, requiring a type parameter
# to conform to (or inherit from) some other type. Appears in `where`
# clauses on generic declarations (e.g. Swift `where T: Equatable`).
bound_type_constraint:
type: type_expr
bound: type_expr
# `infix operator +++` (and the like) — a declaration of a custom operator.
operator_syntax_declaration:
modifier*: modifier
name: identifier
# The fixity specifier (`prefix`, `infix`, `postfix`), when applicable.
fixity?: fixity
# The declared precedence level, when present (e.g. Swift's
# `infix operator +++ : AdditionPrecedence`).
precedence?: expr
# A class-like declaration: class, struct, interface (protocol), enum (or actor).
# The syntactic kind is carried as a `modifier` (e.g. "class", "struct",
# "interface", "enum", "extension"). The `"enum_case"` modifier additionally
# marks a declaration as an enum case with associated values. Extensions are
# represented as a class-like declaration with the `"extension"` modifier and
# no `name`; the extended type appears as a `base_type`.
class_like_declaration:
modifier*: modifier
name?: identifier
type_parameter*: type_parameter
type_constraint*: type_constraint
base_type*: base_type
member*: member
# One of the base types of a class declaration.
#
# If the language has multiple kinds of base classes (e.g. extends/implements) the
# kind should be included as a modifier on this node.
base_type:
modifier*: modifier
type: type_expr
constructor_declaration:
modifier*: modifier
name?: identifier
parameter*: parameter
body: block
# A destructor / finalizer (Swift `deinit`, C++ `~T()`, etc.).
destructor_declaration:
modifier*: modifier
body: block
# Declaration of a single accessor for a property (such as a getter, setter,
# or observer like Swift's `willSet`/`didSet`).
#
# Multiple accessors for the same property are emitted as a sequence of
# accessor_declaration nodes; every accessor after the first is tagged with
# a synthetic `chained_declaration` modifier so the grouping can be recovered
# downstream. Stored properties with observers are emitted as a
# variable_declaration followed by one accessor_declaration per observer
# (each observer also tagged with `chained_declaration`).
accessor_declaration:
modifier*: modifier
name: identifier
accessor_kind: accessor_kind
parameter*: parameter
type?: type_expr
body?: block
# "get", "set", or a language-specific kind like "didSet"
accessor_kind:
# Static or instance initializer block. That is, code that runs at initialization time of either the class or an instance.
initializer_declaration:
modifier*: modifier
body: block
associated_type_declaration:
modifier*: modifier
name: identifier
bound?: type_expr
named_type_expr:
qualifier?: type_expr
name: identifier
generic_type_expr:
base: type_expr
type_argument*: type_expr
# A tuple type such as `(Int, String)` or `(a: A, b: B)`.
tuple_type_expr:
element*: tuple_type_element
# An element of a `tuple_type_expr`, optionally carrying a label.
tuple_type_element:
name?: identifier
type: type_expr
# A function type such as `(Int, String) -> Bool` or `(x: Int) -> Bool`.
function_type_expr:
parameter*: parameter
return_type: type_expr
# A modifier such as 'static', 'public', or 'async'. For now this is just a leaf node with a string value.
modifier: