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.
pub struct Program {
pub items: Vec<Item>,
}
Misc
Some syntactic elements we haven’t fleshed out yet.
pub type Identifier = String;
pub type Abi = String;
Syntax
Mutability: is_mut=mut?
=>
=>
if is_mut.is_some() { Mutability::Mutable } else { Mutability::Immutable }
pub enum Mutability {
Mutable,
Immutable,
}
pub struct GenericParams {}
pub struct WhereClauses {}
pub struct OuterAttribute {}
pub struct InnerAttribute {}
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)
pub enum Visibility {
Pub,
PubCrate,
PubSelf,
PubSuper,
InPath(Path),
}
pub enum Pattern {
Identifier(Identifier),
Wildcard,
}
Submodules
#[path = "expressions.md.rs"]
pub mod expressions;
#[path = "items.md.rs"]
pub mod items;
#[path = "lexing.md.rs"]
pub mod lexing;
#[path = "names.md.rs"]
pub mod names;
#[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 names::*;
pub use print::*;
pub use statements::*;
pub use types::*;
pub use visitor::*;