@devaloop/devalang 0.0.1-alpha.1 → 0.0.1-alpha.10

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 (155) hide show
  1. package/.devalang +4 -0
  2. package/Cargo.toml +49 -45
  3. package/README.md +127 -46
  4. package/docs/CHANGELOG.md +172 -0
  5. package/docs/COMMANDS.md +60 -6
  6. package/docs/CONFIG.md +30 -0
  7. package/docs/ROADMAP.md +10 -7
  8. package/docs/SYNTAX.md +100 -18
  9. package/docs/TODO.md +31 -28
  10. package/examples/condition.deva +20 -0
  11. package/examples/group.deva +12 -0
  12. package/examples/index.deva +13 -4
  13. package/examples/loop.deva +16 -0
  14. package/examples/samples/hat-808.wav +0 -0
  15. package/examples/synth.deva +14 -0
  16. package/examples/variables.deva +9 -0
  17. package/out-tsc/bin/devalang.exe +0 -0
  18. package/out-tsc/scripts/version/fetch.js +1 -5
  19. package/package.json +5 -4
  20. package/project-version.json +3 -3
  21. package/rust/cli/build.rs +114 -28
  22. package/rust/cli/check.rs +96 -103
  23. package/rust/cli/init.rs +79 -0
  24. package/rust/cli/mod.rs +203 -1
  25. package/rust/cli/play.rs +193 -0
  26. package/rust/cli/template.rs +57 -0
  27. package/rust/config/loader.rs +13 -0
  28. package/rust/config/mod.rs +16 -0
  29. package/rust/core/audio/engine.rs +214 -0
  30. package/rust/core/audio/evaluator.rs +31 -0
  31. package/rust/core/audio/interpreter/arrow_call.rs +129 -0
  32. package/rust/core/audio/interpreter/call.rs +70 -0
  33. package/rust/core/audio/interpreter/condition.rs +69 -0
  34. package/rust/core/audio/interpreter/driver.rs +236 -0
  35. package/rust/core/audio/interpreter/let_.rs +19 -0
  36. package/rust/core/audio/interpreter/load.rs +18 -0
  37. package/rust/core/audio/interpreter/loop_.rs +67 -0
  38. package/rust/core/audio/interpreter/mod.rs +12 -0
  39. package/rust/core/audio/interpreter/sleep.rs +36 -0
  40. package/rust/core/audio/interpreter/spawn.rs +84 -0
  41. package/rust/core/audio/interpreter/tempo.rs +16 -0
  42. package/rust/core/audio/interpreter/trigger.rs +69 -0
  43. package/rust/core/audio/loader/mod.rs +1 -0
  44. package/rust/core/audio/loader/trigger.rs +52 -0
  45. package/rust/core/audio/mod.rs +6 -0
  46. package/rust/core/audio/player.rs +54 -0
  47. package/rust/core/audio/renderer.rs +54 -0
  48. package/rust/core/builder/mod.rs +70 -27
  49. package/rust/core/debugger/lexer.rs +27 -0
  50. package/rust/core/debugger/mod.rs +13 -49
  51. package/rust/core/debugger/preprocessor.rs +27 -0
  52. package/rust/core/debugger/store.rs +25 -0
  53. package/rust/core/error/mod.rs +60 -0
  54. package/rust/core/lexer/handler/arrow.rs +31 -0
  55. package/rust/core/lexer/handler/at.rs +21 -0
  56. package/rust/core/lexer/handler/brace.rs +41 -0
  57. package/rust/core/lexer/handler/colon.rs +21 -0
  58. package/rust/core/lexer/handler/comment.rs +30 -0
  59. package/rust/core/lexer/handler/dot.rs +21 -0
  60. package/rust/core/lexer/handler/driver.rs +230 -0
  61. package/rust/core/lexer/handler/identifier.rs +41 -0
  62. package/rust/core/lexer/handler/indent.rs +52 -0
  63. package/rust/core/lexer/handler/mod.rs +14 -0
  64. package/rust/core/lexer/handler/newline.rs +23 -0
  65. package/rust/core/lexer/handler/number.rs +31 -0
  66. package/rust/core/lexer/handler/operator.rs +44 -0
  67. package/rust/core/lexer/handler/string.rs +63 -0
  68. package/rust/core/lexer/mod.rs +37 -319
  69. package/rust/core/lexer/token.rs +86 -0
  70. package/rust/core/mod.rs +6 -2
  71. package/rust/core/parser/driver.rs +331 -0
  72. package/rust/core/parser/handler/arrow_call.rs +126 -0
  73. package/rust/core/parser/handler/at.rs +162 -0
  74. package/rust/core/parser/handler/bank.rs +41 -0
  75. package/rust/core/parser/handler/condition.rs +74 -0
  76. package/rust/core/parser/handler/dot.rs +112 -0
  77. package/rust/core/parser/handler/identifier/call.rs +41 -0
  78. package/rust/core/parser/handler/identifier/group.rs +75 -0
  79. package/rust/core/parser/handler/identifier/let_.rs +133 -0
  80. package/rust/core/parser/handler/identifier/mod.rs +51 -0
  81. package/rust/core/parser/handler/identifier/sleep.rs +33 -0
  82. package/rust/core/parser/handler/identifier/spawn.rs +41 -0
  83. package/rust/core/parser/handler/identifier/synth.rs +65 -0
  84. package/rust/core/parser/handler/loop_.rs +72 -0
  85. package/rust/core/parser/handler/mod.rs +8 -0
  86. package/rust/core/parser/handler/tempo.rs +47 -0
  87. package/rust/core/parser/mod.rs +3 -200
  88. package/rust/core/parser/statement.rs +96 -0
  89. package/rust/core/preprocessor/loader.rs +229 -0
  90. package/rust/core/preprocessor/mod.rs +2 -24
  91. package/rust/core/preprocessor/module.rs +42 -56
  92. package/rust/core/preprocessor/processor.rs +76 -0
  93. package/rust/core/preprocessor/resolver/bank.rs +41 -51
  94. package/rust/core/preprocessor/resolver/call.rs +123 -0
  95. package/rust/core/preprocessor/resolver/condition.rs +92 -0
  96. package/rust/core/preprocessor/resolver/driver.rs +227 -0
  97. package/rust/core/preprocessor/resolver/group.rs +61 -0
  98. package/rust/core/preprocessor/resolver/let_.rs +31 -0
  99. package/rust/core/preprocessor/resolver/loop_.rs +76 -67
  100. package/rust/core/preprocessor/resolver/mod.rs +12 -111
  101. package/rust/core/preprocessor/resolver/spawn.rs +58 -0
  102. package/rust/core/preprocessor/resolver/synth.rs +50 -0
  103. package/rust/core/preprocessor/resolver/tempo.rs +40 -61
  104. package/rust/core/preprocessor/resolver/trigger.rs +90 -154
  105. package/rust/core/preprocessor/resolver/value.rs +78 -0
  106. package/rust/core/shared/duration.rs +8 -0
  107. package/rust/core/shared/mod.rs +2 -0
  108. package/rust/core/shared/value.rs +28 -0
  109. package/rust/core/store/export.rs +28 -0
  110. package/rust/core/store/global.rs +39 -0
  111. package/rust/core/store/import.rs +28 -0
  112. package/rust/core/store/mod.rs +4 -0
  113. package/rust/core/store/variable.rs +28 -0
  114. package/rust/core/utils/mod.rs +2 -0
  115. package/rust/core/utils/path.rs +31 -0
  116. package/rust/core/utils/validation.rs +37 -0
  117. package/rust/lib.rs +161 -1
  118. package/rust/main.rs +46 -30
  119. package/rust/utils/file.rs +35 -0
  120. package/rust/utils/logger.rs +108 -34
  121. package/rust/utils/mod.rs +3 -2
  122. package/rust/utils/{loader.rs → spinner.rs} +2 -0
  123. package/rust/utils/watcher.rs +33 -0
  124. package/templates/minimal/.devalang +5 -0
  125. package/templates/minimal/README.md +202 -0
  126. package/templates/minimal/src/index.deva +2 -0
  127. package/templates/welcome/.devalang +5 -0
  128. package/templates/welcome/README.md +202 -0
  129. package/templates/welcome/samples/kick-808.wav +0 -0
  130. package/templates/welcome/src/index.deva +13 -0
  131. package/templates/welcome/src/variables.deva +5 -0
  132. package/typescript/scripts/version/fetch.ts +1 -6
  133. package/examples/exported.deva +0 -7
  134. package/rust/audio/mod.rs +0 -1
  135. package/rust/cli/new.rs +0 -1
  136. package/rust/core/parser/at.rs +0 -142
  137. package/rust/core/parser/bank.rs +0 -42
  138. package/rust/core/parser/dot.rs +0 -107
  139. package/rust/core/parser/identifer.rs +0 -91
  140. package/rust/core/parser/loop_.rs +0 -62
  141. package/rust/core/parser/tempo.rs +0 -42
  142. package/rust/core/parser/variable.rs +0 -129
  143. package/rust/core/preprocessor/dependencies.rs +0 -54
  144. package/rust/core/preprocessor/resolver/at.rs +0 -24
  145. package/rust/core/types/cli.rs +0 -160
  146. package/rust/core/types/mod.rs +0 -7
  147. package/rust/core/types/module.rs +0 -41
  148. package/rust/core/types/parser.rs +0 -73
  149. package/rust/core/types/statement.rs +0 -105
  150. package/rust/core/types/store.rs +0 -116
  151. package/rust/core/types/token.rs +0 -83
  152. package/rust/core/types/variable.rs +0 -32
  153. package/rust/runner/executer.rs +0 -44
  154. package/rust/runner/mod.rs +0 -1
  155. package/rust/utils/path.rs +0 -46
