The Language
This section is a work-in-progress experiment about making the book executable.
In this section we define the syntactic components of the Rust language, along with their grammar. For now this describes only a very small subset of the full language.
A program consists in a list of items.
#![allow(unused)] fn main() { pub struct Program { pub items: Vec<Item>, } }
Misc
Some syntactic elements we haven’t fleshed out yet.
#![allow(unused)] fn main() { pub type Identifier = String; }
#![allow(unused)] fn main() { pub type Path = Identifier; }
#![allow(unused)] fn main() { pub type Abi = String; }
Syntax
Mutability: is_mut=mut?
=>
=>
if is_mut.is_some() { Mutability::Mutable } else { Mutability::Immutable }
#![allow(unused)] fn main() { pub enum Mutability { Mutable, Immutable, } }
#![allow(unused)] fn main() { pub struct GenericParams {} }
#![allow(unused)] fn main() { pub struct WhereClauses {} }
#![allow(unused)] fn main() { pub struct OuterAttribute {} }
#![allow(unused)] fn main() { pub struct InnerAttribute {} }
#![allow(unused)] fn main() { pub struct Lifetime {} }
Syntax
Visibility:
| pub =>
| pub ( crate ) =>
| pub ( self ) =>
| pub ( super ) =>
| pub ( in path=SimplePath ) =>
| pub =>
Visibility::Pub| pub ( crate ) =>
Visibility::PubCrate| pub ( self ) =>
Visibility::PubSelf| pub ( super ) =>
Visibility::PubSuper| pub ( in path=SimplePath ) =>
Visibility::InPath(path)
#![allow(unused)] fn main() { pub enum Visibility { Pub, PubCrate, PubSelf, PubSuper, InPath(Path), } }
#![allow(unused)] fn main() { pub enum Pattern { Identifier(Identifier), Wildcard, } }
Submodules
#![allow(unused)] fn main() { #[path = "expressions.md.rs"] pub mod expressions; #[path = "items.md.rs"] pub mod items; #[path = "lexing.md.rs"] pub mod lexing; #[path = "print.md.rs"] pub mod print; #[path = "statements.md.rs"] pub mod statements; #[path = "types.md.rs"] pub mod types; #[path = "visitor.md.rs"] pub mod visitor; pub use expressions::*; pub use items::*; pub use lexing::*; pub use print::*; pub use statements::*; pub use types::*; pub use visitor::*; }