2022-04-01 15:12:25 +00:00
|
|
|
// Rust Un-Grammar.
|
|
|
|
//
|
|
|
|
// This grammar specifies the structure of Rust's concrete syntax tree.
|
|
|
|
// It does not specify parsing rules (ambiguities, precedence, etc are out of scope).
|
|
|
|
// Tokens are processed -- contextual keywords are recognised, compound operators glued.
|
|
|
|
//
|
|
|
|
// Legend:
|
|
|
|
//
|
|
|
|
// // -- comment
|
|
|
|
// Name = -- non-terminal definition
|
2024-07-17 08:04:45 +00:00
|
|
|
// 'ident' -- keyword or punct token (terminal)
|
|
|
|
// '?ident' -- contextual keyword (terminal)
|
2024-07-17 08:49:12 +00:00
|
|
|
// too)
|
2024-07-17 08:04:45 +00:00
|
|
|
// '#ident' -- generic token (terminal)
|
|
|
|
// '@ident' -- literal token (terminal)
|
2022-04-01 15:12:25 +00:00
|
|
|
// A B -- sequence
|
|
|
|
// A | B -- alternation
|
|
|
|
// A* -- zero or more repetition
|
|
|
|
// A? -- zero or one repetition
|
|
|
|
// (A) -- same as A
|
|
|
|
// label:A -- suggested name for field of AST node
|
|
|
|
|
|
|
|
//*************************//
|
2024-07-17 08:04:45 +00:00
|
|
|
// Paths //
|
2022-04-01 15:12:25 +00:00
|
|
|
//*************************//
|
|
|
|
|
|
|
|
Name =
|
2024-07-17 08:04:45 +00:00
|
|
|
'#ident' | 'self'
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
NameRef =
|
2024-07-17 08:04:45 +00:00
|
|
|
'#ident' | '@int_number' | 'self' | 'super' | 'crate' | 'Self'
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
Lifetime =
|
2024-07-17 08:04:45 +00:00
|
|
|
'#lifetime_ident'
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
Path =
|
|
|
|
(qualifier:Path '::')? segment:PathSegment
|
|
|
|
|
|
|
|
PathSegment =
|
|
|
|
'::'? NameRef
|
|
|
|
| NameRef GenericArgList?
|
|
|
|
| NameRef ParamList RetType?
|
2023-11-12 03:20:14 +00:00
|
|
|
| '<' Type ('as' PathType)? '>'
|
2022-04-01 15:12:25 +00:00
|
|
|
|
2024-07-17 08:04:45 +00:00
|
|
|
|
|
|
|
//*************************//
|
|
|
|
// Generics //
|
|
|
|
//*************************//
|
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
GenericArgList =
|
|
|
|
'::'? '<' (GenericArg (',' GenericArg)* ','?)? '>'
|
|
|
|
|
|
|
|
GenericArg =
|
|
|
|
TypeArg
|
|
|
|
| AssocTypeArg
|
|
|
|
| LifetimeArg
|
|
|
|
| ConstArg
|
|
|
|
|
|
|
|
TypeArg =
|
|
|
|
Type
|
|
|
|
|
|
|
|
AssocTypeArg =
|
2023-05-06 11:29:13 +00:00
|
|
|
NameRef
|
|
|
|
(GenericArgList | ParamList RetType?)?
|
|
|
|
(':' TypeBoundList | ('=' Type | ConstArg))
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
LifetimeArg =
|
|
|
|
Lifetime
|
|
|
|
|
|
|
|
ConstArg =
|
|
|
|
Expr
|
|
|
|
|
2024-07-17 08:04:45 +00:00
|
|
|
GenericParamList =
|
|
|
|
'<' (GenericParam (',' GenericParam)* ','?)? '>'
|
|
|
|
|
|
|
|
GenericParam =
|
|
|
|
ConstParam
|
|
|
|
| LifetimeParam
|
|
|
|
| TypeParam
|
|
|
|
|
|
|
|
TypeParam =
|
|
|
|
Attr* Name (':' TypeBoundList?)?
|
|
|
|
('=' default_type:Type)?
|
|
|
|
|
|
|
|
ConstParam =
|
|
|
|
Attr* 'const' Name ':' Type
|
|
|
|
('=' default_val:ConstArg)?
|
|
|
|
|
|
|
|
LifetimeParam =
|
|
|
|
Attr* Lifetime (':' TypeBoundList?)?
|
|
|
|
|
|
|
|
WhereClause =
|
|
|
|
'where' predicates:(WherePred (',' WherePred)* ','?)
|
|
|
|
|
|
|
|
WherePred =
|
|
|
|
('for' GenericParamList)? (Lifetime | Type) ':' TypeBoundList?
|
|
|
|
|
|
|
|
|
|
|
|
//*************************//
|
|
|
|
// Macro //
|
|
|
|
//*************************//
|
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
MacroCall =
|
|
|
|
Attr* Path '!' TokenTree ';'?
|
|
|
|
|
|
|
|
TokenTree =
|
|
|
|
'(' ')'
|
|
|
|
| '{' '}'
|
|
|
|
| '[' ']'
|
|
|
|
|
|
|
|
MacroItems =
|
|
|
|
Item*
|
|
|
|
|
|
|
|
MacroStmts =
|
|
|
|
statements:Stmt*
|
|
|
|
Expr?
|
|
|
|
|
2024-07-17 08:04:45 +00:00
|
|
|
Attr =
|
|
|
|
'#' '!'? '[' Meta ']'
|
|
|
|
|
|
|
|
Meta =
|
|
|
|
'unsafe' '(' Path ('=' Expr | TokenTree)? ')'
|
|
|
|
| Path ('=' Expr | TokenTree)?
|
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
//*************************//
|
|
|
|
// Items //
|
|
|
|
//*************************//
|
|
|
|
|
|
|
|
SourceFile =
|
2024-07-17 08:04:45 +00:00
|
|
|
'#shebang'?
|
2022-04-01 15:12:25 +00:00
|
|
|
Attr*
|
|
|
|
Item*
|
|
|
|
|
|
|
|
Item =
|
|
|
|
Const
|
|
|
|
| Enum
|
|
|
|
| ExternBlock
|
|
|
|
| ExternCrate
|
|
|
|
| Fn
|
|
|
|
| Impl
|
|
|
|
| MacroCall
|
|
|
|
| MacroRules
|
|
|
|
| MacroDef
|
|
|
|
| Module
|
|
|
|
| Static
|
|
|
|
| Struct
|
|
|
|
| Trait
|
2023-03-03 15:23:56 +00:00
|
|
|
| TraitAlias
|
2022-04-01 15:12:25 +00:00
|
|
|
| TypeAlias
|
|
|
|
| Union
|
|
|
|
| Use
|
|
|
|
|
|
|
|
MacroRules =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'?macro_rules' '!' Name
|
2022-04-01 15:12:25 +00:00
|
|
|
TokenTree
|
|
|
|
|
|
|
|
MacroDef =
|
|
|
|
Attr* Visibility?
|
|
|
|
'macro' Name args:TokenTree?
|
|
|
|
body:TokenTree
|
|
|
|
|
|
|
|
Module =
|
|
|
|
Attr* Visibility?
|
|
|
|
'mod' Name
|
|
|
|
(ItemList | ';')
|
|
|
|
|
|
|
|
ItemList =
|
|
|
|
'{' Attr* Item* '}'
|
|
|
|
|
|
|
|
ExternCrate =
|
|
|
|
Attr* Visibility?
|
|
|
|
'extern' 'crate' NameRef Rename? ';'
|
|
|
|
|
|
|
|
Rename =
|
|
|
|
'as' (Name | '_')
|
|
|
|
|
|
|
|
Use =
|
|
|
|
Attr* Visibility?
|
|
|
|
'use' UseTree ';'
|
|
|
|
|
|
|
|
UseTree =
|
|
|
|
(Path? '::')? ('*' | UseTreeList)
|
|
|
|
| Path Rename?
|
|
|
|
|
|
|
|
UseTreeList =
|
|
|
|
'{' (UseTree (',' UseTree)* ','?)? '}'
|
|
|
|
|
|
|
|
Fn =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'?default'? 'const'? 'async'? 'unsafe'? Abi?
|
2022-04-01 15:12:25 +00:00
|
|
|
'fn' Name GenericParamList? ParamList RetType? WhereClause?
|
|
|
|
(body:BlockExpr | ';')
|
|
|
|
|
|
|
|
Abi =
|
2024-07-17 09:11:30 +00:00
|
|
|
'extern' '@string'?
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
ParamList =
|
|
|
|
'('(
|
|
|
|
SelfParam
|
|
|
|
| (SelfParam ',')? (Param (',' Param)* ','?)?
|
|
|
|
)')'
|
|
|
|
| '|' (Param (',' Param)* ','?)? '|'
|
|
|
|
|
|
|
|
SelfParam =
|
|
|
|
Attr* (
|
|
|
|
('&' Lifetime?)? 'mut'? Name
|
|
|
|
| 'mut'? Name ':' Type
|
|
|
|
)
|
|
|
|
|
|
|
|
Param =
|
|
|
|
Attr* (
|
|
|
|
Pat (':' Type)?
|
|
|
|
| Type
|
|
|
|
| '...'
|
|
|
|
)
|
|
|
|
|
|
|
|
RetType =
|
|
|
|
'->' Type
|
|
|
|
|
|
|
|
TypeAlias =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'?default'?
|
2022-04-01 15:12:25 +00:00
|
|
|
'type' Name GenericParamList? (':' TypeBoundList?)? WhereClause?
|
|
|
|
('=' Type)? ';'
|
|
|
|
|
|
|
|
Struct =
|
|
|
|
Attr* Visibility?
|
|
|
|
'struct' Name GenericParamList? (
|
|
|
|
WhereClause? (RecordFieldList | ';')
|
|
|
|
| TupleFieldList WhereClause? ';'
|
|
|
|
)
|
|
|
|
|
|
|
|
RecordFieldList =
|
|
|
|
'{' fields:(RecordField (',' RecordField)* ','?)? '}'
|
|
|
|
|
|
|
|
RecordField =
|
|
|
|
Attr* Visibility?
|
|
|
|
Name ':' Type
|
|
|
|
|
|
|
|
TupleFieldList =
|
|
|
|
'(' fields:(TupleField (',' TupleField)* ','?)? ')'
|
|
|
|
|
|
|
|
TupleField =
|
|
|
|
Attr* Visibility?
|
|
|
|
Type
|
|
|
|
|
|
|
|
FieldList =
|
|
|
|
RecordFieldList
|
|
|
|
| TupleFieldList
|
|
|
|
|
|
|
|
Enum =
|
|
|
|
Attr* Visibility?
|
|
|
|
'enum' Name GenericParamList? WhereClause?
|
|
|
|
VariantList
|
|
|
|
|
|
|
|
VariantList =
|
|
|
|
'{' (Variant (',' Variant)* ','?)? '}'
|
|
|
|
|
|
|
|
Variant =
|
|
|
|
Attr* Visibility?
|
|
|
|
Name FieldList? ('=' Expr)?
|
|
|
|
|
|
|
|
Union =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'?union' Name GenericParamList? WhereClause?
|
2022-04-01 15:12:25 +00:00
|
|
|
RecordFieldList
|
|
|
|
|
|
|
|
// A Data Type.
|
|
|
|
//
|
|
|
|
// Not used directly in the grammar, but handy to have anyway.
|
|
|
|
Adt =
|
|
|
|
Enum
|
|
|
|
| Struct
|
|
|
|
| Union
|
|
|
|
|
|
|
|
Const =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'?default'?
|
2022-04-01 15:12:25 +00:00
|
|
|
'const' (Name | '_') ':' Type
|
|
|
|
('=' body:Expr)? ';'
|
|
|
|
|
|
|
|
Static =
|
|
|
|
Attr* Visibility?
|
|
|
|
'static' 'mut'? Name ':' Type
|
|
|
|
('=' body:Expr)? ';'
|
|
|
|
|
|
|
|
Trait =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'unsafe'? '?auto'?
|
2022-11-11 14:25:15 +00:00
|
|
|
'trait' Name GenericParamList?
|
2023-03-03 15:23:56 +00:00
|
|
|
(':' TypeBoundList?)? WhereClause? AssocItemList
|
|
|
|
|
|
|
|
TraitAlias =
|
|
|
|
Attr* Visibility?
|
|
|
|
'trait' Name GenericParamList? '=' TypeBoundList? WhereClause? ';'
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
AssocItemList =
|
|
|
|
'{' Attr* AssocItem* '}'
|
|
|
|
|
|
|
|
AssocItem =
|
|
|
|
Const
|
|
|
|
| Fn
|
|
|
|
| MacroCall
|
|
|
|
| TypeAlias
|
|
|
|
|
|
|
|
Impl =
|
|
|
|
Attr* Visibility?
|
2024-07-17 08:04:45 +00:00
|
|
|
'?default'? 'unsafe'?
|
2022-04-01 15:12:25 +00:00
|
|
|
'impl' GenericParamList? ('const'? '!'? trait:Type 'for')? self_ty:Type WhereClause?
|
|
|
|
AssocItemList
|
|
|
|
|
|
|
|
ExternBlock =
|
|
|
|
Attr* 'unsafe'? Abi ExternItemList
|
|
|
|
|
|
|
|
ExternItemList =
|
|
|
|
'{' Attr* ExternItem* '}'
|
|
|
|
|
|
|
|
ExternItem =
|
|
|
|
Fn
|
|
|
|
| MacroCall
|
|
|
|
| Static
|
|
|
|
| TypeAlias
|
|
|
|
|
|
|
|
Visibility =
|
|
|
|
'pub' ('(' 'in'? Path ')')?
|
|
|
|
|
|
|
|
|
|
|
|
//****************************//
|
|
|
|
// Statements and Expressions //
|
|
|
|
//****************************//
|
|
|
|
|
|
|
|
Stmt =
|
|
|
|
';'
|
|
|
|
| ExprStmt
|
|
|
|
| Item
|
|
|
|
| LetStmt
|
|
|
|
|
|
|
|
LetStmt =
|
|
|
|
Attr* 'let' Pat (':' Type)?
|
|
|
|
'=' initializer:Expr
|
|
|
|
LetElse?
|
|
|
|
';'
|
|
|
|
|
|
|
|
LetElse =
|
|
|
|
'else' BlockExpr
|
|
|
|
|
|
|
|
ExprStmt =
|
|
|
|
Expr ';'?
|
|
|
|
|
|
|
|
Expr =
|
|
|
|
ArrayExpr
|
2023-09-05 08:36:35 +00:00
|
|
|
| AsmExpr
|
2022-04-01 15:12:25 +00:00
|
|
|
| AwaitExpr
|
|
|
|
| BinExpr
|
|
|
|
| BlockExpr
|
|
|
|
| BreakExpr
|
|
|
|
| CallExpr
|
|
|
|
| CastExpr
|
|
|
|
| ClosureExpr
|
|
|
|
| ContinueExpr
|
|
|
|
| FieldExpr
|
|
|
|
| ForExpr
|
2023-09-05 08:36:35 +00:00
|
|
|
| FormatArgsExpr
|
2022-04-01 15:12:25 +00:00
|
|
|
| IfExpr
|
|
|
|
| IndexExpr
|
|
|
|
| Literal
|
|
|
|
| LoopExpr
|
2022-04-05 15:42:07 +00:00
|
|
|
| MacroExpr
|
2022-04-01 15:12:25 +00:00
|
|
|
| MatchExpr
|
|
|
|
| MethodCallExpr
|
2023-09-05 08:36:35 +00:00
|
|
|
| OffsetOfExpr
|
2022-04-01 15:12:25 +00:00
|
|
|
| ParenExpr
|
|
|
|
| PathExpr
|
|
|
|
| PrefixExpr
|
|
|
|
| RangeExpr
|
|
|
|
| RecordExpr
|
|
|
|
| RefExpr
|
|
|
|
| ReturnExpr
|
2023-06-07 16:30:31 +00:00
|
|
|
| BecomeExpr
|
2022-04-01 15:12:25 +00:00
|
|
|
| TryExpr
|
|
|
|
| TupleExpr
|
|
|
|
| WhileExpr
|
|
|
|
| YieldExpr
|
2022-12-28 23:17:13 +00:00
|
|
|
| YeetExpr
|
2022-04-01 15:12:25 +00:00
|
|
|
| LetExpr
|
|
|
|
| UnderscoreExpr
|
|
|
|
|
2023-09-05 08:36:35 +00:00
|
|
|
OffsetOfExpr =
|
2024-07-17 08:04:45 +00:00
|
|
|
Attr* '?builtin' '#' '?offset_of' '(' Type ',' fields:(NameRef ('.' NameRef)* ) ')'
|
2023-09-05 08:36:35 +00:00
|
|
|
|
|
|
|
AsmExpr =
|
2024-07-17 08:04:45 +00:00
|
|
|
Attr* '?builtin' '#' '?asm' '(' Expr ')'
|
2023-09-05 08:36:35 +00:00
|
|
|
|
|
|
|
FormatArgsExpr =
|
2024-07-17 08:04:45 +00:00
|
|
|
Attr* '?builtin' '#' '?format_args' '('
|
2023-09-05 17:06:15 +00:00
|
|
|
template:Expr
|
|
|
|
(',' args:(FormatArgsArg (',' FormatArgsArg)* ','?)? )?
|
|
|
|
')'
|
|
|
|
|
|
|
|
FormatArgsArg =
|
|
|
|
(Name '=')? Expr
|
2023-09-05 08:36:35 +00:00
|
|
|
|
2022-04-05 15:42:07 +00:00
|
|
|
MacroExpr =
|
|
|
|
MacroCall
|
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
Literal =
|
|
|
|
Attr* value:(
|
2024-07-17 08:04:45 +00:00
|
|
|
'@int_number' | '@float_number'
|
|
|
|
| '@string' | '@raw_string'
|
|
|
|
| '@byte_string' | '@raw_byte_string'
|
|
|
|
| '@c_string' | '@raw_c_string'
|
|
|
|
| '@char' | '@byte'
|
2022-04-01 15:12:25 +00:00
|
|
|
| 'true' | 'false'
|
|
|
|
)
|
|
|
|
|
|
|
|
PathExpr =
|
|
|
|
Attr* Path
|
|
|
|
|
|
|
|
StmtList =
|
|
|
|
'{'
|
|
|
|
Attr*
|
|
|
|
statements:Stmt*
|
|
|
|
tail_expr:Expr?
|
|
|
|
'}'
|
|
|
|
|
|
|
|
RefExpr =
|
2024-07-17 08:04:45 +00:00
|
|
|
Attr* '&' (('?raw' 'const'?)| ('?raw'? 'mut') ) Expr
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
TryExpr =
|
|
|
|
Attr* Expr '?'
|
|
|
|
|
|
|
|
BlockExpr =
|
2024-07-17 08:49:12 +00:00
|
|
|
Attr* Label? ('try' | 'unsafe' | ('async' 'move'?) | ('gen' 'move'?) | 'const') StmtList
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
PrefixExpr =
|
|
|
|
Attr* op:('-' | '!' | '*') Expr
|
|
|
|
|
|
|
|
BinExpr =
|
|
|
|
Attr*
|
|
|
|
lhs:Expr
|
|
|
|
op:(
|
|
|
|
'||' | '&&'
|
|
|
|
| '==' | '!=' | '<=' | '>=' | '<' | '>'
|
|
|
|
| '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&'
|
|
|
|
| '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^='
|
|
|
|
)
|
|
|
|
rhs:Expr
|
|
|
|
|
|
|
|
CastExpr =
|
|
|
|
Attr* Expr 'as' Type
|
|
|
|
|
|
|
|
ParenExpr =
|
|
|
|
Attr* '(' Attr* Expr ')'
|
|
|
|
|
|
|
|
ArrayExpr =
|
|
|
|
Attr* '[' Attr* (
|
|
|
|
(Expr (',' Expr)* ','?)?
|
|
|
|
| Expr ';' Expr
|
|
|
|
) ']'
|
|
|
|
|
|
|
|
IndexExpr =
|
|
|
|
Attr* base:Expr '[' index:Expr ']'
|
|
|
|
|
|
|
|
TupleExpr =
|
|
|
|
Attr* '(' Attr* fields:(Expr (',' Expr)* ','?)? ')'
|
|
|
|
|
|
|
|
RecordExpr =
|
|
|
|
Path RecordExprFieldList
|
|
|
|
|
|
|
|
RecordExprFieldList =
|
|
|
|
'{'
|
|
|
|
Attr*
|
|
|
|
fields:(RecordExprField (',' RecordExprField)* ','?)?
|
|
|
|
('..' spread:Expr?)?
|
|
|
|
'}'
|
|
|
|
|
|
|
|
RecordExprField =
|
|
|
|
Attr* (NameRef ':')? Expr
|
|
|
|
|
|
|
|
CallExpr =
|
|
|
|
Attr* Expr ArgList
|
|
|
|
|
|
|
|
ArgList =
|
|
|
|
'(' args:(Expr (',' Expr)* ','?)? ')'
|
|
|
|
|
|
|
|
MethodCallExpr =
|
|
|
|
Attr* receiver:Expr '.' NameRef GenericArgList? ArgList
|
|
|
|
|
|
|
|
FieldExpr =
|
|
|
|
Attr* Expr '.' NameRef
|
|
|
|
|
|
|
|
ClosureExpr =
|
2024-07-17 08:49:12 +00:00
|
|
|
Attr* ClosureBinder? 'const'? 'static'? 'async'? 'gen'? 'move'? ParamList RetType?
|
2022-04-01 15:12:25 +00:00
|
|
|
body:Expr
|
|
|
|
|
2024-07-17 08:49:12 +00:00
|
|
|
ClosureBinder =
|
|
|
|
'for' GenericParamList
|
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
IfExpr =
|
|
|
|
Attr* 'if' condition:Expr then_branch:BlockExpr
|
|
|
|
('else' else_branch:(IfExpr | BlockExpr))?
|
|
|
|
|
|
|
|
LoopExpr =
|
|
|
|
Attr* Label? 'loop'
|
|
|
|
loop_body:BlockExpr
|
|
|
|
|
|
|
|
ForExpr =
|
|
|
|
Attr* Label? 'for' Pat 'in' iterable:Expr
|
|
|
|
loop_body:BlockExpr
|
|
|
|
|
|
|
|
WhileExpr =
|
|
|
|
Attr* Label? 'while' condition:Expr
|
|
|
|
loop_body:BlockExpr
|
|
|
|
|
|
|
|
Label =
|
|
|
|
Lifetime ':'
|
|
|
|
|
|
|
|
BreakExpr =
|
|
|
|
Attr* 'break' Lifetime? Expr?
|
|
|
|
|
|
|
|
ContinueExpr =
|
|
|
|
Attr* 'continue' Lifetime?
|
|
|
|
|
|
|
|
RangeExpr =
|
|
|
|
Attr* start:Expr? op:('..' | '..=') end:Expr?
|
|
|
|
|
|
|
|
MatchExpr =
|
|
|
|
Attr* 'match' Expr MatchArmList
|
|
|
|
|
|
|
|
MatchArmList =
|
|
|
|
'{'
|
|
|
|
Attr*
|
|
|
|
arms:MatchArm*
|
|
|
|
'}'
|
|
|
|
|
|
|
|
MatchArm =
|
|
|
|
Attr* Pat guard:MatchGuard? '=>' Expr ','?
|
|
|
|
|
|
|
|
MatchGuard =
|
|
|
|
'if' condition:Expr
|
|
|
|
|
|
|
|
ReturnExpr =
|
|
|
|
Attr* 'return' Expr?
|
|
|
|
|
2023-06-07 16:30:31 +00:00
|
|
|
BecomeExpr =
|
|
|
|
Attr* 'become' Expr
|
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
YieldExpr =
|
|
|
|
Attr* 'yield' Expr?
|
|
|
|
|
2022-12-28 23:17:13 +00:00
|
|
|
YeetExpr =
|
2024-07-17 08:04:45 +00:00
|
|
|
Attr* 'do' '?yeet' Expr?
|
2022-12-28 23:17:13 +00:00
|
|
|
|
2022-04-01 15:12:25 +00:00
|
|
|
LetExpr =
|
|
|
|
Attr* 'let' Pat '=' Expr
|
|
|
|
|
|
|
|
UnderscoreExpr =
|
|
|
|
Attr* '_'
|
|
|
|
|
|
|
|
AwaitExpr =
|
|
|
|
Attr* Expr '.' 'await'
|
|
|
|
|
|
|
|
//*************************//
|
|
|
|
// Types //
|
|
|
|
//*************************//
|
|
|
|
|
|
|
|
Type =
|
|
|
|
ArrayType
|
|
|
|
| DynTraitType
|
|
|
|
| FnPtrType
|
|
|
|
| ForType
|
|
|
|
| ImplTraitType
|
|
|
|
| InferType
|
|
|
|
| MacroType
|
|
|
|
| NeverType
|
|
|
|
| ParenType
|
|
|
|
| PathType
|
|
|
|
| PtrType
|
|
|
|
| RefType
|
|
|
|
| SliceType
|
|
|
|
| TupleType
|
|
|
|
|
|
|
|
ParenType =
|
|
|
|
'(' Type ')'
|
|
|
|
|
|
|
|
NeverType =
|
|
|
|
'!'
|
|
|
|
|
|
|
|
MacroType =
|
|
|
|
MacroCall
|
|
|
|
|
|
|
|
PathType =
|
|
|
|
Path
|
|
|
|
|
|
|
|
TupleType =
|
|
|
|
'(' fields:(Type (',' Type)* ','?)? ')'
|
|
|
|
|
|
|
|
PtrType =
|
|
|
|
'*' ('const' | 'mut') Type
|
|
|
|
|
|
|
|
RefType =
|
|
|
|
'&' Lifetime? 'mut'? Type
|
|
|
|
|
|
|
|
ArrayType =
|
2023-06-08 20:17:45 +00:00
|
|
|
'[' Type ';' ConstArg ']'
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
SliceType =
|
|
|
|
'[' Type ']'
|
|
|
|
|
|
|
|
InferType =
|
|
|
|
'_'
|
|
|
|
|
|
|
|
FnPtrType =
|
|
|
|
'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType?
|
|
|
|
|
|
|
|
ForType =
|
|
|
|
'for' GenericParamList Type
|
|
|
|
|
|
|
|
ImplTraitType =
|
|
|
|
'impl' TypeBoundList
|
|
|
|
|
|
|
|
DynTraitType =
|
2023-05-06 11:29:13 +00:00
|
|
|
'dyn'? TypeBoundList
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
TypeBoundList =
|
|
|
|
bounds:(TypeBound ('+' TypeBound)* '+'?)
|
|
|
|
|
|
|
|
TypeBound =
|
|
|
|
Lifetime
|
2024-02-16 16:16:34 +00:00
|
|
|
| ('~' 'const' | 'const')? 'async'? '?'? Type
|
2024-07-24 09:42:20 +00:00
|
|
|
| 'use' GenericParamList
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
//************************//
|
|
|
|
// Patterns //
|
|
|
|
//************************//
|
|
|
|
|
|
|
|
Pat =
|
|
|
|
IdentPat
|
|
|
|
| BoxPat
|
|
|
|
| RestPat
|
|
|
|
| LiteralPat
|
|
|
|
| MacroPat
|
|
|
|
| OrPat
|
|
|
|
| ParenPat
|
|
|
|
| PathPat
|
|
|
|
| WildcardPat
|
|
|
|
| RangePat
|
|
|
|
| RecordPat
|
|
|
|
| RefPat
|
|
|
|
| SlicePat
|
|
|
|
| TuplePat
|
|
|
|
| TupleStructPat
|
|
|
|
| ConstBlockPat
|
|
|
|
|
|
|
|
LiteralPat =
|
2023-03-17 10:32:55 +00:00
|
|
|
'-'? Literal
|
2022-04-01 15:12:25 +00:00
|
|
|
|
|
|
|
IdentPat =
|
|
|
|
Attr* 'ref'? 'mut'? Name ('@' Pat)?
|
|
|
|
|
|
|
|
WildcardPat =
|
|
|
|
'_'
|
|
|
|
|
|
|
|
RangePat =
|
|
|
|
// 1..
|
|
|
|
start:Pat op:('..' | '..=')
|
|
|
|
// 1..2
|
|
|
|
| start:Pat op:('..' | '..=') end:Pat
|
|
|
|
// ..2
|
|
|
|
| op:('..' | '..=') end:Pat
|
|
|
|
|
|
|
|
RefPat =
|
|
|
|
'&' 'mut'? Pat
|
|
|
|
|
|
|
|
RecordPat =
|
|
|
|
Path RecordPatFieldList
|
|
|
|
|
|
|
|
RecordPatFieldList =
|
|
|
|
'{'
|
|
|
|
fields:(RecordPatField (',' RecordPatField)* ','?)?
|
|
|
|
RestPat?
|
|
|
|
'}'
|
|
|
|
|
|
|
|
RecordPatField =
|
|
|
|
Attr* (NameRef ':')? Pat
|
|
|
|
|
|
|
|
TupleStructPat =
|
|
|
|
Path '(' fields:(Pat (',' Pat)* ','?)? ')'
|
|
|
|
|
|
|
|
TuplePat =
|
|
|
|
'(' fields:(Pat (',' Pat)* ','?)? ')'
|
|
|
|
|
|
|
|
ParenPat =
|
|
|
|
'(' Pat ')'
|
|
|
|
|
|
|
|
SlicePat =
|
|
|
|
'[' (Pat (',' Pat)* ','?)? ']'
|
|
|
|
|
|
|
|
PathPat =
|
|
|
|
Path
|
|
|
|
|
|
|
|
OrPat =
|
|
|
|
(Pat ('|' Pat)* '|'?)
|
|
|
|
|
|
|
|
BoxPat =
|
|
|
|
'box' Pat
|
|
|
|
|
|
|
|
RestPat =
|
|
|
|
Attr* '..'
|
|
|
|
|
|
|
|
MacroPat =
|
|
|
|
MacroCall
|
|
|
|
|
|
|
|
ConstBlockPat =
|
|
|
|
'const' BlockExpr
|