| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
- // 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.
- // - CARBON_PARSE_NODE_KIND_WITH_TOKEN(Name, LexTokenKind)
- // Defines a parse node kind and specifies its corresponding token kind.
- // - CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Name)
- // Defines a parse node for a prefix operator, with the Name as token.
- // - CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Name)
- // Defines a parse node for an infix operator, with the Name as token.
- // - CARBON_PARSE_NODE_KIND_POSTFIX_OPERATOR(Name)
- // Defines a parse node for a postfix operator, with the Name as token.
- // - CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, LexTokenKind)
- // Defines a parse node that corresponds to a token that is a single-token
- // literal. The token is wrapped for LexTokenKinds.
- // - CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name)
- // A token-based modifier. The Name is the TokenKind, and will be appended
- // with "Modifier" for the parse kind.
- //
- // LexTokenKind indicates the token kind required on a valid node.
- // It will be either `kind_name` to indicate it's required even if the node is
- // an error, or `CARBON_IF_VALID(kind_name)` to indicate that the kind is
- // not enforced on error. A token kind of `Error` may be used if the kind should
- // never be enforced; this should only be used when the node is either not in
- // trees (`Placeholder`) or is always invalid (such as `InvalidParse`).
- //
- // 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. See typed_nodes.h for
- // the expected tree structure under each node kind.
- #if !(defined(CARBON_PARSE_NODE_KIND) || \
- defined(CARBON_PARSE_NODE_KIND_WITH_TOKEN))
- #error "Must define CARBON_PARSE_NODE_KIND family x-macros to use this file."
- #endif
- // The WITH_TOKEN macro will use CARBON_PARSE_NODE_KIND by default when
- // undefined.
- #ifndef CARBON_PARSE_NODE_KIND_WITH_TOKEN
- #define CARBON_PARSE_NODE_KIND_WITH_TOKEN(Name, LexTokenKind) \
- CARBON_PARSE_NODE_KIND(Name)
- #endif
- // This is expected to be used with something like:
- //
- // // Use x-macros to handle modifier cases.
- // #define CARBON_PARSE_NODE_KIND(...)
- // #define CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Name, ...) <code>
- #ifndef CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR
- #define CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Name) \
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PrefixOperator##Name, Name)
- #endif
- // This is expected to be used with something like:
- //
- // // Use x-macros to handle modifier cases.
- // #define CARBON_PARSE_NODE_KIND(...)
- // #define CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Name, ...) <code>
- #ifndef CARBON_PARSE_NODE_KIND_INFIX_OPERATOR
- #define CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Name) \
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InfixOperator##Name, Name)
- #endif
- // This is expected to be used with something like:
- //
- // // Use x-macros to handle modifier cases.
- // #define CARBON_PARSE_NODE_KIND(...)
- // #define CARBON_PARSE_NODE_KIND_POSTFIX_OPERATOR(Name, ...) <code>
- #ifndef CARBON_PARSE_NODE_KIND_POSTFIX_OPERATOR
- #define CARBON_PARSE_NODE_KIND_POSTFIX_OPERATOR(Name) \
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PostfixOperator##Name, 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_WITH_TOKEN(Name, LexTokenKinds)
- #endif
- // This is expected to be used with something like:
- //
- // // Use x-macros to handle modifier cases.
- // #define CARBON_PARSE_NODE_KIND(...)
- // #define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name, ...) <code>
- #ifndef CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER
- #define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name) \
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(Name##Modifier, Name)
- #endif
- // The start of the file.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(FileStart, FileStart)
- // The end of the file.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(FileEnd, FileEnd)
- // An invalid parse. Used to balance the parse tree. Always has an error.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InvalidParse, Error)
- // An invalid subtree. Always has an error.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InvalidParseStart, Error)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InvalidParseSubtree, Error)
- // A placeholder node to be replaced; it will never exist in a valid parse tree.
- // Its token kind is not enforced even when valid.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(Placeholder, Error)
- // An empty declaration, such as `;`.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(EmptyDecl, CARBON_IF_VALID(Semi))
- // An identifier name in a non-expression context, such as a declaration.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IdentifierName, CARBON_IF_VALID(Identifier))
- // An identifier name in an expression context.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IdentifierNameExpr, Identifier)
- // The `self` value and `Self` type identifier keywords. Typically of the form
- // `self: Self`.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(SelfValueName, SelfValueIdentifier)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(SelfValueNameExpr, SelfValueIdentifier)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(SelfTypeNameExpr, SelfTypeIdentifier)
- // The `base` value keyword, introduced by `base: B`. Typically referenced in
- // an expression, as in `x.base` or `{.base = ...}`, but can also be used as a
- // declared name, as in `{.base: partial B}`.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BaseName, Base)
- // The `package` keyword in an expression.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PackageExpr, Package)
- // ----------------------------------------------------------------------------
- // 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:
- // - `_optional_` if this node (or nodes) may be present or omitted in valid
- // parses, depending on which tokens are in the source code.
- // - `_repeated_` if this node (or nodes) may be repeated or omitted in valid
- // parses, depending on which tokens are in the source code.
- // - `_external_:` if this node is the child of multiple kinds of nodes and
- // is documented separately.
- //
- // 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_WITH_TOKEN(PackageName, Identifier)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LibraryName, StringLiteral)
- // `package`:
- // PackageIntroducer
- // _repeated_ _external_: modifier
- // _optional_ _external_: PackageName
- // _optional_ _external_: LibrarySpecifier
- // PackageDecl
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PackageIntroducer, Package)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PackageDecl, CARBON_IF_VALID(Semi))
- // `import`:
- // ImportIntroducer
- // _repeated_ _external_: modifier
- // _optional_ _external_: PackageName
- // _optional_ _external_: LibrarySpecifier
- // ImportDecl
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImportIntroducer, Import)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImportDecl, CARBON_IF_VALID(Semi))
- // `library` as declaration:
- // LibraryIntroducer
- // _repeated_ _external_: modifier
- // DefaultLibrary or _external_: LibraryName
- // LibraryDecl
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(DefaultLibrary, Default)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LibraryIntroducer, Library)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LibraryDecl, CARBON_IF_VALID(Semi))
- // `library` in `package` or `import`:
- // _external_: LibraryName or DefaultLibrary
- // LibrarySpecifier
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LibrarySpecifier, Library)
- // Declaration names.
- //
- // _repeated_: NameQualifier
- // _external_: IdentifierName
- // _optional_ _external_: ImplicitParamList
- // _optional_ _external_: TuplePattern
- // _declaration name_
- //
- // _external_: IdentifierName
- // _optional_ _external_: ImplicitParamList
- // _optional_ _external_: TuplePattern
- // NameQualifier
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(NameQualifier, CARBON_IF_VALID(Period))
- // `export`:
- // ExportIntroducer
- // _external_: _declaration name_
- // ExportDecl
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ExportIntroducer, Export)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ExportDecl, CARBON_IF_VALID(Semi))
- // `namespace`:
- // NamespaceStart
- // _repeated_ _external_: modifier
- // _external_: _declaration name_
- // Namespace
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(NamespaceStart, Namespace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(Namespace, CARBON_IF_VALID(Semi))
- // A code block:
- // CodeBlockStart
- // _repeated_ _external_: statement
- // CodeBlock
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(CodeBlockStart,
- CARBON_IF_VALID(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(CodeBlock, CARBON_IF_VALID(CloseCurlyBrace))
- // `fn` declarations start with a function signature:
- //
- // FunctionIntroducer
- // _repeated_ _external_: modifier
- // _external_: _declaration name_
- // ReturnType
- // _function signature_
- //
- // There are three forms of function declaration:
- //
- // _function signature_
- // FunctionDecl
- //
- // _function signature_
- // FunctionDefinitionStart
- // _repeated_ _external_: statement
- // FunctionDefinition
- //
- // _function signature_
- // BuiltinFunctionDefinitionStart
- // BuiltinName
- // BuiltinFunctionDefinition
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(FunctionIntroducer, Fn)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ReturnType, MinusGreater)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(FunctionDefinitionStart, OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(FunctionDefinition, CloseCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(FunctionDecl, CARBON_IF_VALID(Semi))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BuiltinFunctionDefinitionStart, Equal)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BuiltinName, StringLiteral)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BuiltinFunctionDefinition,
- CARBON_IF_VALID(Semi))
- // `alias`:
- // AliasIntroducer
- // _repeated_ _external_: modifier
- // _external_: _declaration name_
- // AliasInitializer
- // _external_: expression
- // Alias
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(AliasIntroducer, Alias)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(AliasInitializer, Equal)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(Alias, CARBON_IF_VALID(Semi))
- // A tuple pattern:
- // TuplePatternStart
- // _external_: [Generic]BindingPattern
- // PatternListComma
- // _repeated_
- // TuplePattern
- //
- // Patterns and PatternListComma may repeat with PatternListComma as a
- // separator.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(TuplePatternStart, OpenParen)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PatternListComma, Comma)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(TuplePattern, CloseParen)
- // An implicit parameter list:
- // ImplicitParamListStart
- // _external_: [Generic]BindingPattern
- // PatternListComma
- // _repeated_
- // ImplicitParamList
- //
- // Patterns and PatternListComma may repeat with PatternListComma as a
- // separator.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplicitParamListStart, OpenSquareBracket)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplicitParamList, CloseSquareBracket)
- // An array type, such as `[i32; 3]` or `[i32;]`:
- // ArrayExprStart
- // _external_: type expression
- // ArrayExprSemi
- // _optional_ _external_: expression
- // ArrayExpr
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ArrayExprStart, OpenSquareBracket)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ArrayExprSemi, CARBON_IF_VALID(Semi))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ArrayExpr, CloseSquareBracket)
- // A binding pattern, such as `name: Type`:
- // IdentifierName or SelfValueName
- // _external_: type expression
- // [Generic]BindingPattern
- // _optional_ Addr
- // _optional_ Template
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BindingPattern, CARBON_IF_VALID(Colon))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(CompileTimeBindingPattern, ColonExclaim)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(Addr, Addr)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(Template, Template)
- // `let` declarations, including associated constant declarations:
- // LetIntroducer
- // _repeated_ _external_: modifier
- // _external_: BindingPattern or TuplePattern
- // LetInitializer
- // _external_: expression
- // _optional_
- // LetDecl
- //
- // Modifier keywords only appear for `let` declarations, not `let` statements.
- //
- // The LetInitializer and following expression are paired: either both will be
- // present, or neither will.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LetIntroducer, Let)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LetInitializer, Equal)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(LetDecl, CARBON_IF_VALID(Semi))
- // `var` and `returned var`:
- // VariableIntroducer
- // _repeated_ _external_: modifier
- // _optional_ ReturnedModifier
- // _external_: BindingPattern or TuplePattern
- // VariableInitializer
- // _external_: expression
- // _optional_
- // VariableDecl
- //
- // Access and declaration modifier keywords only appear for `var` declarations,
- // whereas the returned modifier only appears on `var` statements.
- //
- // The VariableInitializer and following expression are paired: either both will
- // be present, or neither will.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(VariableIntroducer, CARBON_IF_VALID(Var))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ReturnedModifier, Returned)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(VariableInitializer, Equal)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(VariableDecl, CARBON_IF_VALID(Semi))
- // An expression statement:
- // _external_: expression
- // ExprStatement
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ExprStatement, CARBON_IF_VALID(Semi))
- // `break`:
- // BreakStatementStart
- // BreakStatement
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BreakStatementStart, Break)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BreakStatement, CARBON_IF_VALID(Semi))
- // `continue`:
- // ContinueStatementStart
- // ContinueStatement
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ContinueStatementStart, Continue)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ContinueStatement, CARBON_IF_VALID(Semi))
- // `return`:
- // ReturnStatementStart
- // _optional_ ReturnVarModifier or _external_: expression
- // ReturnStatement
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ReturnStatementStart, Return)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ReturnVarModifier, Var)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ReturnStatement, CARBON_IF_VALID(Semi))
- // `for`:
- // ForHeaderStart
- // VariableIntroducer
- // _external_: BindingPattern
- // ForIn
- // _external_: expression
- // ForHeader
- // _external_: CodeBlock
- // ForStatement
- //
- // Versus a normal `var`, ForIn replaces VariableDecl.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ForHeaderStart, CARBON_IF_VALID(OpenParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ForIn, CARBON_IF_VALID(In))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ForHeader, CARBON_IF_VALID(CloseParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ForStatement, 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_WITH_TOKEN(IfConditionStart, CARBON_IF_VALID(OpenParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IfCondition, CARBON_IF_VALID(CloseParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IfStatementElse, Else)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IfStatement, If)
- // `while`:
- // WhileConditionStart
- // _external_: expression
- // WhileCondition
- // _external_: CodeBlock
- // WhileStatement
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(WhileConditionStart,
- CARBON_IF_VALID(OpenParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(WhileCondition, CARBON_IF_VALID(CloseParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(WhileStatement, While)
- // Index expressions, such as `a[1]`:
- // _external_: expression
- // IndexExprStart
- // _external_: expression
- // IndexExpr
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IndexExprStart, OpenSquareBracket)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IndexExpr, CloseSquareBracket)
- // Parenthesized single expressions, such as `(2)`:
- // ParenExprStart
- // _external_: expression
- // ParenExpr
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ParenExprStart, OpenParen)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ParenExpr, CloseParen)
- // Tuples, such as `(1, 2)`:
- // TupleLiteralStart
- // _external_: expression
- // TupleLiteralComma
- // _repeated_
- // TupleLiteral
- //
- // Expressions and TupleLiteralComma may repeat with TupleLiteralComma as a
- // separator.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(TupleLiteralStart, OpenParen)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(TupleLiteralComma, Comma)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(TupleLiteral, CloseParen)
- // Call expressions, such as `a()`:
- // _external_: expression
- // CallExprStart
- // _external_: expression
- // CallExprComma
- // _repeated_
- // CallExpr
- //
- // Exprs and CallExprComma may repeat with CallExprComma as a separator.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(CallExprStart, OpenParen)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(CallExprComma, Comma)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(CallExpr, CloseParen)
- // A member access expression, such as `a.b` or
- // `GetObject().(Interface.member)`:
- // _external_: lhs expression
- // _external_: rhs expression
- // MemberAccessExpr
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MemberAccessExpr, Period)
- // A pointer member access expression, such as `a->b` or
- // `GetObject()->(Interface.member)`:
- // _external_: lhs expression
- // _external_: rhs expression
- // PointerMemberAccessExpr
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(PointerMemberAccessExpr, MinusGreater)
- // A value literal.
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolLiteralFalse, False)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolLiteralTrue, True)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(IntLiteral, IntLiteral)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(RealLiteral, RealLiteral)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(StringLiteral, StringLiteral)
- // A type literal.
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolTypeLiteral, Bool)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(IntTypeLiteral, IntTypeLiteral)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(UnsignedIntTypeLiteral,
- UnsignedIntTypeLiteral)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(FloatTypeLiteral, FloatTypeLiteral)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(StringTypeLiteral, StringTypeLiteral)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(TypeTypeLiteral, Type)
- CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(AutoTypeLiteral, Auto)
- // A prefix operator, such as `not`:
- // _external_: expression
- // PrefixOperator<name>
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Amp)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Caret)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Const)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Not)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Minus)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(MinusMinus)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(PlusPlus)
- CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR(Star)
- // An infix operator, such as `+`:
- // _external_: lhs expression
- // _external_: rhs expression
- // InfixOperator<name>
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Amp)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(AmpEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(As)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Caret)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(CaretEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Equal)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(EqualEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(ExclaimEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Greater)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(GreaterEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(GreaterGreater)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(GreaterGreaterEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Less)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(LessEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(LessEqualGreater)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(LessLess)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(LessLessEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Minus)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(MinusEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Percent)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(PercentEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Pipe)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(PipeEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Plus)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(PlusEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Slash)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(SlashEqual)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(Star)
- CARBON_PARSE_NODE_KIND_INFIX_OPERATOR(StarEqual)
- // A postfix operator, currently only `*`:
- // _external_: expression
- // PostfixOperator<name>
- CARBON_PARSE_NODE_KIND_POSTFIX_OPERATOR(Star)
- // A short-circuiting infix operator, such as `and`:
- // _external_: expression
- // ShortCircuitOperand(And|Or)
- // _external_: expression
- // ShortCircuitOperand(And|Or)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ShortCircuitOperandAnd, And)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ShortCircuitOperandOr, Or)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ShortCircuitOperatorAnd, And)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ShortCircuitOperatorOr, Or)
- // `if` expression + `then` + `else`:
- // _external_: expression
- // IfExprIf
- // _external_: expression
- // IfExprThen
- // _external_: expression
- // IfExprElse
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IfExprIf, If)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IfExprThen, Then)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(IfExprElse, CARBON_IF_VALID(Else))
- // Struct literals, such as `{.a = 0}`:
- // StructLiteralStart
- // _external_: IdentifierName or BaseName
- // StructFieldDesignator
- // _external_: expression
- // StructField
- // StructComma
- // _repeated_
- // StructLiteral
- //
- // Struct type literals, such as `{.a: i32}`:
- // StructTypeLiteralStart
- // _external_: IdentifierName or BaseName
- // StructFieldDesignator
- // _external_: type expression
- // StructTypeField
- // StructComma
- // _repeated_
- // StructTypeLiteral
- //
- // Elements (StructField and StructTypeField, respectively) and StructComma
- // may repeat with StructComma as a separator.
- //
- // When a valid StructTypeField or StructField cannot be formed, elements
- // may be replaced by InvalidParse, which may have a preceding sibling
- // StructFieldDesignator if one was successfully parsed.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructLiteralStart, OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructTypeLiteralStart, OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructFieldDesignator, Period)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructField, Equal)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructTypeField, Colon)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructComma, Comma)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructLiteral, CloseCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(StructTypeLiteral, CloseCurlyBrace)
- // Various modifiers. These are all a single token.
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Abstract)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Base)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Default)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Export)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Extend)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Extern)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Final)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Impl)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Private)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Protected)
- CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Virtual)
- // `class`:
- // ClassIntroducer
- // _repeated_ _external_: modifier
- // _external_: _declaration name_
- // _optional_ _external_: ImplicitParamList
- // _optional_ _external_: TuplePattern
- // 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_WITH_TOKEN(ClassIntroducer, Class)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ClassDefinitionStart, OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ClassDefinition, CloseCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ClassDecl, CARBON_IF_VALID(Semi))
- // `adapt`:
- // AdaptIntroducer
- // _repeated_ _external_: modifier
- // _external_: expression
- // AdaptDecl
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(AdaptIntroducer, Adapt)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(AdaptDecl, CARBON_IF_VALID(Semi))
- // `base`:
- // BaseIntroducer
- // _repeated_ _external_: modifier
- // BaseColon
- // _external_: expression
- // BaseDecl
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BaseIntroducer, Base)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BaseColon, Colon)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(BaseDecl, CARBON_IF_VALID(Semi))
- // `interface`:
- // InterfaceIntroducer
- // _repeated_ _external_: modifier
- // _external_: _declaration name_
- // _optional_ _external_: ImplicitParamList
- // _optional_ _external_: TuplePattern
- // 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_WITH_TOKEN(InterfaceIntroducer, Interface)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InterfaceDefinitionStart, OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InterfaceDefinition, CloseCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(InterfaceDecl, CARBON_IF_VALID(Semi))
- // `impl ... as`:
- // ImplIntroducer
- // _repeated_ _external_: modifier
- // _optional_ _external_: ImplForall
- // _optional_ _external_: expression
- // _external_: DefaultSelfImplAs or TypeImplAs
- // _external_: expression
- // ImplDefinitionStart
- // _external_: declarations
- // ImplDefinition
- //
- // The above is the structure for a definition; for a declaration,
- // ImplDefinitionStart and later nodes are removed and replaced by
- // ImplDecl.
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplIntroducer, Impl)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplDefinitionStart, OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplDefinition, CloseCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplDecl, CARBON_IF_VALID(Semi))
- // `forall ...`:
- // _external_: ImplicitParamList
- // ImplForall
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ImplForall, Forall)
- // `... as`:
- // _external_: expression
- // TypeImplAs
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(TypeImplAs, As)
- // `as` without a type before it
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(DefaultSelfImplAs, As)
- // `constraint`:
- // NamedConstraintIntroducer
- // _repeated_ _external_: modifier
- // _external_: _declaration name_
- // _optional_ _external_: ImplicitParamList
- // _optional_ _external_: TuplePattern
- // 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_WITH_TOKEN(NamedConstraintIntroducer, Constraint)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(NamedConstraintDefinitionStart,
- OpenCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(NamedConstraintDefinition, CloseCurlyBrace)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(NamedConstraintDecl, CARBON_IF_VALID(Semi))
- // `choice`:
- // ChoiceIntroducer
- // _external_: _declaration name_
- // ChoiceDefinitionStart
- // _optional_ _external_: ChoiceAlternativeList
- // ChoiceDefinition
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ChoiceIntroducer, Choice)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ChoiceDefinitionStart,
- CARBON_IF_VALID(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ChoiceDefinition,
- CARBON_IF_VALID(CloseCurlyBrace))
- // Choice alternative list:
- // _external_: IdentifierName
- // _optional_ _external_ : TuplePattern
- // _optional_: ChoiceAlternativeListComma
- // _repeated_
- // ChoiceAlternativeList
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(ChoiceAlternativeListComma, Comma)
- // `match`:
- // MatchIntroducer
- // MatchConditionStart
- // _external_: expression
- // MatchCondition
- // MatchStatementStart
- // _repeated_ _external_: MatchCase
- // _optional_ _external_: MatchStatementDefault
- // MatchStatement
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchIntroducer, Match)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchConditionStart,
- CARBON_IF_VALID(OpenParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCondition, CARBON_IF_VALID(CloseParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchStatementStart,
- CARBON_IF_VALID(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchStatement,
- CARBON_IF_VALID(CloseCurlyBrace))
- // `case`:
- // MatchCaseIntroducer
- // _external_: Pattern
- // MatchCaseGuardIntroducer
- // MatchCaseGuardStart
- // _external_: expression
- // MatchCaseGuard
- // MatchCaseEqualGreater
- // MatchCaseStart
- // _repeated_ _external_: statement
- // MatchCase
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCaseIntroducer, Case)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCaseGuardIntroducer, If)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCaseGuardStart,
- CARBON_IF_VALID(OpenParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCaseGuard, CARBON_IF_VALID(CloseParen))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCaseEqualGreater,
- CARBON_IF_VALID(EqualGreater))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCaseStart,
- CARBON_IF_VALID(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchCase, CARBON_IF_VALID(CloseCurlyBrace))
- // `default`:
- // MatchDefaultIntroducer
- // MatchDefaultEqualGreater
- // MatchDefaultStart
- // _repeated_ _external_: statement
- // MatchDefault
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchDefaultIntroducer, Default)
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchDefaultEqualGreater,
- CARBON_IF_VALID(EqualGreater))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchDefaultStart,
- CARBON_IF_VALID(OpenCurlyBrace))
- CARBON_PARSE_NODE_KIND_WITH_TOKEN(MatchDefault,
- CARBON_IF_VALID(CloseCurlyBrace))
- #undef CARBON_PARSE_NODE_KIND
- #undef CARBON_PARSE_NODE_KIND_WITH_TOKEN
- #undef CARBON_PARSE_NODE_KIND_INFIX_OPERATOR
- #undef CARBON_PARSE_NODE_KIND_POSTFIX_OPERATOR
- #undef CARBON_PARSE_NODE_KIND_PREFIX_OPERATOR
- #undef CARBON_PARSE_NODE_KIND_TOKEN_LITERAL
- #undef CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER
- #undef CARBON_IF_VALID
|