| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648 |
- // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- // Exceptions. See /LICENSE for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- // This is an X-macro header. It does not use `#include` guards, and instead is
- // designed to be `#include`ed after the x-macro is defined in order for its
- // inclusion to expand to the desired output. Macro definitions are cleaned up
- // at the end of this file.
- //
- // Supported x-macros are:
- // - CARBON_PARSE_NODE_KIND(Name)
- // Used as a fallback if other macros are missing. No kinds should use this
- // directly.
- // - CARBON_PARSE_NODE_KIND_BRACKET(Name, BracketName, LexTokenKinds)
- // Defines a bracketed node kind. BracketName should refer to the node
- // kind that is the _start_ of the bracketed range.
- // - CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ChildCount, LexTokenKinds)
- // Defines a parse node with a set number of children, often 0. This count
- // must be correct even when the node contains errors.
- // - CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, Token)
- // Defines a parse node that corresponds to a token that is a single-token
- // literal. The token is wrapped for LexTokenKinds.
- //
- // In both cases, LexTokenKinds says which Lex::TokenKind values that this
- // parse node can correspond to, and is a sequence of:
- // - CARBON_TOKEN(kind): This node can correspond to this kind of token.
- // - CARBON_ANY_TOKEN: This node can correspond to any token.
- // - CARBON_IF_ERROR(LexTokenKinds): This node can additionally correspond
- // to the given kinds of tokens if its `has_error` flag is set.
- //
- // This tree represents the subset relationship between these macros, where if a
- // specific x-macro isn't defined, it'll fall back to the parent macro.
- //
- // Parse nodes are clustered based on language feature. Comments will show their
- // relationship in postorder, using indentation for child node relationships.
- #if !(defined(CARBON_PARSE_NODE_KIND) || \
- (defined(CARBON_PARSE_NODE_KIND_BRACKET) && \
- defined(CARBON_PARSE_NODE_KIND_CHILD_COUNT)))
- #error "Must define CARBON_PARSE_NODE_KIND family x-macros to use this file."
- #endif
- // The BRACKET and CHILD_COUNT macros will use CARBON_PARSE_NODE_KIND by default
- // when undefined.
- #ifndef CARBON_PARSE_NODE_KIND_BRACKET
- #define CARBON_PARSE_NODE_KIND_BRACKET(Name, ...) CARBON_PARSE_NODE_KIND(Name)
- #endif
- #ifndef CARBON_PARSE_NODE_KIND_CHILD_COUNT
- #define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ...) \
- CARBON_PARSE_NODE_KIND(Name)
- #endif
- // This is expected to be used with something like:
- //
- // // Use x-macros to handle literal cases.
- // #define CARBON_PARSE_NODE_KIND(...)
- // #define CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, ...) <code>
- #ifndef CARBON_PARSE_NODE_KIND_TOKEN_LITERAL
- #define CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, LexTokenKinds) \
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, 0, LexTokenKinds)
- #endif
- // The start of the file.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileStart, 0, CARBON_TOKEN(StartOfFile))
- // The end of the file.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileEnd, 0, CARBON_TOKEN(EndOfFile))
- // An invalid parse. Used to balance the parse tree. Always has an error.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(InvalidParse, 0,
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- // An empty declaration, such as `;`.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(EmptyDecl, 0,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- // A name in a non-expression context, such as a declaration.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, 0,
- CARBON_TOKEN(Identifier)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- // A name in an expression context.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(NameExpr, 0, CARBON_TOKEN(Identifier))
- // ----------------------------------------------------------------------------
- // The comments below follow this pattern:
- //
- // // Descriptive heading:
- // // Child1
- // // Child2
- // // Parent
- //
- // In this, `Child1`, `Child2`, and `Parent` are all kinds of parse nodes, which
- // are then defined using the `CARBON_PARSE_NODE_KIND_*` macros. They are
- // written in postorder, with the indentation showing the tree structure. See
- // tree.h for more information.
- //
- // A parse node kind may be preceded by:
- // - `_external_:` if this node is the child of multiple kinds of nodes and
- // is documented separately.
- // - `_optional_` if this node may be present or omitted in valid parses,
- // depending on which tokens are in the source code.
- //
- // There is generally a close correspondence between handling of tokens and the
- // creation of non-external nodes in a given block.
- // ----------------------------------------------------------------------------
- // The name of a package or library for `package`, `import`, and `library`.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageName, 0, CARBON_TOKEN(Identifier))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(LibraryName, 0, CARBON_TOKEN(StringLiteral))
- // `package`:
- // PackageIntroducer
- // _optional_ _external_: PackageName
- // _optional_ _external_: LibrarySpecifier
- // PackageApi or PackageImpl
- // PackageDirective
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageIntroducer, 0, CARBON_TOKEN(Package))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageApi, 0, CARBON_TOKEN(Api))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageImpl, 0, CARBON_TOKEN(Impl))
- CARBON_PARSE_NODE_KIND_BRACKET(PackageDirective, PackageIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Package)))
- // `import`:
- // ImportIntroducer
- // _optional_ _external_: PackageName
- // _optional_ _external_: LibrarySpecifier
- // ImportDirective
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ImportIntroducer, 0, CARBON_TOKEN(Import))
- CARBON_PARSE_NODE_KIND_BRACKET(ImportDirective, ImportIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Import)))
- // `library` as directive:
- // LibraryIntroducer
- // DefaultLibrary or _external_: LibraryName
- // LibraryDirective
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(DefaultLibrary, 0, CARBON_TOKEN(Default))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(LibraryIntroducer, 0, CARBON_TOKEN(Library))
- CARBON_PARSE_NODE_KIND_BRACKET(LibraryDirective, LibraryIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Library)))
- // `library` in `package` or `import`:
- // _external_: LibraryName
- // LibrarySpecifier
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(LibrarySpecifier, 1, CARBON_TOKEN(Library))
- // `namespace`:
- // NamespaceStart
- // _external_: Name or QualifiedDecl
- // Namespace
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamespaceStart, 0, CARBON_TOKEN(Namespace))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(Namespace, 2,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Namespace)))
- // A code block:
- // CodeBlockStart
- // _external_: statements
- // CodeBlock
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(CodeBlockStart, 0,
- CARBON_TOKEN(OpenCurlyBrace)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart,
- CARBON_TOKEN(CloseCurlyBrace)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- // `fn`:
- // FunctionIntroducer
- // _external_: Name or QualifiedDecl
- // _external_: ParamList
- // _external_: type expression
- // ReturnType
- // FunctionDefinitionStart
- // _external_: statements
- // FunctionDefinition
- //
- // The above is the structure for a definition; for a declaration,
- // FunctionDefinitionStart and later nodes are removed and replaced by
- // FunctionDecl.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(FunctionIntroducer, 0, CARBON_TOKEN(Fn))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnType, 1, CARBON_TOKEN(MinusGreater))
- CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinitionStart, FunctionIntroducer,
- CARBON_TOKEN(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinition, FunctionDefinitionStart,
- CARBON_TOKEN(CloseCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(FunctionDecl, FunctionIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Fn)))
- // A parameter list, possibly implicit:
- // [Implicit]ParamertListStart
- // _external_: [Generic]PatternBinding
- // ParamListComma
- // [Implicit]ParamList
- //
- // Exprs and ParamListComma may repeat with ParamListComma as a
- // separator.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParamListStart, 0, CARBON_TOKEN(OpenParen))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ImplicitParamListStart, 0,
- CARBON_TOKEN(OpenSquareBracket))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParamListComma, 0, CARBON_TOKEN(Comma))
- CARBON_PARSE_NODE_KIND_BRACKET(ParamList, ParamListStart,
- CARBON_TOKEN(CloseParen))
- CARBON_PARSE_NODE_KIND_BRACKET(ImplicitParamList, ImplicitParamListStart,
- CARBON_TOKEN(CloseSquareBracket))
- // An array type, such as `[i32; 3]` or `[i32;]`:
- // ArrayExprStart
- // _external_: type expression
- // ArrayExprSemi
- // _optional_ _external_: expression
- // ArrayExpr
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ArrayExprStart, 0,
- CARBON_TOKEN(OpenSquareBracket))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ArrayExprSemi, 2,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- CARBON_PARSE_NODE_KIND_BRACKET(ArrayExpr, ArrayExprSemi,
- CARBON_TOKEN(CloseSquareBracket))
- // A pattern binding, such as `name: Type`:
- // Name or SelfValueName
- // _external_: type expression
- // [Generic]PatternBinding
- // _optional_ Address
- // _optional_ Template
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PatternBinding, 2,
- CARBON_TOKEN(Colon)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(GenericPatternBinding, 2,
- CARBON_TOKEN(ColonExclaim))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(Address, 1, CARBON_TOKEN(Addr))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(Template, 1, CARBON_TOKEN(Template))
- // `let`:
- // LetIntroducer
- // _external_: PatternBinding
- // LetInitializer
- // _external_: expression
- // LetDecl
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetIntroducer, 0, CARBON_TOKEN(Let))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetInitializer, 0, CARBON_TOKEN(Equal))
- CARBON_PARSE_NODE_KIND_BRACKET(LetDecl, LetIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Let)))
- // `var` and `returned var`:
- // VariableIntroducer
- // _optional_ ReturnedModifier
- // _external_: PatternBinding
- // _optional_ VariableInitializer
- // _optional_ _external_: expression
- // VariableDecl
- //
- // The VariableInitializer and following expression are paired: either both will
- // be present, or neither will.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableIntroducer, 0,
- CARBON_TOKEN(Var)
- CARBON_IF_ERROR(CARBON_TOKEN(Returned)))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnedModifier, 0, CARBON_TOKEN(Returned))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableInitializer, 0, CARBON_TOKEN(Equal))
- CARBON_PARSE_NODE_KIND_BRACKET(VariableDecl, VariableIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Var)
- CARBON_TOKEN(Returned)))
- // An expression statement:
- // _external_: expression
- // ExprStatement
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ExprStatement, 1, CARBON_TOKEN(Semi))
- // `break`:
- // BreakStatementStart
- // BreakStatement
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatementStart, 0, CARBON_TOKEN(Break))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatement, 1,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Break)))
- // `continue`:
- // ContinueStatementStart
- // ContinueStatement
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatementStart, 0,
- CARBON_TOKEN(Continue))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatement, 1,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Continue)))
- // `return`:
- // ReturnStatementStart
- // _optional_ ReturnVarModifier or _external_: expression
- // ReturnStatement
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnStatementStart, 0,
- CARBON_TOKEN(Return))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnVarModifier, 0, CARBON_TOKEN(Var))
- CARBON_PARSE_NODE_KIND_BRACKET(ReturnStatement, ReturnStatementStart,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Return)))
- // `for`:
- // ForHeaderStart
- // VariableIntroducer
- // _external_: PatternBinding
- // ForIn
- // _external_: expression
- // ForHeader
- // _external_: CodeBlock
- // ForStatement
- //
- // Versus a normal `var`, ForIn replaces VariableDecl.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeaderStart, 0,
- CARBON_TOKEN(OpenParen)
- CARBON_IF_ERROR(CARBON_TOKEN(For)))
- CARBON_PARSE_NODE_KIND_BRACKET(ForIn, VariableIntroducer,
- CARBON_TOKEN(In)
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- CARBON_PARSE_NODE_KIND_BRACKET(ForHeader, ForHeaderStart,
- CARBON_TOKEN(CloseParen)
- CARBON_IF_ERROR(CARBON_TOKEN(For)))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForStatement, 2, CARBON_TOKEN(For))
- // `if` statement + `else`:
- // IfConditionStart
- // _external_: expression
- // IfCondition
- // _external_: CodeBlock
- // IfStatementElse
- // _external_: CodeBlock or IfStatement
- // IfStatement
- //
- // IfStatementElse and the following node are optional based on `else` presence.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfConditionStart, 0,
- CARBON_TOKEN(OpenParen)
- CARBON_IF_ERROR(CARBON_TOKEN(If)))
- CARBON_PARSE_NODE_KIND_BRACKET(IfCondition, IfConditionStart,
- CARBON_TOKEN(CloseParen)
- CARBON_IF_ERROR(CARBON_TOKEN(If)))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatementElse, 0, CARBON_TOKEN(Else))
- CARBON_PARSE_NODE_KIND_BRACKET(IfStatement, IfCondition, CARBON_TOKEN(If))
- // `while`:
- // WhileConditionStart
- // _external_: expression
- // WhileCondition
- // _external_: CodeBlock
- // WhileStatement
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileConditionStart, 0,
- CARBON_TOKEN(OpenParen))
- CARBON_PARSE_NODE_KIND_BRACKET(WhileCondition, WhileConditionStart,
- CARBON_TOKEN(CloseParen))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileStatement, 2, CARBON_TOKEN(While))
- // Index expressions, such as `a[1]`:
- // _external_: expression
- // IndexExprStart
- // _external_: expression
- // IndexExpr
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(IndexExprStart, 1,
- CARBON_TOKEN(OpenSquareBracket))
- CARBON_PARSE_NODE_KIND_BRACKET(IndexExpr, IndexExprStart,
- CARBON_TOKEN(CloseSquareBracket))
- // Parenthesized expressions, such as `(2)`:
- // ParenExprOrTupleLiteralStart
- // _external_: expression
- // ParenExpr
- //
- // Tuples, such as `(1, 2)`:
- // ParenExprOrTupleLiteralStart
- // _external_: expression
- // TupleLiteralComma
- // TupleLiteral
- //
- // Exprs and TupleLiteralComma may repeat with TupleLiteralComma as a
- // separator.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExprOrTupleLiteralStart, 0,
- CARBON_TOKEN(OpenParen))
- CARBON_PARSE_NODE_KIND_BRACKET(ParenExpr, ParenExprOrTupleLiteralStart,
- CARBON_TOKEN(CloseParen))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralComma, 0, CARBON_TOKEN(Comma))
- CARBON_PARSE_NODE_KIND_BRACKET(TupleLiteral, ParenExprOrTupleLiteralStart,
- CARBON_TOKEN(CloseParen))
- // Call expressions, such as `a()`:
- // _external_: expression
- // CallExprStart
- // _external_: expression
- // CallExprComma
- // CallExpr
- //
- // Exprs and CallExprComma may repeat with CallExprComma as a
- // separator.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExprStart, 1, CARBON_TOKEN(OpenParen))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExprComma, 0, CARBON_TOKEN(Comma))
- CARBON_PARSE_NODE_KIND_BRACKET(CallExpr, CallExprStart,
- CARBON_TOKEN(CloseParen))
- // A qualified declaration, such as `a.b`:
- // _external_: Name or QualifiedDecl
- // _external_: Name
- // QualifiedDecl
- //
- // TODO: This will eventually more general expressions, for example with
- // `GenericType(type_args).ChildType(child_type_args).Name`.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(QualifiedDecl, 2, CARBON_TOKEN(Period))
- // A member access expression, such as `a.b` or
- // `GetObject().(Interface.member)`:
- // _external_: lhs expression
- // _external_: rhs expression
- // QualifiedExpr
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(MemberAccessExpr, 2, CARBON_TOKEN(Period))
- // A pointer member access expression, such as `a->b` or
- // `GetObject()->(Interface.member)`:
- // _external_: lhs expression
- // _external_: rhs expression
- // QualifiedExpr
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PointerMemberAccessExpr, 2,
- CARBON_TOKEN(MinusGreater))
- // A value literal.
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolLiteralFalse, CARBON_TOKEN(False))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolLiteralTrue, CARBON_TOKEN(True))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(IntegerLiteral,
- CARBON_TOKEN(IntegerLiteral))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(FloatingPointLiteral,
- CARBON_TOKEN(RealLiteral))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(StringLiteral, CARBON_TOKEN(StringLiteral))
- // A type literal.
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolTypeLiteral, CARBON_TOKEN(Bool))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(IntegerTypeLiteral,
- CARBON_TOKEN(IntegerTypeLiteral))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(UnsignedIntegerTypeLiteral,
- CARBON_TOKEN(UnsignedIntegerTypeLiteral))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(FloatingPointTypeLiteral,
- CARBON_TOKEN(FloatingPointTypeLiteral))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(StringTypeLiteral,
- CARBON_TOKEN(StringTypeLiteral))
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(TypeTypeLiteral, CARBON_TOKEN(Type))
- // clang-format off
- // A prefix operator:
- // _external_: expression
- // PrefixOperator
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PrefixOperator, 1,
- CARBON_TOKEN(Star)
- CARBON_TOKEN(Amp)
- CARBON_TOKEN(Not)
- CARBON_TOKEN(Minus)
- CARBON_TOKEN(MinusMinus)
- CARBON_TOKEN(PlusPlus)
- CARBON_TOKEN(Caret)
- CARBON_TOKEN(Const))
- // An infix operator:
- // _external_: lhs expression
- // _external_: rhs expression
- // InfixOperator
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(InfixOperator, 2,
- CARBON_TOKEN(Amp)
- CARBON_TOKEN(AmpEqual)
- CARBON_TOKEN(And)
- CARBON_TOKEN(As)
- CARBON_TOKEN(Caret)
- CARBON_TOKEN(CaretEqual)
- CARBON_TOKEN(Equal)
- CARBON_TOKEN(EqualEqual)
- CARBON_TOKEN(ExclaimEqual)
- CARBON_TOKEN(Greater)
- CARBON_TOKEN(GreaterEqual)
- CARBON_TOKEN(GreaterGreater)
- CARBON_TOKEN(GreaterGreaterEqual)
- CARBON_TOKEN(Less)
- CARBON_TOKEN(LessEqual)
- CARBON_TOKEN(LessLess)
- CARBON_TOKEN(LessLessEqual)
- CARBON_TOKEN(Minus)
- CARBON_TOKEN(MinusEqual)
- CARBON_TOKEN(Or)
- CARBON_TOKEN(Percent)
- CARBON_TOKEN(PercentEqual)
- CARBON_TOKEN(Pipe)
- CARBON_TOKEN(PipeEqual)
- CARBON_TOKEN(Plus)
- CARBON_TOKEN(PlusEqual)
- CARBON_TOKEN(Slash)
- CARBON_TOKEN(SlashEqual)
- CARBON_TOKEN(Star)
- CARBON_TOKEN(StarEqual))
- // clang-format on
- // The first operand of a short-circuiting infix operator:
- // _external_: expression
- // ShortCircuitOperand
- // _external_: expression
- // _external_: InfixOperator
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ShortCircuitOperand, 1,
- CARBON_TOKEN(And) CARBON_TOKEN(Or))
- // A postfix operator:
- // _external_: expression
- // PostfixOperator
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(PostfixOperator, 1, CARBON_TOKEN(Star))
- // `if` expression + `then` + `else`:
- // _external_: expression
- // IfExprIf
- // _external_: expression
- // IfExprThen
- // _external_: expression
- // IfExprElse
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprIf, 1, CARBON_TOKEN(If))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprThen, 1, CARBON_TOKEN(Then))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprElse, 3,
- CARBON_TOKEN(Else)
- CARBON_IF_ERROR(CARBON_TOKEN(If)))
- // Struct literals, such as `{.a = 0}`:
- // StructLiteralOrStructTypeLiteralStart
- // _external_: Name
- // StructFieldDesignator
- // _external_: expression
- // StructFieldValue
- // StructComma
- // StructLiteral
- //
- // Struct type literals, such as `{.a: i32}`:
- // _external_: Name
- // StructFieldDesignator
- // _external_: type expression
- // StructFieldType
- // StructComma
- // StructTypeLiteral
- //
- // Elements (StructFieldValue and StructFieldType, respectively) and StructComma
- // may repeat with StructComma as a separator.
- //
- // When a valid StructFieldType or StructFieldValue cannot be formed, elements
- // may be replaced by StructFieldUnknown, which may have a preceding sibling
- // StructFieldDesignator if one was successfully parsed.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructLiteralOrStructTypeLiteralStart, 0,
- CARBON_TOKEN(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldDesignator, 1,
- CARBON_TOKEN(Period))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldValue, 2, CARBON_TOKEN(Equal))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldType, 2, CARBON_TOKEN(Colon))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldUnknown, 0,
- CARBON_IF_ERROR(CARBON_ANY_TOKEN))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructComma, 0, CARBON_TOKEN(Comma))
- CARBON_PARSE_NODE_KIND_BRACKET(StructLiteral,
- StructLiteralOrStructTypeLiteralStart,
- CARBON_TOKEN(CloseCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
- StructLiteralOrStructTypeLiteralStart,
- CARBON_TOKEN(CloseCurlyBrace))
- // `class`:
- // ClassIntroducer
- // _optional_ AbstractModifier or BaseModifier
- // _external_: Name or QualifiedDecl
- // ClassDefinitionStart
- // _external_: declarations
- // ClassDefinition
- //
- // The above is the structure for a definition; for a declaration,
- // ClassDefinitionStart and later nodes are removed and replaced by
- // ClassDecl.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(ClassIntroducer, 0, CARBON_TOKEN(Class))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(AbstractModifier, 0, CARBON_TOKEN(Abstract))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(BaseModifier, 0, CARBON_TOKEN(Base))
- CARBON_PARSE_NODE_KIND_BRACKET(ClassDefinitionStart, ClassIntroducer,
- CARBON_TOKEN(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(ClassDefinition, ClassDefinitionStart,
- CARBON_TOKEN(CloseCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(ClassDecl, ClassIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Class)))
- // `interface`:
- // InterfaceIntroducer
- // _external_: Name or QualifiedDecl
- // InterfaceDefinitionStart
- // _external_: declarations
- // InterfaceDefinition
- //
- // The above is the structure for a definition; for a declaration,
- // InterfaceDefinitionStart and later nodes are removed and replaced by
- // InterfaceDecl.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceIntroducer, 0,
- CARBON_TOKEN(Interface))
- CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinitionStart, InterfaceIntroducer,
- CARBON_TOKEN(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinition, InterfaceDefinitionStart,
- CARBON_TOKEN(CloseCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDecl, InterfaceIntroducer,
- CARBON_TOKEN(Semi)
- CARBON_IF_ERROR(CARBON_TOKEN(Interface)))
- // `constraint`:
- // NamedConstraintIntroducer
- // _external_: Name or QualifiedDecl
- // NamedConstraintDefinitionStart
- // _external_: declarations
- // NamedConstraintDefinition
- //
- // The above is the structure for a definition; for a declaration,
- // NamedConstraintDefinitionStart and later nodes are removed and replaced by
- // NamedConstraintDecl.
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamedConstraintIntroducer, 0,
- CARBON_TOKEN(Constraint))
- CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDefinitionStart,
- NamedConstraintIntroducer,
- CARBON_TOKEN(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDefinition,
- NamedConstraintDefinitionStart,
- CARBON_TOKEN(CloseCurlyBrace))
- CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDecl, NamedConstraintIntroducer,
- CARBON_TOKEN(Semi))
- // The `self` value and `Self` type identifier keywords. Typically of the form
- // `self: Self`:
- // SelfValueName
- // SelfValueNameExpr
- // SelfTypeNameExpr
- // PatternBinding
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfValueName, 0,
- CARBON_TOKEN(SelfValueIdentifier))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfValueNameExpr, 0,
- CARBON_TOKEN(SelfValueIdentifier))
- CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfTypeNameExpr, 0,
- CARBON_TOKEN(SelfTypeIdentifier))
- #undef CARBON_PARSE_NODE_KIND
- #undef CARBON_PARSE_NODE_KIND_BRACKET
- #undef CARBON_PARSE_NODE_KIND_CHILD_COUNT
- #undef CARBON_PARSE_NODE_KIND_TOKEN_LITERAL
- #undef CARBON_TOKEN
- #undef CARBON_ANY_TOKEN
- #undef CARBON_IF_ERROR
|