@devaloop/devalang 0.0.1-alpha.7 → 0.0.1-alpha.9

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.
Files changed (86) hide show
  1. package/Cargo.toml +1 -1
  2. package/README.md +31 -16
  3. package/docs/CHANGELOG.md +49 -2
  4. package/docs/ROADMAP.md +2 -2
  5. package/docs/SYNTAX.md +41 -7
  6. package/docs/TODO.md +3 -3
  7. package/examples/condition.deva +20 -0
  8. package/examples/group.deva +3 -3
  9. package/examples/index.deva +9 -8
  10. package/examples/loop.deva +10 -8
  11. package/examples/synth.deva +14 -0
  12. package/examples/variables.deva +2 -2
  13. package/out-tsc/bin/devalang.exe +0 -0
  14. package/out-tsc/scripts/version/fetch.js +1 -5
  15. package/package.json +1 -1
  16. package/project-version.json +3 -3
  17. package/rust/cli/build.rs +6 -1
  18. package/rust/core/audio/engine.rs +89 -12
  19. package/rust/core/audio/evaluator.rs +31 -0
  20. package/rust/core/audio/interpreter/arrow_call.rs +129 -0
  21. package/rust/core/audio/interpreter/call.rs +64 -0
  22. package/rust/core/audio/interpreter/condition.rs +69 -0
  23. package/rust/core/audio/interpreter/driver.rs +216 -0
  24. package/rust/core/audio/interpreter/let_.rs +19 -0
  25. package/rust/core/audio/interpreter/load.rs +18 -0
  26. package/rust/core/audio/interpreter/loop_.rs +67 -0
  27. package/rust/core/audio/interpreter/mod.rs +12 -0
  28. package/rust/core/audio/interpreter/sleep.rs +36 -0
  29. package/rust/core/audio/interpreter/spawn.rs +66 -0
  30. package/rust/core/audio/interpreter/tempo.rs +16 -0
  31. package/rust/core/audio/interpreter/trigger.rs +69 -0
  32. package/rust/core/audio/loader/mod.rs +1 -0
  33. package/rust/core/audio/{loader.rs → loader/trigger.rs} +3 -1
  34. package/rust/core/audio/mod.rs +2 -1
  35. package/rust/core/audio/renderer.rs +54 -0
  36. package/rust/core/builder/mod.rs +1 -1
  37. package/rust/core/debugger/lexer.rs +1 -1
  38. package/rust/core/debugger/mod.rs +1 -0
  39. package/rust/core/debugger/store.rs +25 -0
  40. package/rust/core/error/mod.rs +1 -1
  41. package/rust/core/lexer/handler/arrow.rs +31 -0
  42. package/rust/core/lexer/handler/driver.rs +226 -0
  43. package/rust/core/lexer/handler/identifier.rs +3 -0
  44. package/rust/core/lexer/handler/mod.rs +4 -227
  45. package/rust/core/lexer/handler/operator.rs +44 -0
  46. package/rust/core/lexer/mod.rs +25 -4
  47. package/rust/core/lexer/token.rs +40 -9
  48. package/rust/core/parser/driver.rs +331 -0
  49. package/rust/core/parser/handler/arrow_call.rs +126 -0
  50. package/rust/core/parser/handler/at.rs +3 -7
  51. package/rust/core/parser/handler/bank.rs +5 -2
  52. package/rust/core/parser/handler/condition.rs +74 -0
  53. package/rust/core/parser/handler/dot.rs +1 -1
  54. package/rust/core/parser/handler/identifier/call.rs +41 -0
  55. package/rust/core/parser/handler/identifier/group.rs +75 -0
  56. package/rust/core/parser/handler/identifier/let_.rs +133 -0
  57. package/rust/core/parser/handler/identifier/mod.rs +51 -0
  58. package/rust/core/parser/handler/identifier/sleep.rs +33 -0
  59. package/rust/core/parser/handler/identifier/spawn.rs +41 -0
  60. package/rust/core/parser/handler/identifier/synth.rs +65 -0
  61. package/rust/core/parser/handler/loop_.rs +25 -19
  62. package/rust/core/parser/handler/mod.rs +3 -1
  63. package/rust/core/parser/handler/tempo.rs +1 -1
  64. package/rust/core/parser/mod.rs +3 -237
  65. package/rust/core/parser/statement.rs +36 -35
  66. package/rust/core/preprocessor/loader.rs +64 -49
  67. package/rust/core/preprocessor/module.rs +3 -6
  68. package/rust/core/preprocessor/processor.rs +13 -4
  69. package/rust/core/preprocessor/resolver/call.rs +123 -0
  70. package/rust/core/preprocessor/resolver/condition.rs +92 -0
  71. package/rust/core/preprocessor/resolver/driver.rs +227 -0
  72. package/rust/core/preprocessor/resolver/group.rs +35 -87
  73. package/rust/core/preprocessor/resolver/let_.rs +31 -0
  74. package/rust/core/preprocessor/resolver/loop_.rs +62 -116
  75. package/rust/core/preprocessor/resolver/mod.rs +9 -153
  76. package/rust/core/preprocessor/resolver/spawn.rs +58 -0
  77. package/rust/core/preprocessor/resolver/synth.rs +50 -0
  78. package/rust/core/preprocessor/resolver/trigger.rs +51 -50
  79. package/rust/core/preprocessor/resolver/value.rs +78 -0
  80. package/rust/core/utils/path.rs +17 -32
  81. package/rust/core/utils/validation.rs +30 -28
  82. package/typescript/scripts/version/fetch.ts +1 -6
  83. package/rust/core/audio/interpreter.rs +0 -317
  84. package/rust/core/audio/render.rs +0 -53
  85. package/rust/core/lexer/handler/equal.rs +0 -32
  86. package/rust/core/parser/handler/identifier.rs +0 -260
