@devaloop/devalang 0.0.1-alpha.5 → 0.0.1-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +1 -1
- package/README.md +18 -6
- package/docs/CHANGELOG.md +19 -0
- package/docs/SYNTAX.md +42 -14
- package/docs/TODO.md +9 -8
- package/examples/group.deva +12 -0
- package/examples/index.deva +8 -8
- package/examples/loop.deva +15 -0
- package/examples/variables.deva +9 -0
- package/out-tsc/bin/devalang.exe +0 -0
- package/package.json +44 -44
- package/project-version.json +5 -5
- package/rust/cli/build.rs +0 -1
- package/rust/cli/play.rs +2 -1
- package/rust/core/audio/interpreter.rs +317 -0
- package/rust/{audio → core/audio}/loader.rs +4 -0
- package/rust/{audio → core/audio}/render.rs +1 -5
- package/rust/core/builder/mod.rs +2 -1
- package/rust/core/lexer/handler/indent.rs +1 -1
- package/rust/core/lexer/handler/mod.rs +1 -2
- package/rust/core/lexer/handler/string.rs +3 -6
- package/rust/core/mod.rs +2 -1
- package/rust/core/parser/handler/identifier.rs +127 -1
- package/rust/core/parser/statement.rs +9 -5
- package/rust/core/preprocessor/processor.rs +28 -2
- package/rust/core/preprocessor/resolver/bank.rs +10 -9
- package/rust/core/preprocessor/resolver/group.rs +113 -0
- package/rust/core/preprocessor/resolver/loop_.rs +3 -6
- package/rust/core/preprocessor/resolver/mod.rs +7 -0
- package/rust/core/preprocessor/resolver/trigger.rs +0 -3
- package/rust/lib.rs +0 -1
- package/rust/main.rs +0 -1
- package/examples/exported.deva +0 -7
- package/rust/audio/interpreter.rs +0 -143
- /package/rust/{audio → core/audio}/engine.rs +0 -0
- /package/rust/{audio → core/audio}/mod.rs +0 -0
- /package/rust/{audio → core/audio}/player.rs +0 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
use crate::{
|
|
2
|
+
core::{
|
|
3
|
+
audio::{ engine::AudioEngine, loader::load_trigger },
|
|
4
|
+
parser::statement::{ Statement, StatementKind },
|
|
5
|
+
shared::{ duration::Duration, value::Value },
|
|
6
|
+
store::variable::VariableTable,
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
pub fn interprete_statements(
|
|
11
|
+
statements: &Vec<Statement>,
|
|
12
|
+
audio_engine: AudioEngine,
|
|
13
|
+
entry: String,
|
|
14
|
+
output: String
|
|
15
|
+
) -> (AudioEngine, f32, f32) {
|
|
16
|
+
let mut base_bpm = 120.0;
|
|
17
|
+
let mut base_duration = 60.0 / base_bpm;
|
|
18
|
+
|
|
19
|
+
let variable_table = audio_engine.variables.clone();
|
|
20
|
+
|
|
21
|
+
let (updated_audio_engine, base_bpm, max_end_time) = execute_audio_statements(
|
|
22
|
+
audio_engine.clone(),
|
|
23
|
+
variable_table.clone(),
|
|
24
|
+
statements.clone(),
|
|
25
|
+
base_bpm.clone(),
|
|
26
|
+
base_duration.clone(),
|
|
27
|
+
0.0,
|
|
28
|
+
0.0
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
(updated_audio_engine, base_bpm, max_end_time)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
pub fn execute_audio_statements(
|
|
35
|
+
mut audio_engine: AudioEngine,
|
|
36
|
+
mut variable_table: VariableTable,
|
|
37
|
+
mut statements: Vec<Statement>,
|
|
38
|
+
mut base_bpm: f32,
|
|
39
|
+
mut base_duration: f32,
|
|
40
|
+
mut max_end_time: f32,
|
|
41
|
+
mut cursor_time: f32
|
|
42
|
+
) -> (AudioEngine, f32, f32) {
|
|
43
|
+
for stmt in statements {
|
|
44
|
+
match &stmt.kind {
|
|
45
|
+
StatementKind::Load { source, alias } => {
|
|
46
|
+
variable_table.set(alias.to_string(), Value::String(source.clone()));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
StatementKind::Let { name } => {
|
|
50
|
+
variable_table.set(name.to_string(), stmt.value.clone());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
StatementKind::Tempo => {
|
|
54
|
+
if let Value::Number(bpm_) = &stmt.value {
|
|
55
|
+
base_bpm = *bpm_ as f32;
|
|
56
|
+
base_duration = 60.0 / base_bpm;
|
|
57
|
+
} else {
|
|
58
|
+
eprintln!("❌ Invalid tempo value: {:?}", stmt.value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
StatementKind::Trigger { entity, duration } => {
|
|
63
|
+
if let Some(trigger_val) = variable_table.get(entity) {
|
|
64
|
+
// Étape 1 : Résolution de duration
|
|
65
|
+
let duration_secs = match duration {
|
|
66
|
+
Duration::Number(n) => *n,
|
|
67
|
+
|
|
68
|
+
Duration::Identifier(id) => {
|
|
69
|
+
if id == "auto" {
|
|
70
|
+
1.0 // Valeur par défaut pour "auto"
|
|
71
|
+
} else {
|
|
72
|
+
match variable_table.get(id) {
|
|
73
|
+
Some(Value::Number(n)) => *n,
|
|
74
|
+
Some(Value::Identifier(other)) => {
|
|
75
|
+
if other == "auto" {
|
|
76
|
+
1.0 // Valeur par défaut pour "auto"
|
|
77
|
+
} else {
|
|
78
|
+
eprintln!("❌ Invalid duration identifier '{}': expected number or string, got identifier", id);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
Some(other) => {
|
|
83
|
+
eprintln!(
|
|
84
|
+
"❌ Invalid duration reference '{}': expected number or string, got {:?}",
|
|
85
|
+
id,
|
|
86
|
+
other
|
|
87
|
+
);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
None => {
|
|
91
|
+
eprintln!("❌ Duration identifier '{}' not found in variable table", id);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Duration::Auto => {
|
|
99
|
+
// Si "auto", tu choisis une valeur par défaut ou duration du sample ?
|
|
100
|
+
1.0 // ← par exemple 1.0 beat
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Durée réelle en secondes selon tempo
|
|
105
|
+
let duration_final = duration_secs * base_duration;
|
|
106
|
+
|
|
107
|
+
// Chargement de l'audio
|
|
108
|
+
let (src, _) = load_trigger(
|
|
109
|
+
trigger_val,
|
|
110
|
+
duration,
|
|
111
|
+
base_duration,
|
|
112
|
+
variable_table.clone()
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
audio_engine.insert(&src, cursor_time, duration_final, None);
|
|
116
|
+
|
|
117
|
+
cursor_time += duration_final;
|
|
118
|
+
if cursor_time > max_end_time {
|
|
119
|
+
max_end_time = cursor_time;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
eprintln!("❌ Unknown trigger entity: {}", entity);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
StatementKind::Spawn => {
|
|
127
|
+
if let Value::String(identifier) = &stmt.value {
|
|
128
|
+
match variable_table.get(identifier) {
|
|
129
|
+
Some(Value::Map(map)) => {
|
|
130
|
+
if let Some(Value::Block(block)) = map.get("body") {
|
|
131
|
+
let mut local_max = cursor_time;
|
|
132
|
+
|
|
133
|
+
for inner_stmt in block {
|
|
134
|
+
let (inner_engine, _, inner_end_time) =
|
|
135
|
+
execute_audio_statements(
|
|
136
|
+
audio_engine.clone(),
|
|
137
|
+
variable_table.clone(),
|
|
138
|
+
vec![inner_stmt.clone()],
|
|
139
|
+
base_bpm,
|
|
140
|
+
base_duration,
|
|
141
|
+
max_end_time,
|
|
142
|
+
cursor_time // <- important: same cursor time
|
|
143
|
+
);
|
|
144
|
+
audio_engine = inner_engine;
|
|
145
|
+
if inner_end_time > local_max {
|
|
146
|
+
local_max = inner_end_time;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Update cursor once all done
|
|
151
|
+
if local_max > max_end_time {
|
|
152
|
+
max_end_time = local_max;
|
|
153
|
+
}
|
|
154
|
+
cursor_time = local_max;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
_ => eprintln!("❌ Cannot spawn '{}'", identifier),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
StatementKind::Sleep => {
|
|
163
|
+
let duration_secs = match &stmt.value {
|
|
164
|
+
Value::Number(ms) => *ms / 1000.0,
|
|
165
|
+
|
|
166
|
+
Value::String(s) if s.ends_with("ms") => {
|
|
167
|
+
let ms = s.trim_end_matches("ms").parse::<f32>();
|
|
168
|
+
match ms {
|
|
169
|
+
Ok(ms) => ms / 1000.0,
|
|
170
|
+
Err(_) => {
|
|
171
|
+
eprintln!("❌ Invalid sleep value (ms): {}", s);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
Value::String(s) if s.ends_with("s") => {
|
|
178
|
+
let s_ = s.trim_end_matches("s").parse::<f32>();
|
|
179
|
+
match s_ {
|
|
180
|
+
Ok(secs) => secs,
|
|
181
|
+
Err(_) => {
|
|
182
|
+
eprintln!("❌ Invalid sleep value (s): {}", s);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
other => {
|
|
189
|
+
eprintln!("❌ Invalid sleep value: {:?}", other);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
cursor_time += duration_secs;
|
|
195
|
+
|
|
196
|
+
if cursor_time > max_end_time {
|
|
197
|
+
max_end_time = cursor_time;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
StatementKind::Loop => {
|
|
202
|
+
if let Value::Map(loop_value) = &stmt.value {
|
|
203
|
+
let iterator = loop_value.get("iterator");
|
|
204
|
+
let body = loop_value.get("body");
|
|
205
|
+
|
|
206
|
+
let loop_count = if let Some(Value::Number(n)) = iterator {
|
|
207
|
+
*n as usize
|
|
208
|
+
} else {
|
|
209
|
+
eprintln!("❌ Loop iterator must be a number: {:?}", iterator);
|
|
210
|
+
continue;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
let loop_body = if let Some(Value::Block(body)) = body {
|
|
214
|
+
body.clone()
|
|
215
|
+
} else {
|
|
216
|
+
eprintln!("❌ Loop body must be a block: {:?}", body);
|
|
217
|
+
continue;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
for _ in 0..loop_count {
|
|
221
|
+
let (loop_engine, _, loop_end_time) = execute_audio_statements(
|
|
222
|
+
audio_engine.clone(),
|
|
223
|
+
variable_table.clone(),
|
|
224
|
+
loop_body.clone(),
|
|
225
|
+
base_bpm,
|
|
226
|
+
base_duration,
|
|
227
|
+
max_end_time,
|
|
228
|
+
cursor_time
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
audio_engine = loop_engine;
|
|
232
|
+
|
|
233
|
+
// Update time and max_end_time after each loop iteration
|
|
234
|
+
cursor_time = loop_end_time;
|
|
235
|
+
if loop_end_time > max_end_time {
|
|
236
|
+
max_end_time = loop_end_time;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
StatementKind::Call => {
|
|
243
|
+
if let Value::String(identifier) = &stmt.value {
|
|
244
|
+
match variable_table.get(identifier) {
|
|
245
|
+
Some(Value::Map(map)) => {
|
|
246
|
+
match map.get("body") {
|
|
247
|
+
Some(Value::Block(block)) => {
|
|
248
|
+
let (called_engine, _, called_end_time) =
|
|
249
|
+
execute_audio_statements(
|
|
250
|
+
audio_engine.clone(),
|
|
251
|
+
variable_table.clone(),
|
|
252
|
+
block.clone(),
|
|
253
|
+
base_bpm,
|
|
254
|
+
base_duration,
|
|
255
|
+
max_end_time,
|
|
256
|
+
cursor_time
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
audio_engine = called_engine;
|
|
260
|
+
cursor_time = called_end_time;
|
|
261
|
+
if called_end_time > max_end_time {
|
|
262
|
+
max_end_time = called_end_time;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
Some(other) => {
|
|
266
|
+
eprintln!(
|
|
267
|
+
"❌ Cannot call '{}': expected 'body' to be a block, got {:?}",
|
|
268
|
+
identifier,
|
|
269
|
+
other
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
None => {
|
|
273
|
+
eprintln!("❌ Cannot call '{}': missing 'body' in group map", identifier);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
Some(other) => {
|
|
278
|
+
eprintln!(
|
|
279
|
+
"❌ Cannot call '{}': expected a Map with 'body', got {:?}",
|
|
280
|
+
identifier,
|
|
281
|
+
other
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
None => {
|
|
285
|
+
eprintln!("❌ Cannot call '{}': not found in variable table", identifier);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
eprintln!(
|
|
290
|
+
"❌ Invalid call statement: expected a string identifier, got {:?}",
|
|
291
|
+
stmt.value
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
StatementKind::Bank => {}
|
|
297
|
+
|
|
298
|
+
StatementKind::Import { names, source } => {}
|
|
299
|
+
|
|
300
|
+
StatementKind::Export { names, source } => {}
|
|
301
|
+
|
|
302
|
+
StatementKind::Group => {}
|
|
303
|
+
|
|
304
|
+
StatementKind::Unknown => {
|
|
305
|
+
// Ignore unknown statements
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
_ => {
|
|
309
|
+
eprintln!("Unsupported statement kind: {:?}", stmt);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
audio_engine.set_variables(variable_table);
|
|
315
|
+
|
|
316
|
+
(audio_engine, base_bpm, max_end_time)
|
|
317
|
+
}
|
|
@@ -24,6 +24,10 @@ pub fn load_trigger(
|
|
|
24
24
|
duration_as_secs = base_duration;
|
|
25
25
|
} else if let Some(Value::Number(num)) = variable_table.get(duration_identifier) {
|
|
26
26
|
duration_as_secs = *num;
|
|
27
|
+
} else if let Some(Value::String(num_str)) = variable_table.get(duration_identifier) {
|
|
28
|
+
duration_as_secs = num_str.parse::<f32>().unwrap_or(base_duration);
|
|
29
|
+
} else if let Some(Value::Identifier(num_str)) = variable_table.get(duration_identifier) {
|
|
30
|
+
duration_as_secs = num_str.parse::<f32>().unwrap_or(base_duration);
|
|
27
31
|
} else {
|
|
28
32
|
eprintln!("❌ Invalid duration identifier: {}", duration_identifier);
|
|
29
33
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
use std::collections::HashMap;
|
|
2
2
|
|
|
3
3
|
use crate::{
|
|
4
|
-
audio::{
|
|
5
|
-
core::{
|
|
6
|
-
parser::statement::Statement,
|
|
7
|
-
store::global::GlobalStore,
|
|
8
|
-
},
|
|
4
|
+
core::{ audio::{engine::AudioEngine, interpreter::interprete_statements}, parser::statement::Statement, store::global::GlobalStore },
|
|
9
5
|
utils::logger::{ LogLevel, Logger },
|
|
10
6
|
};
|
|
11
7
|
|
package/rust/core/builder/mod.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
use crate::
|
|
1
|
+
use crate::core::audio::render::render_audio_with_modules;
|
|
2
|
+
use crate::core::parser::statement::Statement;
|
|
2
3
|
use crate::core::store::global::GlobalStore;
|
|
3
4
|
use std::{ collections::HashMap, fs::create_dir_all };
|
|
4
5
|
use std::io::Write;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use crate::core::lexer::token::{Token, TokenKind};
|
|
1
|
+
use crate::core::lexer::token::{ Token, TokenKind };
|
|
2
2
|
|
|
3
3
|
pub fn handle_string_lexer(
|
|
4
4
|
ch: char,
|
|
@@ -11,23 +11,20 @@ pub fn handle_string_lexer(
|
|
|
11
11
|
) {
|
|
12
12
|
let quote_char = ch;
|
|
13
13
|
|
|
14
|
-
// Position de départ du token
|
|
15
14
|
let start_column = *column;
|
|
16
15
|
let start_line = *line;
|
|
17
16
|
|
|
18
|
-
// Consommer le guillemet ouvrant
|
|
19
|
-
chars.next();
|
|
20
17
|
*column += 1;
|
|
21
18
|
|
|
22
19
|
let mut string_content = String::new();
|
|
23
20
|
|
|
24
21
|
while let Some(&next_ch) = chars.peek() {
|
|
25
22
|
if next_ch == quote_char {
|
|
26
|
-
chars.next();
|
|
23
|
+
chars.next();
|
|
27
24
|
*column += 1;
|
|
28
25
|
break;
|
|
29
26
|
} else if next_ch == '\\' {
|
|
30
|
-
chars.next();
|
|
27
|
+
chars.next();
|
|
31
28
|
*column += 1;
|
|
32
29
|
|
|
33
30
|
if let Some(escaped) = chars.next() {
|
package/rust/core/mod.rs
CHANGED
|
@@ -6,7 +6,7 @@ use crate::core::{
|
|
|
6
6
|
};
|
|
7
7
|
use std::collections::HashMap;
|
|
8
8
|
|
|
9
|
-
pub fn parse_identifier_token(parser: &mut Parser,
|
|
9
|
+
pub fn parse_identifier_token(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
|
|
10
10
|
let Some(current_token) = parser.peek_clone() else {
|
|
11
11
|
return Statement::unknown();
|
|
12
12
|
};
|
|
@@ -111,6 +111,132 @@ pub fn parse_identifier_token(parser: &mut Parser, _global_store: &mut GlobalSto
|
|
|
111
111
|
line: current_token.line,
|
|
112
112
|
column: current_token.column,
|
|
113
113
|
};
|
|
114
|
+
} else if current_token.lexeme == "group" {
|
|
115
|
+
parser.advance(); // consume "group"
|
|
116
|
+
|
|
117
|
+
let identifier = if let Some(token) = parser.peek_clone() {
|
|
118
|
+
if token.kind == TokenKind::String {
|
|
119
|
+
parser.advance();
|
|
120
|
+
token.lexeme.clone()
|
|
121
|
+
} else if token.kind == TokenKind::Identifier {
|
|
122
|
+
parser.advance();
|
|
123
|
+
token.lexeme.clone()
|
|
124
|
+
} else {
|
|
125
|
+
return Statement::error(
|
|
126
|
+
token,
|
|
127
|
+
"Expected string or identifier after 'group'".to_string()
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
return Statement::error(current_token, "Expected string after 'group'".to_string());
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
let Some(colon_token) = parser.peek_clone() else {
|
|
135
|
+
return Statement::error(
|
|
136
|
+
current_token,
|
|
137
|
+
"Expected ':' after group identifier".to_string()
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if colon_token.kind != TokenKind::Colon {
|
|
142
|
+
let message = format!(
|
|
143
|
+
"Expected ':' after group identifier, got {:?}",
|
|
144
|
+
colon_token.kind
|
|
145
|
+
);
|
|
146
|
+
return Statement::error(colon_token.clone(), message);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let tokens = parser.collect_until(
|
|
150
|
+
|t| (t.kind == TokenKind::Dedent || t.kind == TokenKind::EOF)
|
|
151
|
+
);
|
|
152
|
+
let group_body = parser.parse_block(tokens.clone(), global_store);
|
|
153
|
+
|
|
154
|
+
// Peek for dedent
|
|
155
|
+
if let Some(token) = parser.peek() {
|
|
156
|
+
if token.kind == TokenKind::Dedent {
|
|
157
|
+
parser.advance();
|
|
158
|
+
} else {
|
|
159
|
+
// Unexpected token after group body
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
// EOF or unexpected end of input
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let mut value_map = HashMap::new();
|
|
166
|
+
|
|
167
|
+
value_map.insert("identifier".to_string(), Value::String(identifier));
|
|
168
|
+
value_map.insert("body".to_string(), Value::Block(group_body.clone()));
|
|
169
|
+
|
|
170
|
+
return Statement {
|
|
171
|
+
kind: StatementKind::Group,
|
|
172
|
+
value: Value::Map(value_map),
|
|
173
|
+
indent: current_token.indent,
|
|
174
|
+
line: current_token.line,
|
|
175
|
+
column: current_token.column,
|
|
176
|
+
};
|
|
177
|
+
} else if current_token.lexeme == "call" {
|
|
178
|
+
parser.advance(); // consume "call"
|
|
179
|
+
|
|
180
|
+
let identifier = if let Some(token) = parser.peek_clone() {
|
|
181
|
+
if token.kind == TokenKind::Identifier {
|
|
182
|
+
parser.advance();
|
|
183
|
+
token.lexeme.clone()
|
|
184
|
+
} else {
|
|
185
|
+
return Statement::error(token, "Expected identifier after 'call'".to_string());
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
return Statement::error(current_token, "Expected identifier after 'call'".to_string());
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return Statement {
|
|
192
|
+
kind: StatementKind::Call,
|
|
193
|
+
value: Value::String(identifier),
|
|
194
|
+
indent: current_token.indent,
|
|
195
|
+
line: current_token.line,
|
|
196
|
+
column: current_token.column,
|
|
197
|
+
};
|
|
198
|
+
} else if current_token.lexeme == "spawn" {
|
|
199
|
+
parser.advance(); // consume "spawn"
|
|
200
|
+
|
|
201
|
+
let identifier = if let Some(token) = parser.peek_clone() {
|
|
202
|
+
if token.kind == TokenKind::Identifier {
|
|
203
|
+
parser.advance();
|
|
204
|
+
token.lexeme.clone()
|
|
205
|
+
} else {
|
|
206
|
+
return Statement::error(token, "Expected identifier after 'spawn'".to_string());
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
return Statement::error(current_token, "Expected identifier after 'spawn'".to_string());
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
return Statement {
|
|
213
|
+
kind: StatementKind::Spawn,
|
|
214
|
+
value: Value::String(identifier),
|
|
215
|
+
indent: current_token.indent,
|
|
216
|
+
line: current_token.line,
|
|
217
|
+
column: current_token.column,
|
|
218
|
+
};
|
|
219
|
+
} else if current_token.lexeme == "sleep" {
|
|
220
|
+
parser.advance(); // consume "sleep"
|
|
221
|
+
|
|
222
|
+
let duration = if let Some(token) = parser.peek_clone() {
|
|
223
|
+
if token.kind == TokenKind::Number {
|
|
224
|
+
parser.advance();
|
|
225
|
+
token.lexeme.parse().unwrap_or(0.0)
|
|
226
|
+
} else {
|
|
227
|
+
return Statement::error(token, "Expected number after 'sleep'".to_string());
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
return Statement::error(current_token, "Expected number after 'sleep'".to_string());
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
return Statement {
|
|
234
|
+
kind: StatementKind::Sleep,
|
|
235
|
+
value: Value::Number(duration),
|
|
236
|
+
indent: current_token.indent,
|
|
237
|
+
line: current_token.line,
|
|
238
|
+
column: current_token.column,
|
|
239
|
+
};
|
|
114
240
|
} else {
|
|
115
241
|
// Unknown identifier handling
|
|
116
242
|
Statement {
|
|
@@ -51,12 +51,16 @@ pub enum StatementKind {
|
|
|
51
51
|
// Loop statements
|
|
52
52
|
Loop,
|
|
53
53
|
|
|
54
|
+
// Group statements
|
|
55
|
+
Group,
|
|
56
|
+
|
|
57
|
+
// Special statements
|
|
58
|
+
Call,
|
|
59
|
+
Spawn,
|
|
60
|
+
Sleep,
|
|
61
|
+
|
|
54
62
|
// Conditional statements
|
|
55
|
-
// If
|
|
56
|
-
// // condition: ConditionParts,
|
|
57
|
-
// condition_state: bool,
|
|
58
|
-
// body: Vec<Statement>,
|
|
59
|
-
// },
|
|
63
|
+
// If
|
|
60
64
|
|
|
61
65
|
// Keyword statements
|
|
62
66
|
Tempo,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
|
|
1
3
|
use crate::core::{
|
|
2
4
|
parser::{ statement::StatementKind, Parser },
|
|
3
|
-
preprocessor::loader::ModuleLoader,
|
|
5
|
+
preprocessor::{ loader::ModuleLoader, resolver::group },
|
|
4
6
|
shared::value::Value,
|
|
5
7
|
store::global::GlobalStore,
|
|
6
8
|
};
|
|
@@ -33,7 +35,31 @@ pub fn process_modules(module_loader: &ModuleLoader, global_store: &mut GlobalSt
|
|
|
33
35
|
module.import_table.add_import(name.clone(), Value::String(source.clone()));
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
|
|
39
|
+
StatementKind::Group => {
|
|
40
|
+
if let Value::Map(map) = &stmt.value {
|
|
41
|
+
if
|
|
42
|
+
let (Some(Value::String(name)), Some(Value::Block(body))) = (
|
|
43
|
+
map.get("identifier"),
|
|
44
|
+
map.get("body"),
|
|
45
|
+
)
|
|
46
|
+
{
|
|
47
|
+
let mut stored_map = HashMap::new();
|
|
48
|
+
|
|
49
|
+
stored_map.insert(
|
|
50
|
+
"identifier".to_string(),
|
|
51
|
+
Value::String(name.clone())
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
stored_map.insert("body".to_string(), Value::Block(body.clone()));
|
|
55
|
+
|
|
56
|
+
module.variable_table.set(name.to_string(), Value::Map(stored_map));
|
|
57
|
+
} else {
|
|
58
|
+
eprintln!("❌ Invalid group definition: {:?}", stmt.value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
37
63
|
_ => {}
|
|
38
64
|
}
|
|
39
65
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
use crate::{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
use crate::{
|
|
2
|
+
core::{
|
|
3
|
+
parser::statement::{ Statement, StatementKind },
|
|
4
|
+
preprocessor::module::Module,
|
|
5
|
+
shared::value::Value,
|
|
6
|
+
store::global::GlobalStore,
|
|
7
|
+
},
|
|
8
|
+
utils::logger::Logger,
|
|
9
|
+
};
|
|
7
10
|
|
|
8
11
|
pub fn resolve_bank(
|
|
9
12
|
stmt: &Statement,
|
|
@@ -28,9 +31,7 @@ pub fn resolve_bank(
|
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
Value::String(_) => {
|
|
32
|
-
// Pas de résolution nécessaire
|
|
33
|
-
}
|
|
34
|
+
Value::String(_) => {}
|
|
34
35
|
|
|
35
36
|
other => {
|
|
36
37
|
let message = format!("Expected a string or identifier for bank, found {:?}", other);
|