devalang_core/core/parser/
statement.rs

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