@@ -0,0 +1,331 @@
1
+ use crate::core::{
2
+ lexer::token::{ Token, TokenKind },
3
+ parser::{
4
+ handler::{
5
+ arrow_call::parse_arrow_call,
6
+ at::parse_at_token,
7
+ bank::parse_bank_token,
8
+ condition::parse_condition_token,
9
+ dot::parse_dot_token,
10
+ identifier::parse_identifier_token,
11
+ loop_::parse_loop_token,
12
+ tempo::parse_tempo_token,
13
+ },
14
+ statement::Statement,
15
+ },
16
+ shared::value::Value,
17
+ store::global::GlobalStore,
18
+ };
19
+
20
+ #[derive(Debug, Clone, PartialEq)]
21
+ pub struct Parser {
22
+ pub resolve_modules: bool,
23
+ pub tokens: Vec<Token>,
24
+ pub token_index: usize,
25
+ pub current_module: String,
26
+ pub previous: Option<Token>,
27
+ }
28
+
29
+ impl Parser {
30
+ pub fn new() -> Self {
31
+ Parser {
32
+ resolve_modules: false,
33
+ tokens: Vec::new(),
34
+ token_index: 0,
35
+ current_module: String::new(),
36
+ previous: None,
37
+ }
38
+ }
39
+
40
+ pub fn set_current_module(&mut self, module_path: String) {
41
+ self.current_module = module_path;
42
+ }
43
+
44
+ pub fn advance(&mut self) -> Option<&Token> {
45
+ if self.is_eof() {
46
+ return None;
47
+ }
48
+
49
+ self.previous = self.tokens.get(self.token_index).cloned();
50
+ self.token_index += 1;
51
+
52
+ self.tokens.get(self.token_index - 1)
53
+ }
54
+
55
+ pub fn peek_is(&self, expected: &str) -> bool {
56
+ self.peek().map_or(false, |t| t.lexeme == expected)
57
+ }
58
+
59
+ pub fn peek_nth(&self, n: usize) -> Option<&Token> {
60
+ if self.token_index + n < self.tokens.len() {
61
+ self.tokens.get(self.token_index + n)
62
+ } else {
63
+ None
64
+ }
65
+ }
66
+
67
+ pub fn advance_if(&mut self, kind: TokenKind) -> bool {
68
+ if self.match_token(kind) { true } else { false }
69
+ }
70
+
71
+ pub fn match_token(&mut self, kind: TokenKind) -> bool {
72
+ if let Some(tok) = self.peek() {
73
+ if tok.kind == kind {
74
+ self.advance();
75
+ return true;
76
+ }
77
+ }
78
+ false
79
+ }
80
+
81
+ pub fn previous_clone(&self) -> Option<Token> {
82
+ self.previous.clone()
83
+ }
84
+
85
+ pub fn parse_block(
86
+ &self,
87
+ tokens: Vec<Token>,
88
+ global_store: &mut GlobalStore
89
+ ) -> Vec<Statement> {
90
+ let mut inner_parser = Parser {
91
+ resolve_modules: self.resolve_modules,
92
+ tokens,
93
+ token_index: 0,
94
+ current_module: self.current_module.clone(),
95
+ previous: None,
96
+ };
97
+
98
+ inner_parser.parse_tokens(inner_parser.tokens.clone(), global_store)
99
+ }
100
+
101
+ pub fn parse_tokens(
102
+ &mut self,
103
+ tokens: Vec<Token>,
104
+ global_store: &mut GlobalStore
105
+ ) -> Vec<Statement> {
106
+ self.tokens = tokens;
107
+ self.token_index = 0;
108
+
109
+ let mut statements = Vec::new();
110
+
111
+ while !self.is_eof() {
112
+ let token = match self.peek() {
113
+ Some(t) => t.clone(),
114
+ None => {
115
+ break;
116
+ }
117
+ };
118
+
119
+ let statement = match &token.kind {
120
+ TokenKind::At => parse_at_token(self, global_store),
121
+ TokenKind::Identifier => {
122
+ if let Some(next) = self.peek_nth(1).cloned() {
123
+ if next.kind == TokenKind::Arrow {
124
+ parse_arrow_call(self, global_store)
125
+ } else {
126
+ parse_identifier_token(self, global_store)
127
+ }
128
+ } else {
129
+ parse_identifier_token(self, global_store)
130
+ }
131
+ }
132
+ TokenKind::Dot => parse_dot_token(self, global_store),
133
+ TokenKind::Tempo => parse_tempo_token(self, global_store),
134
+ TokenKind::Bank => parse_bank_token(self, global_store),
135
+ TokenKind::Loop => parse_loop_token(self, global_store),
136
+ TokenKind::If => parse_condition_token(self, global_store),
137
+
138
+ | TokenKind::Else // Ignore else, already handled in `parse_condition_token`
139
+ | TokenKind::Comment
140
+ | TokenKind::Equals
141
+ | TokenKind::Colon
142
+ | TokenKind::Number
143
+ | TokenKind::String
144
+ | TokenKind::LBrace
145
+ | TokenKind::RBrace
146
+ | TokenKind::Comma
147
+ | TokenKind::Newline
148
+ | TokenKind::Dedent
149
+ | TokenKind::Indent => {
150
+ self.advance();
151
+ continue;
152
+ }
153
+
154
+ TokenKind::EOF => {
155
+ break;
156
+ }
157
+
158
+ _ => {
159
+ println!("Unhandled token: {:?}", token);
160
+ self.advance();
161
+ Statement::unknown()
162
+ }
163
+ };
164
+
165
+ statements.push(statement);
166
+ }
167
+
168
+ statements
169
+ }
170
+
171
+ pub fn check_token(&self, kind: TokenKind) -> bool {
172
+ self.peek().map_or(false, |t| t.kind == kind)
173
+ }
174
+
175
+ pub fn parse_map_value(&mut self) -> Option<Value> {
176
+ if !self.match_token(TokenKind::LBrace) {
177
+ return None;
178
+ }
179
+
180
+ let mut map = std::collections::HashMap::new();
181
+
182
+ while !self.check_token(TokenKind::RBrace) && !self.is_eof() {
183
+ let key = if let Some(token) = self.advance() {
184
+ token.lexeme.clone()
185
+ } else {
186
+ break;
187
+ };
188
+
189
+ if !self.match_token(TokenKind::Colon) {
190
+ println!("Expected ':' after map key '{}'", key);
191
+ break;
192
+ }
193
+
194
+ let value = if let Some(token) = self.peek_clone() {
195
+ match token.kind {
196
+ TokenKind::String => {
197
+ self.advance();
198
+ Value::String(token.lexeme.clone())
199
+ }
200
+ TokenKind::Number => {
201
+ self.advance();
202
+ Value::Number(token.lexeme.parse().unwrap_or(0.0))
203
+ }
204
+ TokenKind::Identifier => {
205
+ self.advance();
206
+ Value::Identifier(token.lexeme.clone())
207
+ }
208
+ _ => {
209
+ println!("Unexpected token in map value: {:?}", token);
210
+ Value::Null
211
+ }
212
+ }
213
+ } else {
214
+ Value::Null
215
+ };
216
+
217
+ map.insert(key, value);
218
+ }
219
+
220
+ if !self.match_token(TokenKind::RBrace) {
221
+ println!("Expected '}}' at end of map");
222
+ }
223
+
224
+ Some(Value::Map(map))
225
+ }
226
+
227
+ pub fn peek(&self) -> Option<&Token> {
228
+ self.tokens.get(self.token_index)
229
+ }
230
+
231
+ pub fn peek_clone(&self) -> Option<Token> {
232
+ self.tokens.get(self.token_index).cloned()
233
+ }
234
+
235
+ pub fn expect(&mut self, kind: TokenKind) -> Result<&Token, String> {
236
+ let tok = self.advance().ok_or("Unexpected end of input")?;
237
+ if tok.kind == kind {
238
+ Ok(tok)
239
+ } else {
240
+ Err(format!("Expected {:?}, got {:?}", kind, tok.kind))
241
+ }
242
+ }
243
+
244
+ pub fn collect_block_tokens(&mut self, base_indent: usize) -> Vec<Token> {
245
+ let mut tokens = Vec::new();
246
+
247
+ while let Some(tok) = self.peek() {
248
+ if tok.indent <= base_indent && tok.kind != TokenKind::Newline {
249
+ break;
250
+ }
251
+ tokens.push(self.advance().unwrap().clone());
252
+ }
253
+
254
+ tokens
255
+ }
256
+
257
+ pub fn collect_until<F>(&mut self, condition: F) -> Vec<Token> where F: Fn(&Token) -> bool {
258
+ let mut collected = Vec::new();
259
+ while let Some(token) = self.peek() {
260
+ if token.kind == TokenKind::Newline || token.kind == TokenKind::Indent {
261
+ self.advance(); // Skip newlines and indents
262
+ continue;
263
+ }
264
+ if token.kind == TokenKind::EOF {
265
+ break;
266
+ }
267
+ if condition(token) {
268
+ break;
269
+ }
270
+ collected.push(self.advance().unwrap().clone());
271
+ }
272
+ collected
273
+ }
274
+
275
+ pub fn is_eof(&self) -> bool {
276
+ self.token_index >= self.tokens.len()
277
+ }
278
+
279
+ pub fn parse_block_until_next_else(
280
+ &mut self,
281
+ base_indent: usize,
282
+ global_store: &mut GlobalStore
283
+ ) -> Vec<Statement> {
284
+ let mut block_tokens = Vec::new();
285
+
286
+ while let Some(tok) = self.peek() {
287
+ // Stop if we encounter an 'else' at same indent level
288
+ if tok.lexeme == "else" && tok.indent == base_indent {
289
+ break;
290
+ }
291
+ block_tokens.push(self.advance().unwrap().clone());
292
+ }
293
+
294
+ self.parse_block(block_tokens, global_store)
295
+ }
296
+
297
+ pub fn parse_condition_until_colon(&mut self) -> Option<Value> {
298
+ let tokens = self.collect_until(|t| t.kind == TokenKind::Colon);
299
+ if tokens.is_empty() {
300
+ return None;
301
+ }
302
+
303
+ let condition = tokens
304
+ .iter()
305
+ .map(|t| t.lexeme.clone())
306
+ .collect::<Vec<_>>()
307
+ .join(" ");
308
+
309
+ Some(Value::String(condition))
310
+ }
311
+
312
+ pub fn parse_block_until_else_or_dedent(
313
+ &mut self,
314
+ base_indent: usize,
315
+ global_store: &mut GlobalStore
316
+ ) -> Vec<Statement> {
317
+ let mut tokens = Vec::new();
318
+
319
+ while let Some(tok) = self.peek() {
320
+ if tok.lexeme == "else" && tok.indent == base_indent {
321
+ break;
322
+ }
323
+ if tok.indent < base_indent && tok.kind != TokenKind::Newline {
324
+ break;
325
+ }
326
+ tokens.push(self.advance().unwrap().clone());
327
+ }
328
+
329
+ self.parse_block(tokens, global_store)
330
+ }
331
+ }
@@ -0,0 +1,126 @@
1
+ use crate::core::{
2
+ lexer::token::TokenKind,
3
+ parser::{ driver::Parser, statement::{ Statement, StatementKind } },
4
+ shared::value::Value,
5
+ store::global::GlobalStore,
6
+ };
7
+
8
+ pub fn parse_arrow_call(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
9
+ let Some(target_token) = parser.peek_clone() else {
10
+ return Statement::unknown();
11
+ };
12
+
13
+ if target_token.kind != TokenKind::Identifier {
14
+ parser.advance(); // consume target token
15
+ return Statement::unknown();
16
+ }
17
+
18
+ let Some(arrow_token) = parser.peek_nth(1).cloned() else {
19
+ parser.advance(); // consume arrow token
20
+ return Statement {
21
+ kind: StatementKind::Unknown,
22
+ value: Value::String(target_token.lexeme.clone()),
23
+ indent: target_token.indent,
24
+ line: target_token.line,
25
+ column: target_token.column,
26
+ };
27
+ };
28
+
29
+ if arrow_token.kind != TokenKind::Arrow {
30
+ parser.advance(); // consume method token
31
+ return Statement {
32
+ kind: StatementKind::Unknown,
33
+ value: Value::String(target_token.lexeme.clone()),
34
+ indent: target_token.indent,
35
+ line: target_token.line,
36
+ column: target_token.column,
37
+ };
38
+ }
39
+
40
+ // We have a valid arrow call, so we consume the arrow token
41
+ let Some(method_token) = parser.peek_nth(2).cloned() else {
42
+ parser.advance();
43
+ return Statement::unknown();
44
+ };
45
+
46
+ if method_token.kind != TokenKind::Identifier {
47
+ parser.advance();
48
+ return Statement::unknown();
49
+ }
50
+
51
+ // Consume the tokens for target, arrow, and method
52
+ parser.advance(); // target
53
+ parser.advance(); // ->
54
+ parser.advance(); // method
55
+
56
+ let mut args = Vec::new();
57
+
58
+ while let Some(token) = parser.peek_clone() {
59
+ if token.kind == TokenKind::Newline || token.kind == TokenKind::EOF {
60
+ break;
61
+ }
62
+
63
+ parser.advance();
64
+
65
+ let value = match token.kind {
66
+ TokenKind::Identifier => Value::Identifier(token.lexeme.clone()),
67
+ TokenKind::String => Value::String(token.lexeme.clone()),
68
+ TokenKind::Number => Value::Number(token.lexeme.parse::<f32>().unwrap_or(0.0)),
69
+ TokenKind::LBrace => {
70
+ // Handle map literal
71
+ let mut map = std::collections::HashMap::new();
72
+ while let Some(inner_token) = parser.peek_clone() {
73
+ if inner_token.kind == TokenKind::RBrace {
74
+ parser.advance(); // consume RBrace
75
+ break;
76
+ }
77
+ if inner_token.kind == TokenKind::Newline || inner_token.kind == TokenKind::EOF {
78
+ break;
79
+ }
80
+ parser.advance(); // consume key token
81
+ let key = inner_token.lexeme.clone();
82
+
83
+ if let Some(colon_token) = parser.peek_clone() {
84
+ if colon_token.kind == TokenKind::Colon {
85
+ parser.advance(); // consume colon
86
+ if let Some(value_token) = parser.peek_clone() {
87
+ parser.advance(); // consume value token
88
+ let value = match value_token.kind {
89
+ TokenKind::Identifier =>
90
+ Value::Identifier(value_token.lexeme.clone()),
91
+ TokenKind::String => Value::String(value_token.lexeme.clone()),
92
+ TokenKind::Number =>
93
+ Value::Number(
94
+ value_token.lexeme.parse::<f32>().unwrap_or(0.0)
95
+ ),
96
+ TokenKind::Boolean =>
97
+ Value::Boolean(
98
+ value_token.lexeme.parse::<bool>().unwrap_or(false)
99
+ ),
100
+ _ => Value::Unknown,
101
+ };
102
+ map.insert(key, value);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ Value::Map(map)
108
+ }
109
+ _ => Value::Unknown,
110
+ };
111
+
112
+ args.push(value);
113
+ }
114
+
115
+ Statement {
116
+ kind: StatementKind::ArrowCall {
117
+ target: target_token.lexeme.clone(),
118
+ method: method_token.lexeme.clone(),
119
+ args,
120
+ },
121
+ value: Value::Null,
122
+ indent: target_token.indent,
123
+ line: target_token.line,
124
+ column: target_token.column,
125
+ }
126
+ }
@@ -0,0 +1,162 @@
1
+ use crate::core::{
2
+ lexer::token::TokenKind,
3
+ parser::{ driver::Parser, statement::{ Statement, StatementKind } },
4
+ shared::value::Value,
5
+ store::global::GlobalStore,
6
+ };
7
+ pub fn parse_at_token(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
8
+ parser.advance(); // consume '@'
9
+
10
+ let Some(token) = parser.peek_clone() else {
11
+ return Statement::unknown();
12
+ };
13
+
14
+ let keyword = token.lexeme.as_str();
15
+
16
+ match keyword {
17
+ "import" => {
18
+ parser.advance(); // consume 'import'
19
+
20
+ if !parser.match_token(TokenKind::LBrace) {
21
+ return Statement::error(token, "Expected '{{' after 'import'".to_string());
22
+ }
23
+
24
+ let mut names = Vec::new();
25
+ while let Some(token) = parser.peek() {
26
+ match &token.kind {
27
+ TokenKind::Identifier => {
28
+ names.push(token.lexeme.clone());
29
+ parser.advance();
30
+ }
31
+ TokenKind::Comma => {
32
+ parser.advance();
33
+ }
34
+ TokenKind::RBrace => {
35
+ parser.advance();
36
+ break;
37
+ }
38
+ _ => {
39
+ let message = format!(
40
+ "Unexpected token in import list: {:?}",
41
+ token.kind.clone()
42
+ );
43
+ return Statement::error(token.clone(), message);
44
+ }
45
+ }
46
+ }
47
+
48
+ let Some(from_token) = parser.peek_clone() else {
49
+ return Statement::error(token, "Expected 'from' after import list".to_string());
50
+ };
51
+
52
+ if from_token.lexeme != "from" {
53
+ return Statement::error(token, "Expected keyword 'from'".to_string());
54
+ }
55
+
56
+ parser.advance(); // consume 'from'
57
+
58
+ let Some(source_token) = parser.peek() else {
59
+ return Statement::error(token, "Expected string after 'from'".to_string());
60
+ };
61
+
62
+ if source_token.kind != TokenKind::String {
63
+ return Statement::error(token, "Expected string after 'from'".to_string());
64
+ }
65
+
66
+ let source = source_token.lexeme.clone();
67
+ parser.advance(); // consume string
68
+
69
+ Statement {
70
+ kind: StatementKind::Import { names, source },
71
+ value: Value::Null,
72
+ indent: token.indent,
73
+ line: token.line,
74
+ column: token.column,
75
+ }
76
+ }
77
+
78
+ "export" => {
79
+ parser.advance(); // consume 'export'
80
+
81
+ parser.advance(); // consume '{'
82
+
83
+ let names_tokens = parser.collect_until(|t| TokenKind::RBrace == t.kind);
84
+ let mut names: Vec<String> = Vec::new();
85
+
86
+ for token in names_tokens {
87
+ if token.kind == TokenKind::Identifier {
88
+ names.push(token.lexeme.clone());
89
+ } else if token.kind == TokenKind::Comma {
90
+ continue; // Ignore commas
91
+ } else if token.kind == TokenKind::RBrace {
92
+ break; // Stop at the closing brace
93
+ } else {
94
+ return Statement::error(token, "Unexpected token in export list".to_string());
95
+ }
96
+ }
97
+
98
+ Statement {
99
+ kind: StatementKind::Export {
100
+ names: names.clone(),
101
+ source: parser.current_module.clone(),
102
+ },
103
+ value: Value::Null,
104
+ indent: token.indent,
105
+ line: token.line,
106
+ column: token.column,
107
+ }
108
+ }
109
+
110
+ "load" => {
111
+ parser.advance(); // consume 'load'
112
+
113
+ // Exemple : @load "preset.mydeva"
114
+ let Some(path_token) = parser.peek() else {
115
+ return Statement::error(token, "Expected string after 'load'".to_string());
116
+ };
117
+
118
+ if path_token.kind != TokenKind::String {
119
+ return Statement::error(token, "Expected string after 'load'".to_string());
120
+ }
121
+
122
+ let path = path_token.lexeme.clone();
123
+
124
+ parser.advance(); // consume string
125
+ parser.advance(); // consume 'as'
126
+
127
+ let Some(as_token) = parser.peek_clone() else {
128
+ return Statement::error(
129
+ token,
130
+ "Expected 'as' after path in load statement".to_string()
131
+ );
132
+ };
133
+
134
+ if as_token.kind != TokenKind::Identifier {
135
+ return Statement::error(
136
+ token,
137
+ "Expected identifier after 'as' in load statement".to_string()
138
+ );
139
+ }
140
+
141
+ let alias = as_token.lexeme.clone();
142
+
143
+ parser.advance(); // consume identifier
144
+
145
+ Statement {
146
+ kind: StatementKind::Load {
147
+ source: path,
148
+ alias,
149
+ },
150
+ value: Value::Null,
151
+ indent: token.indent,
152
+ line: token.line,
153
+ column: token.column,
154
+ }
155
+ }
156
+
157
+ _ => {
158
+ let message = format!("Unknown keyword after '@' : {}", keyword);
159
+ Statement::error(token, message)
160
+ }
161
+ }
162
+ }
@@ -0,0 +1,41 @@
1
+ use crate::core::{
2
+ lexer::token::TokenKind,
3
+ parser::{ statement::{ Statement, StatementKind }, driver::Parser },
4
+ shared::value::Value,
5
+ store::global::GlobalStore,
6
+ };
7
+
8
+ pub fn parse_bank_token(parser: &mut Parser, _global_store: &mut GlobalStore) -> Statement {
9
+ parser.advance(); // consume 'bank'
10
+
11
+ let Some(bank_token) = parser.previous_clone() else {
12
+ return Statement::unknown();
13
+ };
14
+
15
+ let bank_value = if let Some(token) = parser.peek_clone() {
16
+ match token.kind {
17
+ TokenKind::Identifier => {
18
+ parser.advance();
19
+ Value::Identifier(token.lexeme.clone())
20
+ }
21
+ TokenKind::Number => {
22
+ parser.advance();
23
+ Value::Number(token.lexeme.parse::<f32>().unwrap_or(0.0))
24
+ }
25
+ _ => Value::Unknown,
26
+ }
27
+ } else {
28
+ return Statement::error(
29
+ bank_token,
30
+ "Expected identifier or number after 'bank'".to_string()
31
+ );
32
+ };
33
+
34
+ Statement {
35
+ kind: StatementKind::Bank,
36
+ value: bank_value,
37
+ indent: bank_token.indent,
38
+ line: bank_token.line,
39
+ column: bank_token.column,
40
+ }
41
+ }