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
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.
rhs: Box<SpannedExpr<'src>>
The RHS of the binop.
UnOp
A unary operation. Negation (!
) is currently the only UnOp
.
Fields
expr: Box<SpannedExpr<'src>>
The expression to apply the operator to.
Implementations§
Source§impl<'src> Expr<'src>
impl<'src> Expr<'src>
Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Returns whether the expression is a literal.
Sourcepub fn constant_reducible(&self) -> bool
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:
- Literals, which reduce to their literal value;
- Binops/unops with reducible subexpressions, which reduce to their evaluation;
- 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.
Sourcepub fn parse(expr: &'src str) -> Result<SpannedExpr<'src>>
pub fn parse(expr: &'src str) -> Result<SpannedExpr<'src>>
Parses the given string into an expression.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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