pub enum Expr<'src> {
Literal(Literal<'src>),
Star,
Call {
func: Function<'src>,
args: Vec<Expr<'src>>,
},
Identifier(Identifier<'src>),
Index(Box<Expr<'src>>),
Context(Context<'src>),
BinOp {
lhs: Box<Expr<'src>>,
op: BinOp,
rhs: Box<Expr<'src>>,
},
UnOp {
op: UnOp,
expr: Box<Expr<'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
Identifier(Identifier<'src>)
A context identifier component, e.g. github in github.actor.
Index(Box<Expr<'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
UnOp
A unary operation. Negation (!) is currently the only UnOp.
Implementations§
Source§impl<'src> Expr<'src>
impl<'src> Expr<'src>
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 has_constant_reducible_subexpr(&self) -> bool
pub fn has_constant_reducible_subexpr(&self) -> bool
Like Self::constant_reducible, but for all subexpressions
rather than the top-level expression.
This has slightly different semantics than constant_reducible:
it doesn’t include “trivially” reducible expressions like literals,
since flagging these as reducible within a larger expression
would be misleading.
Sourcepub fn dataflow_contexts(&self) -> Vec<&Context<'src>>
pub fn dataflow_contexts(&self) -> Vec<&Context<'src>>
Returns the contexts in this expression that directly flow into the expression’s evaluation.
For example ${{ foo.bar }} returns foo.bar since the value
of foo.bar flows into the evaluation. On the other hand,
${{ foo.bar == 'abc' }} returns no expanded contexts,
since the value of foo.bar flows into a boolean evaluation
that gets expanded.
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