@@ -1,317 +0,0 @@
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
- }
@@ -1,53 +0,0 @@
1
- use std::collections::HashMap;
2
-
3
- use crate::{
4
- core::{ audio::{engine::AudioEngine, interpreter::interprete_statements}, parser::statement::Statement, store::global::GlobalStore },
5
- utils::logger::{ LogLevel, Logger },
6
- };
7
-
8
- pub fn render_audio_with_modules(
9
- modules: HashMap<String, Vec<Statement>>,
10
- output_dir: &str,
11
- global_store: &mut GlobalStore
12
- ) -> HashMap<String, AudioEngine> {
13
- let mut result = HashMap::new();
14
-
15
- for (module_name, statements) in modules {
16
- let mut global_max_end_time = 0.0;
17
- let mut audio_engine = AudioEngine::new();
18
-
19
- // Apply the module's variable table if it exists
20
- if let Some(module) = global_store.get_module(&module_name) {
21
- audio_engine.set_variables(module.variable_table.clone());
22
- }
23
-
24
- // Interpret the statements to fill the audio buffer
25
- let (mut audio_engine, module_base_bpm, module_max_end_time) = interprete_statements(
26
- &statements,
27
- audio_engine,
28
- module_name.clone(),
29
- output_dir.to_string()
30
- );
31
-
32
- // Calculate the module's maximum duration
33
- global_max_end_time = module_max_end_time.max(global_max_end_time);
34
- audio_engine.set_duration(global_max_end_time);
35
-
36
- // Check if the buffer contains at least one non-zero sample
37
- if audio_engine.buffer.iter().all(|&s| s == 0) {
38
- let logger = Logger::new();
39
-
40
- logger.log_message(
41
- LogLevel::Warning,
42
- format!("Module '{}' ignored: silent buffer (no non-zero samples)", module_name).as_str()
43
- );
44
-
45
- continue;
46
- }
47
-
48
- // Insert only if the module produces sound
49
- result.insert(module_name, audio_engine);
50
- }
51
-
52
- result
53
- }
@@ -1,32 +0,0 @@
1
- use crate::core::lexer::token::{Token, TokenKind};
2
-
3
- pub fn handle_equal_lexer(
4
- char: char,
5
- chars: &mut std::iter::Peekable<std::str::Chars>,
6
- current_indent: &mut usize,
7
- indent_stack: &mut Vec<usize>,
8
- tokens: &mut Vec<Token>,
9
- line: &mut usize,
10
- column: &mut usize
11
- ) {
12
- if let Some('=') = chars.peek() {
13
- chars.next();
14
- tokens.push(Token {
15
- kind: TokenKind::DoubleEquals,
16
- lexeme: char.to_string(),
17
- line: *line,
18
- column: *column,
19
- indent: *current_indent,
20
- });
21
- *column += 2;
22
- } else {
23
- tokens.push(Token {
24
- kind: TokenKind::Equals,
25
- lexeme: char.to_string(),
26
- line: *line,
27
- column: *column,
28
- indent: *current_indent,
29
- });
30
- *column += 1;
31
- }
32
- }
@@ -1,260 +0,0 @@
1
- use crate::core::{
2
- lexer::token::{ Token, TokenKind },
3
- parser::{ statement::{ Statement, StatementKind }, Parser },
4
- shared::value::Value,
5
- store::global::GlobalStore,
6
- };
7
- use std::collections::HashMap;
8
-
9
- pub fn parse_identifier_token(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
10
- let Some(current_token) = parser.peek_clone() else {
11
- return Statement::unknown();
12
- };
13
-
14
- if current_token.lexeme == "let" {
15
- parser.advance(); // consume "let"
16
-
17
- let identifier = if let Some(token) = parser.peek_clone() {
18
- if token.kind == TokenKind::Identifier {
19
- parser.advance();
20
- token.lexeme.clone()
21
- } else {
22
- return Statement::error(token, "Expected identifier after 'let'".to_string());
23
- }
24
- } else {
25
- return Statement::error(current_token, "Expected identifier after 'let'".to_string());
26
- };
27
-
28
- if !parser.match_token(TokenKind::Equals) {
29
- return Statement::error(current_token, "Expected '=' after identifier".to_string());
30
- }
31
-
32
- let value = match parser.peek_clone() {
33
- Some(token) if token.kind == TokenKind::Identifier => {
34
- parser.advance();
35
- Value::Identifier(token.lexeme.clone())
36
- }
37
- Some(token) if token.kind == TokenKind::String => {
38
- parser.advance();
39
- Value::String(token.lexeme.clone())
40
- }
41
- Some(token) if token.kind == TokenKind::Number => {
42
- parser.advance();
43
- Value::Number(token.lexeme.parse().unwrap_or(0.0))
44
- }
45
- Some(token) if token.kind == TokenKind::LBrace => {
46
- parser.advance(); // consume '{'
47
- let mut map = HashMap::new();
48
-
49
- while let Some(key_token) = parser.peek_clone() {
50
- if key_token.kind == TokenKind::RBrace {
51
- parser.advance(); // consume '}'
52
- break;
53
- }
54
-
55
- if key_token.kind != TokenKind::Identifier {
56
- return Statement::error(
57
- token,
58
- "Expected key identifier in map".to_string()
59
- );
60
- }
61
- parser.advance();
62
- let key = key_token.lexeme.clone();
63
-
64
- if !parser.match_token(TokenKind::Colon) {
65
- let message = format!("Expected ':' after key '{}'", key);
66
- return Statement::error(token, message);
67
- }
68
-
69
- let val = match parser.peek_clone() {
70
- Some(t) if t.kind == TokenKind::Number => {
71
- parser.advance();
72
- Value::Number(t.lexeme.parse().unwrap_or(0.0))
73
- }
74
- Some(t) if t.kind == TokenKind::String => {
75
- parser.advance();
76
- Value::String(t.lexeme.clone())
77
- }
78
- Some(t) if t.kind == TokenKind::Identifier => {
79
- parser.advance();
80
- Value::Identifier(t.lexeme.clone())
81
- }
82
- _ => { Value::Null }
83
- };
84
-
85
- if val == Value::Null {
86
- let message = format!("Invalid value for key '{}'", key);
87
- return Statement::error(token, message);
88
- }
89
-
90
- map.insert(key, val);
91
-
92
- if let Some(t) = parser.peek() {
93
- if t.kind == TokenKind::Comma {
94
- parser.advance(); // skip comma
95
- }
96
- }
97
- }
98
-
99
- Value::Map(map)
100
- }
101
- other => {
102
- let message = format!("Unexpected value token in let: {:?}", other);
103
- return Statement::error(current_token, message);
104
- }
105
- };
106
-
107
- return Statement {
108
- kind: StatementKind::Let { name: identifier },
109
- value,
110
- indent: current_token.indent,
111
- line: current_token.line,
112
- column: current_token.column,
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
- };
240
- } else {
241
- // Unknown identifier handling
242
- Statement {
243
- kind: StatementKind::Unknown,
244
- value: Value::String(current_token.lexeme.clone()),
245
- indent: current_token.indent,
246
- line: current_token.line,
247
- column: current_token.column,
248
- };
249
- }
250
-
251
- parser.advance(); // unknown identifier fallback
252
-
253
- Statement {
254
- kind: StatementKind::Unknown,
255
- value: Value::String(current_token.lexeme.clone()),
256
- indent: current_token.indent,
257
- line: current_token.line,
258
- column: current_token.column,
259
- }
260
- }