Skip to content

enum

Expr

pub enum Expr {
    Null,
    Bool(bool),
    Num(f64),
    Str(TextTemplate),
    Path(Path),
    List(Vec<Expr>),
    Record(Vec<(String, Expr)>),
    Unary(UnOp, Box<Expr>),
    Binary(BinOp, Box<Expr>, Box<Expr>),
    If(Box<Expr>, Box<Expr>, Box<Expr>),
    Call(String, Vec<Expr>),
    Pipe(Box<Expr>, Box<Expr>),
    Lambda(Vec<String>, Box<Expr>),
    Comprehension(Box<Expr>, Vec<Qualifier>),
    Field(Box<Expr>, Vec<String>),
    Update(Box<Expr>, Vec<(String, Expr)>),
}

An expression.

Variants

Null

Null

null

Bool

Bool(bool)

true or false.

Num

Num(f64)

A number.

Str

Str(TextTemplate)

A string, which may interpolate.

Path

Path(Path)

A name in the scope, with fields: post.author.name.

List

List(Vec<Expr>)

A list: [a, b].

Record

Record(Vec<(String, Expr)>)

A record: { name: a, count: b }.

Unary

Unary(UnOp, Box<Expr>)

A unary operator applied to an operand.

Binary

Binary(BinOp, Box<Expr>, Box<Expr>)

A binary operator applied to two operands.

If

If(Box<Expr>, Box<Expr>, Box<Expr>)

if c then a else b

Call

Call(String, Vec<Expr>)

f(a, b)

Pipe

Pipe(Box<Expr>, Box<Expr>)

x |> f(a): f(x, a). The right side is a [Expr::Call].

Lambda

Lambda(Vec<String>, Box<Expr>)

(a, b) -> body, only as a call's argument.

Comprehension

Comprehension(Box<Expr>, Vec<Qualifier>)

[t.title | t <- todos, !t.done]: a list built from generators and conditions, read left to right.

Field

Field(Box<Expr>, Vec<String>)

(expr).a.b

Update

Update(Box<Expr>, Vec<(String, Expr)>)

{ t | done: true }: a copy of a record with fields changed.

Methods

call_parts

pub fn call_parts(&self) -> Option<(&str, Vec<&Expr>)>

The arguments a call gets: a pipe's left side first.

references

pub fn references(&self, bound: &mut Vec<String>, out: &mut BTreeSet<String>)

Names the expression reads from its scope (lambda parameters excluded), added to out.

Trait implementations