| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101 |
- // 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_STATE(Name)
- // Defines a parser state.
- //
- // Parser states may be clustered when there are multiple related variants,
- // named `StateAsVariant`. When there are variants, they share a common helper
- // function for most logic.
- //
- // The comments before each state describe the portion of the grammar that the
- // state is implementing, by giving an example of each kind of token sequence
- // that this state handles. In this example, `...` indicates a sequence of
- // tokens handled by some other state, and `???` indicates a sequence of invalid
- // tokens. A trailing `??? ;` indicates an attempt to skip to the end of the
- // declaration, which may or may not actually find a `;` token.
- //
- // The position in the token stream before the state is indicated by the caret
- // `^` on the line below the example, and all tokens consumed by the state are
- // underlined by the caret and following `~`s. If no tokens are consumed, the
- // caret will point between tokens. Therefore, the position in the token stream
- // after the state is the first token in the example after the underlined
- // region.
- //
- // Following each set of examples, the output states for that situation are
- // listed. States are numbered in the order they'll be executed; in other
- // words, `1` is the top of the state stack. The comment `(state done)`
- // indicates that no new states are added to the stack.
- #ifndef CARBON_PARSE_STATE
- #error "Must define the x-macro to use this file."
- #endif
- // Use CARBON_PARSE_STATE_VARIANTSN(State, Variant1, Variant2, ...) to generate
- // StateAsVariant1, StateAsVariant2, ... states.
- #define CARBON_PARSE_STATE_VARIANT(State, Variant) \
- CARBON_PARSE_STATE(State##As##Variant)
- #define CARBON_PARSE_STATE_VARIANTS2(State, Variant1, Variant2) \
- CARBON_PARSE_STATE_VARIANT(State, Variant1) \
- CARBON_PARSE_STATE_VARIANT(State, Variant2)
- #define CARBON_PARSE_STATE_VARIANTS3(State, Variant1, Variant2, Variant3) \
- CARBON_PARSE_STATE_VARIANT(State, Variant1) \
- CARBON_PARSE_STATE_VARIANTS2(State, Variant2, Variant3)
- #define CARBON_PARSE_STATE_VARIANTS4(State, Variant1, Variant2, Variant3, \
- Variant4) \
- CARBON_PARSE_STATE_VARIANT(State, Variant1) \
- CARBON_PARSE_STATE_VARIANTS3(State, Variant2, Variant3, Variant4)
- // Handles an index expression:
- //
- // a[0]
- // ^
- // 1. Expression
- // 2. IndexExpressionFinish
- CARBON_PARSE_STATE(IndexExpr)
- // Handles finishing the index expression.
- //
- // a[0]
- // ^
- // (state done)
- CARBON_PARSE_STATE(IndexExprFinish)
- // Handles an array expression.
- //
- // [T; N]
- // ^
- // 1. Expr
- // 2. ArrayExprSemi
- CARBON_PARSE_STATE(ArrayExpr)
- // Handles ';' in an array expression.
- //
- // [T;]
- // ^
- // 1. ArrayExprFinish
- //
- // [T; N]
- // ^
- // 1. Expr
- // 2. ArrayExprFinish
- CARBON_PARSE_STATE(ArrayExprSemi)
- // Handles finishing the array expression.
- //
- // [T;]
- // ^
- // [T; N]
- // ^
- // (state done)
- CARBON_PARSE_STATE(ArrayExprFinish)
- // Handles the `{` of a brace expression.
- //
- // {}
- // ^
- // 1. BraceExprFinishAsUnknown
- //
- // { ... }
- // ^
- // 1. BraceExprParamAsUnknown
- // 2. BraceExprFinishAsUnknown
- CARBON_PARSE_STATE(BraceExpr)
- // Handles a brace expression parameter. Note this will always start as unknown,
- // but should be known after the first valid parameter. All later inconsistent
- // parameters are invalid.
- //
- // { .foo ... }
- // ^
- // 1. PeriodAsStruct
- // 2. BraceExprParamAfterDesignatorAs(Type|Value|Unknown)
- //
- // { ???
- // ^
- // 1. BraceExprParamFinishAs(Type|Value|Unknown)
- CARBON_PARSE_STATE_VARIANTS3(BraceExprParam, Type, Value, Unknown)
- // Handles a brace expression parameter after the initial designator. This
- // should be at a `:` or `=`, depending on whether it's a type or value literal.
- //
- // { .foo = bar ... }
- // ^
- // 1. Expr
- // 2. BraceExprParamFinishAsValue
- //
- // { .foo: bar ... }
- // ^
- // 1. Expr
- // 2. BraceExprParamFinishAsType
- //
- // { .foo ???
- // ^
- // 1. BraceExprParamFinishAs(Type|Value|Unknown)
- CARBON_PARSE_STATE_VARIANTS3(BraceExprParamAfterDesignator, Type, Value,
- Unknown)
- // Handles the end of a brace expression parameter.
- //
- // { ... }
- // ^
- // (state done)
- //
- // { .foo = bar, ... }
- // ^
- // 1. BraceExprParamAsValue
- //
- // { .foo: bar, ... }
- // ^
- // 1. BraceExprParamAsType
- //
- // { ??? , ... }
- // ^
- // 1. BraceExprParamAsUnknown
- CARBON_PARSE_STATE_VARIANTS3(BraceExprParamFinish, Type, Value, Unknown)
- // Handles the `}` of a brace expression.
- //
- // { ... }
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(BraceExprFinish, Type, Value, Unknown)
- // Handles a call expression `(...)`.
- //
- // F()
- // ^
- // 1. CallExprFinish
- //
- // F( ...
- // ^
- // 1. Expr
- // 2. CallExprParamFinish
- // 3. CallExprFinish
- CARBON_PARSE_STATE(CallExpr)
- // Handles the `,` or `)` after a call parameter.
- //
- // F(a, ...)
- // ^
- // 1. Expr
- // 2. CallExprParamFinish
- //
- // F(a )
- // ^
- // (state done)
- CARBON_PARSE_STATE(CallExprParamFinish)
- // Handles finishing the call expression.
- //
- // F(a, b)
- // ^
- // (state done)
- CARBON_PARSE_STATE(CallExprFinish)
- // Handles processing at the `{` on a typical code block.
- //
- // if (cond) {
- // ^
- // 1. StatementScopeLoop
- // 2. CodeBlockFinish
- //
- // if (cond) ???
- // ^
- // 1. Statement
- // 2. CodeBlockFinish
- CARBON_PARSE_STATE(CodeBlock)
- // Handles processing at the `}` on a typical code block, after a statement
- // scope is done.
- //
- // if (cond) { ... }
- // ^
- // (state done)
- CARBON_PARSE_STATE(CodeBlockFinish)
- // Handles a declaration name and parameters, such as `Foo[...](...)`.
- //
- // Allowed parameters:
- // - None: `Foo` only.
- // - Optional: `Foo`, `Foo(...)`, or `Foo[...](...)`.
- // - Required: `Foo(...)` or `Foo[...](...)`.
- //
- // name . ...
- // ^~~~
- // 1. PeriodAsDecl
- // 2. DeclNameAndParamsAfterNameAs(None|Optional|Required)
- //
- // name ...
- // ^~~~
- // 1. DeclNameAndParamsAfterNameAs(None|Optional|Required)
- //
- // ???
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(DeclNameAndParams, None, Optional, Required)
- // Handles a declaration name between the main name and implicit parameters.
- //
- // name . ...
- // ^
- // 1. PeriodAsDecl
- // 2. DeclNameAndParamsAfterNameAs(None|Optional|Required)
- //
- // name [ ... ] (variant is not None)
- // ^
- // 1. ParamListAsImplicit
- // 2. DeclNameAndParamsAfterImplicit
- //
- // name ( ... ) (variant is not None)
- // ^
- // 1. ParamListAsRegular
- //
- // name ... (variant is not Required)
- // ^
- // (state done)
- //
- // name ??? (variant is Required)
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(DeclNameAndParamsAfterName, None, Optional,
- Required)
- // Handles regular parameters such as `(...)` for the general declaration case.
- // Only used after implicit parameters.
- //
- // name [ ... ] ( ... )
- // ^
- // 1. ParamListAsRegular
- //
- // name [ ... ] ???
- // ^
- // (state done)
- CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit)
- // Handles processing of a declaration scope. Things like fn, class, interface,
- // and so on.
- //
- // class ...
- // ^~~~~
- // abstract class ...
- // ^~~~~~~~~~~~~~
- // base class ...
- // ^~~~~~~~~~
- // 1. TypeAfterIntroducerAsClass
- // 2. DeclScopeLoop
- //
- // constraint ...
- // ^~~~~~~~~~
- // 1. TypeAfterIntroducerAsNamedConstraint
- // 2. DeclScopeLoop
- //
- // fn ...
- // ^
- // 1. FunctionIntroducer
- // 2. DeclScopeLoop
- //
- // interface ...
- // ^~~~~~~~~
- // 1. TypeAfterIntroducerAsInterface
- // 2. DeclScopeLoop
- //
- // namespace ...
- // ^
- // 1. Namespace
- // 2. DeclScopeLoop
- //
- // ;
- // ^
- // 1. DeclScopeLoop
- //
- // var ...
- // ^
- // 1. VarAsDecl
- // 2. DeclScopeLoop
- //
- // let ...
- // ^
- // 1. Let
- // 2. DeclScopeLoop
- //
- // ??? ;
- // ^~~~~
- // (state done)
- CARBON_PARSE_STATE(DeclScopeLoop)
- // Handles periods. Only does one `.<expression>` segment; the source is
- // responsible for handling chaining.
- //
- // The forms of this are:
- // - Qualified names in declarations.
- // - Member access expressions.
- // - Designated names in structs.
- //
- // Declarations and expressions have qualifiers such as `x.y`, while structs
- // have designators such as `.z`.
- //
- // . name
- // ^~~~~~
- // (state done)
- //
- // . ??? (??? consumed if it is a keyword)
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(Period, Decl, Expr, Struct)
- // Handles `->name` expressions. Identical to PeriodAsExpr except for the
- // leading token.
- //
- // -> name
- // ^~~~~~~
- // (state done)
- //
- // -> ??? (??? consumed if it is a keyword)
- // ^~
- // (state done)
- CARBON_PARSE_STATE(ArrowExpr)
- // Handles processing of an expression.
- //
- // if ...
- // ^~
- // 1. Expr
- // 2. IfExprCondition
- // 3. IfExprFinish
- //
- // <prefix operator> ...
- // ^~~~~~~~~~~~~~~~~
- // 1. Expr
- // 2. ExprLoopForPrefix
- //
- // ...
- // ^
- // 1. ExprInPostfix
- // 2. ExprLoop
- CARBON_PARSE_STATE(Expr)
- // Handles the initial part of postfix expressions, such as an identifier or
- // literal value, then proceeds to the loop.
- //
- // identifier
- // ^~~~~~~~~~
- // literal
- // ^~~~~~~
- // self
- // ^~~~
- // Self
- // ^~~~
- // 1. ExprInPostfixLoop
- //
- // {
- // ^
- // 1. BraceExpr
- // 2. ExprInPostfixLoop
- //
- // (
- // ^
- // 1. ParenExpr
- // 2. ExprInPostfixLoop
- //
- // [
- // ^
- // 1. ArrayExpr
- // 2. ExprInPostfixLoop
- //
- // ???
- // ^
- // (state done)
- CARBON_PARSE_STATE(ExprInPostfix)
- // Handles looping through elements following the initial postfix expression,
- // such as designators or parenthesized parameters.
- //
- // expr . ...
- // ^
- // 1. PeriodAsExpr
- // 2. ExprInPostfixLoop
- //
- // expr -> ...
- // ^
- // 1. ArrowExpr
- // 2. ExprInPostfixLoop
- //
- // expr ( ... )
- // ^
- // 1. CallExpr
- // 2. ExprInPostfixLoop
- //
- // expr [ ... ]
- // ^
- // 1. IndexExprStart
- // 2. ExprInPostfixLoop
- //
- // ...
- // ^
- // (state done)
- CARBON_PARSE_STATE(ExprInPostfixLoop)
- // Handles processing of an expression.
- //
- // expr <binary operator> ...
- // ^~~~~~~~~~~~~~~~~
- // 1. Expr
- // 2. ExprLoopForBinary
- //
- // expr <postfix operator>
- // ^~~~~~~~~~~~~~~~~~
- // 1. ExprLoop
- //
- // expr ...
- // ^
- // (state done)
- CARBON_PARSE_STATE(ExprLoop)
- // Completes an ExprLoop pass by adding an infix operator, then goes back
- // to ExprLoop.
- //
- // expr <binary operator> expr ...
- // ^
- // 1. ExprLoop
- CARBON_PARSE_STATE(ExprLoopForBinary)
- // Completes an ExprLoop pass by adding a prefix operator, then goes back
- // to ExprLoop.
- //
- // <prefix operator> expr ...
- // ^
- // 1. ExprLoop
- CARBON_PARSE_STATE(ExprLoopForPrefix)
- // Completes the condition of an `if` expression and handles the `then` token.
- //
- // if expr then ...
- // ^~~~
- // 1. Expr
- // 2. IfExprFinishThen
- //
- // if expr ???
- // ^
- // (state done)
- CARBON_PARSE_STATE(IfExprFinishCondition)
- // Completes the first alternative in an `if` expression and handles the `else`
- // token.
- //
- // if expr then expr else ...
- // ^~~~
- // 1. Expr
- // 2. IfExprFinishElse
- //
- // if expr then expr ???
- // ^
- // (state done)
- CARBON_PARSE_STATE(IfExprFinishThen)
- // Completes the second alternative in an `if` expression.
- //
- // if expr then expr else expr
- // ^
- // (state done)
- CARBON_PARSE_STATE(IfExprFinishElse)
- // Completes an IfExpr.
- //
- // if expr then expr else expr
- // ^
- // if ???
- // ^
- // (state done)
- CARBON_PARSE_STATE(IfExprFinish)
- // Handles the `;` for an expression statement, which is different from most
- // keyword statements.
- //
- // expr ;
- // ^
- // expr ??? ;
- // ^~~~~
- // (state done)
- CARBON_PARSE_STATE(ExprStatementFinish)
- // Handles a function's introducer.
- //
- // fn ...
- // ^~
- // 1. DeclNameAndParamsAsRequired
- // 2. FunctionAfterParams
- CARBON_PARSE_STATE(FunctionIntroducer)
- // Handles processing of a function's syntax after `)`, primarily the
- // possibility a `->` return type is there. Always enqueues signature finish
- // handling.
- //
- // fn F(...) -> ...
- // ^~
- // 1. Expr
- // 2. FunctionReturnTypeFinish
- // 3. FunctionSignatureFinish
- //
- // fn F(...) ...
- // ^
- // 1. FunctionSignatureFinish
- CARBON_PARSE_STATE(FunctionAfterParams)
- // Finishes a function return type.
- //
- // fn F(...) -> expr ...
- // ^
- // (state done)
- CARBON_PARSE_STATE(FunctionReturnTypeFinish)
- // Finishes a function signature. If it's a declaration, the function is done;
- // otherwise, this also starts definition processing.
- //
- // fn ... ;
- // ^
- // (state done)
- //
- // fn ... {
- // ^
- // 1. StatementScopeLoop
- // 2. FunctionDefinitionFinish
- //
- // fn ... ??? ;
- // ^~~~~
- // (state done)
- CARBON_PARSE_STATE(FunctionSignatureFinish)
- // Finishes a function definition.
- //
- // fn ... }
- // ^
- // fn ... ;
- // ^
- // (state done)
- CARBON_PARSE_STATE(FunctionDefinitionFinish)
- // Handles `import`.
- //
- // import pkgname [library "libname"] ;
- // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // import ??? ;
- // ^~~~~~~~~~~~
- // (state done)
- CARBON_PARSE_STATE(Import)
- // Handles `library` in directive form.
- //
- // Always:
- // (state done)
- CARBON_PARSE_STATE(Library)
- // Handles `namespace`.
- //
- // namespace ...
- // ^~~~~~~~~
- // 1. DeclNameAndParamsAsNone
- // 2. NamespaceFinish
- CARBON_PARSE_STATE(Namespace)
- // Handles `namespace` after the name.
- //
- // namespace ... ;
- // ^
- // namespace ... ??? ;
- // ^~~~~
- // (state done)
- CARBON_PARSE_STATE(NamespaceFinish)
- // Handles `package`.
- //
- // package pkgname [library "libname"] [api|impl] ;
- // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // package ??? ;
- // ^~~~~~~~~~~~~
- // (state done)
- CARBON_PARSE_STATE(Package)
- // Starts parameter parsing.
- //
- // ...
- // ^
- // 1. PatternAs(ImplicitParam|Param)
- // 2. ParamFinishAs(Implicit|Regular)
- CARBON_PARSE_STATE_VARIANTS2(Param, Implicit, Regular)
- // Finishes parsing a parameter, including the optional trailing `,`. If there
- // are more parameters, enqueues another parameter parsing state.
- //
- // ... , )
- // ^
- // (state done)
- //
- // ... , ...
- // ^
- // 1. ParamAs(Implicit|Regular)
- //
- // ...
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(ParamFinish, Implicit, Regular)
- // Handles processing of a parameter list `[` or `(`.
- //
- // ( ) (variant is Regular)
- // ^
- // [ ] (variant is Implicit)
- // ^
- // 1. ParamListFinishAs(Regular|Implicit)
- //
- // ( ... ) (variant is Regular)
- // ^
- // [ ... ] (variant is Implicit)
- // ^
- // 1. ParamAs(Regular|Implicit)
- // 2. ParamListFinishAs(Regular|Implicit)
- CARBON_PARSE_STATE_VARIANTS2(ParamList, Implicit, Regular)
- // Handles processing of a parameter list `]` or `)`.
- //
- // ( ... ) (variant is Regular)
- // ^
- // [ ... ] (variant is Implicit)
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(ParamListFinish, Implicit, Regular)
- // Handles the processing of a `(condition)` up through the expression.
- //
- // if/while { (invalid)
- // ^
- // 1. ParenConditionAs(If|While)Finish
- //
- // if/while ( ... )
- // ^
- // if/while ???
- // ^
- // 1. Expr
- // 2. ParenConditionAs(If|While)Finish
- CARBON_PARSE_STATE_VARIANTS2(ParenCondition, If, While)
- // Finishes the processing of a `(condition)` after the expression.
- //
- // if/while ( expr )
- // ^
- // if/while {
- // ^
- // if/while ??? {
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(ParenConditionFinish, If, While)
- // Handles the `(` of a parenthesized expression.
- //
- // ( )
- // ^
- // 1. ParenExprFinishAsTuple
- //
- // ( ... )
- // ^
- // 1. Expr
- // 2. ParenExprParamFinishAsUnknown
- // 3. ParenExprFinishAsNormal (SPECIAL: may be replaced)
- CARBON_PARSE_STATE(ParenExpr)
- // Handles the end of a parenthesized expression's parameter. This will start as
- // AsUnknown on the first parameter; if there are more, it switches to AsTuple
- // processing.
- //
- // ( ... , )
- // ^
- // (state done)
- // SPECIAL (variant is Unknown): parent becomes ParenExprFinishAsTuple
- //
- // ( ... , ... )
- // ^
- // 1. Expression
- // 2. ParenExpressionParamFinishAsTuple
- // SPECIAL (variant is Unknown): parent becomes ParenExprFinishAsTuple
- //
- // ...
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(ParenExprParamFinish, Unknown, Tuple)
- // Handles the `)` of a parenthesized expression.
- //
- // ( ... )
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(ParenExprFinish, Normal, Tuple)
- // Handles pattern parsing for a pattern, enqueuing type expression processing.
- // This covers parameter, `let`, and `var` support.
- //
- // template (variant is not Variable)
- // ^~~~~~~~
- // 4. PatternTemplate
- //
- // THEN
- //
- // addr (variant is not Variable)
- // ^~~~
- // 3. PatternAddress
- //
- // THEN
- //
- // name: ...
- // ^~~~~
- // self: ...
- // ^~~~~
- // 1. Expr
- // 2. PatternFinishAsRegular
- //
- // name:! ...
- // ^~~~~~
- // self:! ...
- // ^~~~~~
- // 1. Expr
- // 2. PatternFinishAsGeneric
- //
- // ???
- // ^
- // 1. PatternFinishAsRegular
- CARBON_PARSE_STATE_VARIANTS4(Pattern, ImplicitParam, Param, Variable,
- Let)
- // Handles `addr` in a pattern.
- //
- // addr name: type
- // ^
- // (state done)
- CARBON_PARSE_STATE(PatternAddress)
- // Handles `template` in a pattern.
- //
- // template name:! type
- // ^
- // (state done)
- CARBON_PARSE_STATE(PatternTemplate)
- // Finishes pattern processing.
- //
- // name: type
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(PatternFinish, Generic, Regular)
- // Handles a single statement. While typically within a statement block, this
- // can also be used for error recovery where we expect a statement block and
- // are missing braces.
- //
- // break ...
- // ^~~~~
- // 1. StatementBreakFinish
- //
- // continue ...
- // ^~~~~~~~
- // 1. StatementContinueFinish
- //
- // for ...
- // ^~~
- // 1. StatementForHeader
- // 2. StatementForFinish
- //
- // if ...
- // ^
- // 1. StatementIf
- //
- // return ...
- // ^
- // 1. StatementReturn
- //
- // var ...
- // ^
- // 1. VarAsDecl
- //
- // returned ...
- // ^
- // 1. VarAsReturned
- //
- // while ...
- // ^
- // 1. StatementWhile
- //
- // ...
- // ^
- // 1. Expr
- // 2. ExprStatementFinish
- CARBON_PARSE_STATE(Statement)
- // Handles `break` processing at the `;`.
- //
- // break ;
- // ^
- // (state done)
- CARBON_PARSE_STATE(StatementBreakFinish)
- // Handles `continue` processing at the `;`.
- //
- // continue ;
- // ^
- // (state done)
- CARBON_PARSE_STATE(StatementContinueFinish)
- // Handles `for` processing of `(var`, proceeding to a pattern before
- // continuing.
- //
- // for ( var ... )
- // ^
- // 1. VarAsFor
- // 2. StatementForHeaderIn
- //
- // for ( ???
- // ^
- // for ( ??? in ...
- // ^~~~~~~~
- // for ??? in ...
- // ^~~~~~
- // for ???
- // ^
- // 1. StatementForHeaderIn
- CARBON_PARSE_STATE(StatementForHeader)
- // Handles `for` processing of `in`, proceeding to an expression before
- // continuing.
- //
- // for ( ... in ... )
- // ^
- // 1. Expr
- // 2. StatementForHeaderFinish
- CARBON_PARSE_STATE(StatementForHeaderIn)
- // Handles `for` processing of `)`, proceeding to the statement block.
- //
- // for ( ... ) ...
- // ^
- // 1. CodeBlock
- CARBON_PARSE_STATE(StatementForHeaderFinish)
- // Handles `for` processing after the final `}`.
- //
- // for ( ... ) { ... }
- // ^
- // (state done)
- CARBON_PARSE_STATE(StatementForFinish)
- // Handles `if` processing at the start.
- //
- // if ...
- // ^~
- // 1. ParenConditionAsIf
- // 2. StatementIfConditionFinish
- CARBON_PARSE_STATE(StatementIf)
- // Handles `if` processing between the condition and start of the first code
- // block.
- //
- // if ( ... ) ...
- // ^
- // 1. CodeBlock
- // 2. StatementIfThenBlockFinish
- CARBON_PARSE_STATE(StatementIfConditionFinish)
- // Handles `if` processing after the end of the first code block, with the
- // optional `else`.
- //
- // if ( ... ) { ... } else if ...
- // ^~~~
- // 1. StatementIf
- // 2. StatementIfElseBlockFinish
- //
- // if ( ... ) { ... } else ...
- // ^~~~
- // 1. CodeBlock
- // 2. StatementIfElseBlockFinish
- //
- // if ( ... ) { ... } ...
- // (state done)
- CARBON_PARSE_STATE(StatementIfThenBlockFinish)
- // Handles `if` processing after a provided `else` code block.
- //
- // if ( ... ) { ... } else { ... }
- // ^
- // (state done)
- CARBON_PARSE_STATE(StatementIfElseBlockFinish)
- // Handles `return` processing.
- //
- // return ;
- // ^~~~~~
- // 1. StatementReturnFinish
- //
- // return var ...
- // ^~~~~~~~~~
- // 1. StatementReturnFinish
- //
- // return ...
- // ^~~~~~
- // 1. Expr
- // 2. StatementReturnFinish
- CARBON_PARSE_STATE(StatementReturn)
- // Handles `return` processing at the `;`.
- //
- // return ... ;
- // ^
- // (state done)
- CARBON_PARSE_STATE(StatementReturnFinish)
- // Handles processing of statements within a scope.
- //
- // { ... }
- // ^
- // (state done)
- //
- // { ... ... }
- // ^
- // 1. Statement
- // 2. StatementScopeLoop
- CARBON_PARSE_STATE(StatementScopeLoop)
- // Handles `while` processing.
- //
- // while ...
- // ^~~~~
- // 1. ParenConditionAsWhile
- // 2. StatementWhileConditionFinish
- CARBON_PARSE_STATE(StatementWhile)
- // Handles `while` processing between the condition and start of the code block.
- //
- // while ( ... ) ...
- // ^
- // 1. CodeBlock
- // 2. StatementWhileBlockFinish
- CARBON_PARSE_STATE(StatementWhileConditionFinish)
- // Handles `while` processing after the end of the code block.
- //
- // while ( ... ) { ... }
- // ^
- // (state done)
- CARBON_PARSE_STATE(StatementWhileBlockFinish)
- // Handles parsing after the declaration scope of a type.
- //
- // class/interface/constraint { ... }
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(TypeDefinitionFinish, Class, Interface,
- NamedConstraint)
- // Handles processing of a type after its introducer.
- //
- // class/interface/constraint ...
- // ^~~~~~~~~~~~~~~~~~~~~~~~~~
- // 1. DeclNameAndParamsAsOptional
- // 2. TypeAfterParamsAs(Class|Interface|NamedConstraint)
- CARBON_PARSE_STATE_VARIANTS3(TypeAfterIntroducer, Class, Interface, NamedConstraint)
- // Handles processing of a type after its optional parameters.
- //
- // class/interface/constraint name ( ... ) {
- // ^
- // 1. DeclScopeLoop
- // 2. TypeDefinitionFinishAs(Class|Interface|NamedConstraint)
- //
- // class/interface/constraint name ( ... ) ;
- // ^
- // class/interface/constraint name ( ... ) ???
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(TypeAfterParams, Class, Interface, NamedConstraint)
- // Handles the start of a `var` or `returned var`.
- //
- // var ... (variant is not Returned)
- // ^~~
- // 1. PatternAsVariable
- // 2. VarAfterPattern
- // 3. VarFinishAs(Decl|For)
- //
- // returned var ... (variant is Returned)
- // ^~~~~~~~~~~~
- // 1. PatternAsVariable
- // 2. VarAfterPattern
- // 3. VarFinishAsDecl
- //
- // returned ??? ; (variant is Returned)
- // ^~~~~~~~~~~~~~
- // (state done)
- CARBON_PARSE_STATE_VARIANTS3(Var, Decl, Returned, For)
- // Handles `var` after the pattern, either followed by an initializer or the
- // semicolon.
- //
- // var ... = ...
- // ^
- // var ... ??? = ...
- // ^~~~~
- // 1. Expr
- //
- // var ... ...
- // ^
- // (state done)
- CARBON_PARSE_STATE(VarAfterPattern)
- // Handles `var` parsing at the end.
- //
- // var ... ; (variant is Semicolon)
- // ^
- // var ... ??? ; (variant is Semicolon)
- // ^~~~~
- // (state done)
- //
- // var ... in (variant is For)
- // ^~
- // var ... : (variant is For, invalid)
- // ^
- // (state done)
- CARBON_PARSE_STATE_VARIANTS2(VarFinish, Decl, For)
- // Handles the start of a `let`.
- //
- // let ...
- // ^~~
- // 1. PatternAsLet
- // 2. LetAfterPattern
- // 3. LetFinish
- CARBON_PARSE_STATE(Let)
- // Handles `let` after the pattern, followed by an initializer.
- //
- // let ... = ...
- // ^
- // let ... ??? = ...
- // ^~~~~
- // 1. Expr
- //
- // let ... ??? ;
- // ^~~
- // (state done)
- CARBON_PARSE_STATE(LetAfterPattern)
- // Handles `let` parsing at the end.
- //
- // let ... ;
- // ^
- // (state done)
- CARBON_PARSE_STATE(LetFinish)
- #undef CARBON_PARSE_STATE
|