state.def 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // This is an X-macro header. It does not use `#include` guards, and instead is
  6. // designed to be `#include`ed after the x-macro is defined in order for its
  7. // inclusion to expand to the desired output. Macro definitions are cleaned up
  8. // at the end of this file.
  9. //
  10. // Supported x-macros are:
  11. // - CARBON_PARSE_STATE(Name)
  12. // Defines a parser state.
  13. //
  14. // Parser states may be clustered when there are multiple related variants,
  15. // named `StateAsVariant`. When there are variants, they share a common helper
  16. // function for most logic.
  17. //
  18. // The comments before each state describe the portion of the grammar that the
  19. // state is implementing, by giving an example of each kind of token sequence
  20. // that this state handles. In this example, `...` indicates a sequence of
  21. // tokens handled by some other state, and `???` indicates a sequence of invalid
  22. // tokens. A trailing `??? ;` indicates an attempt to skip to the end of the
  23. // declaration, which may or may not actually find a `;` token.
  24. //
  25. // The position in the token stream before the state is indicated by the caret
  26. // `^` on the line below the example, and all tokens consumed by the state are
  27. // underlined by the caret and following `~`s. If no tokens are consumed, the
  28. // caret will point between tokens. Therefore, the position in the token stream
  29. // after the state is the first token in the example after the underlined
  30. // region.
  31. //
  32. // Following each set of examples, the output states for that situation are
  33. // listed. States are numbered in the order they'll be executed; in other
  34. // words, `1` is the top of the state stack. The comment `(state done)`
  35. // indicates that no new states are added to the stack.
  36. #ifndef CARBON_PARSE_STATE
  37. #error "Must define the x-macro to use this file."
  38. #endif
  39. // Use CARBON_PARSE_STATE_VARIANTSN(State, Variant1, Variant2, ...) to generate
  40. // StateAsVariant1, StateAsVariant2, ... states.
  41. #define CARBON_PARSE_STATE_VARIANT(State, Variant) \
  42. CARBON_PARSE_STATE(State##As##Variant)
  43. #define CARBON_PARSE_STATE_VARIANTS2(State, Variant1, Variant2) \
  44. CARBON_PARSE_STATE_VARIANT(State, Variant1) \
  45. CARBON_PARSE_STATE_VARIANT(State, Variant2)
  46. #define CARBON_PARSE_STATE_VARIANTS3(State, Variant1, Variant2, Variant3) \
  47. CARBON_PARSE_STATE_VARIANT(State, Variant1) \
  48. CARBON_PARSE_STATE_VARIANTS2(State, Variant2, Variant3)
  49. #define CARBON_PARSE_STATE_VARIANTS4(State, Variant1, Variant2, Variant3, \
  50. Variant4) \
  51. CARBON_PARSE_STATE_VARIANT(State, Variant1) \
  52. CARBON_PARSE_STATE_VARIANTS3(State, Variant2, Variant3, Variant4)
  53. // Used as a default for StateStackEntry initialization in some cases. Should
  54. // not be put on the state stack.
  55. CARBON_PARSE_STATE(Invalid)
  56. // Handles an index expression:
  57. //
  58. // a[0]
  59. // ^
  60. // 1. Expr
  61. // 2. IndexExprFinish
  62. CARBON_PARSE_STATE(IndexExpr)
  63. // Handles finishing the index expression.
  64. //
  65. // a[0]
  66. // ^
  67. // (state done)
  68. CARBON_PARSE_STATE(IndexExprFinish)
  69. // Handles an array expression.
  70. //
  71. // [T; N]
  72. // ^
  73. // 1. Expr
  74. // 2. ArrayExprSemi
  75. CARBON_PARSE_STATE(ArrayExpr)
  76. // Handles ';' in an array expression.
  77. //
  78. // [T;]
  79. // ^
  80. // 1. ArrayExprFinish
  81. //
  82. // [T; N]
  83. // ^
  84. // 1. Expr
  85. // 2. ArrayExprFinish
  86. CARBON_PARSE_STATE(ArrayExprSemi)
  87. // Handles finishing the array expression.
  88. //
  89. // [T;]
  90. // ^
  91. // [T; N]
  92. // ^
  93. // (state done)
  94. CARBON_PARSE_STATE(ArrayExprFinish)
  95. // Handles the `{` of a brace expression.
  96. //
  97. // {}
  98. // ^
  99. // 1. BraceExprFinishAsUnknown
  100. //
  101. // { ... }
  102. // ^
  103. // 1. BraceExprParamAsUnknown
  104. // 2. BraceExprFinishAsUnknown
  105. CARBON_PARSE_STATE(BraceExpr)
  106. // Handles a brace expression parameter. Note this will always start as unknown,
  107. // but should be known after the first valid parameter. All later inconsistent
  108. // parameters are invalid.
  109. //
  110. // { .foo ... }
  111. // ^
  112. // 1. PeriodAsStruct
  113. // 2. BraceExprParamAfterDesignatorAs(Type|Value|Unknown)
  114. //
  115. // { ???
  116. // ^
  117. // 1. BraceExprParamFinishAs(Type|Value|Unknown)
  118. CARBON_PARSE_STATE_VARIANTS3(BraceExprParam, Type, Value, Unknown)
  119. // Handles a brace expression parameter after the initial designator. This
  120. // should be at a `:` or `=`, depending on whether it's a type or value literal.
  121. //
  122. // { .foo = bar ... }
  123. // ^
  124. // 1. Expr
  125. // 2. BraceExprParamFinishAsValue
  126. //
  127. // { .foo: bar ... }
  128. // ^
  129. // 1. Expr
  130. // 2. BraceExprParamFinishAsType
  131. //
  132. // { .foo ???
  133. // ^
  134. // 1. BraceExprParamFinishAs(Type|Value|Unknown)
  135. CARBON_PARSE_STATE_VARIANTS3(BraceExprParamAfterDesignator, Type, Value,
  136. Unknown)
  137. // Handles the end of a brace expression parameter.
  138. //
  139. // { ... }
  140. // ^
  141. // (state done)
  142. //
  143. // { .foo = bar, ... }
  144. // ^
  145. // 1. BraceExprParamAsValue
  146. //
  147. // { .foo: bar, ... }
  148. // ^
  149. // 1. BraceExprParamAsType
  150. //
  151. // { ??? , ... }
  152. // ^
  153. // 1. BraceExprParamAsUnknown
  154. CARBON_PARSE_STATE_VARIANTS3(BraceExprParamFinish, Type, Value, Unknown)
  155. // Handles the `}` of a brace expression.
  156. //
  157. // { ... }
  158. // ^
  159. // (state done)
  160. CARBON_PARSE_STATE_VARIANTS3(BraceExprFinish, Type, Value, Unknown)
  161. // Handles a call expression `(...)`.
  162. //
  163. // F()
  164. // ^
  165. // 1. CallExprFinish
  166. //
  167. // F( ...
  168. // ^
  169. // 1. Expr
  170. // 2. CallExprParamFinish
  171. // 3. CallExprFinish
  172. CARBON_PARSE_STATE(CallExpr)
  173. // Handles the `,` or `)` after a call parameter.
  174. //
  175. // F(a, ...)
  176. // ^
  177. // 1. Expr
  178. // 2. CallExprParamFinish
  179. //
  180. // F(a )
  181. // ^
  182. // (state done)
  183. CARBON_PARSE_STATE(CallExprParamFinish)
  184. // Handles finishing the call expression.
  185. //
  186. // F(a, b)
  187. // ^
  188. // (state done)
  189. CARBON_PARSE_STATE(CallExprFinish)
  190. // Handles processing at the `{` on a typical code block.
  191. //
  192. // if (cond) {
  193. // ^
  194. // 1. StatementScopeLoop
  195. // 2. CodeBlockFinish
  196. //
  197. // if (cond) ???
  198. // ^
  199. // 1. Statement
  200. // 2. CodeBlockFinish
  201. CARBON_PARSE_STATE(CodeBlock)
  202. // Handles processing at the `}` on a typical code block, after a statement
  203. // scope is done.
  204. //
  205. // if (cond) { ... }
  206. // ^
  207. // (state done)
  208. CARBON_PARSE_STATE(CodeBlockFinish)
  209. // Handles a declaration name and parameters, such as `Foo[...](...)`.
  210. //
  211. // Allowed parameters:
  212. // - None: `Foo` only.
  213. // - Optional: `Foo`, `Foo(...)`, or `Foo[...](...)`.
  214. // - Required: `Foo(...)` or `Foo[...](...)`.
  215. //
  216. // name . ...
  217. // ^~~~
  218. // 1. PeriodAsDecl
  219. // 2. DeclNameAndParamsAfterNameAs(None|Optional|Required)
  220. //
  221. // name ...
  222. // ^~~~
  223. // 1. DeclNameAndParamsAfterNameAs(None|Optional|Required)
  224. //
  225. // ???
  226. // ^
  227. // (state done)
  228. CARBON_PARSE_STATE_VARIANTS3(DeclNameAndParams, None, Optional, Required)
  229. // Handles a declaration name between the main name and implicit parameters.
  230. //
  231. // name . ...
  232. // ^
  233. // 1. PeriodAsDecl
  234. // 2. DeclNameAndParamsAfterNameAs(None|Optional|Required)
  235. //
  236. // name [ ... ] (variant is not None)
  237. // ^
  238. // 1. PatternListAsImplicit
  239. // 2. DeclNameAndParamsAfterImplicit
  240. //
  241. // name ( ... ) (variant is not None)
  242. // ^
  243. // 1. PatternListAsTuple
  244. //
  245. // name ... (variant is not Required)
  246. // ^
  247. // (state done)
  248. //
  249. // name ??? (variant is Required)
  250. // ^
  251. // (state done)
  252. CARBON_PARSE_STATE_VARIANTS3(DeclNameAndParamsAfterName, None, Optional,
  253. Required)
  254. // Handles regular parameters such as `(...)` for the general declaration case.
  255. // Only used after implicit parameters.
  256. //
  257. // name [ ... ] ( ... )
  258. // ^
  259. // 1. PatternListAsTuple
  260. //
  261. // name [ ... ] ???
  262. // ^
  263. // (state done)
  264. CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit)
  265. // Handles processing of a declaration scope. Things like fn, class, interface,
  266. // and so on.
  267. //
  268. // abstract
  269. // ^~~~~~~~
  270. // base class
  271. // ^~~~
  272. // default
  273. // ^~~~~~~
  274. // extend base
  275. // ^~~~~~
  276. // final
  277. // ^~~~~
  278. // impl fn
  279. // ^~~~
  280. // private
  281. // ^~~~~~~
  282. // protected
  283. // ^~~~~~~~~
  284. // virtual
  285. // ^~~~~~~
  286. // 1. DeclScopeLoop
  287. //
  288. // alias ...
  289. // ^~~~~
  290. // 1. Alias
  291. // 2. DeclScopeLoop
  292. //
  293. // class ...
  294. // ^~~~~
  295. // 1. TypeAfterIntroducerAsClass
  296. // 2. DeclScopeLoop
  297. //
  298. // base : ...
  299. // ^~~~~~
  300. // 1. Expr
  301. // 2. BaseDecl
  302. // 3. DeclScopeLoop
  303. //
  304. // constraint ...
  305. // ^~~~~~~~~~
  306. // 1. TypeAfterIntroducerAsNamedConstraint
  307. // 2. DeclScopeLoop
  308. //
  309. // fn ...
  310. // ^~
  311. // 1. FunctionIntroducer
  312. // 2. DeclScopeLoop
  313. //
  314. // impl ...
  315. // ^~~~
  316. // 1. ImplAfterIntroducer
  317. // 2. DeclScopeLoop
  318. //
  319. // interface ...
  320. // ^~~~~~~~~
  321. // 1. TypeAfterIntroducerAsInterface
  322. // 2. DeclScopeLoop
  323. //
  324. // namespace ...
  325. // ^~~~~~~~~
  326. // 1. Namespace
  327. // 2. DeclScopeLoop
  328. //
  329. // ;
  330. // ^
  331. // 1. DeclScopeLoop
  332. //
  333. // var ...
  334. // ^~~
  335. // 1. VarAsDecl
  336. // 2. DeclScopeLoop
  337. //
  338. // let ...
  339. // ^~~
  340. // 1. Let
  341. // 2. DeclScopeLoop
  342. //
  343. // choice ...
  344. // ^
  345. // 1. ChoiceIntroducer
  346. // 2. DeclScopeLoop
  347. //
  348. // ??? ;
  349. // ^~~~~
  350. // (state done)
  351. CARBON_PARSE_STATE(DeclScopeLoop)
  352. // Handles periods. Only does one `.<expression>` segment; the source is
  353. // responsible for handling chaining.
  354. //
  355. // The forms of this are:
  356. // - Qualified names in declarations.
  357. // - Member access expressions.
  358. // - Designated names in structs.
  359. //
  360. // Declarations and expressions have qualifiers such as `x.y`, while structs
  361. // have designators such as `.z`.
  362. //
  363. // . name
  364. // ^~~~~~
  365. // (state done)
  366. //
  367. // . ??? (??? consumed if it is a keyword)
  368. // ^
  369. // (state done)
  370. CARBON_PARSE_STATE_VARIANTS3(Period, Decl, Expr, Struct)
  371. // Handles `->name` expressions. Identical to PeriodAsExpr except for the
  372. // leading token.
  373. //
  374. // -> name
  375. // ^~~~~~~
  376. // (state done)
  377. //
  378. // -> ??? (??? consumed if it is a keyword)
  379. // ^~
  380. // (state done)
  381. CARBON_PARSE_STATE(ArrowExpr)
  382. // Handles processing of an expression.
  383. //
  384. // if ...
  385. // ^~
  386. // 1. Expr
  387. // 2. IfExprCondition
  388. // 3. IfExprFinish
  389. //
  390. // <prefix operator> ...
  391. // ^~~~~~~~~~~~~~~~~
  392. // 1. Expr
  393. // 2. ExprLoopForPrefix
  394. //
  395. // ...
  396. // ^
  397. // 1. ExprInPostfix
  398. // 2. ExprLoop
  399. CARBON_PARSE_STATE(Expr)
  400. // Handles the initial part of postfix expressions, such as an identifier or
  401. // literal value, then proceeds to the loop.
  402. //
  403. // identifier
  404. // ^~~~~~~~~~
  405. // literal
  406. // ^~~~~~~
  407. // self
  408. // ^~~~
  409. // Self
  410. // ^~~~
  411. // 1. ExprInPostfixLoop
  412. //
  413. // {
  414. // ^
  415. // 1. BraceExpr
  416. // 2. ExprInPostfixLoop
  417. //
  418. // (
  419. // ^
  420. // 1. ParenExpr
  421. // 2. ExprInPostfixLoop
  422. //
  423. // [
  424. // ^
  425. // 1. ArrayExpr
  426. // 2. ExprInPostfixLoop
  427. //
  428. // ???
  429. // ^
  430. // (state done)
  431. CARBON_PARSE_STATE(ExprInPostfix)
  432. // Handles looping through elements following the initial postfix expression,
  433. // such as designators or parenthesized parameters.
  434. //
  435. // expr . ...
  436. // ^
  437. // 1. PeriodAsExpr
  438. // 2. ExprInPostfixLoop
  439. //
  440. // expr -> ...
  441. // ^
  442. // 1. ArrowExpr
  443. // 2. ExprInPostfixLoop
  444. //
  445. // expr ( ... )
  446. // ^
  447. // 1. CallExpr
  448. // 2. ExprInPostfixLoop
  449. //
  450. // expr [ ... ]
  451. // ^
  452. // 1. IndexExprStart
  453. // 2. ExprInPostfixLoop
  454. //
  455. // ...
  456. // ^
  457. // (state done)
  458. CARBON_PARSE_STATE(ExprInPostfixLoop)
  459. // Handles processing of an expression.
  460. //
  461. // expr <infix operator> ...
  462. // ^~~~~~~~~~~~~~~~
  463. // 1. Expr
  464. // 2. ExprLoopForBinary
  465. //
  466. // expr <postfix operator>
  467. // ^~~~~~~~~~~~~~~~~~
  468. // 1. ExprLoop
  469. //
  470. // expr <short circuit operator> ...
  471. // ^~~~~~~~~~~~~~~~~~~~~~~~
  472. // 1. Expr
  473. // 2. ExprLoopForShortCircuitOperator
  474. //
  475. // expr ...
  476. // ^
  477. // (state done)
  478. CARBON_PARSE_STATE(ExprLoop)
  479. // Completes an ExprLoop pass by adding an infix operator, then goes back
  480. // to ExprLoop.
  481. //
  482. // expr <infix operator> expr ...
  483. // ^
  484. // 1. ExprLoop
  485. CARBON_PARSE_STATE(ExprLoopForInfixOperator)
  486. // Completes an ExprLoop pass by adding a prefix operator, then goes back
  487. // to ExprLoop.
  488. //
  489. // <prefix operator> expr ...
  490. // ^
  491. // 1. ExprLoop
  492. CARBON_PARSE_STATE(ExprLoopForPrefixOperator)
  493. // Completes an ExprLoop pass by adding a short circuit operator, then goes back
  494. // to ExprLoop.
  495. //
  496. // expr <short circuit operator> expr ...
  497. // ^
  498. // 1. ExprLoop
  499. CARBON_PARSE_STATE_VARIANTS2(ExprLoopForShortCircuitOperator, And, Or)
  500. // Completes the condition of an `if` expression and handles the `then` token.
  501. //
  502. // if expr then ...
  503. // ^~~~
  504. // 1. Expr
  505. // 2. IfExprFinishThen
  506. //
  507. // if expr ???
  508. // ^
  509. // (state done)
  510. CARBON_PARSE_STATE(IfExprFinishCondition)
  511. // Completes the first alternative in an `if` expression and handles the `else`
  512. // token.
  513. //
  514. // if expr then expr else ...
  515. // ^~~~
  516. // 1. Expr
  517. // 2. IfExprFinishElse
  518. //
  519. // if expr then expr ???
  520. // ^
  521. // (state done)
  522. CARBON_PARSE_STATE(IfExprFinishThen)
  523. // Completes the second alternative in an `if` expression.
  524. //
  525. // if expr then expr else expr
  526. // ^
  527. // (state done)
  528. CARBON_PARSE_STATE(IfExprFinishElse)
  529. // Completes an IfExpr.
  530. //
  531. // if expr then expr else expr
  532. // ^
  533. // if ???
  534. // ^
  535. // (state done)
  536. CARBON_PARSE_STATE(IfExprFinish)
  537. // Handles the `;` for an expression statement, which is different from most
  538. // keyword statements.
  539. //
  540. // expr ;
  541. // ^
  542. // expr ??? ;
  543. // ^~~~~
  544. // (state done)
  545. CARBON_PARSE_STATE(ExprStatementFinish)
  546. // Handles a function's introducer.
  547. //
  548. // fn ...
  549. // ^
  550. // 1. DeclNameAndParamsAsRequired
  551. // 2. FunctionAfterParams
  552. CARBON_PARSE_STATE(FunctionIntroducer)
  553. // Handles processing of a function's syntax after `)`, primarily the
  554. // possibility a `->` return type is there. Always enqueues signature finish
  555. // handling.
  556. //
  557. // fn F(...) -> ...
  558. // ^~
  559. // 1. Expr
  560. // 2. FunctionReturnTypeFinish
  561. // 3. FunctionSignatureFinish
  562. //
  563. // fn F(...) ...
  564. // ^
  565. // 1. FunctionSignatureFinish
  566. CARBON_PARSE_STATE(FunctionAfterParams)
  567. // Finishes a function return type.
  568. //
  569. // fn F(...) -> expr ...
  570. // ^
  571. // (state done)
  572. CARBON_PARSE_STATE(FunctionReturnTypeFinish)
  573. // Finishes a function signature. If it's a declaration, the function is done;
  574. // otherwise, this also starts definition processing.
  575. //
  576. // fn ... ;
  577. // ^
  578. // (state done)
  579. //
  580. // fn ... {
  581. // ^
  582. // 1. StatementScopeLoop
  583. // 2. FunctionDefinitionFinish
  584. //
  585. // fn ... ??? ;
  586. // ^~~~~
  587. // (state done)
  588. CARBON_PARSE_STATE(FunctionSignatureFinish)
  589. // Finishes a function definition.
  590. //
  591. // fn ... }
  592. // ^
  593. // fn ... ;
  594. // ^
  595. // (state done)
  596. CARBON_PARSE_STATE(FunctionDefinitionFinish)
  597. // Handles `import`.
  598. //
  599. // import pkgname [library "libname"] ;
  600. // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  601. // import ??? ;
  602. // ^~~~~~~~~~~~
  603. // (state done)
  604. CARBON_PARSE_STATE(Import)
  605. // Handles `library` in directive form.
  606. //
  607. // Always:
  608. // (state done)
  609. CARBON_PARSE_STATE(Library)
  610. // Handles `namespace`.
  611. //
  612. // namespace ...
  613. // ^
  614. // 1. DeclNameAndParamsAsNone
  615. // 2. NamespaceFinish
  616. CARBON_PARSE_STATE(Namespace)
  617. // Handles `namespace` after the name.
  618. //
  619. // namespace ... ;
  620. // ^
  621. // namespace ... ??? ;
  622. // ^~~~~
  623. // (state done)
  624. CARBON_PARSE_STATE(NamespaceFinish)
  625. // Handles `package`.
  626. //
  627. // package pkgname [library "libname"] [api|impl] ;
  628. // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  629. // package ??? ;
  630. // ^~~~~~~~~~~~~
  631. // (state done)
  632. CARBON_PARSE_STATE(Package)
  633. // Handles `alias` after the introducer.
  634. //
  635. // alias ...
  636. // ^
  637. // 1. DeclNameAndParamsAsNone
  638. // 2. AliasInitializer
  639. CARBON_PARSE_STATE(Alias)
  640. // Handles `alias` after the name.
  641. //
  642. // alias ... = ... ;
  643. // ^
  644. // 1. Expr
  645. // 2. AliasFinish
  646. //
  647. // alias ???
  648. // ^
  649. // (state done)
  650. CARBON_PARSE_STATE(AliasAfterName)
  651. // Handles `alias` at the end.
  652. //
  653. // alias ... ;
  654. // ^
  655. // alias ???
  656. // ^
  657. // (state done)
  658. CARBON_PARSE_STATE(AliasFinish)
  659. // Starts parsing a pattern in a comma-separated list. The variants mark
  660. // whether it is part of an implicit parameter list or a tuple pattern.
  661. //
  662. // ...
  663. // ^
  664. // 1. BindingPattern
  665. // 2. PatternListElementFinishAs(Implicit|Tuple)
  666. CARBON_PARSE_STATE_VARIANTS2(PatternListElement, Implicit, Tuple)
  667. // Finishes parsing a pattern in a comma-separated list, including the
  668. // optional trailing `,`. If there are more patterns, enqueues another
  669. // pattern parsing state.
  670. //
  671. // ... , ) (variant is Tuple)
  672. // ^
  673. // (state done)
  674. //
  675. // ... , ] (variant is Implicit)
  676. // ^
  677. // (state done)
  678. //
  679. // ... , ...
  680. // ^
  681. // 1. PatternListElementAs(Implicit|Tuple)
  682. //
  683. // ...
  684. // ^
  685. // (state done)
  686. CARBON_PARSE_STATE_VARIANTS2(PatternListElementFinish, Implicit, Tuple)
  687. // Handles processing of a tuple pattern (parentheses) or implicit parameter
  688. // list (square brackets).
  689. //
  690. // ( ) (variant is Tuple)
  691. // ^
  692. // [ ] (variant is Implicit)
  693. // ^
  694. // 1. PatternListFinishAs(Tuple|Implicit)
  695. //
  696. // ( ... ) (variant is Tuple)
  697. // ^
  698. // [ ... ] (variant is Implicit)
  699. // ^
  700. // 1. PatternListElementAs(Tuple|Implicit)
  701. // 2. PatternListFinishAs(Tuple|Implicit)
  702. CARBON_PARSE_STATE_VARIANTS2(PatternList, Implicit, Tuple)
  703. // Handles processing of a parameter list `]` or `)`.
  704. //
  705. // ( ... ) (variant is Tuple)
  706. // ^
  707. // [ ... ] (variant is Implicit)
  708. // ^
  709. // (state done)
  710. CARBON_PARSE_STATE_VARIANTS2(PatternListFinish, Implicit, Tuple)
  711. // Handles the processing of a `(condition)` up through the expression.
  712. //
  713. // if/while/match { (invalid)
  714. // ^
  715. // 1. ParenConditionAs(If|While|Match)Finish
  716. //
  717. // if/while/match ( ... )
  718. // ^
  719. // if/while/match ???
  720. // ^
  721. // 1. Expr
  722. // 2. ParenConditionAs(If|While|Match)Finish
  723. CARBON_PARSE_STATE_VARIANTS3(ParenCondition, If, While, Match)
  724. // Finishes the processing of a `(condition)` after the expression.
  725. //
  726. // if/while/match ( expr )
  727. // ^
  728. // if/while/match {
  729. // ^
  730. // if/while/match ??? {
  731. // ^
  732. // (state done)
  733. CARBON_PARSE_STATE_VARIANTS3(ParenConditionFinish, If, While, Match)
  734. // Handles the `(` of a parenthesized single expression
  735. //
  736. // ( )
  737. // ^
  738. // 1. TupleLiteralFinish
  739. //
  740. // ( ... )
  741. // ^
  742. // 1. Expr
  743. // 2. ExprAfterOpenParenFinish
  744. // 3. ParenExprFinish (SPECIAL: may be replaced)
  745. CARBON_PARSE_STATE(ParenExpr)
  746. // Handles the `)` of a tuple literal.
  747. //
  748. // ( ... )
  749. // ^
  750. // (state done)
  751. CARBON_PARSE_STATE(TupleLiteralFinish)
  752. // Handles the end of an expression following an open parenthesis.
  753. //
  754. // ( ... , )
  755. // ^
  756. // (state done)
  757. // SPECIAL: parent becomes TupleLiteralFinish
  758. //
  759. // ( ... , ... )
  760. // ^
  761. // 1. Expr
  762. // 2. TupleLiteralElementFinish
  763. // SPECIAL: parent becomes TupleLiteralFinish
  764. //
  765. // ( ... )
  766. // ^
  767. // (state done)
  768. CARBON_PARSE_STATE(ExprAfterOpenParenFinish)
  769. // Handles the end of an expression that is known to be an element of a tuple
  770. // literal expression.
  771. //
  772. // ( ... , )
  773. // ^
  774. // (state done)
  775. //
  776. // ( ... , ... )
  777. // ^
  778. // 1. Expr
  779. // 2. TupleLiteralElementFinish
  780. //
  781. // ( ... )
  782. // ^
  783. // (state done)
  784. CARBON_PARSE_STATE(TupleLiteralElementFinish)
  785. // Handles the `)` of a parenthesized single expression.
  786. //
  787. // ( ... )
  788. // ^
  789. // (state done)
  790. CARBON_PARSE_STATE(ParenExprFinish)
  791. // Handles processing of a pattern.
  792. //
  793. // ( ... )
  794. // ^
  795. // 1. PatternListAsTuple
  796. //
  797. // ...
  798. // ^
  799. // 1. BindingPattern
  800. CARBON_PARSE_STATE(Pattern)
  801. // Handles the initial part of a binding pattern, enqueuing type expression
  802. // processing.
  803. //
  804. // template (variant is not Variable)
  805. // ^~~~~~~~
  806. // 4. BindingPatternTemplate
  807. //
  808. // THEN
  809. //
  810. // addr (variant is not Variable)
  811. // ^~~~
  812. // 3. BindingPatternAddr
  813. //
  814. // THEN
  815. //
  816. // name: ...
  817. // ^~~~~
  818. // self: ...
  819. // ^~~~~
  820. // 1. Expr
  821. // 2. BindingPatternFinishAsRegular
  822. //
  823. // name:! ...
  824. // ^~~~~~
  825. // self:! ...
  826. // ^~~~~~
  827. // 1. Expr
  828. // 2. BindingPatternFinishAsGeneric
  829. //
  830. // ???
  831. // ^
  832. // 1. BindingPatternFinishAsRegular
  833. CARBON_PARSE_STATE(BindingPattern)
  834. // Handles `addr` in a binding pattern.
  835. //
  836. // addr name: type
  837. // ^
  838. // (state done)
  839. CARBON_PARSE_STATE(BindingPatternAddr)
  840. // Handles `template` in a binding pattern.
  841. //
  842. // template name:! type
  843. // ^
  844. // (state done)
  845. CARBON_PARSE_STATE(BindingPatternTemplate)
  846. // Finishes binding pattern processing.
  847. //
  848. // name: type
  849. // ^
  850. // (state done)
  851. CARBON_PARSE_STATE_VARIANTS2(BindingPatternFinish, Generic, Regular)
  852. // Handles a single statement. While typically within a statement block, this
  853. // can also be used for error recovery where we expect a statement block and
  854. // are missing braces.
  855. //
  856. // break ...
  857. // ^~~~~
  858. // 1. StatementBreakFinish
  859. //
  860. // continue ...
  861. // ^~~~~~~~
  862. // 1. StatementContinueFinish
  863. //
  864. // for ...
  865. // ^~~
  866. // 1. StatementForHeader
  867. // 2. StatementForFinish
  868. //
  869. // if ...
  870. // ^
  871. // 1. StatementIf
  872. //
  873. // return ...
  874. // ^
  875. // 1. StatementReturn
  876. //
  877. // var ...
  878. // ^
  879. // 1. VarAsDecl
  880. //
  881. // returned ...
  882. // ^
  883. // 1. VarAsReturned
  884. //
  885. // while ...
  886. // ^
  887. // 1. StatementWhile
  888. //
  889. // ...
  890. // ^
  891. // 1. Expr
  892. // 2. ExprStatementFinish
  893. //
  894. // match ...
  895. // ^
  896. // 1. MatchIntroducer
  897. CARBON_PARSE_STATE(Statement)
  898. // Handles `break` processing at the `;`.
  899. //
  900. // break ;
  901. // ^
  902. // (state done)
  903. CARBON_PARSE_STATE(StatementBreakFinish)
  904. // Handles `continue` processing at the `;`.
  905. //
  906. // continue ;
  907. // ^
  908. // (state done)
  909. CARBON_PARSE_STATE(StatementContinueFinish)
  910. // Handles `for` processing of `(var`, proceeding to a binding pattern before
  911. // continuing.
  912. //
  913. // for ( var ... )
  914. // ^
  915. // 1. VarAsFor
  916. // 2. StatementForHeaderIn
  917. //
  918. // for ( ???
  919. // ^
  920. // for ( ??? in ...
  921. // ^~~~~~~~
  922. // for ??? in ...
  923. // ^~~~~~
  924. // for ???
  925. // ^
  926. // 1. StatementForHeaderIn
  927. CARBON_PARSE_STATE(StatementForHeader)
  928. // Handles `for` processing of `in`, proceeding to an expression before
  929. // continuing.
  930. //
  931. // for ( ... in ... )
  932. // ^
  933. // 1. Expr
  934. // 2. StatementForHeaderFinish
  935. CARBON_PARSE_STATE(StatementForHeaderIn)
  936. // Handles `for` processing of `)`, proceeding to the statement block.
  937. //
  938. // for ( ... ) ...
  939. // ^
  940. // 1. CodeBlock
  941. CARBON_PARSE_STATE(StatementForHeaderFinish)
  942. // Handles `for` processing after the final `}`.
  943. //
  944. // for ( ... ) { ... }
  945. // ^
  946. // (state done)
  947. CARBON_PARSE_STATE(StatementForFinish)
  948. // Handles `if` processing at the start.
  949. //
  950. // if ...
  951. // ^~
  952. // 1. ParenConditionAsIf
  953. // 2. StatementIfConditionFinish
  954. CARBON_PARSE_STATE(StatementIf)
  955. // Handles `if` processing between the condition and start of the first code
  956. // block.
  957. //
  958. // if ( ... ) ...
  959. // ^
  960. // 1. CodeBlock
  961. // 2. StatementIfThenBlockFinish
  962. CARBON_PARSE_STATE(StatementIfConditionFinish)
  963. // Handles `if` processing after the end of the first code block, with the
  964. // optional `else`.
  965. //
  966. // if ( ... ) { ... } else if ...
  967. // ^~~~
  968. // 1. StatementIf
  969. // 2. StatementIfElseBlockFinish
  970. //
  971. // if ( ... ) { ... } else ...
  972. // ^~~~
  973. // 1. CodeBlock
  974. // 2. StatementIfElseBlockFinish
  975. //
  976. // if ( ... ) { ... } ...
  977. // (state done)
  978. CARBON_PARSE_STATE(StatementIfThenBlockFinish)
  979. // Handles `if` processing after a provided `else` code block.
  980. //
  981. // if ( ... ) { ... } else { ... }
  982. // ^
  983. // (state done)
  984. CARBON_PARSE_STATE(StatementIfElseBlockFinish)
  985. // Handles `return` processing.
  986. //
  987. // return ;
  988. // ^~~~~~
  989. // 1. StatementReturnFinish
  990. //
  991. // return var ...
  992. // ^~~~~~~~~~
  993. // 1. StatementReturnFinish
  994. //
  995. // return ...
  996. // ^~~~~~
  997. // 1. Expr
  998. // 2. StatementReturnFinish
  999. CARBON_PARSE_STATE(StatementReturn)
  1000. // Handles `return` processing at the `;`.
  1001. //
  1002. // return ... ;
  1003. // ^
  1004. // (state done)
  1005. CARBON_PARSE_STATE(StatementReturnFinish)
  1006. // Handles processing of statements within a scope.
  1007. //
  1008. // { ... }
  1009. // ^
  1010. // (state done)
  1011. //
  1012. // { ... ... }
  1013. // ^
  1014. // 1. Statement
  1015. // 2. StatementScopeLoop
  1016. CARBON_PARSE_STATE(StatementScopeLoop)
  1017. // Handles `while` processing.
  1018. //
  1019. // while ...
  1020. // ^~~~~
  1021. // 1. ParenConditionAsWhile
  1022. // 2. StatementWhileConditionFinish
  1023. CARBON_PARSE_STATE(StatementWhile)
  1024. // Handles `while` processing between the condition and start of the code block.
  1025. //
  1026. // while ( ... ) ...
  1027. // ^
  1028. // 1. CodeBlock
  1029. // 2. StatementWhileBlockFinish
  1030. CARBON_PARSE_STATE(StatementWhileConditionFinish)
  1031. // Handles `while` processing after the end of the code block.
  1032. //
  1033. // while ( ... ) { ... }
  1034. // ^
  1035. // (state done)
  1036. CARBON_PARSE_STATE(StatementWhileBlockFinish)
  1037. // Handles parsing after the declaration scope of a type.
  1038. //
  1039. // class/impl/interface/constraint ... { ... }
  1040. // ^
  1041. // (state done)
  1042. CARBON_PARSE_STATE_VARIANTS4(DeclDefinitionFinish, Class, Impl, Interface,
  1043. NamedConstraint)
  1044. // Handles processing of a type after its introducer.
  1045. //
  1046. // class/interface/constraint ...
  1047. // ^
  1048. // 1. DeclNameAndParamsAsOptional
  1049. // 2. DeclOrDefinitionAs(Class|Interface|NamedConstraint)
  1050. CARBON_PARSE_STATE_VARIANTS3(TypeAfterIntroducer, Class, Interface,
  1051. NamedConstraint)
  1052. // Handles processing of a type after its optional parameters.
  1053. //
  1054. // class/impl/interface/constraint name ( ... ) {
  1055. // ^
  1056. // 1. DeclScopeLoop
  1057. // 2. DeclDefinitionFinishAs(Class|Impl|Interface|NamedConstraint)
  1058. //
  1059. // class/impl/interface/constraint name ( ... ) ;
  1060. // ^
  1061. // class/impl/interface/constraint name ( ... ) ???
  1062. // ^
  1063. // (state done)
  1064. CARBON_PARSE_STATE_VARIANTS4(DeclOrDefinition, Class, Impl, Interface, NamedConstraint)
  1065. // Handles processing of a completed `base: B` declaration.
  1066. //
  1067. // base: B ;
  1068. // ^
  1069. // base: B ??? ;
  1070. // ^
  1071. // (state done)
  1072. CARBON_PARSE_STATE(BaseDecl)
  1073. // Handles processing of an `impl...as` declaration after the introducer.
  1074. //
  1075. // impl forall [ ...
  1076. // ^~~~~~
  1077. // 1. PatternListAsImplicit
  1078. // 2. ImplAfterForall
  1079. // 3. DeclOrDefinitionAsImpl
  1080. // impl as ...
  1081. // ^~
  1082. // 1. Expr
  1083. // 2. DeclOrDefinitionAsImpl
  1084. // impl type_expression as ...
  1085. // ^
  1086. // 1. Expr
  1087. // 2. ImplBeforeAs
  1088. // 3. DeclOrDefinitionAsImpl
  1089. CARBON_PARSE_STATE(ImplAfterIntroducer)
  1090. // Handles processing of an `impl forall` declaration after the implicit
  1091. // parameter list.
  1092. //
  1093. // impl forall [ ... ] as ...
  1094. // ^~
  1095. // 1. Expr
  1096. // impl forall [ ... ] type_expression as ...
  1097. // ^
  1098. // 1. Expr
  1099. // 2. ImplBeforeAs
  1100. CARBON_PARSE_STATE(ImplAfterForall)
  1101. // Handles processing of the `as` in an `impl` declaration after the type
  1102. // expression.
  1103. //
  1104. // impl TypeExpression as ...
  1105. // ^~
  1106. // 1. Expr
  1107. CARBON_PARSE_STATE(ImplBeforeAs)
  1108. // Handles the start of a `var` or `returned var`.
  1109. //
  1110. // var ... (variant is Decl)
  1111. // ^
  1112. // 1. Pattern
  1113. // 2. VarAfterPattern
  1114. // 3. VarFinishAsDecl
  1115. //
  1116. // var ... (variant is For)
  1117. // ^
  1118. // 1. Pattern
  1119. // 2. VarFinishAsFor
  1120. //
  1121. // returned var ... (variant is Returned)
  1122. // ^~~~~~~~~~~~
  1123. // 1. Pattern
  1124. // 2. VarAfterPattern
  1125. // 3. VarFinishAsDecl
  1126. //
  1127. // returned ??? ; (variant is Returned)
  1128. // ^~~~~~~~~~~~~~
  1129. // (state done)
  1130. CARBON_PARSE_STATE_VARIANTS3(Var, Decl, Returned, For)
  1131. // Handles `var` after the pattern, either followed by an initializer or the
  1132. // semicolon.
  1133. //
  1134. // var ... = ...
  1135. // ^
  1136. // var ... ??? = ...
  1137. // ^~~~~
  1138. // 1. Expr
  1139. //
  1140. // var ... ...
  1141. // ^
  1142. // (state done)
  1143. CARBON_PARSE_STATE(VarAfterPattern)
  1144. // Handles `var` parsing at the end.
  1145. //
  1146. // var ... ; (variant is Semicolon)
  1147. // ^
  1148. // var ... ??? ; (variant is Semicolon)
  1149. // ^~~~~
  1150. // (state done)
  1151. //
  1152. // var ... in (variant is For)
  1153. // ^~
  1154. // var ... : (variant is For, invalid)
  1155. // ^
  1156. // (state done)
  1157. CARBON_PARSE_STATE_VARIANTS2(VarFinish, Decl, For)
  1158. // Handles the start of a `let`.
  1159. //
  1160. // let ...
  1161. // ^
  1162. // 1. Pattern
  1163. // 2. LetAfterPattern
  1164. // 3. LetFinish
  1165. CARBON_PARSE_STATE(Let)
  1166. // Handles `let` after the pattern, followed by an initializer.
  1167. //
  1168. // let ... = ...
  1169. // ^
  1170. // let ... ??? = ...
  1171. // ^~~~~
  1172. // 1. Expr
  1173. //
  1174. // let ... ??? ;
  1175. // ^~~
  1176. // (state done)
  1177. CARBON_PARSE_STATE(LetAfterPattern)
  1178. // Handles `let` parsing at the end.
  1179. //
  1180. // let ... ;
  1181. // ^
  1182. // (state done)
  1183. CARBON_PARSE_STATE(LetFinish)
  1184. // Handles a choice's introducer.
  1185. //
  1186. // choice ...
  1187. // ^~~~~~
  1188. // 1. DeclNameAndParamsAsOptional
  1189. // 2. ChoiceAlternativeListStart
  1190. // 3. ChoiceDefinitionFinish
  1191. CARBON_PARSE_STATE(ChoiceIntroducer)
  1192. // Handles processing of a choice after its optional parameters.
  1193. //
  1194. // choice name ... {}
  1195. // ^
  1196. // (state done)
  1197. //
  1198. // choice name ... { ... }
  1199. // ^
  1200. // 1. ChoiceAlternative
  1201. //
  1202. // choice name ... ???
  1203. // ^
  1204. // (state done)
  1205. CARBON_PARSE_STATE(ChoiceDefinitionStart)
  1206. // Starts alternative parsing.
  1207. //
  1208. // name( ... )
  1209. // ^~~~
  1210. // 1. ParamListAsRegular
  1211. // 2. ChoiceAlternativeFinish
  1212. // name ...
  1213. // ^~~~
  1214. // 1. ChoiceAlternativeFinish
  1215. CARBON_PARSE_STATE(ChoiceAlternative)
  1216. // Finishes parsing a choice's alternative, including the optional trailing `,`. If there
  1217. // are more alternatives, enqueues another alternative parsing state.
  1218. //
  1219. // ... , }
  1220. // ^
  1221. // (state done)
  1222. //
  1223. // ... , ...
  1224. // ^
  1225. // 1. ChoiceAlternative
  1226. //
  1227. // ...
  1228. // ^
  1229. // (state done)
  1230. CARBON_PARSE_STATE(ChoiceAlternativeFinish)
  1231. // Finishes a choice definition.
  1232. //
  1233. // choice ... }
  1234. // ^
  1235. // (state done)
  1236. CARBON_PARSE_STATE(ChoiceDefinitionFinish)
  1237. // Handles `match` introducer.
  1238. //
  1239. // match ...
  1240. // ^~~~~
  1241. // 1. ParenConditionAsMatch
  1242. // 2. MatchConditionFinish
  1243. CARBON_PARSE_STATE(MatchIntroducer)
  1244. // Handles `match` cases block start after the condition.
  1245. //
  1246. // match (...) { ... }
  1247. // ^
  1248. // 1. MatchCaseLoop
  1249. // 2. MatchStatementFinish
  1250. //
  1251. // match (...) ???
  1252. // ^
  1253. // (state done)
  1254. CARBON_PARSE_STATE(MatchConditionFinish)
  1255. // Handles `match` cases.
  1256. //
  1257. // match (...) { case ...}
  1258. // ^
  1259. // 1. MatchCaseIntroducer
  1260. // 2. MatchCaseLoop
  1261. // match (...) { default ...}
  1262. // ^
  1263. // 1. MatchDefaultIntroducer
  1264. // 2. MatchCaseLoopAfterDefault
  1265. CARBON_PARSE_STATE(MatchCaseLoop)
  1266. // Handles `match` `case` introducer.
  1267. //
  1268. // match (...) { case ...}
  1269. // ^~~~
  1270. // 1. Pattern
  1271. // 2. MatchCaseAfterPattern
  1272. CARBON_PARSE_STATE(MatchCaseIntroducer)
  1273. // Handles `match` case after pattern.
  1274. //
  1275. // match (...) { case ... => ... }
  1276. // ^
  1277. // 1. MatchCaseStart
  1278. // match (...) { case ... if (...) }
  1279. // ^~~~
  1280. // 1. Expr
  1281. // 2. MatchCaseGuardFinish
  1282. // 3. MatchCaseStart
  1283. CARBON_PARSE_STATE(MatchCaseAfterPattern)
  1284. // Handles `match` case guard closing parenthesis.
  1285. //
  1286. // match (...) { case ... if (...) => ... }
  1287. // ^
  1288. // (state done)
  1289. CARBON_PARSE_STATE(MatchCaseGuardFinish)
  1290. // Handles `match` case `=>` and `{` opening statements block.
  1291. //
  1292. // match (...) { case ... => {...} }
  1293. // ^~~~
  1294. // 1. StatementScopeLoop
  1295. // 2. MatchCaseFinish
  1296. //
  1297. // match (...) { case ... ??? }
  1298. // ^
  1299. // (state done)
  1300. //
  1301. // match (...) { case ... => ??? }
  1302. // ^
  1303. // (state done)
  1304. CARBON_PARSE_STATE(MatchCaseStart)
  1305. // Handles `match` case statements block closing `}`.
  1306. //
  1307. // match (...) { case ... => {...} }
  1308. // ^
  1309. // (state done)
  1310. CARBON_PARSE_STATE(MatchCaseFinish)
  1311. // Handles `match` default introducer, `=>` and `{` opening statements block.
  1312. //
  1313. // match (...) { default => {...} }
  1314. // ^~~~~~~~~~~~
  1315. // 1. StatementScopeLoop
  1316. // 2. MatchDefaultFinish
  1317. //
  1318. // match (...) { default ??? }
  1319. // ^
  1320. // (state done)
  1321. //
  1322. // match (...) { default => ??? }
  1323. // ^
  1324. // (state done)
  1325. CARBON_PARSE_STATE(MatchDefaultIntroducer)
  1326. // Handles `match` default case statements block closing `}`.
  1327. //
  1328. // match (...) { default => {...} }
  1329. // ^
  1330. // (state done)
  1331. CARBON_PARSE_STATE(MatchDefaultFinish)
  1332. // Handles `match` cases after the `default` case.
  1333. //
  1334. // match (...) { default => {...} case ... }
  1335. // ^~~~
  1336. // 1. MatchCaseLoopAfterDefault
  1337. //
  1338. // match (...) { default => {...} default ... }
  1339. // ^~~~~~~
  1340. // 1. MatchCaseLoopAfterDefault
  1341. //
  1342. // match (...) { default => {...} }
  1343. // ^
  1344. // (state done)
  1345. CARBON_PARSE_STATE(MatchCaseLoopAfterDefault)
  1346. // Finishes `match` statement.
  1347. //
  1348. // match (...) {...}
  1349. // ^
  1350. // (state done)
  1351. CARBON_PARSE_STATE(MatchStatementFinish)
  1352. #undef CARBON_PARSE_STATE