Skip to main content

Expr

Enum Expr 

Source
#[non_exhaustive]
pub enum Expr {
Show 17 variants Var { qualifier: Option<String>, name: String, pos: Pos, span: Span, }, Con { qualifier: Option<String>, name: String, 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: String, 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, }, Section { op: String, operand: Option<Box<Self>>, side: SectionSide, 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<String>
§name: String
§pos: Pos
§span: Span
§

Con

Constructor / data-constructor reference, possibly qualified.

Fields

§qualifier: Option<String>
§name: String
§pos: Pos
§span: Span
§

Lit

Fields

§kind: LitKind
§text: String
§pos: Pos
§span: Span
§

App

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

Fields

§func: Box<Self>
§args: Vec<Self>
§pos: Pos
§span: Span
§

BinOp

Binary operator application with source-level operator text.

Fields

§lhs: Box<Self>
§rhs: Box<Self>
§pos: Pos
§span: Span
§

Neg

Unary negation.

Fields

§expr: Box<Self>
§pos: Pos
§span: Span
§

Lambda

Fields

§params: Vec<Pat>
§body: Box<Self>
§pos: Pos
§span: Span
§

If

Fields

§cond: Box<Self>
§then_branch: Box<Self>
§else_branch: Box<Self>
§pos: Pos
§span: Span
§

Case

Fields

§scrutinee: Box<Self>
§alts: Vec<Alt>
§pos: Pos
§span: Span
§

Do

Fields

§stmts: Vec<DoStmt>
§pos: Pos
§span: Span
§

LetIn

Fields

§bindings: Vec<Binding>
§body: Box<Self>
§pos: Pos
§span: Span
§

Record

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

Fields

§base: Box<Self>
§pos: Pos
§span: Span
§

Tuple

Fields

§items: Vec<Self>
§pos: Pos
§span: Span
§

List

Fields

§items: Vec<Self>
§pos: Pos
§span: Span
§

Try

try <body> catch <alts>

Fields

§body: Box<Self>
§handlers: Vec<Alt>
§pos: Pos
§span: Span
§

Section

Right operator section like (+ 1) / left section (1 +).

Fields

§operand: Option<Box<Self>>
§pos: Pos
§span: Span
§

Error

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

Fields

§pos: Pos
§span: Span

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

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.