forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.def
1610 lines (1484 loc) · 34.9 KB
/
state.def
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This is an X-macro header. It does not use `#include` guards, and instead is
// designed to be `#include`ed after the x-macro is defined in order for its
// inclusion to expand to the desired output. Macro definitions are cleaned up
// at the end of this file.
//
// Supported x-macros are:
// - CARBON_PARSE_STATE(Name)
// Defines a parser state.
//
// Parser states may be clustered when there are multiple related variants,
// named `StateAsVariant`. When there are variants, they share a common helper
// function for most logic.
//
// The comments before each state describe the portion of the grammar that the
// state is implementing, by giving an example of each kind of token sequence
// that this state handles. In these examples, `...` indicates a sequence of
// tokens handled by some other state, and `???` indicates a sequence of invalid
// tokens. A trailing `??? ;` indicates an attempt to skip to the end of the
// declaration, which may or may not actually find a `;` token.
//
// The position in the token stream before the state is indicated by the caret
// `^` on the line below the example, and all tokens consumed by the state are
// underlined by the caret and following `~`s. If no tokens are consumed, the
// caret will point between tokens. Therefore, the position in the token stream
// after the state is the first token in the example after the underlined
// region.
//
// Following each set of examples, the output states for that situation are
// listed. States are numbered in the order they'll be executed; in other
// words, `1` is the top of the state stack. The comment `(state done)`
// indicates that no new states are added to the stack.
#ifndef CARBON_PARSE_STATE
#error "Must define the x-macro to use this file."
#define CARBON_PARSE_STATE(Name)
#endif
// Use CARBON_PARSE_STATE_VARIANTSN(State, Variant1, Variant2, ...) to generate
// StateAsVariant1, StateAsVariant2, ... states.
#define CARBON_PARSE_STATE_VARIANT(State, Variant) \
CARBON_PARSE_STATE(State##As##Variant)
#define CARBON_PARSE_STATE_VARIANTS2(State, Variant1, Variant2) \
CARBON_PARSE_STATE_VARIANT(State, Variant1) \
CARBON_PARSE_STATE_VARIANT(State, Variant2)
#define CARBON_PARSE_STATE_VARIANTS3(State, Variant1, Variant2, Variant3) \
CARBON_PARSE_STATE_VARIANT(State, Variant1) \
CARBON_PARSE_STATE_VARIANTS2(State, Variant2, Variant3)
#define CARBON_PARSE_STATE_VARIANTS4(State, Variant1, Variant2, Variant3, \
Variant4) \
CARBON_PARSE_STATE_VARIANT(State, Variant1) \
CARBON_PARSE_STATE_VARIANTS3(State, Variant2, Variant3, Variant4)
// Used as a default for StateStackEntry initialization in some cases. Should
// not be put on the state stack.
CARBON_PARSE_STATE(Invalid)
// Handles an index expression:
//
// a[0]
// ^
// 1. Expr
// 2. IndexExprFinish
CARBON_PARSE_STATE(IndexExpr)
// Handles finishing the index expression.
//
// a[0]
// ^
// (state done)
CARBON_PARSE_STATE(IndexExprFinish)
// Handles the array keyword and opening paren in an array expression.
//
// array(T, N)
// ^~~~~~
// 1. Expr
// 2. ArrayExprComma
CARBON_PARSE_STATE(ArrayExpr)
// Handles ',' in an array expression.
//
// array(T, N)
// ^
// 1. Expr
// 2. ArrayExprFinish
CARBON_PARSE_STATE(ArrayExprComma)
// Handles finishing the array expression.
//
// array(T, N)
// ^
// (state done)
CARBON_PARSE_STATE(ArrayExprFinish)
// Handles the `{` of a brace expression.
//
// {}
// ^
// 1. BraceExprFinishAsUnknown
//
// { ... }
// ^
// 1. BraceExprParamAsUnknown
// 2. BraceExprFinishAsUnknown
CARBON_PARSE_STATE(BraceExpr)
// Handles a brace expression parameter. Note this will always start as unknown,
// but should be known after the first valid parameter. All later inconsistent
// parameters are invalid.
//
// { .foo ... }
// ^
// 1. PeriodAsStruct
// 2. BraceExprParamAfterDesignatorAs(Type|Value|Unknown)
//
// { ???
// ^
// 1. BraceExprParamFinishAs(Type|Value|Unknown)
CARBON_PARSE_STATE_VARIANTS3(BraceExprParam, Type, Value, Unknown)
// Handles a brace expression parameter after the initial designator. This
// should be at a `:` or `=`, depending on whether it's a type or value literal.
//
// { .foo = bar ... }
// ^
// 1. Expr
// 2. BraceExprParamFinishAsValue
//
// { .foo: bar ... }
// ^
// 1. Expr
// 2. BraceExprParamFinishAsType
//
// { .foo ???
// ^
// 1. BraceExprParamFinishAs(Type|Value|Unknown)
CARBON_PARSE_STATE_VARIANTS3(BraceExprParamAfterDesignator, Type, Value,
Unknown)
// Handles the end of a brace expression parameter.
//
// { ... }
// ^
// (state done)
//
// { .foo = bar, ... }
// ^
// 1. BraceExprParamAsValue
//
// { .foo: bar, ... }
// ^
// 1. BraceExprParamAsType
//
// { ??? , ... }
// ^
// 1. BraceExprParamAsUnknown
CARBON_PARSE_STATE_VARIANTS3(BraceExprParamFinish, Type, Value, Unknown)
// Handles the `}` of a brace expression.
//
// { ... }
// ^
// (state done)
CARBON_PARSE_STATE_VARIANTS3(BraceExprFinish, Type, Value, Unknown)
// Handles a call expression `(...)`.
//
// F()
// ^
// 1. CallExprFinish
//
// F( ...
// ^
// 1. Expr
// 2. CallExprParamFinish
// 3. CallExprFinish
CARBON_PARSE_STATE(CallExpr)
// Handles the `,` or `)` after a call parameter.
//
// F(a, ...)
// ^
// 1. Expr
// 2. CallExprParamFinish
//
// F(a )
// ^
// (state done)
CARBON_PARSE_STATE(CallExprParamFinish)
// Handles finishing the call expression.
//
// F(a, b)
// ^
// (state done)
CARBON_PARSE_STATE(CallExprFinish)
// Handles processing at the `{` on a typical code block.
//
// if (cond) {
// ^
// 1. StatementScopeLoop
// 2. CodeBlockFinish
//
// if (cond) ???
// ^
// 1. Statement
// 2. CodeBlockFinish
CARBON_PARSE_STATE(CodeBlock)
// Handles processing at the `}` on a typical code block, after a statement
// scope is done.
//
// if (cond) { ... }
// ^
// (state done)
CARBON_PARSE_STATE(CodeBlockFinish)
// Handles a declaration name and parameters, such as `Foo[...](...)`.
//
// name . ...
// ^~~~~~
// 1. DeclNameAndParams
//
// name [ ... ]
// ^~~~
// 1. PatternListAsImplicit
// 2. DeclNameAndParamsAfterImplicit
//
// name ( ... )
// ^~~~
// 1. PatternListAsExplicit
// 2. DeclNameAndParamsAfterParams
//
// name ...
// ^~~~
// (state done)
//
// ???
// ^
// (state done)
CARBON_PARSE_STATE(DeclNameAndParams)
// Inside a declaration, conditionally starts explicit parameter handling. Only
// used after implicit parameters.
//
// name [ ... ] ( ... )
// ^
// 1. PatternListAsExplicit
// 2. DeclNameAndParamsAfterParams
//
// name [ ... ] ???
// ^
// (state done)
CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit)
// Inside a declaration, conditionally starts another qualified name. Only used
// after regular parameters.
//
// name [ ... ] ( ... ) .
// ^
// 1. DeclNameAndParams
//
// name [ ... ] ( ... ) ...
// ^
// (state done)
CARBON_PARSE_STATE(DeclNameAndParamsAfterParams)
// Handles processing of a declaration. Things like fn, class, interface, and so
// on.
//
// abstract
// ^~~~~~~~
// base class
// ^~~~
// default
// ^~~~~~~
// export import
// ^~~~~~
// extend base
// ^~~~~~
// final
// ^~~~~
// impl fn
// ^~~~
// private
// ^~~~~~~
// protected
// ^~~~~~~~~
// virtual
// ^~~~~~~
// 1. Decl
//
// adapt ...
// ^~~~~
// 1. AdaptAfterIntroducer
//
// alias ...
// ^~~~~
// 1. Alias
//
// base : ...
// ^~~~
// 1. BaseAfterIntroducer
//
// choice ...
// ^~~~~~
// 1. ChoiceIntroducer
//
// class ...
// ^~~~~
// 1. TypeAfterIntroducerAsClass
//
// constraint ...
// ^~~~~~~~~~
// 1. TypeAfterIntroducerAsNamedConstraint
//
// export <name> ...
// ^~~~~~
// 1. ExportName
//
// fn ...
// ^~
// 1. FunctionIntroducer
//
// impl ...
// ^~~~
// 1. ImplAfterIntroducer
//
// import ... (in packaging directives)
// ^~~~~~
// 1. Import
//
// interface ...
// ^~~~~~~~~
// 1. TypeAfterIntroducerAsInterface
//
// let ...
// ^~~
// 1. Let
//
// library ... (in packaging directives)
// ^~~~~~~
// 1. Library
//
// namespace ...
// ^~~~~~~~~
// 1. Namespace
//
// package ... (in packaging directives)
// ^~~~~~~
// 1. Package
//
// var ...
// ^~~
// 1. VarAsDecl
//
// ;
// ^
// (state done)
//
// ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(Decl)
// Handles processing of a declaration scope, which contains a sequence of
// declarations.
//
// }
// ^
// <eof>
// ^
// (state done)
//
// ...
// ^
// 1. Decl
// 2. DeclScopeLoop
//
CARBON_PARSE_STATE(DeclScopeLoop)
// Handles periods. Only does one `.<expression>` segment; the source is
// responsible for handling chaining.
//
// The forms of this are:
// - Member access expressions.
// - Designated names in structs.
//
// Expressions have member accesses such as `x.y`, while structs have
// designators such as `.z`.
//
// . name
// ^~~~~~
// -> name
// ^~~~~~~
// . base (variant is not Decl)
// ^~~~~~
// -> base (variant is not Decl)
// ^~~~~~~
// . ??? (??? consumed if it is a keyword)
// ^
// -> ??? (??? consumed if it is a keyword)
// ^~
// (state done)
//
// expr . ( ... )
// ^
// 1. OnlyParenExpr
// 2. CompoundMemberAccess
//
// expr -> ( ... )
// ^~
// 1. OnlyParenExpr
// 2. CompoundPointerMemberAccess
CARBON_PARSE_STATE_VARIANTS2(Period, Expr, Struct)
// Handles a compound member access after we parse the name expression.
//
// expr . ( expr )
// ^
CARBON_PARSE_STATE(CompoundMemberAccess)
// Handles a compound pointer member access after we parse the name expression.
//
// expr -> ( expr )
// ^
CARBON_PARSE_STATE(CompoundPointerMemberAccess)
// Handles `->name` expressions. Identical to PeriodAsExpr except for the
// leading token.
//
// -> name
// ^~~~~~~
// (state done)
//
// -> ??? (??? consumed if it is a keyword)
// ^~
// (state done)
CARBON_PARSE_STATE(ArrowExpr)
// Handles processing of an expression.
//
// if ...
// ^~
// 1. Expr
// 2. IfExprCondition
// 3. IfExprFinish
//
// <prefix operator> ...
// ^~~~~~~~~~~~~~~~~
// 1. Expr
// 2. ExprLoopForPrefix
//
// ...
// ^
// 1. ExprInPostfix
// 2. ExprLoop
CARBON_PARSE_STATE(Expr)
// Handles the initial part of postfix expressions, such as an identifier or
// literal value, then proceeds to the loop.
//
// identifier
// ^~~~~~~~~~
// literal
// ^~~~~~~
// self
// ^~~~
// Self
// ^~~~
// 1. ExprInPostfixLoop
//
// {
// ^
// 1. BraceExpr
// 2. ExprInPostfixLoop
//
// (
// ^
// 1. ParenExpr
// 2. ExprInPostfixLoop
//
// [
// ^
// 1. ArrayExpr
// 2. ExprInPostfixLoop
//
// ???
// ^
// (state done)
CARBON_PARSE_STATE(ExprInPostfix)
// Handles looping through elements following the initial postfix expression,
// such as designators or parenthesized parameters.
//
// expr . ...
// ^
// 1. PeriodAsExpr
// 2. ExprInPostfixLoop
//
// expr -> ...
// ^
// 1. ArrowExpr
// 2. ExprInPostfixLoop
//
// expr ( ... )
// ^
// 1. CallExpr
// 2. ExprInPostfixLoop
//
// expr [ ... ]
// ^
// 1. IndexExprStart
// 2. ExprInPostfixLoop
//
// ...
// ^
// (state done)
CARBON_PARSE_STATE(ExprInPostfixLoop)
// Handles processing of an expression.
//
// expr <infix operator> ...
// ^~~~~~~~~~~~~~~~
// 1. Expr
// 2. ExprLoopForBinary
//
// expr <postfix operator>
// ^~~~~~~~~~~~~~~~~~
// 1. ExprLoop
//
// expr <short circuit operator> ...
// ^~~~~~~~~~~~~~~~~~~~~~~~
// 1. Expr
// 2. ExprLoopForShortCircuitOperator
//
// expr ...
// ^
// (state done)
CARBON_PARSE_STATE(ExprLoop)
// Completes an ExprLoop pass by adding an infix operator, then goes back
// to ExprLoop.
//
// expr <infix operator> expr ...
// ^
// 1. ExprLoop
CARBON_PARSE_STATE(ExprLoopForInfixOperator)
// Completes an ExprLoop pass by adding a prefix operator, then goes back
// to ExprLoop.
//
// <prefix operator> expr ...
// ^
// 1. ExprLoop
CARBON_PARSE_STATE(ExprLoopForPrefixOperator)
// Completes an ExprLoop pass by adding a short circuit operator, then goes back
// to ExprLoop.
//
// expr <short circuit operator> expr ...
// ^
// 1. ExprLoop
CARBON_PARSE_STATE_VARIANTS2(ExprLoopForShortCircuitOperator, And, Or)
// Completes the condition of an `if` expression and handles the `then` token.
//
// if expr then ...
// ^~~~
// 1. Expr
// 2. IfExprFinishThen
//
// if expr ???
// ^
// (state done)
CARBON_PARSE_STATE(IfExprFinishCondition)
// Completes the first alternative in an `if` expression and handles the `else`
// token.
//
// if expr then expr else ...
// ^~~~
// 1. Expr
// 2. IfExprFinishElse
//
// if expr then expr ???
// ^
// (state done)
CARBON_PARSE_STATE(IfExprFinishThen)
// Completes the second alternative in an `if` expression.
//
// if expr then expr else expr
// ^
// (state done)
CARBON_PARSE_STATE(IfExprFinishElse)
// Completes an IfExpr.
//
// if expr then expr else expr
// ^
// if ???
// ^
// (state done)
CARBON_PARSE_STATE(IfExprFinish)
// Handles the beginning of a requirement expression after a `where` operator in
// an expression.
// TODO: Also a `require` declaration?
//
// expr where .designator = ...
// ^~~~~~~~~~~~~
// 1. Expr
// 2. RequirementOperatorFinish
// expr where ...
// ^
// 1. Expr
// 2. RequirementOperator
CARBON_PARSE_STATE(RequirementBegin)
// Handles a requirement operator in a `where` expression.
//
// expr where expr impls ...
// ^~~~
// expr where expr = ...
// ^
// expr where expr == ...
// ^~
// 1. Expr
// 2. RequirementOperatorFinish
CARBON_PARSE_STATE(RequirementOperator)
// Finishes a requirement operator in a `where` expression.
//
// expr where expr impls expr
// ^
// expr where expr = expr
// ^
// expr where expr == expr
// ^
// (state done)
// expr where expr impls expr and
// ^~~
// expr where expr = expr and
// ^~~
// expr where expr == expr and
// ^~~
// 1. RequirementBegin
CARBON_PARSE_STATE(RequirementOperatorFinish)
// Finishes an `where` expression.
//
// expr where requirement
// ^
// (state done)
CARBON_PARSE_STATE(WhereFinish)
// Handles the `;` for an expression statement, which is different from most
// keyword statements.
//
// expr ;
// ^
// expr ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(ExprStatementFinish)
// Handles a function's introducer.
//
// fn ...
// ^
// 1. DeclNameAndParams
// 2. FunctionAfterParams
CARBON_PARSE_STATE(FunctionIntroducer)
// Handles processing of a function's syntax after `)`, primarily the
// possibility a `->` return type is there. Always enqueues signature finish
// handling.
//
// fn F(...) -> ...
// ^~
// 1. Expr
// 2. FunctionReturnTypeFinish
// 3. FunctionSignatureFinish
//
// fn F(...) ...
// ^
// 1. FunctionSignatureFinish
CARBON_PARSE_STATE(FunctionAfterParams)
// Finishes a function return type.
//
// fn F(...) -> expr ...
// ^
// (state done)
CARBON_PARSE_STATE(FunctionReturnTypeFinish)
// Finishes a function signature. If it's a declaration, the function is done;
// otherwise, this also starts definition processing.
//
// fn ... ;
// ^
// (state done)
//
// fn ... {
// ^
// 1. StatementScopeLoop
// 2. FunctionDefinitionFinish
//
// fn ... ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(FunctionSignatureFinish)
// Finishes a function definition.
//
// fn ... }
// ^
// fn ... ;
// ^
// (state done)
CARBON_PARSE_STATE(FunctionDefinitionFinish)
// Handles `export <name>`.
//
// export Name;
// ^
// 1. DeclNameAndParams
// 2. ExportFinish
CARBON_PARSE_STATE(ExportName)
// Finishes an `export <name>`.
//
// export Name;
// ^
// (state done)
CARBON_PARSE_STATE(ExportNameFinish)
// Handles `import`.
//
// import pkgname [library "libname"] ;
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// import library "libname" ;
// ^~~~~~~~~~~~~~~~~~~
// import ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(Import)
// Handles `library` in declaration form.
//
// library "libname" ;
// ^~~~~~~~~~~
// library ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(Library)
// Handles `namespace`.
//
// namespace ...
// ^
// 1. DeclNameAndParams
// 2. NamespaceFinish
CARBON_PARSE_STATE(Namespace)
// Handles `namespace` after the name.
//
// namespace ... ;
// ^
// namespace ... ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(NamespaceFinish)
// Handles `package`.
//
// package pkgname [library "libname"] ;
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// package ??? ;
// ^~~~~
// (state done)
CARBON_PARSE_STATE(Package)
// Handles `alias` after the introducer.
//
// alias ...
// ^
// 1. DeclNameAndParams
// 2. AliasInitializer
CARBON_PARSE_STATE(Alias)
// Handles `alias` after the name.
//
// alias ... = ... ;
// ^
// 1. Expr
// 2. AliasFinish
//
// alias ???
// ^
// (state done)
CARBON_PARSE_STATE(AliasAfterName)
// Handles `alias` at the end.
//
// alias ... ;
// ^
// alias ???
// ^
// (state done)
CARBON_PARSE_STATE(AliasFinish)
// Starts parsing a pattern in a comma-separated list. The variants mark
// whether it is part of an implicit parameter list or a tuple pattern.
//
// ...
// ^
// 1. Pattern
// 2. PatternListElementFinishAs(Tuple|Explicit|Implicit)
CARBON_PARSE_STATE_VARIANTS3(PatternListElement, Tuple, Explicit, Implicit)
// Finishes parsing a pattern in a comma-separated list, including the
// optional trailing `,`. If there are more patterns, enqueues another
// pattern parsing state.
//
// ... , ) (variant is Tuple)
// ^
// (state done)
//
// ... , ] (variant is Implicit)
// ^
// (state done)
//
// ... , ...
// ^
// 1. PatternListElementAs(Tuple|Explicit|Implicit)
//
// ...
// ^
// (state done)
CARBON_PARSE_STATE_VARIANTS3(PatternListElementFinish, Tuple, Explicit,
Implicit)
// Handles processing of a tuple pattern (parentheses) or implicit parameter
// list (square brackets).
//
// ( ) (variant is Tuple or Explicit)
// ^
// [ ] (variant is Implicit)
// ^
// 1. PatternListFinishAs(Tuple|Explicit|Implicit)
//
// ( ... ) (variant is Tuple or Explicit)
// ^
// [ ... ] (variant is Implicit)
// ^
// 1. PatternListElementAs(Tuple|Explicit|Implicit)
// 2. PatternListFinishAs(Tuple|Explicit|Implicit)
CARBON_PARSE_STATE_VARIANTS3(PatternList, Tuple, Explicit, Implicit)
// Handles processing of a parameter list `]` or `)`.
//
// ( ... ) (variant is Tuple or Explicit)
// ^
// [ ... ] (variant is Implicit)
// ^
// (state done)
CARBON_PARSE_STATE_VARIANTS3(PatternListFinish, Tuple, Explicit, Implicit)
// Handles the processing of a `(condition)` up through the expression.
//
// if/while/match { (invalid)
// ^
// 1. ParenConditionAs(If|While|Match)Finish
//
// if/while/match ( ... )
// ^
// if/while/match ???
// ^
// 1. Expr
// 2. ParenConditionAs(If|While|Match)Finish
CARBON_PARSE_STATE_VARIANTS3(ParenCondition, If, While, Match)
// Finishes the processing of a `(condition)` after the expression.
//
// if/while/match ( expr )
// ^
// if/while/match {
// ^
// if/while/match ??? {
// ^
// (state done)
CARBON_PARSE_STATE_VARIANTS3(ParenConditionFinish, If, While, Match)
// Handles compound member access `(` after `->` or `.`
//
// ( ... )
// ^
// 1. Expr
// 2. OnlyParenExprFinish
CARBON_PARSE_STATE(OnlyParenExpr)
// Handles the `)` after `->(`... or `.(`...
//
// ( ... )
// ^
CARBON_PARSE_STATE(OnlyParenExprFinish)
// Handles the `(` of a parenthesized single expression
//
// ( )
// ^
// 1. TupleLiteralFinish
//
// ( ... )
// ^
// 1. Expr
// 2. ExprAfterOpenParenFinish
// 3. ParenExprFinish (SPECIAL: may be replaced)
CARBON_PARSE_STATE(ParenExpr)
// Handles the `)` of a tuple literal.
//
// ( ... )
// ^
// (state done)
CARBON_PARSE_STATE(TupleLiteralFinish)
// Handles the end of an expression following an open parenthesis.
//
// ( ... , )
// ^
// (state done)
// SPECIAL: parent becomes TupleLiteralFinish
//
// ( ... , ... )
// ^
// 1. Expr
// 2. TupleLiteralElementFinish
// SPECIAL: parent becomes TupleLiteralFinish
//
// ( ... )
// ^
// (state done)
CARBON_PARSE_STATE(ExprAfterOpenParenFinish)
// Handles the end of an expression that is known to be an element of a tuple
// literal expression.
//
// ( ... , )
// ^
// (state done)
//
// ( ... , ... )
// ^
// 1. Expr
// 2. TupleLiteralElementFinish
//
// ( ... )
// ^
// (state done)
CARBON_PARSE_STATE(TupleLiteralElementFinish)
// Handles the `)` of a parenthesized single expression.
//
// ( ... )
// ^
// (state done)
CARBON_PARSE_STATE(ParenExprFinish)
// Handles processing of a pattern.
//
// ( ... )
// ^
// 1. PatternListAsTuple
//
// ...
// ^
// 1. BindingPattern
CARBON_PARSE_STATE(Pattern)
// Handles the initial part of a binding pattern, enqueuing type expression
// processing.
//
// addr (variant is not Variable)
// ^~~~
// 3. BindingPatternAddr
//
// THEN
//
// name: ...
// ^~~~~
// self: ...
// ^~~~~