Skip to main content

Expr

Enum Expr 

Source
#[non_exhaustive]
pub enum Expr {
Show 19 variants Var { qualifier: Option<ModuleName>, name: Identifier, pos: Pos, span: Span, }, Con { qualifier: Option<ModuleName>, name: Identifier, pos: Pos, span: Span, }, Lit { kind: LitKind, text: String, pos: Pos, span: Span, }, App { func: Box<Self>, args: Vec<Self>, pos: Pos, span: Span, }, BinOp { op: Operator, lhs: Box<Self>, rhs: Box<Self>, pos: Pos, span: Span, }, Neg { expr: Box<Self>, pos: Pos, span: Span, }, Lambda { params: Vec<Pat>, body: Box<Self>, pos: Pos, span: Span, }, If { cond: Box<Self>, then_branch: Box<Self>, else_branch: Box<Self>, pos: Pos, span: Span, }, Case { scrutinee: Box<Self>, alts: Vec<Alt>, pos: Pos, span: Span, }, Do { stmts: Vec<DoStmt>, pos: Pos, span: Span, }, LetIn { bindings: Vec<Binding>, body: Box<Self>, pos: Pos, span: Span, }, Record { base: Box<Self>, fields: Vec<FieldAssign>, pos: Pos, span: Span, }, Tuple { items: Vec<Self>, pos: Pos, span: Span, }, List { items: Vec<Self>, pos: Pos, span: Span, }, Try { body: Box<Self>, handlers: Vec<Alt>, pos: Pos, span: Span, }, OperatorRef { op: Operator, pos: Pos, span: Span, }, LeftSection { op: Operator, operand: Box<Self>, pos: Pos, span: Span, }, RightSection { op: Operator, operand: Box<Self>, pos: Pos, span: Span, }, Error { raw: String, pos: Pos, span: Span, },
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Var

Lowercase variable reference, possibly qualified.

Fields

§qualifier: Option<ModuleName>

Optional module qualifier before the variable name.

§name: Identifier

Variable name.

§pos: Pos

Position of the variable token.

§span: Span

Span of the variable token.

§

Con

Constructor / data-constructor reference, possibly qualified.

Fields

§qualifier: Option<ModuleName>

Optional module qualifier before the constructor name.

§name: Identifier

Constructor name.

§pos: Pos

Position of the constructor token.

§span: Span

Span of the constructor token.

§

Lit

Literal expression; text is the parser’s normalized literal text.

Fields

§kind: LitKind

Literal family.

§text: String

Normalized literal payload.

§pos: Pos

Position of the literal token.

§span: Span

Span of the literal token in the source.

§

App

Application, flattened: f a b c is one App with three args.

Fields

§func: Box<Self>

Function expression being applied.

§args: Vec<Self>

Arguments in source order.

§pos: Pos

Position of the application’s first token.

§span: Span

Span of the whole application.

§

BinOp

Binary operator application with source-level operator text.

Fields

§op: Operator

Operator token text.

§lhs: Box<Self>

Left operand.

§rhs: Box<Self>

Right operand.

§pos: Pos

Position of the left operand.

§span: Span

Span of the whole infix expression.

§

Neg

Unary negation.

Fields

§expr: Box<Self>

Negated expression.

§pos: Pos

Position of the - token.

§span: Span

Span of the whole negated expression.

§

Lambda

Lambda expression (\params -> body).

Fields

§params: Vec<Pat>

Parameter patterns in source order.

§body: Box<Self>

Lambda body.

§pos: Pos

Position of the lambda token.

§span: Span

Span of the whole lambda expression.

§

If

Conditional expression.

Fields

§cond: Box<Self>

Condition after if.

§then_branch: Box<Self>

Expression after then.

§else_branch: Box<Self>

Expression after else.

§pos: Pos

Position of the if token.

§span: Span

Span of the whole conditional expression.

§

Case

Case expression with source-ordered alternatives.

Fields

§scrutinee: Box<Self>

Scrutinee after case.

§alts: Vec<Alt>

Alternatives in source order.

§pos: Pos

Position of the case token.

§span: Span

Span of the whole case expression.

§

Do

Do block.

Fields

§stmts: Vec<DoStmt>

Statements in source order.

§pos: Pos

Position of the do token.

§span: Span

Span of the whole do block.

§

LetIn

Let/in expression.

Fields

§bindings: Vec<Binding>

Bindings in source order.

§body: Box<Self>

Body expression after in.

§pos: Pos

Position of the let token.

§span: Span

Span of the whole let/in expression.

§

Record

base with f = e, ... — record construction when base is a Con, record update otherwise.

Fields

§base: Box<Self>

Constructor or record value being constructed/updated.

§fields: Vec<FieldAssign>

Field assignments in source order.

§pos: Pos

Position of the base expression.

§span: Span

Span of the whole record expression.

§

Tuple

Tuple expression with source-ordered items.

Fields

§items: Vec<Self>

Tuple items in source order.

§pos: Pos

Position of the opening parenthesis.

§span: Span

Span from ( through ).

§

List

List expression with source-ordered items.

Fields

§items: Vec<Self>

List items in source order.

§pos: Pos

Position of the opening bracket.

§span: Span

Span from [ through ].

§

Try

try <body> catch <alts>

Fields

§body: Box<Self>

Body after try.

§handlers: Vec<Alt>

Catch handlers in source order.

§pos: Pos

Position of the try token.

§span: Span

Span of the whole try/catch expression.

§

OperatorRef

Parenthesized operator reference like (+).

Fields

§op: Operator

Referenced operator.

§pos: Pos

Position of the opening parenthesis.

§span: Span

Span from ( through ).

§

LeftSection

Left operator section like (1 +).

Fields

§op: Operator

Section operator.

§operand: Box<Self>

Left operand before the operator.

§pos: Pos

Position of the opening parenthesis.

§span: Span

Span from ( through ).

§

RightSection

Right operator section like (+ 1).

Fields

§op: Operator

Section operator.

§operand: Box<Self>

Right operand after the operator.

§pos: Pos

Position of the opening parenthesis.

§span: Span

Span from ( through ).

§

Error

Expression the parser could not understand; raw text preserved so a parse failure degrades to the shim’s behavior instead of dying.

Fields

§raw: String

Raw source text preserved for the malformed expression.

§pos: Pos

Position of the malformed expression’s first token.

§span: Span

Span of the preserved raw expression text.

Implementations§

Source§

impl Expr

Source

pub const fn pos(&self) -> Pos

Source

pub const fn span(&self) -> Span

Byte span covering the whole expression.

Source

pub fn render(&self) -> String

Render back to compact, source-like text for diagnostics and raw fields.

This is lossy and normalizing, not byte-faithful: original layout is dropped (e.g. do/let statements are joined with ; ), operators and spacing are normalized, and comments/trivia are gone. Use it for a quick human-readable echo of an expression; for source-exact reconstruction use the node’s span into the original text (that is how daml-fmt and crate::ast_span::render_from_ast stay lossless).

Source

pub fn application_head(&self) -> &Self

The head of an application spine: for Foo.exercise cid X, the Foo.exercise Var. For non-apps, the expression itself.

Source

pub fn application_args(&self) -> &[Self]

Application arguments, empty for non-apps. The App spine is flattened (see the App variant), so for f a b c this returns all three arguments [a, b, c], not a single curried layer.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Expr

Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.