Enum Expr

Source
pub enum Expr<'src> {
    Literal(Literal<'src>),
    Star,
    Call {
        func: Function<'src>,
        args: Vec<SpannedExpr<'src>>,
    },
    Identifier(Identifier<'src>),
    Index(Box<SpannedExpr<'src>>),
    Context(Context<'src>),
    BinOp {
        lhs: Box<SpannedExpr<'src>>,
        op: BinOp,
        rhs: Box<SpannedExpr<'src>>,
    },
    UnOp {
        op: UnOp,
        expr: Box<SpannedExpr<'src>>,
    },
}
Expand description

Represents a GitHub Actions expression.

Variants§

§

Literal(Literal<'src>)

A literal value.

§

Star

The * literal within an index or context.

§

Call

A function call.

Fields

§func: Function<'src>

The function name, e.g. foo in foo().

§args: Vec<SpannedExpr<'src>>

The function’s arguments.

§

Identifier(Identifier<'src>)

A context identifier component, e.g. github in github.actor.

§

Index(Box<SpannedExpr<'src>>)

A context index component, e.g. [0] in foo[0].

§

Context(Context<'src>)

A full context reference.

§

BinOp

A binary operation, either logical or arithmetic.

Fields

§lhs: Box<SpannedExpr<'src>>

The LHS of the binop.

§op: BinOp

The binary operator.

§rhs: Box<SpannedExpr<'src>>

The RHS of the binop.

§

UnOp

A unary operation. Negation (!) is currently the only UnOp.

Fields

§op: UnOp

The unary operator.

§expr: Box<SpannedExpr<'src>>

The expression to apply the operator to.

Implementations§

Source§

impl<'src> Expr<'src>

Source

pub fn is_literal(&self) -> bool

Returns whether the expression is a literal.

Source

pub fn constant_reducible(&self) -> bool

Returns whether the expression is constant reducible.

“Constant reducible” is similar to “constant foldable” but with meta-evaluation semantics: the expression 5 would not be constant foldable in a normal program (because it’s already an atom), but is “constant reducible” in a GitHub Actions expression because an expression containing it (e.g. ${{ 5 }}) can be elided entirely and replaced with 5.

There are three kinds of reducible expressions:

  1. Literals, which reduce to their literal value;
  2. Binops/unops with reducible subexpressions, which reduce to their evaluation;
  3. Select function calls where the semantics of the function mean that reducible arguments make the call itself reducible.

NOTE: This implementation is sound but not complete.

Source

pub fn parse(expr: &'src str) -> Result<SpannedExpr<'src>>

Parses the given string into an expression.

Trait Implementations§

Source§

impl<'src> Debug for Expr<'src>

Source§

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

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

impl<'src> From<&'src str> for Expr<'src>

Source§

fn from(s: &'src str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Expr<'_>

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Expr<'_>

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Expr<'_>

Source§

fn from(n: f64) -> Self

Converts to this type from the input type.
Source§

impl<'src> PartialEq for Expr<'src>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const 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<'src> StructuralPartialEq for Expr<'src>

Auto Trait Implementations§

§

impl<'src> Freeze for Expr<'src>

§

impl<'src> RefUnwindSafe for Expr<'src>

§

impl<'src> Send for Expr<'src>

§

impl<'src> Sync for Expr<'src>

§

impl<'src> Unpin for Expr<'src>

§

impl<'src> UnwindSafe for Expr<'src>

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.