Grammar
→ HeaderDecl* Declaration* EOF
→ ImportDecl | ExportDecl
Used by Program
→ "import" ImportPath ";"
Used by HeaderDecl
→ "export" ImportPath ";"
Used by HeaderDecl
→ PathRoot "::" ImportTree
Used by ImportDeclExportDecl
→ "root" | "std" | "self" | "super" | IDENTIFIER
Used by ImportPath
Used by ImportPath
→ IDENTIFIER ( "as" IDENTIFIER )?
Used by ImportTree
→ "let" IDENTIFIER ( ":" Type )? "=" Expression ";"
Used by Declaration
→ "mut" IDENTIFIER ( ":" Type )? "=" Expression ";"
Used by DeclarationForInit
→ NativeBinding? "pub"? "fun" IDENTIFIER GenericParams? "(" Params? ")" ( "->" Type )? WhereClause? ( Block | ";" )
Used by DeclarationImplBlock
→ "native" "(" "@" IDENTIFIER ( "." IDENTIFIER )* ")" // standard library only
Used by FunDeclaration
→ "pub"? "struct" IDENTIFIER GenericParams? WhereClause? "{" StructFields "}"
Used by Declaration
→ "pub"? "enum" IDENTIFIER GenericParams? WhereClause? "{" EnumVariants "}"
Used by Declaration
→ "impl" ( Type "for" )? Type "{" FunDeclaration* "}"
Used by Declaration
→ "pub"? "aspect" IDENTIFIER "{" TraitMethod* "}"
Used by Declaration
Used by TraitDeclaration
→ ( "mut" )? "self" | IDENTIFIER ( ":" Type )?
Used by Params
→ StructField ( "," StructField )* ","?
Used by StructDeclarationEnumVariant
→ IDENTIFIER ":" Type
Used by StructFields
→ EnumVariant ( "," EnumVariant )* ","?
Used by EnumDeclaration
→ IDENTIFIER ( "{" StructFields "}" )?
Used by EnumVariants
→ "<" GenericParam ( "," GenericParam )* ">"
→ IDENTIFIER ( ":" BoundList )? // since v0.7.0; RFC-0034
Used by GenericParams
Used by GenericParamWhereConstraint
→ "where" WhereConstraint ( "," WhereConstraint )* // since v0.7.0; RFC-0002
Used by WhereClause
→ ExpressionStatement| Block| IfStatement| WhileStatement| ForStatement| LoopStatement| ReturnStatement| BreakStatement| ContinueStatement
Used by Declaration
→ Expression ";"
→ "{" Declaration* "}"
→ "if" "(" Expression ")" Block ( "else" ( IfStatement | Block ) )?
Used by Statement
→ "while" "(" Expression ")" Block
Used by Statement
→ "for" "(" ForInit Expression? ";" Expression? ")" Block| "for" "(" "let" IDENTIFIER "in" Expression ")" Block
Used by Statement
→ MutDeclaration | ExpressionStatement | ";"
Used by ForStatement
→ "loop" Block
Used by Statement
→ "return" Expression? ";"
Used by Statement
→ "break" Expression? ";"
Used by Statement
→ "continue" ";"
Used by Statement
Used by Expression
→ IDENTIFIER | CallExpression "." IDENTIFIER | CallExpression "[" Expression "]"
Used by AssignmentExpression
→ "=" | "+=" | "-=" | "*=" | "/=" | "%="
Used by AssignmentExpression
→ LogicalAndExpression ( "||" LogicalAndExpression )*
Used by AssignmentExpression
→ ComparisonExpression ( "&&" ComparisonExpression )*
Used by LogicalOrExpression
→ TermExpression ( ( ">" | ">=" | "<" | "<=" | "!=" | "==" ) TermExpression )?
Used by LogicalAndExpression
→ FactorExpression ( ( "+" | "-" ) FactorExpression )*
Used by ComparisonExpression
→ CastExpression ( ( "*" | "/" | "%" ) CastExpression )*
Used by TermExpression
→ AscribeExpression ( "as" Type )*
Used by FactorExpression
→ UnaryExpression ( ":" Type )?
Used by CastExpression
→ ( "!" | "-" | "*" | "&" | "&mut" ) UnaryExpression | PostfixExpression
Used by AscribeExpression
→ PrimaryExpression ( "(" Arguments? ")" | "." IDENTIFIER | "[" Expression "]" | "?" )*
Used by UnaryExpression
→ Expression ( "," Expression )* ","?
Used by PostfixExpression
→ INT | FLOAT | STRING | "true" | "false" | "None" | "()"| "(" Expression ( "," Expression )+ ")" // tuple| "(" Expression ")"| "[" ( Expression ( "," Expression )* ","? )? "]" // array literal| "[" Expression ";" INT "]" // repeat construction [expr; N]| Path| StructLiteral| MatchExpression| IfExpression| LoopExpression| ClosureExpression
Used by PostfixExpression
→ ( "root" | "std" | "self" | "super" | IDENTIFIER ) ( "::" IDENTIFIER )*
Used by PrimaryExpressionStructLiteral
Used by PrimaryExpression
→ IDENTIFIER ( ":" Expression )? // omitting ": Expression" uses the local variable of the same name
Used by StructLiteral
→ "match" Expression "{" MatchArm ( "," MatchArm )* ","? "}"
Used by PrimaryExpression
→ Pattern ( "if" Expression )? "=>" Expression
Used by MatchExpression
→ "if" "(" Expression ")" Block "else" Block
Used by PrimaryExpression
→ "loop" Block
Used by PrimaryExpression
Used by PrimaryExpression
→ "_"| "None"| IDENTIFIER| "(" Pattern ( "," Pattern )* ")" // tuple pattern| IDENTIFIER "::" IDENTIFIER ( "{" PatternFields "}" )?| INT | FLOAT | STRING | "true" | "false"
Used by MatchArm
→ IDENTIFIER ( "," IDENTIFIER )*
Used by Pattern
→ IDENTIFIER ( "<" TypeArgs ">" )?| "*" "mut"? Type // regular pointer types| "()"| "(" Type ( "," Type )+ ")" // tuple type| Type "[]" // array shorthand| "[" Type ";" INT "]" // fixed-size array type (since v0.19.0; RFC-0053)| "(" TypeList? ")" "->" Type // function / closure type| "impl" Type // anonymous bounded param; parameter position only (since v0.7.0; RFC-0035)
Used by Type
Used by Type