Enum rune::ast::Expr[][src]

pub enum Expr {
    Path(Box<Path>),
    Item(Box<Item>),
    Assign(Box<ExprAssign>),
    While(Box<ExprWhile>),
    Loop(Box<ExprLoop>),
    For(Box<ExprFor>),
    Let(Box<ExprLet>),
    If(Box<ExprIf>),
    Match(Box<ExprMatch>),
    Call(Box<ExprCall>),
    FieldAccess(Box<ExprFieldAccess>),
    Group(Box<ExprGroup>),
    Binary(Box<ExprBinary>),
    Unary(Box<ExprUnary>),
    Index(Box<ExprIndex>),
    Break(Box<ExprBreak>),
    Continue(Box<ExprContinue>),
    Yield(Box<ExprYield>),
    Block(Box<ExprBlock>),
    Return(Box<ExprReturn>),
    Await(Box<ExprAwait>),
    Try(Box<ExprTry>),
    Select(Box<ExprSelect>),
    Closure(Box<ExprClosure>),
    Lit(Box<ExprLit>),
    ForceSemi(Box<ForceSemi>),
    MacroCall(Box<MacroCall>),
    Object(Box<ExprObject>),
    Tuple(Box<ExprTuple>),
    Vec(Box<ExprVec>),
    Range(Box<ExprRange>),
}

A rune expression.

Variants

Path(Box<Path>)

An path expression.

Item(Box<Item>)

A declaration.

Assign(Box<ExprAssign>)

An assign expression.

While(Box<ExprWhile>)

A while loop.

Loop(Box<ExprLoop>)

An unconditional loop.

For(Box<ExprFor>)

An for loop.

Let(Box<ExprLet>)

A let expression.

If(Box<ExprIf>)

An if expression.

Match(Box<ExprMatch>)

An match expression.

Call(Box<ExprCall>)

A function call,

FieldAccess(Box<ExprFieldAccess>)

A field access on an expression.

Group(Box<ExprGroup>)

A grouped expression.

Binary(Box<ExprBinary>)

A binary expression.

Unary(Box<ExprUnary>)

A unary expression.

Index(Box<ExprIndex>)

An index set operation.

Break(Box<ExprBreak>)

A break expression.

Continue(Box<ExprContinue>)

A continue expression.

Yield(Box<ExprYield>)

A yield expression.

Block(Box<ExprBlock>)

A block as an expression.

Return(Box<ExprReturn>)

A return statement.

Await(Box<ExprAwait>)

An await expression.

Try(Box<ExprTry>)

Try expression.

Select(Box<ExprSelect>)

A select expression.

Closure(Box<ExprClosure>)

A closure expression.

Lit(Box<ExprLit>)

A literal expression.

ForceSemi(Box<ForceSemi>)

Force a specific semi-colon policy.

MacroCall(Box<MacroCall>)

A macro call,

Object(Box<ExprObject>)

An object literal

Tuple(Box<ExprTuple>)

A tuple literal

Vec(Box<ExprVec>)

A vec literal

Range(Box<ExprRange>)

A range expression.

Implementations

impl Expr[src]

pub fn needs_semi(&self) -> bool[src]

Indicates if an expression needs a semicolon or must be last in a block.

pub fn is_callable(&self, callable: bool) -> bool[src]

Indicates if an expression is callable unless it’s permitted by an override.

pub fn take_attributes(&mut self) -> Vec<Attribute>[src]

Take the attributes from the expression.

pub fn attributes(&self) -> &[Attribute][src]

Access the attributes of the expression.

pub fn is_lit(&self) -> bool[src]

Check if this expression is a literal expression.

There are exactly two kinds of literal expressions:

  • Ones that are ExprLit
  • Unary expressions which are the negate operation.

pub fn parse_open_paren(
    p: &mut Parser<'_>,
    attributes: Vec<Attribute>
) -> Result<Self, ParseError>
[src]

Parsing something that opens with a parenthesis.

Trait Implementations

impl Clone for Expr[src]

impl Debug for Expr[src]

impl Eq for Expr[src]

impl Parse for Expr[src]

Parsing a block expression.

Examples

use rune::{testing, ast};

testing::roundtrip::<ast::Expr>("()");
testing::roundtrip::<ast::Expr>("foo[\"foo\"]");
testing::roundtrip::<ast::Expr>("foo.bar()");
testing::roundtrip::<ast::Expr>("var()");
testing::roundtrip::<ast::Expr>("var");
testing::roundtrip::<ast::Expr>("42");
testing::roundtrip::<ast::Expr>("1 + 2 / 3 - 4 * 1");
testing::roundtrip::<ast::Expr>("foo[\"bar\"]");
testing::roundtrip::<ast::Expr>("let var = 42");
testing::roundtrip::<ast::Expr>("let var = \"foo bar\"");
testing::roundtrip::<ast::Expr>("var[\"foo\"] = \"bar\"");
testing::roundtrip::<ast::Expr>("let var = objects[\"foo\"] + 1");
testing::roundtrip::<ast::Expr>("var = 42");

let expr = testing::roundtrip::<ast::Expr>(r#"
    if 1 { } else { if 2 { } else { } }
"#);
assert!(matches!(expr, ast::Expr::If(..)));

// Chained function calls.
testing::roundtrip::<ast::Expr>("foo.bar.baz()");
testing::roundtrip::<ast::Expr>("foo[0][1][2]");
testing::roundtrip::<ast::Expr>("foo.bar()[0].baz()[1]");

testing::roundtrip::<ast::Expr>("42 is int::int");
testing::roundtrip::<ast::Expr>("{ let x = 1; x }");

let expr = testing::roundtrip::<ast::Expr>("#[cfg(debug_assertions)] { assert_eq(x, 32); }");
assert!(matches!(expr, ast::Expr::Block(b) if b.attributes.len() == 1 && b.block.statements.len() == 1));

testing::roundtrip::<ast::Expr>("#{\"foo\": b\"bar\"}");
testing::roundtrip::<ast::Expr>("Disco {\"never_died\": true }");
testing::roundtrip::<ast::Expr>("(false, 1, 'n')");
testing::roundtrip::<ast::Expr>("[false, 1, 'b']");

impl PartialEq<Expr> for Expr[src]

impl Peek for Expr[src]

impl Spanned for Expr[src]

impl StructuralEq for Expr[src]

impl StructuralPartialEq for Expr[src]

impl ToTokens for Expr[src]

Auto Trait Implementations

impl RefUnwindSafe for Expr

impl Send for Expr

impl Sync for Expr

impl Unpin for Expr

impl UnwindSafe for Expr

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.