pub struct Context<'src> {
pub parts: Vec<SpannedExpr<'src>>,
}Expand description
Represents a context in a GitHub Actions expression.
These typically look something like github.actor or inputs.foo,
although they can also be a “call” context like fromJSON(...).foo.bar,
i.e. where the head of the context is a function call rather than an
identifier.
Fields§
§parts: Vec<SpannedExpr<'src>>The individual parts of the context.
Implementations§
Source§impl<'src> Context<'src>
impl<'src> Context<'src>
Sourcepub fn parse(raw: &'src str) -> Option<Self>
pub fn parse(raw: &'src str) -> Option<Self>
Parse a context from the given string.
Returns None if the string is not a valid context.
Sourcepub fn matches(&self, pattern: impl TryInto<ContextPattern<'src>>) -> bool
pub fn matches(&self, pattern: impl TryInto<ContextPattern<'src>>) -> bool
Returns whether the context matches the given pattern exactly.
Sourcepub fn child_of(&self, parent: impl TryInto<ContextPattern<'src>>) -> bool
pub fn child_of(&self, parent: impl TryInto<ContextPattern<'src>>) -> bool
Returns whether the context is a child of the given pattern.
A context is considered its own child, i.e. foo.bar is a child of
foo.bar.
Sourcepub fn single_tail(&self) -> Option<&str>
pub fn single_tail(&self) -> Option<&str>
Return this context’s “single tail,” if it has one.
This is useful primarily for contexts under env and inputs,
where we expect only a single tail part, e.g. env.FOO or
inputs['bar'].
Returns None if the context has more than one tail part,
or if the context’s head part is not an identifier.
Sourcepub fn as_pattern(&self) -> Option<String>
pub fn as_pattern(&self) -> Option<String>
Returns the “pattern equivalent” of this context.
This is a string that can be used to efficiently match the context,
such as is done in zizmor’s template-injection audit via a
finite state transducer.
Returns None if the context doesn’t have a sensible pattern equivalent, e.g. if it starts with a call.