node_kind.def 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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_NODE_KIND(Name)
  12. // Used as a fallback if other macros are missing. No kinds should use this
  13. // directly.
  14. // - CARBON_PARSE_NODE_KIND_BRACKET(Name, BracketName, LexTokenKinds)
  15. // Defines a bracketed node kind. BracketName should refer to the node
  16. // kind that is the _start_ of the bracketed range.
  17. // - CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ChildCount, LexTokenKinds)
  18. // Defines a parse node with a set number of children, often 0. This count
  19. // must be correct even when the node contains errors.
  20. //
  21. // In both cases, LexTokenKinds says which Lex::TokenKind values that this
  22. // parse node can correspond to, and is a sequence of:
  23. // - CARBON_TOKEN(kind): This node can correspond to this kind of token.
  24. // - CARBON_ANY_TOKEN: This node can correspond to any token.
  25. // - CARBON_IF_ERROR(LexTokenKinds): This node can additionally correspond
  26. // to the given kinds of tokens if its `has_error` flag is set.
  27. //
  28. // This tree represents the subset relationship between these macros, where if a
  29. // specific x-macro isn't defined, it'll fall back to the parent macro.
  30. //
  31. // Parse nodes are clustered based on language feature. Comments will show their
  32. // relationship in postorder, using indentation for child node relationships.
  33. #if !(defined(CARBON_PARSE_NODE_KIND) || \
  34. (defined(CARBON_PARSE_NODE_KIND_BRACKET) && \
  35. defined(CARBON_PARSE_NODE_KIND_CHILD_COUNT)))
  36. #error "Must define CARBON_PARSE_NODE_KIND family x-macros to use this file."
  37. #endif
  38. // The BRACKET and CHILD_COUNT macros will use CARBON_PARSE_NODE_KIND by default
  39. // when undefined.
  40. #ifndef CARBON_PARSE_NODE_KIND_BRACKET
  41. #define CARBON_PARSE_NODE_KIND_BRACKET(Name, ...) CARBON_PARSE_NODE_KIND(Name)
  42. #endif
  43. #ifndef CARBON_PARSE_NODE_KIND_CHILD_COUNT
  44. #define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ...) \
  45. CARBON_PARSE_NODE_KIND(Name)
  46. #endif
  47. // The start of the file.
  48. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileStart, 0, CARBON_TOKEN(StartOfFile))
  49. // The end of the file.
  50. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileEnd, 0, CARBON_TOKEN(EndOfFile))
  51. // An invalid parse. Used to balance the parse tree. Always has an error.
  52. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InvalidParse, 0,
  53. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  54. // An empty declaration, such as `;`.
  55. CARBON_PARSE_NODE_KIND_CHILD_COUNT(EmptyDecl, 0,
  56. CARBON_TOKEN(Semi)
  57. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  58. // A name in a non-expression context, such as a declaration.
  59. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, 0,
  60. CARBON_TOKEN(Identifier)
  61. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  62. // A name in an expression context.
  63. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NameExpr, 0, CARBON_TOKEN(Identifier))
  64. // ----------------------------------------------------------------------------
  65. // The comments below follow this pattern:
  66. //
  67. // // Descriptive heading:
  68. // // Child1
  69. // // Child2
  70. // // Parent
  71. //
  72. // In this, `Child1`, `Child2`, and `Parent` are all kinds of parse nodes, which
  73. // are then defined using the `CARBON_PARSE_NODE_KIND_*` macros. They are
  74. // written in postorder, with the indentation showing the tree structure. See
  75. // tree.h for more information.
  76. //
  77. // A parse node kind may be preceded by:
  78. // - `_external_:` if this node is the child of multiple kinds of nodes and
  79. // is documented separately.
  80. // - `_optional_` if this node may be present or omitted in valid parses,
  81. // depending on which tokens are in the source code.
  82. //
  83. // There is generally a close correspondence between handling of tokens and the
  84. // creation of non-external nodes in a given block.
  85. // ----------------------------------------------------------------------------
  86. // `library`:
  87. // _external_: Literal
  88. // Library
  89. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Library, 1, CARBON_TOKEN(Library))
  90. // `package`:
  91. // PackageIntroducer
  92. // _external_: Name
  93. // _optional_ _external_: Library
  94. // PackageApi or PackageImpl
  95. // PackageDirective
  96. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageIntroducer, 0, CARBON_TOKEN(Package))
  97. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageApi, 0, CARBON_TOKEN(Api))
  98. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageImpl, 0, CARBON_TOKEN(Impl))
  99. CARBON_PARSE_NODE_KIND_BRACKET(PackageDirective, PackageIntroducer,
  100. CARBON_TOKEN(Semi)
  101. CARBON_IF_ERROR(CARBON_TOKEN(Package)))
  102. // `import`:
  103. // ImportIntroducer
  104. // _external_: Name
  105. // _optional_ _external_: Library
  106. // ImportDirective
  107. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ImportIntroducer, 0, CARBON_TOKEN(Import))
  108. CARBON_PARSE_NODE_KIND_BRACKET(ImportDirective, ImportIntroducer,
  109. CARBON_TOKEN(Semi)
  110. CARBON_IF_ERROR(CARBON_TOKEN(Import)))
  111. // `namespace`:
  112. // NamespaceStart
  113. // _external_: Name or QualifiedDecl
  114. // Namespace
  115. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamespaceStart, 0, CARBON_TOKEN(Namespace))
  116. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Namespace, 2, CARBON_TOKEN(Semi))
  117. // A code block:
  118. // CodeBlockStart
  119. // _external_: statements
  120. // CodeBlock
  121. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CodeBlockStart, 0,
  122. CARBON_TOKEN(OpenCurlyBrace)
  123. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  124. CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart,
  125. CARBON_TOKEN(CloseCurlyBrace)
  126. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  127. // `fn`:
  128. // FunctionIntroducer
  129. // _external_: Name or QualifiedDecl
  130. // _external_: ParameterList
  131. // _external_: type expression
  132. // ReturnType
  133. // FunctionDefinitionStart
  134. // _external_: statements
  135. // FunctionDefinition
  136. //
  137. // The above is the structure for a definition; for a declaration,
  138. // FunctionDefinitionStart and later nodes are removed and replaced by
  139. // FunctionDecl.
  140. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FunctionIntroducer, 0, CARBON_TOKEN(Fn))
  141. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnType, 1, CARBON_TOKEN(MinusGreater))
  142. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinitionStart, FunctionIntroducer,
  143. CARBON_TOKEN(OpenCurlyBrace))
  144. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinition, FunctionDefinitionStart,
  145. CARBON_TOKEN(CloseCurlyBrace))
  146. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDecl, FunctionIntroducer,
  147. CARBON_TOKEN(Semi)
  148. CARBON_IF_ERROR(CARBON_TOKEN(Fn)))
  149. // A parameter list, possibly implicit:
  150. // [Implicit]ParamertListStart
  151. // _external_: [Generic]PatternBinding
  152. // ParameterListComma
  153. // [Implicit]ParameterList
  154. //
  155. // Exprs and ParameterListComma may repeat with ParameterListComma as a
  156. // separator.
  157. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListStart, 0,
  158. CARBON_TOKEN(OpenParen))
  159. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ImplicitParameterListStart, 0,
  160. CARBON_TOKEN(OpenSquareBracket))
  161. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListComma, 0, CARBON_TOKEN(Comma))
  162. CARBON_PARSE_NODE_KIND_BRACKET(ParameterList, ParameterListStart,
  163. CARBON_TOKEN(CloseParen))
  164. CARBON_PARSE_NODE_KIND_BRACKET(ImplicitParameterList,
  165. ImplicitParameterListStart,
  166. CARBON_TOKEN(CloseSquareBracket))
  167. // An array type, such as `[i32; 3]` or `[i32;]`:
  168. // ArrayExprStart
  169. // _external_: type expression
  170. // ArrayExprSemi
  171. // _optional_ _external_: expression
  172. // ArrayExpr
  173. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ArrayExprStart, 0,
  174. CARBON_TOKEN(OpenSquareBracket))
  175. CARBON_PARSE_NODE_KIND_CHILD_COUNT(
  176. ArrayExprSemi, 2,
  177. CARBON_TOKEN(Semi) CARBON_IF_ERROR(CARBON_TOKEN(CloseSquareBracket)))
  178. CARBON_PARSE_NODE_KIND_BRACKET(ArrayExpr, ArrayExprSemi,
  179. CARBON_TOKEN(CloseSquareBracket))
  180. // A pattern binding, such as `name: Type`:
  181. // Name or SelfValueName
  182. // _external_: type expression
  183. // [Generic]PatternBinding
  184. // _optional_ Address
  185. // _optional_ Template
  186. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PatternBinding, 2,
  187. CARBON_TOKEN(Colon)
  188. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  189. CARBON_PARSE_NODE_KIND_CHILD_COUNT(GenericPatternBinding, 2,
  190. CARBON_TOKEN(ColonExclaim))
  191. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Address, 1, CARBON_TOKEN(Addr))
  192. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Template, 1, CARBON_TOKEN(Template))
  193. // `let`:
  194. // LetIntroducer
  195. // _external_: PatternBinding
  196. // LetInitializer
  197. // _external_: expression
  198. // LetDecl
  199. CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetIntroducer, 0, CARBON_TOKEN(Let))
  200. CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetInitializer, 0, CARBON_TOKEN(Equal))
  201. CARBON_PARSE_NODE_KIND_BRACKET(LetDecl, LetIntroducer,
  202. CARBON_TOKEN(Semi)
  203. CARBON_IF_ERROR(CARBON_TOKEN(Let)))
  204. // `var`:
  205. // VariableIntroducer
  206. // _external_: PatternBinding
  207. // _optional_ VariableInitializer
  208. // _optional_ _external_: expression
  209. // VariableDecl
  210. //
  211. // The VariableInitializer and following expression are paired: either both will
  212. // be present, or neither will.
  213. CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableIntroducer, 0, CARBON_TOKEN(Var))
  214. CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableInitializer, 0, CARBON_TOKEN(Equal))
  215. CARBON_PARSE_NODE_KIND_BRACKET(VariableDecl, VariableIntroducer,
  216. CARBON_TOKEN(Semi)
  217. CARBON_IF_ERROR(CARBON_TOKEN(Var)))
  218. // An expression statement:
  219. // _external_: expression
  220. // ExprStatement
  221. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ExprStatement, 1, CARBON_TOKEN(Semi))
  222. // `break`:
  223. // BreakStatementStart
  224. // BreakStatement
  225. CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatementStart, 0, CARBON_TOKEN(Break))
  226. CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatement, 1,
  227. CARBON_TOKEN(Semi)
  228. CARBON_IF_ERROR(CARBON_TOKEN(Break)))
  229. // `continue`:
  230. // ContinueStatementStart
  231. // ContinueStatement
  232. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatementStart, 0,
  233. CARBON_TOKEN(Continue))
  234. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatement, 1,
  235. CARBON_TOKEN(Semi)
  236. CARBON_IF_ERROR(CARBON_TOKEN(Continue)))
  237. // `return`:
  238. // ReturnStatementStart
  239. // _optional_ _external_: expression
  240. // ReturnStatement
  241. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnStatementStart, 0,
  242. CARBON_TOKEN(Return))
  243. CARBON_PARSE_NODE_KIND_BRACKET(ReturnStatement, ReturnStatementStart,
  244. CARBON_TOKEN(Semi)
  245. CARBON_IF_ERROR(CARBON_TOKEN(Return)))
  246. // `for`:
  247. // ForHeaderStart
  248. // VariableIntroducer
  249. // _external_: PatternBinding
  250. // ForIn
  251. // _external_: expression
  252. // ForHeader
  253. // _external_: CodeBlock
  254. // ForStatement
  255. //
  256. // Versus a normal `var`, ForIn replaces VariableDecl.
  257. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeaderStart, 0,
  258. CARBON_TOKEN(OpenParen)
  259. CARBON_IF_ERROR(CARBON_TOKEN(For)))
  260. CARBON_PARSE_NODE_KIND_BRACKET(ForIn, VariableIntroducer,
  261. CARBON_TOKEN(In)
  262. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  263. CARBON_PARSE_NODE_KIND_BRACKET(ForHeader, ForHeaderStart,
  264. CARBON_TOKEN(CloseParen)
  265. CARBON_IF_ERROR(CARBON_TOKEN(For)))
  266. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForStatement, 2, CARBON_TOKEN(For))
  267. // `if` statement + `else`:
  268. // IfConditionStart
  269. // _external_: expression
  270. // IfCondition
  271. // _external_: CodeBlock
  272. // IfStatementElse
  273. // _external_: CodeBlock or IfStatement
  274. // IfStatement
  275. //
  276. // IfStatementElse and the following node are optional based on `else` presence.
  277. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfConditionStart, 0,
  278. CARBON_TOKEN(OpenParen)
  279. CARBON_IF_ERROR(CARBON_TOKEN(If)))
  280. CARBON_PARSE_NODE_KIND_BRACKET(IfCondition, IfConditionStart,
  281. CARBON_TOKEN(CloseParen)
  282. CARBON_IF_ERROR(CARBON_TOKEN(If)))
  283. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatementElse, 0, CARBON_TOKEN(Else))
  284. CARBON_PARSE_NODE_KIND_BRACKET(IfStatement, IfCondition, CARBON_TOKEN(If))
  285. // `while`:
  286. // WhileConditionStart
  287. // _external_: expression
  288. // WhileCondition
  289. // _external_: CodeBlock
  290. // WhileStatement
  291. CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileConditionStart, 0,
  292. CARBON_TOKEN(OpenParen))
  293. CARBON_PARSE_NODE_KIND_BRACKET(WhileCondition, WhileConditionStart,
  294. CARBON_TOKEN(CloseParen))
  295. CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileStatement, 2, CARBON_TOKEN(While))
  296. // Index expressions, such as `a[1]`:
  297. // _external_: expression
  298. // IndexExprStart
  299. // _external_: expression
  300. // IndexExpr
  301. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IndexExprStart, 1,
  302. CARBON_TOKEN(OpenSquareBracket))
  303. CARBON_PARSE_NODE_KIND_BRACKET(IndexExpr, IndexExprStart,
  304. CARBON_TOKEN(CloseSquareBracket))
  305. // Parenthesized expressions, such as `(2)`:
  306. // ParenExprOrTupleLiteralStart
  307. // _external_: expression
  308. // ParenExpr
  309. //
  310. // Tuples, such as `(1, 2)`:
  311. // ParenExprOrTupleLiteralStart
  312. // _external_: expression
  313. // TupleLiteralComma
  314. // TupleLiteral
  315. //
  316. // Exprs and TupleLiteralComma may repeat with TupleLiteralComma as a
  317. // separator.
  318. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExprOrTupleLiteralStart, 0,
  319. CARBON_TOKEN(OpenParen))
  320. CARBON_PARSE_NODE_KIND_BRACKET(ParenExpr, ParenExprOrTupleLiteralStart,
  321. CARBON_TOKEN(CloseParen))
  322. CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralComma, 0, CARBON_TOKEN(Comma))
  323. CARBON_PARSE_NODE_KIND_BRACKET(TupleLiteral, ParenExprOrTupleLiteralStart,
  324. CARBON_TOKEN(CloseParen))
  325. // Call expressions, such as `a()`:
  326. // _external_: expression
  327. // CallExprStart
  328. // _external_: expression
  329. // CallExprComma
  330. // CallExpr
  331. //
  332. // Exprs and CallExprComma may repeat with CallExprComma as a
  333. // separator.
  334. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExprStart, 1, CARBON_TOKEN(OpenParen))
  335. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExprComma, 0, CARBON_TOKEN(Comma))
  336. CARBON_PARSE_NODE_KIND_BRACKET(CallExpr, CallExprStart,
  337. CARBON_TOKEN(CloseParen))
  338. // A qualified declaration, such as `a.b`:
  339. // _external_: Name or QualifiedDecl
  340. // _external_: Name
  341. // QualifiedDecl
  342. //
  343. // TODO: This will eventually more general expressions, for example with
  344. // `GenericType(type_args).ChildType(child_type_args).Name`.
  345. CARBON_PARSE_NODE_KIND_CHILD_COUNT(QualifiedDecl, 2, CARBON_TOKEN(Period))
  346. // A member access expression, such as `a.b` or
  347. // `GetObject().(Interface.member)`:
  348. // _external_: lhs expression
  349. // _external_: rhs expression
  350. // QualifiedExpr
  351. CARBON_PARSE_NODE_KIND_CHILD_COUNT(MemberAccessExpr, 2, CARBON_TOKEN(Period))
  352. // A pointer member access expression, such as `a->b` or
  353. // `GetObject()->(Interface.member)`:
  354. // _external_: lhs expression
  355. // _external_: rhs expression
  356. // QualifiedExpr
  357. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PointerMemberAccessExpr, 2,
  358. CARBON_TOKEN(MinusGreater))
  359. // clang-format off
  360. // A literal.
  361. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Literal, 0,
  362. CARBON_TOKEN(False)
  363. CARBON_TOKEN(True)
  364. CARBON_TOKEN(IntegerLiteral)
  365. CARBON_TOKEN(RealLiteral)
  366. CARBON_TOKEN(StringLiteral)
  367. CARBON_TOKEN(Bool)
  368. CARBON_TOKEN(IntegerTypeLiteral)
  369. CARBON_TOKEN(UnsignedIntegerTypeLiteral)
  370. CARBON_TOKEN(FloatingPointTypeLiteral)
  371. CARBON_TOKEN(StringTypeLiteral)
  372. CARBON_TOKEN(Type))
  373. // A prefix operator:
  374. // _external_: expression
  375. // PrefixOperator
  376. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PrefixOperator, 1,
  377. CARBON_TOKEN(Star)
  378. CARBON_TOKEN(Amp)
  379. CARBON_TOKEN(Not)
  380. CARBON_TOKEN(Minus)
  381. CARBON_TOKEN(MinusMinus)
  382. CARBON_TOKEN(PlusPlus)
  383. CARBON_TOKEN(Caret)
  384. CARBON_TOKEN(Const))
  385. // An infix operator:
  386. // _external_: lhs expression
  387. // _external_: rhs expression
  388. // InfixOperator
  389. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InfixOperator, 2,
  390. CARBON_TOKEN(Amp)
  391. CARBON_TOKEN(AmpEqual)
  392. CARBON_TOKEN(And)
  393. CARBON_TOKEN(As)
  394. CARBON_TOKEN(Caret)
  395. CARBON_TOKEN(CaretEqual)
  396. CARBON_TOKEN(Equal)
  397. CARBON_TOKEN(EqualEqual)
  398. CARBON_TOKEN(ExclaimEqual)
  399. CARBON_TOKEN(Greater)
  400. CARBON_TOKEN(GreaterEqual)
  401. CARBON_TOKEN(GreaterGreater)
  402. CARBON_TOKEN(GreaterGreaterEqual)
  403. CARBON_TOKEN(Less)
  404. CARBON_TOKEN(LessEqual)
  405. CARBON_TOKEN(LessLess)
  406. CARBON_TOKEN(LessLessEqual)
  407. CARBON_TOKEN(Minus)
  408. CARBON_TOKEN(MinusEqual)
  409. CARBON_TOKEN(Or)
  410. CARBON_TOKEN(Percent)
  411. CARBON_TOKEN(PercentEqual)
  412. CARBON_TOKEN(Pipe)
  413. CARBON_TOKEN(PipeEqual)
  414. CARBON_TOKEN(Plus)
  415. CARBON_TOKEN(PlusEqual)
  416. CARBON_TOKEN(Slash)
  417. CARBON_TOKEN(SlashEqual)
  418. CARBON_TOKEN(Star)
  419. CARBON_TOKEN(StarEqual))
  420. // clang-format on
  421. // The first operand of a short-circuiting infix operator:
  422. // _external_: expression
  423. // ShortCircuitOperand
  424. // _external_: expression
  425. // _external_: InfixOperator
  426. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ShortCircuitOperand, 1,
  427. CARBON_TOKEN(And) CARBON_TOKEN(Or))
  428. // A postfix operator:
  429. // _external_: expression
  430. // PostfixOperator
  431. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PostfixOperator, 1, CARBON_TOKEN(Star))
  432. // `if` expression + `then` + `else`:
  433. // _external_: expression
  434. // IfExprIf
  435. // _external_: expression
  436. // IfExprThen
  437. // _external_: expression
  438. // IfExprElse
  439. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprIf, 1, CARBON_TOKEN(If))
  440. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprThen, 1, CARBON_TOKEN(Then))
  441. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprElse, 3,
  442. CARBON_TOKEN(Else)
  443. CARBON_IF_ERROR(CARBON_TOKEN(If)))
  444. // Struct literals, such as `{.a = 0}`:
  445. // StructLiteralOrStructTypeLiteralStart
  446. // _external_: Name
  447. // StructFieldDesignator
  448. // _external_: expression
  449. // StructFieldValue
  450. // StructComma
  451. // StructLiteral
  452. //
  453. // Struct type literals, such as `{.a: i32}`:
  454. // _external_: Name
  455. // StructFieldDesignator
  456. // _external_: type expression
  457. // StructFieldType
  458. // StructComma
  459. // StructTypeLiteral
  460. //
  461. // Elements (StructFieldValue and StructFieldType, respectively) and StructComma
  462. // may repeat with StructComma as a separator.
  463. //
  464. // When a valid StructFieldType or StructFieldValue cannot be formed, elements
  465. // may be replaced by StructFieldUnknown, which may have a preceding sibling
  466. // StructFieldDesignator if one was successfully parsed.
  467. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructLiteralOrStructTypeLiteralStart, 0,
  468. CARBON_TOKEN(OpenCurlyBrace))
  469. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldDesignator, 1,
  470. CARBON_TOKEN(Period))
  471. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldValue, 2, CARBON_TOKEN(Equal))
  472. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldType, 2, CARBON_TOKEN(Colon))
  473. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldUnknown, 0,
  474. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  475. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructComma, 0, CARBON_TOKEN(Comma))
  476. CARBON_PARSE_NODE_KIND_BRACKET(StructLiteral,
  477. StructLiteralOrStructTypeLiteralStart,
  478. CARBON_TOKEN(CloseCurlyBrace))
  479. CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
  480. StructLiteralOrStructTypeLiteralStart,
  481. CARBON_TOKEN(CloseCurlyBrace))
  482. // `class`:
  483. // ClassIntroducer
  484. // _external_: Name or QualifiedDecl
  485. // ClassDefinitionStart
  486. // _external_: declarations
  487. // ClassDefinition
  488. //
  489. // The above is the structure for a definition; for a declaration,
  490. // ClassDefinitionStart and later nodes are removed and replaced by
  491. // ClassDecl.
  492. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ClassIntroducer, 0, CARBON_TOKEN(Class))
  493. CARBON_PARSE_NODE_KIND_BRACKET(ClassDefinitionStart, ClassIntroducer,
  494. CARBON_TOKEN(OpenCurlyBrace))
  495. CARBON_PARSE_NODE_KIND_BRACKET(ClassDefinition, ClassDefinitionStart,
  496. CARBON_TOKEN(CloseCurlyBrace))
  497. CARBON_PARSE_NODE_KIND_BRACKET(ClassDecl, ClassIntroducer,
  498. CARBON_TOKEN(Semi)
  499. CARBON_IF_ERROR(CARBON_TOKEN(Class)))
  500. // `interface`:
  501. // InterfaceIntroducer
  502. // _external_: Name or QualifiedDecl
  503. // InterfaceDefinitionStart
  504. // _external_: declarations
  505. // InterfaceDefinition
  506. //
  507. // The above is the structure for a definition; for a declaration,
  508. // InterfaceDefinitionStart and later nodes are removed and replaced by
  509. // InterfaceDecl.
  510. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceIntroducer, 0,
  511. CARBON_TOKEN(Interface))
  512. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinitionStart, InterfaceIntroducer,
  513. CARBON_TOKEN(OpenCurlyBrace))
  514. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinition, InterfaceDefinitionStart,
  515. CARBON_TOKEN(CloseCurlyBrace))
  516. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDecl, InterfaceIntroducer,
  517. CARBON_TOKEN(Semi)
  518. CARBON_IF_ERROR(CARBON_TOKEN(Interface)))
  519. // `constraint`:
  520. // NamedConstraintIntroducer
  521. // _external_: Name or QualifiedDecl
  522. // NamedConstraintDefinitionStart
  523. // _external_: declarations
  524. // NamedConstraintDefinition
  525. //
  526. // The above is the structure for a definition; for a declaration,
  527. // NamedConstraintDefinitionStart and later nodes are removed and replaced by
  528. // NamedConstraintDecl.
  529. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamedConstraintIntroducer, 0,
  530. CARBON_TOKEN(Constraint))
  531. CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDefinitionStart,
  532. NamedConstraintIntroducer,
  533. CARBON_TOKEN(OpenCurlyBrace))
  534. CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDefinition,
  535. NamedConstraintDefinitionStart,
  536. CARBON_TOKEN(CloseCurlyBrace))
  537. CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDecl, NamedConstraintIntroducer,
  538. CARBON_TOKEN(Semi))
  539. // The `self` value and `Self` type identifier keywords. Typically of the form
  540. // `self: Self`:
  541. // SelfValueName
  542. // SelfValueNameExpr
  543. // SelfTypeNameExpr
  544. // PatternBinding
  545. CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfValueName, 0,
  546. CARBON_TOKEN(SelfValueIdentifier))
  547. CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfValueNameExpr, 0,
  548. CARBON_TOKEN(SelfValueIdentifier))
  549. CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfTypeNameExpr, 0,
  550. CARBON_TOKEN(SelfTypeIdentifier))
  551. #undef CARBON_PARSE_NODE_KIND
  552. #undef CARBON_PARSE_NODE_KIND_BRACKET
  553. #undef CARBON_PARSE_NODE_KIND_CHILD_COUNT
  554. #undef CARBON_TOKEN
  555. #undef CARBON_ANY_TOKEN
  556. #undef CARBON_IF_ERROR