devalang_core/core/parser/
statement.rs

1use crate::core::{
2    lexer::token::Token,
3    shared::{duration::Duration, value::Value},
4};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8pub struct Statement {
9    pub kind: StatementKind,
10    pub value: Value,
11    pub indent: usize,
12    pub line: usize,
13    pub column: usize,
14}
15
16impl Statement {
17    pub fn unknown() -> Self {
18        Statement {
19            kind: StatementKind::Unknown,
20            value: Value::Null,
21            indent: 0,
22            line: 0,
23            column: 0,
24        }
25    }
26
27    pub fn unknown_from_token(token: &Token) -> Self {
28        Statement {
29            kind: StatementKind::Unknown,
30            value: Value::Null,
31            indent: token.indent,
32            line: token.line,
33            column: token.column,
34        }
35    }
36
37    pub fn error(token: Token, message: String) -> Self {
38        Statement {
39            kind: StatementKind::Error { message },
40            value: Value::Null,
41            indent: token.indent,
42            line: token.line,
43            column: token.column,
44        }
45    }
46}
47
48#[derive(Debug, Serialize, Clone, Deserialize, PartialEq)]
49pub enum StatementKind {
50    // ───── Core Instructions ─────
51    Tempo,
52    Bank {
53        alias: Option<String>,
54    },
55    Print,
56    Load {
57        source: String,
58        alias: String,
59    },
60    Use {
61        name: String,
62        alias: Option<String>,
63    },
64    Let {
65        name: String,
66    },
67    Automate {
68        target: String,
69    },
70    ArrowCall {
71        target: String,
72        method: String,
73        args: Vec<Value>,
74    },
75    Function {
76        name: String,
77        parameters: Vec<String>,
78        body: Vec<Statement>,
79    },
80
81    // ───── Instruments ─────
82    Synth,
83
84    // ───── Playback / Scheduling ─────
85    Trigger {
86        entity: String,
87        duration: Duration,
88        effects: Option<Value>,
89    },
90    Sleep,
91    Call {
92        name: String,
93        args: Vec<Value>,
94    },
95    Spawn {
96        name: String,
97        args: Vec<Value>,
98    },
99    Loop,
100
101    // ───── Structure & Logic ─────
102    Group,
103
104    // ───── Module System ─────
105    Include(String),
106    Export {
107        names: Vec<String>,
108        source: String,
109    },
110    Import {
111        names: Vec<String>,
112        source: String,
113    },
114
115    // ───── Conditions ─────
116    If,
117    Else,
118    ElseIf,
119
120    // ───── Internal / Utility ─────
121    Comment,
122    Indent,
123    Dedent,
124    NewLine,
125
126    // ───── Events / Live coding ─────
127    On {
128        event: String,
129        args: Option<Vec<Value>>,
130        body: Vec<Statement>,
131    },
132    Emit {
133        event: String,
134        payload: Option<Value>,
135    },
136
137    // ───── Error Handling ─────
138    Unknown,
139    Error {
140        message: String,
141    },
142}