parser_state.def 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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_PARSER_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 TokenKind should be used rather than the string name in order to make it
  25. // easier to compare with code.
  26. #ifndef CARBON_PARSER_STATE
  27. #error "Must define the x-macro to use this file."
  28. #endif
  29. // Use CARBON_PARSER_STATE_VARIANTSN(State, Variant1, Variant2, ...) to generate
  30. // StateAsVariant1, StateAsVariant2, ... states.
  31. #define CARBON_PARSER_STATE_VARIANT(State, Variant) \
  32. CARBON_PARSER_STATE(State##As##Variant)
  33. #define CARBON_PARSER_STATE_VARIANTS2(State, Variant1, Variant2) \
  34. CARBON_PARSER_STATE_VARIANT(State, Variant1) \
  35. CARBON_PARSER_STATE_VARIANT(State, Variant2)
  36. #define CARBON_PARSER_STATE_VARIANTS3(State, Variant1, Variant2, Variant3) \
  37. CARBON_PARSER_STATE_VARIANT(State, Variant1) \
  38. CARBON_PARSER_STATE_VARIANTS2(State, Variant2, Variant3)
  39. // Handles the `{` of a brace expression.
  40. //
  41. // If `CloseCurlyBrace`:
  42. // 1. BraceExpressionFinishAsUnknown
  43. // Else:
  44. // 1. BraceExpressionParameterAsUnknown
  45. // 2. BraceExpressionFinishAsUnknown
  46. CARBON_PARSER_STATE(BraceExpression)
  47. // Handles a brace expression parameter. Note this will always start as unknown,
  48. // but should be known after the first valid parameter. All later inconsistent
  49. // parameters are invalid.
  50. //
  51. // If valid:
  52. // 1. DesignatorExpressionAsStruct
  53. // 2. BraceExpressionParameterAfterDesignatorAs(Type|Value|Unknown)
  54. // Else:
  55. // 1. BraceExpressionParameterFinishAs(Type|Value|Unknown)
  56. CARBON_PARSER_STATE_VARIANTS3(BraceExpressionParameter, Type, Value, Unknown)
  57. // Handles a brace expression parameter after the initial designator. This
  58. // should be at a `:` or `=`, depending on whether it's a type or value literal.
  59. //
  60. // If valid:
  61. // 1. Expression
  62. // 2. BraceExpressionParameterFinishAs(Type|Value|Unknown)
  63. // Else:
  64. // 1. BraceExpressionParameterFinishAs(Type|Value|Unknown)
  65. CARBON_PARSER_STATE_VARIANTS3(BraceExpressionParameterAfterDesignator, Type,
  66. Value, Unknown)
  67. // Handles the end of a brace expression parameter.
  68. //
  69. // If `Comma`:
  70. // 1. BraceExpressionParameterAsUnknown
  71. // Else:
  72. // (state done)
  73. CARBON_PARSER_STATE_VARIANTS3(BraceExpressionParameterFinish, Type, Value,
  74. Unknown)
  75. // Handles the `}` of a brace expression.
  76. //
  77. // Always:
  78. // (state done)
  79. CARBON_PARSER_STATE_VARIANTS3(BraceExpressionFinish, Type, Value, Unknown)
  80. // Handles a call expression `(...)`.
  81. //
  82. // If `CloseParen`:
  83. // 1. CallExpressionFinish
  84. // Else:
  85. // 1. Expression
  86. // 2. CallExpressionParameterFinish
  87. // 3. CallExpressionFinish
  88. CARBON_PARSER_STATE(CallExpression)
  89. // Handles the `,` or `)` after a call parameter.
  90. //
  91. // If `Comma`:
  92. // 1. Expression
  93. // 2. CallExpressionParameterFinish
  94. // Else:
  95. // (state done)
  96. CARBON_PARSER_STATE(CallExpressionParameterFinish)
  97. // Handles finishing the call expression.
  98. //
  99. // Always:
  100. // (state done)
  101. CARBON_PARSER_STATE(CallExpressionFinish)
  102. // Handles processing at the `{` on a typical code block.
  103. //
  104. // If `OpenCurlyBrace`:
  105. // 1. StatementScopeLoop
  106. // 2. CodeBlockFinish
  107. // Else:
  108. // 1. Statement
  109. // 2. CodeBlockFinish
  110. CARBON_PARSER_STATE(CodeBlock)
  111. // Handles processing at the `}` on a typical code block, after a statement
  112. // scope is done.
  113. //
  114. // Always:
  115. // (state done)
  116. CARBON_PARSER_STATE(CodeBlockFinish)
  117. // Handles a declaration name and parameters, such as `Foo[...](...)`.
  118. //
  119. // Allowed parameters:
  120. // - None: `Foo` only.
  121. // - Optional: `Foo`, `Foo(...)`, or `Foo[...](...)`.
  122. // - Required: ``Foo(...)` or `Foo[...](...)`.
  123. //
  124. // If `Identifier` followed by `Period`:
  125. // 1. DeclarationNameAndParamsAfterNameAs(None|Optional|Required)
  126. // If `Identifier`:
  127. // 1. DeclarationNameAndParamsAfterNameAs(None|Optional|Required)
  128. // 2. PeriodAsDeclaration
  129. // Else:
  130. // (state done)
  131. CARBON_PARSER_STATE_VARIANTS3(DeclarationNameAndParams, None, Optional,
  132. Required)
  133. // Handles a declaration name between the main name and deduced parameters.
  134. //
  135. // For `None`, parameters aren't supported so only `Period` or `Else` paths are
  136. // used.
  137. //
  138. // If `Period`:
  139. // 1. DeclarationNameAndParamsAfterNameAs(None|Optional|Required)
  140. // 2. PeriodAsDeclaration
  141. // If `OpenSquareBracket`:
  142. // 1. ParameterListAsDeduced
  143. // 2. DeclarationNameAndParamsAfterDeduced
  144. // If `OpenParen`:
  145. // 1. ParameterListAsRegular
  146. // Else:
  147. // (state done)
  148. CARBON_PARSER_STATE_VARIANTS3(DeclarationNameAndParamsAfterName, None, Optional,
  149. Required)
  150. // Handles regular parameters such as `(...)` for the general declaration case.
  151. // Only used after deduced parameters.
  152. //
  153. // If `OpenParen`:
  154. // 1. ParameterListAsRegular
  155. // Else:
  156. // (state done)
  157. CARBON_PARSER_STATE(DeclarationNameAndParamsAfterDeduced)
  158. // Handles processing of a declaration scope. Things like fn, class, interface,
  159. // and so on.
  160. //
  161. // If `EndOfFile`:
  162. // (state done)
  163. // If `Class`:
  164. // 1. TypeIntroducerAsClass
  165. // 2. DeclarationScopeLoop
  166. // If `Constraint`:
  167. // 1. TypeIntroducerAsNamedConstraint
  168. // 2. DeclarationScopeLoop
  169. // If `Fn`:
  170. // 1. FunctionIntroducer
  171. // 2. DeclarationScopeLoop
  172. // If `Interface`:
  173. // 1. TypeIntroducerAsInterface
  174. // 2. DeclarationScopeLoop
  175. // If `Namespace`:
  176. // 2. Namespace
  177. // 3. DeclarationScopeLoop
  178. // If `Semi`:
  179. // 1. DeclarationScopeLoop
  180. // If `Var`:
  181. // 1. Var
  182. // 2. DeclarationScopeLoop
  183. // Else:
  184. // 1. DeclarationScopeLoop
  185. CARBON_PARSER_STATE(DeclarationScopeLoop)
  186. // Handles periods. Only does one `.<expression>` segment; the source is
  187. // responsible for handling chaining.
  188. //
  189. // The forms of this are:
  190. // - Designated names in structs.
  191. // - Qualified names in declarations.
  192. // - Member access expressions.
  193. //
  194. // Declarations and expressions have qualifiers such as `x.y`, while structs
  195. // have designators such as `.z`.
  196. //
  197. // Always:
  198. // (state done)
  199. CARBON_PARSER_STATE_VARIANTS3(Period, Declaration, Expression, Struct)
  200. // Handles processing of an expression.
  201. //
  202. // If `If`:
  203. // 1. Expression
  204. // 2. IfExpressionCondition
  205. // 3. IfExpressionFinish
  206. // Else if valid prefix operator:
  207. // 1. Expression
  208. // 2. ExpressionLoopForPrefix
  209. // Else:
  210. // 1. ExpressionInPostfix
  211. // 2. ExpressionLoop
  212. CARBON_PARSER_STATE(Expression)
  213. // Handles the initial part of postfix expressions, such as an identifier or
  214. // literal value, then proceeds to the loop.
  215. //
  216. // If `Identifier` or literal (including type literals):
  217. // 1. ExpressionInPostfixLoop
  218. // If `OpenCurlyBrace`:
  219. // 1. BraceExpression
  220. // 2. ExpressionInPostfixLoop
  221. // If `OpenParen`:
  222. // 1. ParenExpression
  223. // 2. ExpressionInPostfixLoop
  224. // Else:
  225. // (state done)
  226. CARBON_PARSER_STATE(ExpressionInPostfix)
  227. // Handles looping through elements following the initial postfix expression,
  228. // such as designators or parenthesized parameters.
  229. //
  230. // If `Period`:
  231. // 1. PeriodAsExpression
  232. // 2. ExpressionInPostfixLoop
  233. // If `OpenParen`:
  234. // 1. CallExpression
  235. // 2. ExpressionInPostfixLoop
  236. // Else:
  237. // (state done)
  238. CARBON_PARSER_STATE(ExpressionInPostfixLoop)
  239. // Handles processing of an expression.
  240. //
  241. // If binary operator:
  242. // 1. Expression
  243. // 2. ExpressionLoopForBinary
  244. // If postfix operator:
  245. // 1. ExpressionLoop
  246. // Else:
  247. // (state done)
  248. CARBON_PARSER_STATE(ExpressionLoop)
  249. // Completes an ExpressionLoop pass by adding an infix operator, then goes back
  250. // to ExpressionLoop.
  251. //
  252. // Always:
  253. // 1. ExpressionLoop
  254. CARBON_PARSER_STATE(ExpressionLoopForBinary)
  255. // Completes an ExpressionLoop pass by adding a prefix operator, then goes back
  256. // to ExpressionLoop.
  257. //
  258. // Always:
  259. // 1. ExpressionLoop
  260. CARBON_PARSER_STATE(ExpressionLoopForPrefix)
  261. // Completes the condition of an `if` expression and handles the `then` token.
  262. //
  263. // If `Then`:
  264. // 1. Expression
  265. // 2. IfExpressionFinishThen
  266. // Else:
  267. // (state done)
  268. CARBON_PARSER_STATE(IfExpressionFinishCondition)
  269. // Completes the first alternative in an `if` expression and handles the `else`
  270. // token.
  271. //
  272. // If `Else`:
  273. // 1. Expression
  274. // 2. IfExpressionFinishElse
  275. // Else:
  276. // (state done)
  277. CARBON_PARSER_STATE(IfExpressionFinishThen)
  278. // Completes the second alternative in an `if` expression.
  279. //
  280. // Always:
  281. // (state done)
  282. CARBON_PARSER_STATE(IfExpressionFinishElse)
  283. // Completes an IfExpression.
  284. //
  285. // Always:
  286. // (state done)
  287. CARBON_PARSER_STATE(IfExpressionFinish)
  288. // Handles the `;` for an expression statement, which is different from most
  289. // keyword statements.
  290. //
  291. // Always:
  292. // (state done)
  293. CARBON_PARSER_STATE(ExpressionStatementFinish)
  294. // Handles a function's introducer.
  295. //
  296. // If invalid:
  297. // (state done)
  298. // Else:
  299. // 1. DeclarationNameAndParamsAsRequired
  300. // 2. FunctionAfterParameters
  301. CARBON_PARSER_STATE(FunctionIntroducer)
  302. // Handles processing of a function's syntax after `)`, primarily the
  303. // possibility a `->` return type is there. Always enqueues signature finish
  304. // handling.
  305. //
  306. // If `MinusGreater`:
  307. // 1. Expression
  308. // 2. FunctionReturnTypeFinish
  309. // 3. FunctionSignatureFinish
  310. // Else:
  311. // 1. FunctionSignatureFinish
  312. CARBON_PARSER_STATE(FunctionAfterParameters)
  313. // Finishes a function return type.
  314. //
  315. // Always:
  316. // (state done)
  317. CARBON_PARSER_STATE(FunctionReturnTypeFinish)
  318. // Finishes a function signature. If it's a declaration, the function is done;
  319. // otherwise, this also starts definition processing.
  320. //
  321. // If `Semi`:
  322. // (state done)
  323. // If `OpenCurlyBrace`:
  324. // 1. StatementScopeLoop
  325. // 2. FunctionDefinitionFinish
  326. // Else:
  327. // (state done)
  328. CARBON_PARSER_STATE(FunctionSignatureFinish)
  329. // Finishes a function definition.
  330. //
  331. // Always:
  332. // (state done)
  333. CARBON_PARSER_STATE(FunctionDefinitionFinish)
  334. // Handles `namespace`.
  335. //
  336. // Always:
  337. // 1. DeclarationNameAndParamsAsNone
  338. // 2. NamespaceFinish
  339. CARBON_PARSER_STATE(Namespace)
  340. // Handles `namespace` after the name.
  341. //
  342. // Always:
  343. // (state done)
  344. CARBON_PARSER_STATE(NamespaceFinish)
  345. // Handles `package`.
  346. //
  347. // Always:
  348. // (state done)
  349. CARBON_PARSER_STATE(Package)
  350. // Starts deduced parameter processing.
  351. //
  352. // Always:
  353. // 1. PatternAs(DeducedParameter|Parameter)
  354. // 2. ParameterFinishAs(Deduced|Regular)
  355. CARBON_PARSER_STATE_VARIANTS2(Parameter, Deduced, Regular)
  356. // Finishes deduced parameter processing, including `,`. If there are more
  357. // parameters, enqueues another parameter processing state.
  358. //
  359. // If `Comma` without the list close token:
  360. // 1. ParameterAs(Deduced|Regular)
  361. // Else:
  362. // (state done)
  363. CARBON_PARSER_STATE_VARIANTS2(ParameterFinish, Deduced, Regular)
  364. // Handles processing of a parameter list `[` or `(`.
  365. //
  366. // If the list close token:
  367. // 1. ParameterListFinishAs(Deduced|Regular)
  368. // Else:
  369. // 1. ParameterAs(Deduced|Regular)
  370. // 2. ParameterListFinishAs(Deduced|Regular)
  371. CARBON_PARSER_STATE_VARIANTS2(ParameterList, Deduced, Regular)
  372. // Handles processing of a parameter list `]` or `)`.
  373. //
  374. // Always:
  375. // (state done)
  376. CARBON_PARSER_STATE_VARIANTS2(ParameterListFinish, Deduced, Regular)
  377. // Handles the processing of a `(condition)` up through the expression.
  378. //
  379. // Always:
  380. // 1. Expression
  381. // 2. ParenConditionAs(If|While)Finish
  382. CARBON_PARSER_STATE_VARIANTS2(ParenCondition, If, While)
  383. // Finishes the processing of a `(condition)` after the expression.
  384. //
  385. // Always:
  386. // (state done)
  387. CARBON_PARSER_STATE_VARIANTS2(ParenConditionFinish, If, While)
  388. // Handles the `(` of a parenthesized expression.
  389. //
  390. // If `CloseParen`:
  391. // 1. ParenExpressionFinishAsTuple
  392. // Else:
  393. // 1. Expression
  394. // 2. ParenExpressionParameterFinishAsUnknown
  395. // 3. ParenExpressionFinish
  396. CARBON_PARSER_STATE(ParenExpression)
  397. // Handles the end of a parenthesized expression's parameter. This will start as
  398. // AsUnknown on the first parameter; if there are more, it switches to AsTuple
  399. // processing.
  400. //
  401. // If `Comma` without `CloseParen`:
  402. // 1. Expression
  403. // 2. ParenExpressionParameterFinishAsTuple
  404. // SPECIAL: Parent becomes ParenExpressionFinishAsTuple
  405. // If `Comma` with `CloseParen`:
  406. // (state done)
  407. // SPECIAL: Parent becomes ParenExpressionFinishAsTuple
  408. // Else `CloseParen`:
  409. // (state done)
  410. CARBON_PARSER_STATE_VARIANTS2(ParenExpressionParameterFinish, Unknown, Tuple)
  411. // Handles the `)` of a parenthesized expression.
  412. //
  413. // Always:
  414. // (state done)
  415. CARBON_PARSER_STATE_VARIANTS2(ParenExpressionFinish, Normal, Tuple)
  416. // Handles pattern parsing for a pattern, enqueuing type expression processing.
  417. // This covers parameter and `var` support.
  418. //
  419. // If valid:
  420. // 1. Expression
  421. // 2. PatternFinishAs(Generic|Regular)
  422. // Else:
  423. // 1. PatternFinish
  424. CARBON_PARSER_STATE_VARIANTS3(Pattern, DeducedParameter, Parameter, Variable)
  425. // Handles `addr` in a pattern.
  426. //
  427. // Always:
  428. // (state done)
  429. CARBON_PARSER_STATE(PatternAddress)
  430. // Handles `template` in a pattern.
  431. //
  432. // Always:
  433. // (state done)
  434. CARBON_PARSER_STATE(PatternTemplate)
  435. // Finishes pattern processing.
  436. //
  437. // Always:
  438. // (state done)
  439. CARBON_PARSER_STATE_VARIANTS2(PatternFinish, Generic, Regular)
  440. // Handles a single statement. While typically within a statement block, this
  441. // can also be used for error recovery where we expect a statement block and
  442. // are missing braces.
  443. //
  444. // If `Break`:
  445. // 1. StatementBreakFinish
  446. // (state done)
  447. // If `Continue`:
  448. // 1. StatementContinueFinish
  449. // (state done)
  450. // If `For`:
  451. // 1. StatementForHeader
  452. // 2. StatementForFinish
  453. // If `If`:
  454. // 1. StatementIf
  455. // If `Return`:
  456. // 1. StatementReturn
  457. // If `Var`:
  458. // 1. VarAsSemicolon
  459. // If `While`:
  460. // 1. StatementWhile
  461. // Else:
  462. // 1. Expression
  463. // 2. ExpressionStatementFinish
  464. CARBON_PARSER_STATE(Statement)
  465. // Handles `break` processing at the `;`.
  466. //
  467. // Always:
  468. // (state done)
  469. CARBON_PARSER_STATE(StatementBreakFinish)
  470. // Handles `continue` processing at the `;`.
  471. //
  472. // Always:
  473. // (state done)
  474. CARBON_PARSER_STATE(StatementContinueFinish)
  475. // Handles `for` processing of `(var`, proceeding to a pattern before
  476. // continuing.
  477. //
  478. // If no `OpenParen`:
  479. // 1. CodeBlock
  480. // If `Var`:
  481. // 1. VarAsFor
  482. // 2. StatementForHeaderIn
  483. // Else:
  484. // 1. StatementForHeaderIn
  485. CARBON_PARSER_STATE(StatementForHeader)
  486. // Handles `for` procesisng of `in`, proceeding to an expression before
  487. // continuing.
  488. //
  489. // If `In` or `Colon`:
  490. // 1. Expression
  491. // 2. StatementForHeaderFinish
  492. // Else:
  493. // 1. StatementForHeaderFinish
  494. CARBON_PARSER_STATE(StatementForHeaderIn)
  495. // Handles `for` processing of `)`, proceeding to the statement block.
  496. //
  497. // Always:
  498. // 1. CodeBlock
  499. CARBON_PARSER_STATE(StatementForHeaderFinish)
  500. // Handles `for` processing at the final `}`.
  501. //
  502. // Always:
  503. // (state done)
  504. CARBON_PARSER_STATE(StatementForFinish)
  505. // Handles `if` processing at the start.
  506. //
  507. // Always:
  508. // 1. ParenConditionAsIf
  509. // 2. StatementIfConditionFinish
  510. CARBON_PARSER_STATE(StatementIf)
  511. // Handles `if` processing between the condition and start of the first code
  512. // block.
  513. //
  514. // Always:
  515. // 1. CodeBlock
  516. // 2. StatementIfThenBlockFinish
  517. CARBON_PARSER_STATE(StatementIfConditionFinish)
  518. // Handles `if` processing after the end of the first code block, with the
  519. // optional `else`.
  520. //
  521. // If `Else` then `If`:
  522. // 1. CodeBlock
  523. // 2. StatementIfElseBlockFinish
  524. // If `Else`:
  525. // 1. StatementIf
  526. // 2. StatementIfElseBlockFinish
  527. // Else:
  528. // (state done)
  529. CARBON_PARSER_STATE(StatementIfThenBlockFinish)
  530. // Handles `if` processing after a provided `else` code block.
  531. //
  532. // Always:
  533. // (state done)
  534. CARBON_PARSER_STATE(StatementIfElseBlockFinish)
  535. // Handles `return` processing.
  536. //
  537. // If `Semi`:
  538. // 1. StatementReturnFinish
  539. // Else:
  540. // 1. Expression
  541. // 2. StatementReturnFinish
  542. CARBON_PARSER_STATE(StatementReturn)
  543. // Handles `return` processing at the `;` when there's an expression.
  544. //
  545. // Always:
  546. // (state done)
  547. CARBON_PARSER_STATE(StatementReturnFinish)
  548. // Handles processing of statements within a scope.
  549. //
  550. // If `CloseCurlyBrace`:
  551. // (state done)
  552. // Else:
  553. // 1. Statement
  554. // 2. StatementScopeLoop
  555. CARBON_PARSER_STATE(StatementScopeLoop)
  556. // Handles `while` processing.
  557. //
  558. // Always:
  559. // 1. ParenConditionAsWhile
  560. // 2. StatementWhileConditionFinish
  561. CARBON_PARSER_STATE(StatementWhile)
  562. // Handles `while` processing between the condition and start of the code block.
  563. //
  564. // Always:
  565. // 1. CodeBlock
  566. // 2. StatementWhileBlockFinish
  567. CARBON_PARSER_STATE(StatementWhileConditionFinish)
  568. // Handles `while` processing after the end of the code block.
  569. //
  570. // Always:
  571. // (state done)
  572. CARBON_PARSER_STATE(StatementWhileBlockFinish)
  573. // Handles parsing after the declaration scope of a type.
  574. //
  575. // Always:
  576. // (state done)
  577. CARBON_PARSER_STATE_VARIANTS3(TypeDefinitionFinish, Class, Interface,
  578. NamedConstraint)
  579. // Handles processing of a type's introducer.
  580. //
  581. // Always:
  582. // 1. DeclarationNameAndParamsAsOptional
  583. // 2. TypeAfterParamsAs(Class|Interface|NamedConstraint)
  584. CARBON_PARSER_STATE_VARIANTS3(TypeIntroducer, Class, Interface, NamedConstraint)
  585. // Handles processing of a type after its optional parameters.
  586. //
  587. // If `Semi`:
  588. // (state done)
  589. // If `OpenCurlyBrace`:
  590. // 1. DeclarationScopeLoop
  591. // 2. TypeDefinitionFinishAs(Class|Interface|NamedConstraint)
  592. // Else:
  593. // (state done)
  594. CARBON_PARSER_STATE_VARIANTS3(TypeAfterParams, Class, Interface,
  595. NamedConstraint)
  596. // Handles the start of a `var`.
  597. //
  598. // Always:
  599. // 1. PatternAsVariable
  600. // 2. VarAfterPattern
  601. // 3. VarFinishAs(Semicolon|For)
  602. CARBON_PARSER_STATE_VARIANTS2(Var, Semicolon, For)
  603. // Handles `var` after the pattern, either followed by an initializer or the
  604. // semicolon.
  605. //
  606. // If `Equal`:
  607. // 1. Expression
  608. // Else:
  609. // (state done)
  610. CARBON_PARSER_STATE(VarAfterPattern)
  611. // Handles `var` parsing at the end.
  612. //
  613. // Always:
  614. // (state done)
  615. CARBON_PARSER_STATE_VARIANTS2(VarFinish, Semicolon, For)
  616. #undef CARBON_PARSER_STATE