Grammar summary
│ │ │The following is a summary of the grammar production rules. For details on the syntax of this grammar, see notation.grammar.syntax.
│ │ │ -Macros summary
│ │ │ +Items summary
│ │ │Syntax
│ │ │
│ │ │ -MacroRulesDefinition →
macro_rules ! IDENTIFIER MacroRulesDef
MacroRulesDef →
( MacroRules ) ;
| [ MacroRules ] ;
| { MacroRules }
MacroRules →
MacroRule ( ; MacroRule )* ;?
MacroRule →
MacroMatcher => MacroTranscriber
MacroMatcher →
( MacroMatch* )
| [ MacroMatch* ]
| { MacroMatch* }
MacroMatch →
Tokenexcept $ and delimiters
| MacroMatcher
| $ ( IDENTIFIER_OR_KEYWORDexcept crate | RAW_IDENTIFIER ) : MacroFragSpec
| $ ( MacroMatch+ ) MacroRepSep? MacroRepOp
MacroFragSpec →
block | expr | expr_2021 | ident | item | lifetime | literal
| meta | pat | pat_param | path | stmt | tt | ty | vis
MacroRepSep → Tokenexcept delimiters and MacroRepOp
│ │ │ -MacroRepOp → * | + | ?
│ │ │ -MacroTranscriber → DelimTokenTree
│ │ │ -MacroInvocation →
SimplePath ! DelimTokenTree
DelimTokenTree →
( TokenTree* )
| [ TokenTree* ]
| { TokenTree* }
TokenTree →
Tokenexcept delimiters | DelimTokenTree
MacroInvocationSemi →
SimplePath ! ( TokenTree* ) ;
| SimplePath ! [ TokenTree* ] ;
| SimplePath ! { TokenTree* }
OuterAttribute* ( VisItem | MacroItem ) │ │ │ +
VisItem →
Visibility?
(
Module
| ExternCrate
| UseDeclaration
| Function
| TypeAlias
| Struct
| Enumeration
| Union
| ConstantItem
| StaticItem
| Trait
| Implementation
| ExternBlock
)
MacroItem →
MacroInvocationSemi
| MacroRulesDefinition
Crate →
InnerAttribute*
Item*
Visibility →
pub
| pub ( crate )
| pub ( self )
| pub ( super )
| pub ( in SimplePath )
Trait →
unsafe? trait IDENTIFIER GenericParams? ( : Bounds? )? WhereClause?
{
InnerAttribute*
AssociatedItem*
}
TypeAlias →
type IDENTIFIER GenericParams? ( : Bounds? )?
WhereClause?
( = Type WhereClause? )? ;
ConstantItem →
const ( IDENTIFIER | _ ) : Type ( = Expression )? ;
Struct →
StructStruct
| TupleStruct
StructStruct →
struct IDENTIFIER GenericParams? WhereClause? ( { StructFields? } | ; )
TupleStruct →
struct IDENTIFIER GenericParams? ( TupleFields? ) WhereClause? ;
StructFields → StructField ( , StructField )* ,?
│ │ │ +StructField → OuterAttribute* Visibility? IDENTIFIER : Type
│ │ │ +TupleFields → TupleField ( , TupleField )* ,?
│ │ │ +TupleField → OuterAttribute* Visibility? Type
│ │ │ +Implementation → InherentImpl | TraitImpl
│ │ │ +InherentImpl →
impl GenericParams? Type WhereClause? {
InnerAttribute*
AssociatedItem*
}
TraitImpl →
unsafe? impl GenericParams? !? TypePath for Type
WhereClause?
{
InnerAttribute*
AssociatedItem*
}
Function →
FunctionQualifiers fn IDENTIFIER GenericParams?
( FunctionParameters? )
FunctionReturnType? WhereClause?
( BlockExpression | ; )
FunctionQualifiers → const? async? ItemSafety? ( extern Abi? )?
│ │ │ +ItemSafety → safe | unsafe
│ │ │ +Abi → STRING_LITERAL | RAW_STRING_LITERAL
│ │ │ +FunctionParameters →
SelfParam ,?
| ( SelfParam , )? FunctionParam ( , FunctionParam )* ,?
SelfParam → OuterAttribute* ( ShorthandSelf | TypedSelf )
│ │ │ +ShorthandSelf → ( & | & Lifetime )? mut? self
│ │ │ + │ │ │ +FunctionParam → OuterAttribute* ( FunctionParamPattern | ... | Type )
│ │ │ +FunctionParamPattern → PatternNoTopAlt : ( Type | ... )
│ │ │ +FunctionReturnType → -> Type
│ │ │ +GenericParams → < ( GenericParam ( , GenericParam )* ,? )? >
│ │ │ +GenericParam → OuterAttribute* ( LifetimeParam | TypeParam | ConstParam )
│ │ │ +LifetimeParam → Lifetime ( : LifetimeBounds? )?
│ │ │ +TypeParam → IDENTIFIER ( : Bounds? )? ( = Type )?
│ │ │ +ConstParam →
const IDENTIFIER : Type
( = ( BlockExpression | IDENTIFIER | -? LiteralExpression ) )?
WhereClause → where ( WhereClauseItem , )* WhereClauseItem?
│ │ │ +WhereClauseItem →
LifetimeWhereClauseItem
| TypeBoundWhereClauseItem
LifetimeWhereClauseItem → Lifetime : LifetimeBounds?
│ │ │ +TypeBoundWhereClauseItem → ForLifetimes? Type : Bounds?
│ │ │ +StaticItem →
ItemSafety? static mut? IDENTIFIER : Type ( = Expression )? ;
ExternCrate → extern crate CrateRef AsClause? ;
│ │ │ +CrateRef → IDENTIFIER | self
│ │ │ +AsClause → as ( IDENTIFIER | _ )
│ │ │ +AssociatedItem →
OuterAttribute* (
MacroInvocationSemi
| ( Visibility? ( TypeAlias | ConstantItem | Function ) )
)
ExternBlock →
unsafe? extern Abi? {
InnerAttribute*
ExternalItem*
}
ExternalItem →
OuterAttribute* (
MacroInvocationSemi
| Visibility? StaticItem
| Visibility? Function
)
Union →
union IDENTIFIER GenericParams? WhereClause? { StructFields? }
UseDeclaration → use UseTree ;
│ │ │ +UseTree →
( SimplePath? :: )? *
| ( SimplePath? :: )? { ( UseTree ( , UseTree )* ,? )? }
| SimplePath ( as ( IDENTIFIER | _ ) )?
Module →
unsafe? mod IDENTIFIER ;
| unsafe? mod IDENTIFIER {
InnerAttribute*
Item*
}
Enumeration →
enum IDENTIFIER GenericParams? WhereClause? { EnumVariants? }
EnumVariants → EnumVariant ( , EnumVariant )* ,?
│ │ │ +EnumVariant →
OuterAttribute* Visibility?
IDENTIFIER ( EnumVariantTuple | EnumVariantStruct )? EnumVariantDiscriminant?
EnumVariantTuple → ( TupleFields? )
│ │ │ +EnumVariantStruct → { StructFields? }
│ │ │ + │ │ │ │ │ │