state.def 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. // Comments will describe a series of possible output states. States are listed
  19. // in the order they'll be executed; in other words, `1` is the top of the state
  20. // stack. The comment `(state done)` indicates that no new states are added to
  21. // the stack.
  22. //
  23. // Where state output is conditional on a lexed token, the name of
  24. // the Lex::TokenKind should be used rather than the string name in order to
  25. // make it easier to compare with code.
  26. #ifndef CARBON_PARSE_STATE
  27. #error "Must define the x-macro to use this file."
  28. #endif
  29. // Use CARBON_PARSE_STATE_VARIANTSN(State, Variant1, Variant2, ...) to generate
  30. // StateAsVariant1, StateAsVariant2, ... states.
  31. #define CARBON_PARSE_STATE_VARIANT(State, Variant) \
  32. CARBON_PARSE_STATE(State##As##Variant)
  33. #define CARBON_PARSE_STATE_VARIANTS2(State, Variant1, Variant2) \
  34. CARBON_PARSE_STATE_VARIANT(State, Variant1) \
  35. CARBON_PARSE_STATE_VARIANT(State, Variant2)
  36. #define CARBON_PARSE_STATE_VARIANTS3(State, Variant1, Variant2, Variant3) \
  37. CARBON_PARSE_STATE_VARIANT(State, Variant1) \
  38. CARBON_PARSE_STATE_VARIANTS2(State, Variant2, Variant3)
  39. #define CARBON_PARSE_STATE_VARIANTS4(State, Variant1, Variant2, Variant3, \
  40. Variant4) \
  41. CARBON_PARSE_STATE_VARIANT(State, Variant1) \
  42. CARBON_PARSE_STATE_VARIANTS3(State, Variant2, Variant3, Variant4)
  43. // Handles an index expression `a[0]`.
  44. //
  45. // Always:
  46. // 1. Expr
  47. // 2. IndexExprFinish
  48. CARBON_PARSE_STATE(IndexExpr)
  49. // Handles finishing the index expression.
  50. //
  51. // Always:
  52. // (state done)
  53. CARBON_PARSE_STATE(IndexExprFinish)
  54. // Handles an array expression `[T; N]`.
  55. //
  56. // Always:
  57. // 1. Expr
  58. // 2. ArrayExprSemi
  59. CARBON_PARSE_STATE(ArrayExpr)
  60. // Handles ';' in an array expression `[T; N]`.
  61. //
  62. // If `CloseSquareBracket`:
  63. // 1. ArrayExprFinish
  64. // Else:
  65. // 1. Expr
  66. // 2. ArrayExprFinish
  67. CARBON_PARSE_STATE(ArrayExprSemi)
  68. // Handles finishing the array expression.
  69. //
  70. // Always:
  71. // (state done)
  72. CARBON_PARSE_STATE(ArrayExprFinish)
  73. // Handles the `{` of a brace expression.
  74. //
  75. // If `CloseCurlyBrace`:
  76. // 1. BraceExprFinishAsUnknown
  77. // Else:
  78. // 1. BraceExprParameterAsUnknown
  79. // 2. BraceExprFinishAsUnknown
  80. CARBON_PARSE_STATE(BraceExpr)
  81. // Handles a brace expression parameter. Note this will always start as unknown,
  82. // but should be known after the first valid parameter. All later inconsistent
  83. // parameters are invalid.
  84. //
  85. // If valid:
  86. // 1. DesignatorExprAsStruct
  87. // 2. BraceExprParameterAfterDesignatorAs(Type|Value|Unknown)
  88. // Else:
  89. // 1. BraceExprParameterFinishAs(Type|Value|Unknown)
  90. CARBON_PARSE_STATE_VARIANTS3(BraceExprParameter, Type, Value, Unknown)
  91. // Handles a brace expression parameter after the initial designator. This
  92. // should be at a `:` or `=`, depending on whether it's a type or value literal.
  93. //
  94. // If valid:
  95. // 1. Expr
  96. // 2. BraceExprParameterFinishAs(Type|Value|Unknown)
  97. // Else:
  98. // 1. BraceExprParameterFinishAs(Type|Value|Unknown)
  99. CARBON_PARSE_STATE_VARIANTS3(BraceExprParameterAfterDesignator, Type, Value,
  100. Unknown)
  101. // Handles the end of a brace expression parameter.
  102. //
  103. // If `Comma`:
  104. // 1. BraceExprParameterAsUnknown
  105. // Else:
  106. // (state done)
  107. CARBON_PARSE_STATE_VARIANTS3(BraceExprParameterFinish, Type, Value, Unknown)
  108. // Handles the `}` of a brace expression.
  109. //
  110. // Always:
  111. // (state done)
  112. CARBON_PARSE_STATE_VARIANTS3(BraceExprFinish, Type, Value, Unknown)
  113. // Handles a call expression `(...)`.
  114. //
  115. // If `CloseParen`:
  116. // 1. CallExprFinish
  117. // Else:
  118. // 1. Expr
  119. // 2. CallExprParameterFinish
  120. // 3. CallExprFinish
  121. CARBON_PARSE_STATE(CallExpr)
  122. // Handles the `,` or `)` after a call parameter.
  123. //
  124. // If `Comma`:
  125. // 1. Expr
  126. // 2. CallExprParameterFinish
  127. // Else:
  128. // (state done)
  129. CARBON_PARSE_STATE(CallExprParameterFinish)
  130. // Handles finishing the call expression.
  131. //
  132. // Always:
  133. // (state done)
  134. CARBON_PARSE_STATE(CallExprFinish)
  135. // Handles processing at the `{` on a typical code block.
  136. //
  137. // If `OpenCurlyBrace`:
  138. // 1. StatementScopeLoop
  139. // 2. CodeBlockFinish
  140. // Else:
  141. // 1. Statement
  142. // 2. CodeBlockFinish
  143. CARBON_PARSE_STATE(CodeBlock)
  144. // Handles processing at the `}` on a typical code block, after a statement
  145. // scope is done.
  146. //
  147. // Always:
  148. // (state done)
  149. CARBON_PARSE_STATE(CodeBlockFinish)
  150. // Handles a declaration name and parameters, such as `Foo[...](...)`.
  151. //
  152. // Allowed parameters:
  153. // - None: `Foo` only.
  154. // - Optional: `Foo`, `Foo(...)`, or `Foo[...](...)`.
  155. // - Required: `Foo(...)` or `Foo[...](...)`.
  156. //
  157. // If `Identifier` followed by `Period`:
  158. // 1. DeclNameAndParamsAfterNameAs(None|Optional|Required)
  159. // If `Identifier`:
  160. // 1. DeclNameAndParamsAfterNameAs(None|Optional|Required)
  161. // 2. PeriodAsDecl
  162. // Else:
  163. // (state done)
  164. CARBON_PARSE_STATE_VARIANTS3(DeclNameAndParams, None, Optional, Required)
  165. // Handles a declaration name between the main name and implicit parameters.
  166. //
  167. // For `None`, parameters aren't supported so only `Period` or `Else` paths are
  168. // used.
  169. //
  170. // If `Period`:
  171. // 1. DeclNameAndParamsAfterNameAs(None|Optional|Required)
  172. // 2. PeriodAsDecl
  173. // If `OpenSquareBracket`:
  174. // 1. ParameterListAsImplicit
  175. // 2. DeclNameAndParamsAfterImplicit
  176. // If `OpenParen`:
  177. // 1. ParameterListAsRegular
  178. // Else:
  179. // (state done)
  180. CARBON_PARSE_STATE_VARIANTS3(DeclNameAndParamsAfterName, None, Optional,
  181. Required)
  182. // Handles regular parameters such as `(...)` for the general declaration case.
  183. // Only used after implicit parameters.
  184. //
  185. // If `OpenParen`:
  186. // 1. ParameterListAsRegular
  187. // Else:
  188. // (state done)
  189. CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit)
  190. // Handles processing of a declaration scope. Things like fn, class, interface,
  191. // and so on.
  192. //
  193. // If `Class`:
  194. // 1. TypeIntroducerAsClass
  195. // 2. DeclScopeLoop
  196. // If `Constraint`:
  197. // 1. TypeIntroducerAsNamedConstraint
  198. // 2. DeclScopeLoop
  199. // If `Fn`:
  200. // 1. FunctionIntroducer
  201. // 2. DeclScopeLoop
  202. // If `Interface`:
  203. // 1. TypeIntroducerAsInterface
  204. // 2. DeclScopeLoop
  205. // If `Namespace`:
  206. // 1. Namespace
  207. // 2. DeclScopeLoop
  208. // If `Semi`:
  209. // 1. DeclScopeLoop
  210. // If `Var`:
  211. // 1. VarAsDecl
  212. // 2. DeclScopeLoop
  213. // If `Let`:
  214. // 1. Let
  215. // 2. DeclScopeLoop
  216. // Else:
  217. // (state done)
  218. CARBON_PARSE_STATE(DeclScopeLoop)
  219. // Handles periods. Only does one `.<expression>` segment; the source is
  220. // responsible for handling chaining.
  221. //
  222. // The forms of this are:
  223. // - Qualified names in declarations.
  224. // - Member access expressions.
  225. // - Designated names in structs.
  226. //
  227. // Declarations and expressions have qualifiers such as `x.y`, while structs
  228. // have designators such as `.z`.
  229. //
  230. // Always:
  231. // (state done)
  232. CARBON_PARSE_STATE_VARIANTS3(Period, Decl, Expr, Struct)
  233. // Handles `->name` expressions. Identical to PeriodAsExpr except for the
  234. // leading token.
  235. //
  236. // Always:
  237. // (state done)
  238. CARBON_PARSE_STATE(ArrowExpr)
  239. // Handles processing of an expression.
  240. //
  241. // If `If`:
  242. // 1. Expr
  243. // 2. IfExprCondition
  244. // 3. IfExprFinish
  245. // Else if valid prefix operator:
  246. // 1. Expr
  247. // 2. ExprLoopForPrefix
  248. // Else:
  249. // 1. ExprInPostfix
  250. // 2. ExprLoop
  251. CARBON_PARSE_STATE(Expr)
  252. // Handles the initial part of postfix expressions, such as an identifier or
  253. // literal value, then proceeds to the loop.
  254. //
  255. // If `Identifier` or literal (including type literals):
  256. // 1. ExprInPostfixLoop
  257. // If `OpenCurlyBrace`:
  258. // 1. BraceExpr
  259. // 2. ExprInPostfixLoop
  260. // If `OpenParen`:
  261. // 1. ParenExpr
  262. // 2. ExprInPostfixLoop
  263. // If `OpenSquareBracket`:
  264. // 1. ArrayExpr
  265. // 2. ExprInPostfixLoop
  266. // Else:
  267. // (state done)
  268. CARBON_PARSE_STATE(ExprInPostfix)
  269. // Handles looping through elements following the initial postfix expression,
  270. // such as designators or parenthesized parameters.
  271. //
  272. // If `Period`:
  273. // 1. PeriodAsExpr
  274. // 2. ExprInPostfixLoop
  275. // If `MinusGreater`:
  276. // 1. ArrowExpr
  277. // 2. ExprInPostfixLoop
  278. // If `OpenParen`:
  279. // 1. CallExpr
  280. // 2. ExprInPostfixLoop
  281. // If `OpenSquareBracket`:
  282. // 1. IndexExprStart
  283. // 2. ExprInPostfixLoop
  284. // Else:
  285. // (state done)
  286. CARBON_PARSE_STATE(ExprInPostfixLoop)
  287. // Handles processing of an expression.
  288. //
  289. // If binary operator:
  290. // 1. Expr
  291. // 2. ExprLoopForBinary
  292. // If postfix operator:
  293. // 1. ExprLoop
  294. // Else:
  295. // (state done)
  296. CARBON_PARSE_STATE(ExprLoop)
  297. // Completes an ExprLoop pass by adding an infix operator, then goes back
  298. // to ExprLoop.
  299. //
  300. // Always:
  301. // 1. ExprLoop
  302. CARBON_PARSE_STATE(ExprLoopForBinary)
  303. // Completes an ExprLoop pass by adding a prefix operator, then goes back
  304. // to ExprLoop.
  305. //
  306. // Always:
  307. // 1. ExprLoop
  308. CARBON_PARSE_STATE(ExprLoopForPrefix)
  309. // Completes the condition of an `if` expression and handles the `then` token.
  310. //
  311. // If `Then`:
  312. // 1. Expr
  313. // 2. IfExprFinishThen
  314. // Else:
  315. // (state done)
  316. CARBON_PARSE_STATE(IfExprFinishCondition)
  317. // Completes the first alternative in an `if` expression and handles the `else`
  318. // token.
  319. //
  320. // If `Else`:
  321. // 1. Expr
  322. // 2. IfExprFinishElse
  323. // Else:
  324. // (state done)
  325. CARBON_PARSE_STATE(IfExprFinishThen)
  326. // Completes the second alternative in an `if` expression.
  327. //
  328. // Always:
  329. // (state done)
  330. CARBON_PARSE_STATE(IfExprFinishElse)
  331. // Completes an IfExpr.
  332. //
  333. // Always:
  334. // (state done)
  335. CARBON_PARSE_STATE(IfExprFinish)
  336. // Handles the `;` for an expression statement, which is different from most
  337. // keyword statements.
  338. //
  339. // Always:
  340. // (state done)
  341. CARBON_PARSE_STATE(ExprStatementFinish)
  342. // Handles a function's introducer.
  343. //
  344. // If invalid:
  345. // (state done)
  346. // Else:
  347. // 1. DeclNameAndParamsAsRequired
  348. // 2. FunctionAfterParameters
  349. CARBON_PARSE_STATE(FunctionIntroducer)
  350. // Handles processing of a function's syntax after `)`, primarily the
  351. // possibility a `->` return type is there. Always enqueues signature finish
  352. // handling.
  353. //
  354. // If `MinusGreater`:
  355. // 1. Expr
  356. // 2. FunctionReturnTypeFinish
  357. // 3. FunctionSignatureFinish
  358. // Else:
  359. // 1. FunctionSignatureFinish
  360. CARBON_PARSE_STATE(FunctionAfterParameters)
  361. // Finishes a function return type.
  362. //
  363. // Always:
  364. // (state done)
  365. CARBON_PARSE_STATE(FunctionReturnTypeFinish)
  366. // Finishes a function signature. If it's a declaration, the function is done;
  367. // otherwise, this also starts definition processing.
  368. //
  369. // If `Semi`:
  370. // (state done)
  371. // If `OpenCurlyBrace`:
  372. // 1. StatementScopeLoop
  373. // 2. FunctionDefinitionFinish
  374. // Else:
  375. // (state done)
  376. CARBON_PARSE_STATE(FunctionSignatureFinish)
  377. // Finishes a function definition.
  378. //
  379. // Always:
  380. // (state done)
  381. CARBON_PARSE_STATE(FunctionDefinitionFinish)
  382. // Handles `import`.
  383. //
  384. // Always:
  385. // (state done)
  386. CARBON_PARSE_STATE(Import)
  387. // Handles `namespace`.
  388. //
  389. // Always:
  390. // 1. DeclNameAndParamsAsNone
  391. // 2. NamespaceFinish
  392. CARBON_PARSE_STATE(Namespace)
  393. // Handles `namespace` after the name.
  394. //
  395. // Always:
  396. // (state done)
  397. CARBON_PARSE_STATE(NamespaceFinish)
  398. // Handles `package`.
  399. //
  400. // Always:
  401. // (state done)
  402. CARBON_PARSE_STATE(Package)
  403. // Starts implicit parameter processing.
  404. //
  405. // Always:
  406. // 1. PatternAs(ImplicitParameter|Parameter)
  407. // 2. ParameterFinishAs(Implicit|Regular)
  408. CARBON_PARSE_STATE_VARIANTS2(Parameter, Implicit, Regular)
  409. // Finishes implicit parameter processing, including `,`. If there are more
  410. // parameters, enqueues another parameter processing state.
  411. //
  412. // If `Comma` without the list close token:
  413. // 1. ParameterAs(Implicit|Regular)
  414. // Else:
  415. // (state done)
  416. CARBON_PARSE_STATE_VARIANTS2(ParameterFinish, Implicit, Regular)
  417. // Handles processing of a parameter list `[` or `(`.
  418. //
  419. // If the list close token:
  420. // 1. ParameterListFinishAs(Implicit|Regular)
  421. // Else:
  422. // 1. ParameterAs(Implicit|Regular)
  423. // 2. ParameterListFinishAs(Implicit|Regular)
  424. CARBON_PARSE_STATE_VARIANTS2(ParameterList, Implicit, Regular)
  425. // Handles processing of a parameter list `]` or `)`.
  426. //
  427. // Always:
  428. // (state done)
  429. CARBON_PARSE_STATE_VARIANTS2(ParameterListFinish, Implicit, Regular)
  430. // Handles the processing of a `(condition)` up through the expression.
  431. //
  432. // If `OpenCurlyBrace`:
  433. // 1. ParenConditionAs(If|While)Finish
  434. // Else:
  435. // 1. Expr
  436. // 2. ParenConditionAs(If|While)Finish
  437. CARBON_PARSE_STATE_VARIANTS2(ParenCondition, If, While)
  438. // Finishes the processing of a `(condition)` after the expression.
  439. //
  440. // Always:
  441. // (state done)
  442. CARBON_PARSE_STATE_VARIANTS2(ParenConditionFinish, If, While)
  443. // Handles the `(` of a parenthesized expression.
  444. //
  445. // If `CloseParen`:
  446. // 1. ParenExprFinishAsTuple
  447. // Else:
  448. // 1. Expr
  449. // 2. ParenExprParameterFinishAsUnknown
  450. // 3. ParenExprFinish
  451. CARBON_PARSE_STATE(ParenExpr)
  452. // Handles the end of a parenthesized expression's parameter. This will start as
  453. // AsUnknown on the first parameter; if there are more, it switches to AsTuple
  454. // processing.
  455. //
  456. // If `Comma` without `CloseParen`:
  457. // 1. Expr
  458. // 2. ParenExprParameterFinishAsTuple
  459. // SPECIAL: Parent becomes ParenExprFinishAsTuple
  460. // If `Comma` with `CloseParen`:
  461. // (state done)
  462. // SPECIAL: Parent becomes ParenExprFinishAsTuple
  463. // Else `CloseParen`:
  464. // (state done)
  465. CARBON_PARSE_STATE_VARIANTS2(ParenExprParameterFinish, Unknown, Tuple)
  466. // Handles the `)` of a parenthesized expression.
  467. //
  468. // Always:
  469. // (state done)
  470. CARBON_PARSE_STATE_VARIANTS2(ParenExprFinish, Normal, Tuple)
  471. // Handles pattern parsing for a pattern, enqueuing type expression processing.
  472. // This covers parameter, `let`, and `var` support.
  473. //
  474. // If valid:
  475. // 1. Expr
  476. // 2. PatternFinishAs(Generic|Regular)
  477. // Else:
  478. // 1. PatternFinish
  479. CARBON_PARSE_STATE_VARIANTS4(Pattern, ImplicitParameter, Parameter, Variable,
  480. Let)
  481. // Handles `addr` in a pattern.
  482. //
  483. // Always:
  484. // (state done)
  485. CARBON_PARSE_STATE(PatternAddress)
  486. // Handles `template` in a pattern.
  487. //
  488. // Always:
  489. // (state done)
  490. CARBON_PARSE_STATE(PatternTemplate)
  491. // Finishes pattern processing.
  492. //
  493. // Always:
  494. // (state done)
  495. CARBON_PARSE_STATE_VARIANTS2(PatternFinish, Generic, Regular)
  496. // Handles a single statement. While typically within a statement block, this
  497. // can also be used for error recovery where we expect a statement block and
  498. // are missing braces.
  499. //
  500. // If `Break`:
  501. // 1. StatementBreakFinish
  502. // (state done)
  503. // If `Continue`:
  504. // 1. StatementContinueFinish
  505. // (state done)
  506. // If `For`:
  507. // 1. StatementForHeader
  508. // 2. StatementForFinish
  509. // If `If`:
  510. // 1. StatementIf
  511. // If `Return`:
  512. // 1. StatementReturn
  513. // If `Var`:
  514. // 1. VarAsDecl
  515. // If `Returned`:
  516. // 1. VarAsReturned
  517. // If `While`:
  518. // 1. StatementWhile
  519. // Else:
  520. // 1. Expr
  521. // 2. ExprStatementFinish
  522. CARBON_PARSE_STATE(Statement)
  523. // Handles `break` processing at the `;`.
  524. //
  525. // Always:
  526. // (state done)
  527. CARBON_PARSE_STATE(StatementBreakFinish)
  528. // Handles `continue` processing at the `;`.
  529. //
  530. // Always:
  531. // (state done)
  532. CARBON_PARSE_STATE(StatementContinueFinish)
  533. // Handles `for` processing of `(var`, proceeding to a pattern before
  534. // continuing.
  535. //
  536. // If no `OpenParen`:
  537. // 1. CodeBlock
  538. // If `Var`:
  539. // 1. VarAsFor
  540. // 2. StatementForHeaderIn
  541. // Else:
  542. // 1. StatementForHeaderIn
  543. CARBON_PARSE_STATE(StatementForHeader)
  544. // Handles `for` procesisng of `in`, proceeding to an expression before
  545. // continuing.
  546. //
  547. // If `In` or `Colon`:
  548. // 1. Expr
  549. // 2. StatementForHeaderFinish
  550. // Else:
  551. // 1. StatementForHeaderFinish
  552. CARBON_PARSE_STATE(StatementForHeaderIn)
  553. // Handles `for` processing of `)`, proceeding to the statement block.
  554. //
  555. // Always:
  556. // 1. CodeBlock
  557. CARBON_PARSE_STATE(StatementForHeaderFinish)
  558. // Handles `for` processing at the final `}`.
  559. //
  560. // Always:
  561. // (state done)
  562. CARBON_PARSE_STATE(StatementForFinish)
  563. // Handles `if` processing at the start.
  564. //
  565. // Always:
  566. // 1. ParenConditionAsIf
  567. // 2. StatementIfConditionFinish
  568. CARBON_PARSE_STATE(StatementIf)
  569. // Handles `if` processing between the condition and start of the first code
  570. // block.
  571. //
  572. // Always:
  573. // 1. CodeBlock
  574. // 2. StatementIfThenBlockFinish
  575. CARBON_PARSE_STATE(StatementIfConditionFinish)
  576. // Handles `if` processing after the end of the first code block, with the
  577. // optional `else`.
  578. //
  579. // If `Else` then `If`:
  580. // 1. CodeBlock
  581. // 2. StatementIfElseBlockFinish
  582. // If `Else`:
  583. // 1. StatementIf
  584. // 2. StatementIfElseBlockFinish
  585. // Else:
  586. // (state done)
  587. CARBON_PARSE_STATE(StatementIfThenBlockFinish)
  588. // Handles `if` processing after a provided `else` code block.
  589. //
  590. // Always:
  591. // (state done)
  592. CARBON_PARSE_STATE(StatementIfElseBlockFinish)
  593. // Handles `return` processing.
  594. //
  595. // If `Semi`:
  596. // 1. StatementReturnFinish
  597. // If `Var`:
  598. // 1. StatementReturnFinish
  599. // Else:
  600. // 1. Expr
  601. // 2. StatementReturnFinish
  602. CARBON_PARSE_STATE(StatementReturn)
  603. // Handles `return` processing at the `;` when there's an expression.
  604. //
  605. // Always:
  606. // (state done)
  607. CARBON_PARSE_STATE(StatementReturnFinish)
  608. // Handles processing of statements within a scope.
  609. //
  610. // If `CloseCurlyBrace`:
  611. // (state done)
  612. // Else:
  613. // 1. Statement
  614. // 2. StatementScopeLoop
  615. CARBON_PARSE_STATE(StatementScopeLoop)
  616. // Handles `while` processing.
  617. //
  618. // Always:
  619. // 1. ParenConditionAsWhile
  620. // 2. StatementWhileConditionFinish
  621. CARBON_PARSE_STATE(StatementWhile)
  622. // Handles `while` processing between the condition and start of the code block.
  623. //
  624. // Always:
  625. // 1. CodeBlock
  626. // 2. StatementWhileBlockFinish
  627. CARBON_PARSE_STATE(StatementWhileConditionFinish)
  628. // Handles `while` processing after the end of the code block.
  629. //
  630. // Always:
  631. // (state done)
  632. CARBON_PARSE_STATE(StatementWhileBlockFinish)
  633. // Handles parsing after the declaration scope of a type.
  634. //
  635. // Always:
  636. // (state done)
  637. CARBON_PARSE_STATE_VARIANTS3(TypeDefinitionFinish, Class, Interface,
  638. NamedConstraint)
  639. // Handles processing of a type's introducer.
  640. //
  641. // Always:
  642. // 1. DeclNameAndParamsAsOptional
  643. // 2. TypeAfterParamsAs(Class|Interface|NamedConstraint)
  644. CARBON_PARSE_STATE_VARIANTS3(TypeIntroducer, Class, Interface, NamedConstraint)
  645. // Handles processing of a type after its optional parameters.
  646. //
  647. // If `Semi`:
  648. // (state done)
  649. // If `OpenCurlyBrace`:
  650. // 1. DeclScopeLoop
  651. // 2. TypeDefinitionFinishAs(Class|Interface|NamedConstraint)
  652. // Else:
  653. // (state done)
  654. CARBON_PARSE_STATE_VARIANTS3(TypeAfterParams, Class, Interface, NamedConstraint)
  655. // Handles the start of a `var` or `returned var`.
  656. //
  657. // On error:
  658. // (state done)
  659. // Else:
  660. // 1. PatternAsVariable
  661. // 2. VarAfterPattern
  662. // 3. VarFinishAs(Decl|For)
  663. //
  664. // VarAsReturned uses VarFinishAsDecl.
  665. CARBON_PARSE_STATE_VARIANTS3(Var, Decl, Returned, For)
  666. // Handles `var` after the pattern, either followed by an initializer or the
  667. // semicolon.
  668. //
  669. // If `Equal`:
  670. // 1. Expr
  671. // Else:
  672. // (state done)
  673. CARBON_PARSE_STATE(VarAfterPattern)
  674. // Handles `var` parsing at the end.
  675. //
  676. // Always:
  677. // (state done)
  678. CARBON_PARSE_STATE_VARIANTS2(VarFinish, Decl, For)
  679. // Handles the start of a `let`.
  680. //
  681. // Always:
  682. // 1. PatternAsLet
  683. // 2. LetAfterPattern
  684. // 3. LetFinish
  685. CARBON_PARSE_STATE(Let)
  686. // Handles `let` after the pattern, followed by an initializer.
  687. //
  688. // If `Equal`:
  689. // 1. Expr
  690. // Else:
  691. // (state done)
  692. CARBON_PARSE_STATE(LetAfterPattern)
  693. // Handles `let` parsing at the end.
  694. //
  695. // Always:
  696. // (state done)
  697. CARBON_PARSE_STATE(LetFinish)
  698. #undef CARBON_PARSE_STATE