Grammar Pocket Reference

Checksum: 4ab4e767d61092f8b4f0c031e617d8ddaccf9515fbf6ba702a107b2bca58b7f2

  • program ::= WS? { toplevel WS? } EOF ;
  • toplevel ::= inner_attribute
  • space_decl ::= "space" WS1 module_path ;
  • use_decl ::= "use" WS1 package_path [ use_group | use_glob ] [ WS1 "as" WS1 ident ] ;
  • use_glob ::= "." "*" ;
  • use_group ::= "." "{" WS? ( "*" | import_items [ WS? "," WS? "*" ]? ) WS? "}" ;
  • import_items ::= import_item { WS? "," WS? import_item } [ WS? "," ] ;
  • import_item ::= ident [ WS1 "as" WS1 ident ] ;
  • export_decl ::= "export" WS1 ( "*" | ident_list | "{" WS? ident_list WS? "}" ) ;
  • const_decl ::= { attr_prefix WS? } "const" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
  • static_decl ::= { attr_prefix WS? } "static" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
  • region_decl ::= { attr_prefix WS? } "region" WS1 ident [ WS? ":" WS? region_kind ] [ WS? region_capabilities ] WS? meta_tail ;
  • region_kind ::= "stack" | "heap" | "arena" | "static" | "mmio" | "dma" | ident ;
  • region_capabilities ::= "(" WS? ident_list? WS? ")" ;
  • type_alias_decl ::= { attr_prefix WS? } "type" WS1 ident [ generic_params ] WS? "=" WS? type_expr ;
  • opaque_type_decl ::= { attr_prefix WS? } "opaque" WS1 "type" WS1 ident [ generic_params ] [ WS? "=" WS? type_expr ] ;
  • extern_type_decl ::= { attr_prefix WS? } "extern" WS1 "type" WS1 ident [ generic_params ] [ WS? ";" ] ;
  • form_decl ::= { attr_prefix WS? } "form" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? form_items? WS? "}" ;
  • class_decl ::= { attr_prefix WS? } "class" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? class_items? WS? "}" ;
  • union_decl ::= { attr_prefix WS? } "union" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? field_list? WS? "}" ;
  • form_items ::= form_item { WS? ","? WS? form_item } [ WS? "," ] ;
  • form_item ::= field_item | const_decl | type_alias_decl | proc_decl ;
  • class_items ::= class_item { WS? ","? WS? class_item } [ WS? "," ] ;
  • class_item ::= field_item | const_decl | type_alias_decl | proc_decl ;
  • field_list ::= field_item { WS? "," WS? field_item } [ WS? "," ] ;
  • field_item ::= { attr_prefix WS? } [ visibility WS1 ] ident WS? ":" WS? type_expr [ WS? "=" WS? expr ] ;
  • bits_decl ::= { attr_prefix WS? } "bits" WS1 ident [ WS? ":" WS? type_expr ] WS? "{" WS? bitfield_list? WS? "}" ;
  • bitfield_list ::= bitfield_item { WS? "," WS? bitfield_item } [ WS? "," ] ;
  • bitfield_item ::= ident WS? ":" WS? expr WS? ".." WS? expr ;
  • pick_decl ::= { attr_prefix WS? } "pick" WS1 ident [ generic_params ] [ WS? ":" WS? type_expr ] [ WS? where_clause ] WS? "{" WS? case_list? WS? "}" ;
  • case_list ::= case_item { WS? "," WS? case_item } [ WS? "," ] ;
  • case_item ::= [ "case" WS1 ] ident [ "(" WS? case_payload? WS? ")" ] [ WS? "=" WS? expr ] ;
  • case_payload ::= case_field { WS? "," WS? case_field } [ WS? "," ] ;
  • case_field ::= ident WS? ":" WS? type_expr | type_expr ;
  • flags_decl ::= { attr_prefix WS? } "flags" WS1 ident [ WS? ":" WS? type_expr ] WS? "{" WS? flag_list? WS? "}" ;
  • flag_list ::= flag_item { WS? "," WS? flag_item } [ WS? "," ] ;
  • flag_item ::= ident [ WS? "=" WS? expr ] ;
  • trait_decl ::= { attr_prefix WS? } [ "unsafe" WS1 ] "trait" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? trait_item* WS? "}" ;
  • trait_item ::= proc_signature | const_decl | associated_type_decl ;
  • associated_type_decl ::= "type" WS1 ident [ WS? ":" WS? trait_bound ] [ WS? "=" WS? type_expr ] ;
  • impl_decl ::= { attr_prefix WS? } [ "unsafe" WS1 ] "impl" WS1 impl_head [ WS? where_clause ] WS? "{" WS? impl_item* WS? "}" ;
  • impl_head ::= type_expr | type_expr WS1 "for" WS1 type_expr ;
  • impl_item ::= const_decl | type_alias_decl | associated_type_decl | proc_decl ;
  • proc_signature ::= { attr_prefix WS? } "proc" WS1 ident [ generic_params ]
  • proc_decl ::= { attr_prefix WS? } [ visibility WS1 ] proc_modifier* [ extern_clause WS1 ] "proc" WS1 proc_name [ generic_params ]
  • proc_name ::= ident | "operator" WS? operator_symbol ;
  • operator_symbol ::= "+" | "-" | "*" | "/" | "%"
  • proc_modifier ::= "async" WS1
  • proc_suffix ::= effects_clause
  • extern_block ::= { attr_prefix WS? } "extern" WS1 extern_abi WS? "{" WS? extern_item* WS? "}" ;
  • extern_item ::= extern_proc_decl | extern_type_decl | const_decl ;
  • extern_proc_decl ::= { attr_prefix WS? } "proc" WS1 ident [ generic_params ]
  • extern_clause ::= "extern" WS1 extern_abi ;
  • extern_abi ::= callconv | string_lit ;
  • callconv ::= "C" | "sysv64" | "win64" | "interrupt" | "naked" ;
  • intrinsic_decl ::= { attr_prefix WS? } "intrinsic" WS1 ident [ generic_params ]
  • macro_decl ::= { attr_prefix WS? } "macro" WS1 ident [ "(" WS? macro_param_list? WS? ")" ] WS? meta_tail ;
  • macro_param_list ::= macro_param { WS? "," WS? macro_param } [ WS? "," ] ;
  • macro_param ::= ident [ WS? ":" WS? macro_kind ] ;
  • macro_kind ::= "expr" | "stmt" | "type" | "ident" | "block" | "item" ;
  • static_assert_decl ::= "static_assert" WS? "(" WS? expr [ WS? "," WS? expr ] WS? ")" ;
  • test_decl ::= { attr_prefix WS? } "test" WS1 string_lit WS? block ;
  • bench_decl ::= { attr_prefix WS? } "bench" WS1 string_lit WS? block ;
  • entry_decl ::= { attr_prefix WS? } "entry" WS1 ident_or_string [ WS? meta_args ] WS? meta_tail ;
  • visibility ::= "pub" | "priv" | "pub" WS? "(" WS? visibility_scope WS? ")" ;
  • visibility_scope ::= "package" | "module" | "super" ;
  • generic_params ::= "[" WS? generic_param_list? WS? "]" ;
  • generic_param_list ::= generic_param { WS? "," WS? generic_param } [ WS? "," ] ;
  • generic_param ::= ident [ WS? ":" WS? trait_bound ] [ WS? "=" WS? type_expr ]
  • where_clause ::= "where" WS1 where_bounds ;
  • where_bounds ::= where_bound { WS? "," WS? where_bound } [ WS? "," ] ;
  • where_bound ::= type_expr WS? ":" WS? trait_bound
  • trait_bound ::= type_expr { WS? "+" WS? type_expr } ;
  • param_list ::= param { WS? "," WS? param } [ WS? "," ] ;
  • param ::= self_param | normal_param | variadic_param ;
  • self_param ::= [ "&" WS? ] [ "mut" WS1 ] "self" ;
  • normal_param ::= [ param_mode WS1 ] pattern [ WS? ":" WS? type_expr ] [ WS? "=" WS? expr ] ;
  • variadic_param ::= "..." | ident WS? ":" WS? "..." type_expr ;
  • param_mode ::= "mut" | "owned" | "borrow" | "move" ;
  • effects_clause ::= "effects" WS? "(" WS? ident_list? WS? ")" ;
  • requires_clause ::= "requires" WS? "(" WS? capability_list? WS? ")" ;
  • capability_list ::= capability { WS? "," WS? capability } [ WS? "," ] ;
  • capability ::= ident { "." ident } ;
  • module_path ::= relative? package_parts ;
  • package_path ::= relative? package_parts ;
  • relative ::= { "." } ;
  • package_parts ::= ident { ( "/" | "." | "::" ) ident } ;
  • ident_list ::= ident { WS? "," WS? ident } [ WS? "," ] ;
  • query_decl ::= { attr_prefix WS? } "query" WS1 ident
  • query_body ::= block | ";" ;
  • compiler_decl ::= { attr_prefix WS? } "compiler" WS1 ident_or_string [ WS? meta_args ] WS? meta_tail ;
  • pass_decl ::= { attr_prefix WS? } "pass" WS1 ident_or_string [ WS? meta_args ] WS? meta_tail ;
  • backend_decl ::= { attr_prefix WS? } "backend" WS1 ident_or_string [ WS? meta_args ] WS? meta_tail ;
  • diagnostic_decl ::= { attr_prefix WS? } "diagnostic" WS1 ident_or_string [ WS? meta_args ] WS? meta_tail ;
  • ident_or_string ::= ident | string_lit ;
  • meta_args ::= "(" WS? meta_arg_list? WS? ")" ;
  • meta_arg_list ::= meta_arg { WS? "," WS? meta_arg } [ WS? "," ] ;
  • meta_arg ::= ident_or_string ;
  • meta_tail ::= block | ";" ;
  • attr_prefix ::= outer_attribute | doc_comment | docstring ;
  • inner_attribute ::= "#![" attr_path [ "(" WS? attr_arg_list? WS? ")" ] "]" ;
  • outer_attribute ::= "#[" attr_path [ "(" WS? attr_arg_list? WS? ")" ] "]" ;
  • doc_comment ::= "///" { ~NEWLINE ANY } ;
  • docstring ::= raw_string_lit ;
  • attr_path ::= ident { "." ident } ;
  • attr_arg_list ::= attr_arg { WS? "," WS? attr_arg } [ WS? "," ] ;
  • attr_arg ::= ident
  • block ::= "{" WS? { stmt WS? } "}" ;
  • stmt ::= local_const_stmt stmt_end
  • stmt_end ::= WS? ";" ;
  • local_const_stmt ::= "const" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
  • let_stmt ::= "let" WS1 [ "mut" WS1 ] pattern [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
  • set_stmt ::= "set" WS1 assign_target WS? assign_op WS? expr ;
  • assign_target ::= unary_expr ;
  • give_stmt ::= "give" [ WS1 expr ] ;
  • try_stmt ::= "try" WS1 expr ;
  • defer_stmt ::= "defer" WS? block ;
  • asm_stmt ::= "asm" WS? "(" WS? asm_arg_list? WS? ")" ;
  • asm_arg_list ::= asm_arg { WS? "," WS? asm_arg } [ WS? "," ] ;
  • asm_arg ::= string_lit | ident WS? "(" WS? arg_list? WS? ")" | ident WS? ":" WS? expr ;