expr
Source: crates/lvcs-action/src/expr.rs.
/// A number, compared and ordered by its bits so the canonical form is
/// totally ordered.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Num(pub f64);
/// A value: GitHub's null, booleans, numbers, strings, arrays, and objects,
/// each object's keys sorted.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Value {
/// `null`.
Null,
/// A boolean.
Bool(bool),
/// A number.
Num(Num),
/// A string.
Str(String),
/// An array.
Array(Vec<Value>),
/// An object, its keys sorted.
Object(BTreeMap<String, Value>),
}
/// A function GitHub's expressions call.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Func {
/// `contains(haystack, needle)`.
Contains,
/// `startsWith(text, prefix)`.
StartsWith,
/// `endsWith(text, suffix)`.
EndsWith,
/// `format(spec, args...)`.
Format,
/// `join(items, separator?)`.
Join,
/// `toJSON(value)`.
ToJson,
/// `fromJSON(text)`.
FromJson,
/// `hashFiles(globs...)`: the shell's digest of the matched files.
HashFiles,
/// `case(pred, value, ..., default)`.
Case,
/// `success()`.
Success,
/// `always()`.
Always,
/// `cancelled()`.
Cancelled,
/// `failure()`.
Failure,
}
/// A binary operator.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BinOp {
/// `&&`, returning the left value when it is falsy, else the right.
And,
/// `||`, returning the left value when it is truthy, else the right.
Or,
/// `==`.
Eq,
/// `!=`.
Neq,
/// `<`.
Lt,
/// `<=`.
Le,
/// `>`.
Gt,
/// `>=`.
Ge,
}
/// One access after a path's head.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Seg {
/// `.name`, looked up case-insensitively.
Prop(String),
/// `[expr]`.
Index(Box<Ast>),
/// `.*` or `[*]`: the object filter.
Star,
}
/// What a path starts from.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Head {
/// A context, by its lowercase name.
Context(String),
/// A call or a parenthesized expression.
Expr(Box<Ast>),
}
/// An expression's tree.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Ast {
/// A value.
Lit(Value),
/// A context read, or accesses into an expression's value.
Path {
/// What it starts from.
head: Head,
/// Its accesses, in order.
segs: Vec<Seg>,
},
/// A function call.
Call {
/// The function.
func: Func,
/// Its arguments.
args: Vec<Ast>,
},
/// A binary expression.
Bin {
/// The operator.
op: BinOp,
/// The left side.
lhs: Box<Ast>,
/// The right side.
rhs: Box<Ast>,
},
/// `!expr`.
Not(Box<Ast>),
}