Struct rustlr::generic_absyn::LBox[][src]

pub struct LBox<T> {
    pub exp: Box<T>,
    pub line: usize,
    pub column: usize,
    pub src_id: usize,
}
Expand description

custom smart pointer that encapsulates line number, column and other information for warnings and error messages after the parsing stage. Implements Deref and DerefMut so the encapsulated expression can be accessed as in a standard Box. For example, an abstract syntax type can be defined by

 enum Expr {
   Val(i64),
   PlusExpr(LBox<Expr>,LBox<Expr>),
   ...
 }
 fn check(e:&Expr) {
   match e {
     PlusExpr(a,b) => {
       println!("checking subexpressions on line {} and {}",a.line,b.line);
       check(a); check(b); // Deref coercion used here
     },
   ...

The RuntimeParser::lb function can be called from the semantic actions of a grammar to create LBoxed-values that include line/column information. LBox implements the Default trait if T does, so an LBox type can also serve as the absyntract syntax type for a grammar. The src_id field of LBox can be used to point to externally kept information about the source being compiled, such as the source file name when mulitple files are compiled together.

Fields

exp: Box<T>line: usizecolumn: usizesrc_id: usize

Implementations

Trait Implementations

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.