1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! `maplibre_expr` — a pure-Rust parser and evaluator for
//! [MapLibre GL style expressions][spec].
//!
//! The crate turns a MapLibre expression (a `serde_json::Value` such as
//! `["*", ["get", "x"], 2]`) into an [`Expr`] tree with [`parse`], then
//! evaluates that tree against an [`EvaluationContext`] with [`evaluate`].
//!
//! ```
//! use maplibre_expr::{parse, evaluate, EvaluationContext, Feature, Value};
//! use std::collections::BTreeMap;
//!
//! let json: serde_json::Value = serde_json::json!(["*", ["get", "x"], 2]);
//! let expr = parse(&json).unwrap();
//!
//! let mut props = BTreeMap::new();
//! props.insert("x".to_string(), Value::Number(21.0));
//! let ctx = EvaluationContext::new().with_feature(Feature {
//! properties: props,
//! ..Feature::default()
//! });
//!
//! assert_eq!(evaluate(&expr, &ctx).unwrap(), Value::Number(42.0));
//! ```
//!
//! Conformance is validated against a vendored snapshot of the
//! `maplibre-style-spec` expression test fixtures; see `tests/spec.rs`.
//!
//! [spec]: https://maplibre.org/maplibre-style-spec/expressions/
pub use ;
pub use Color;
pub use ;
pub use ;
pub use ;
pub use Type;
pub use ;
/// Parse a MapLibre expression from its JSON representation.
/// Parse an expression with user [`Options`] (macros expand at parse time;
/// function names are accepted as callable operators).
/// Statically type-check a parsed expression, optionally against the type a
/// property expects. On success returns a rewritten tree with type-directed
/// coercion/assertion nodes inserted (evaluate this returned expression so the
/// coercions take effect). Returns a [`ParseError`] for expressions the
/// reference implementation rejects at compile time (bad comparisons, malformed
/// `match` branches, non-interpolatable outputs, misused `zoom`, and so on).
///
/// `coerce_top_string` reflects whether the target property is string-typed
/// (not merely enum-typed): such properties coerce the top-level result to a
/// string rather than asserting it.
/// Evaluate a parsed expression against an evaluation context.
/// Evaluate with user [`Options`], so calls to user functions are dispatched to
/// their (recursion-limited) bodies.