1pub mod ast;
4pub mod builtins;
5pub mod eval;
6pub mod parser;
7
8use crate::{error::ExpressionError, graph::Graph};
9
10pub use ast::{
11 BinaryOp, BuiltinFn, ExprNode, Expression, ExpressionId, ExpressionReference, ExpressionValue,
12 GlobalVar, PropertyPath, UnaryOp, VirtualPropertyId,
13};
14pub use eval::property_value_to_expression_value;
15
16impl Expression {
17 pub fn parse(source: &str) -> Result<Self, ExpressionError> {
18 parser::parse_expression(source)
19 }
20}
21
22#[derive(Debug)]
23pub struct ExpressionContext<'a> {
24 pub frame: u32,
25 pub fps: f32,
26 pub width: u32,
27 pub height: u32,
28 pub duration_frames: u32,
29 pub path: Option<String>,
30 pub graph: Option<&'a Graph>,
31}
32
33impl Default for ExpressionContext<'_> {
34 fn default() -> Self {
35 Self {
36 frame: 0,
37 fps: 0.0,
38 width: 0,
39 height: 0,
40 duration_frames: 0,
41 path: None,
42 graph: None,
43 }
44 }
45}
46
47impl ExpressionContext<'_> {
48 pub fn time_seconds(&self) -> f64 {
49 if self.fps <= 0.0 {
50 0.0
51 } else {
52 self.frame as f64 / self.fps as f64
53 }
54 }
55}