workshop_rs/wir/value.rs
1//! Canonical Workshop value and expression forms.
2
3use crate::core::source::Span;
4
5use super::{GlobalVarId, PlayerVarId, SubroutineId, ValueId};
6
7/// A workshop value (expression) node with its source span.
8#[derive(Debug, Clone)]
9pub struct ValueNode {
10 pub value: Value,
11 pub span: Option<Span>,
12}
13
14/// A workshop value (expression).
15#[derive(Debug, Clone)]
16pub enum Value {
17 /// A numeric literal with its source spelling (`5`, `0.0`, `-22.05`);
18 /// computed values (constant folding) carry the formatted spelling.
19 Number {
20 value: f64,
21 text: String,
22 },
23 String(String),
24 /// A reviewed localized Workshop preset-string identity.
25 LocalizedString(String),
26 Bool(bool),
27 Null,
28 Array(Vec<ValueId>),
29 Vector {
30 x: ValueId,
31 y: ValueId,
32 z: ValueId,
33 },
34 /// A built-in enumerated value, e.g. `Team.ALL`.
35 Enum {
36 value_type: String,
37 value: String,
38 },
39 GlobalVariable(GlobalVarId),
40 PlayerVariable {
41 player: ValueId,
42 variable: PlayerVarId,
43 },
44 /// A declared Workshop subroutine referenced by a generic action such as
45 /// `Start Rule`. The identity is source-owned, not a catalog builtin.
46 Subroutine(SubroutineId),
47 EventPlayer,
48 /// A function call over workshop values.
49 Call {
50 name: String,
51 args: Vec<ValueId>,
52 },
53}
54
55impl ValueNode {
56 /// Build a value node with a source span.
57 pub fn new(value: Value, span: Option<Span>) -> Self {
58 ValueNode { value, span }
59 }
60}