@devaloop/devalang 0.0.1-alpha.2 → 0.0.1-alpha.3

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 (96) hide show
  1. package/Cargo.toml +46 -46
  2. package/README.md +7 -6
  3. package/docs/CHANGELOG.md +11 -6
  4. package/docs/ROADMAP.md +5 -1
  5. package/docs/TODO.md +6 -31
  6. package/examples/exported.deva +1 -1
  7. package/examples/index.deva +1 -0
  8. package/out-tsc/bin/devalang.exe +0 -0
  9. package/package.json +1 -2
  10. package/project-version.json +3 -3
  11. package/rust/cli/build.rs +57 -40
  12. package/rust/cli/check.rs +47 -111
  13. package/rust/cli/init.rs +1 -1
  14. package/rust/cli/mod.rs +174 -2
  15. package/rust/{utils/config.rs → config/loader.rs} +3 -2
  16. package/rust/{core/types/config.rs → config/mod.rs} +5 -5
  17. package/rust/core/builder/mod.rs +21 -27
  18. package/rust/core/debugger/lexer.rs +12 -0
  19. package/rust/core/debugger/mod.rs +12 -49
  20. package/rust/core/debugger/preprocessor.rs +23 -0
  21. package/rust/core/error/mod.rs +60 -0
  22. package/rust/core/lexer/{at.rs → handler/at.rs} +1 -1
  23. package/rust/core/lexer/{brace.rs → handler/brace.rs} +1 -1
  24. package/rust/core/lexer/{colon.rs → handler/colon.rs} +1 -1
  25. package/rust/core/lexer/{comment.rs → handler/comment.rs} +3 -3
  26. package/rust/core/lexer/{dot.rs → handler/dot.rs} +1 -1
  27. package/rust/core/lexer/{equal.rs → handler/equal.rs} +1 -1
  28. package/rust/core/lexer/{identifier.rs → handler/identifier.rs} +1 -1
  29. package/rust/core/lexer/{indent.rs → handler/indent.rs} +10 -5
  30. package/rust/core/lexer/handler/mod.rs +238 -0
  31. package/rust/core/lexer/{newline.rs → handler/newline.rs} +6 -10
  32. package/rust/core/lexer/{number.rs → handler/number.rs} +1 -1
  33. package/rust/core/lexer/handler/string.rs +66 -0
  34. package/rust/core/lexer/mod.rs +25 -14
  35. package/rust/core/lexer/token.rs +55 -0
  36. package/rust/core/mod.rs +5 -2
  37. package/rust/core/parser/handler/at.rs +166 -0
  38. package/rust/core/parser/handler/bank.rs +38 -0
  39. package/rust/core/parser/handler/dot.rs +112 -0
  40. package/rust/core/parser/handler/identifier.rs +134 -0
  41. package/rust/core/parser/handler/loop_.rs +55 -0
  42. package/rust/core/parser/handler/mod.rs +6 -0
  43. package/rust/core/parser/handler/tempo.rs +47 -0
  44. package/rust/core/parser/mod.rs +204 -166
  45. package/rust/core/parser/statement.rs +91 -0
  46. package/rust/core/preprocessor/loader.rs +105 -0
  47. package/rust/core/preprocessor/mod.rs +2 -24
  48. package/rust/core/preprocessor/module.rs +37 -56
  49. package/rust/core/preprocessor/processor.rs +41 -0
  50. package/rust/core/preprocessor/resolver.rs +372 -0
  51. package/rust/core/shared/duration.rs +8 -0
  52. package/rust/core/shared/mod.rs +2 -0
  53. package/rust/core/shared/value.rs +18 -0
  54. package/rust/core/store/export.rs +28 -0
  55. package/rust/core/store/global.rs +39 -0
  56. package/rust/core/store/import.rs +28 -0
  57. package/rust/core/store/mod.rs +4 -0
  58. package/rust/core/store/variable.rs +28 -0
  59. package/rust/core/utils/mod.rs +2 -0
  60. package/rust/core/utils/validation.rs +35 -0
  61. package/rust/lib.rs +0 -1
  62. package/rust/main.rs +17 -19
  63. package/rust/utils/logger.rs +69 -34
  64. package/rust/utils/mod.rs +3 -5
  65. package/templates/minimal/.devalang +1 -1
  66. package/templates/welcome/.devalang +1 -1
  67. package/rust/audio/mod.rs +0 -1
  68. package/rust/core/lexer/bracket.rs +0 -41
  69. package/rust/core/lexer/driver.rs +0 -286
  70. package/rust/core/lexer/quote.rs +0 -61
  71. package/rust/core/parser/at.rs +0 -142
  72. package/rust/core/parser/bank.rs +0 -42
  73. package/rust/core/parser/dot.rs +0 -137
  74. package/rust/core/parser/identifer.rs +0 -91
  75. package/rust/core/parser/loop_.rs +0 -62
  76. package/rust/core/parser/tempo.rs +0 -42
  77. package/rust/core/parser/variable.rs +0 -129
  78. package/rust/core/preprocessor/dependencies.rs +0 -54
  79. package/rust/core/preprocessor/resolver/at.rs +0 -24
  80. package/rust/core/preprocessor/resolver/bank.rs +0 -59
  81. package/rust/core/preprocessor/resolver/loop_.rs +0 -82
  82. package/rust/core/preprocessor/resolver/mod.rs +0 -113
  83. package/rust/core/preprocessor/resolver/tempo.rs +0 -70
  84. package/rust/core/preprocessor/resolver/trigger.rs +0 -176
  85. package/rust/core/types/cli.rs +0 -182
  86. package/rust/core/types/mod.rs +0 -8
  87. package/rust/core/types/module.rs +0 -41
  88. package/rust/core/types/parser.rs +0 -73
  89. package/rust/core/types/statement.rs +0 -105
  90. package/rust/core/types/store.rs +0 -116
  91. package/rust/core/types/token.rs +0 -83
  92. package/rust/core/types/variable.rs +0 -32
  93. package/rust/runner/executer.rs +0 -44
  94. package/rust/runner/mod.rs +0 -1
  95. /package/rust/{utils → core/utils}/path.rs +0 -0
  96. /package/rust/utils/{loader.rs → spinner.rs} +0 -0
@@ -0,0 +1,238 @@
1
+ pub mod at;
2
+ pub mod brace;
3
+ pub mod colon;
4
+ pub mod comment;
5
+ pub mod dot;
6
+ pub mod equal;
7
+ pub mod identifier;
8
+ pub mod newline;
9
+ pub mod number;
10
+ pub mod indent;
11
+ pub mod string;
12
+
13
+ use crate::core::lexer::{
14
+ handler::{
15
+ at::handle_at_lexer,
16
+ brace::{ handle_lbrace_lexer, handle_rbrace_lexer },
17
+ colon::handle_colon_lexer,
18
+ comment::handle_comment_lexer,
19
+ dot::handle_dot_lexer,
20
+ equal::handle_equal_lexer,
21
+ identifier::handle_identifier_lexer,
22
+ indent::handle_indent_lexer,
23
+ newline::handle_newline_lexer,
24
+ number::handle_number_lexer,
25
+ string::handle_string_lexer,
26
+ },
27
+ token::{ Token, TokenKind },
28
+ };
29
+
30
+ fn advance_char<I: Iterator<Item = char>>(
31
+ chars: &mut std::iter::Peekable<I>,
32
+ line: &mut usize,
33
+ column: &mut usize
34
+ ) -> Option<char> {
35
+ let c = chars.next()?;
36
+ if c == '\n' {
37
+ *line += 1;
38
+ *column = 1;
39
+ } else {
40
+ *column += 1;
41
+ }
42
+ Some(c)
43
+ }
44
+
45
+ pub fn handle_content_lexing(content: String) -> Vec<Token> {
46
+ let mut tokens = Vec::new();
47
+
48
+ let mut line = 1;
49
+ let mut column = 1;
50
+
51
+ let mut indent_stack: Vec<usize> = vec![0];
52
+ let mut current_indent = 0;
53
+ let mut at_line_start = true;
54
+
55
+ let mut chars = content.chars().peekable();
56
+
57
+ while chars.peek().is_some() {
58
+ if at_line_start {
59
+ handle_indent_lexer(
60
+ &mut chars,
61
+ &mut current_indent,
62
+ &mut indent_stack,
63
+ &mut tokens,
64
+ &mut line,
65
+ &mut column
66
+ );
67
+
68
+ at_line_start = false;
69
+ }
70
+
71
+ let Some(ch) = advance_char(&mut chars, &mut line, &mut column) else {
72
+ break;
73
+ };
74
+
75
+ match ch {
76
+ '\n' => {
77
+ handle_newline_lexer(
78
+ ch,
79
+ &mut chars,
80
+ &mut tokens,
81
+ &mut line,
82
+ &mut column,
83
+ &mut at_line_start,
84
+ &mut current_indent
85
+ );
86
+ }
87
+ ' ' | '\t' => {
88
+ // Already handled by indent_lexer
89
+ }
90
+ '#' => {
91
+ handle_comment_lexer(
92
+ ch,
93
+ &mut chars,
94
+ &mut current_indent,
95
+ &mut indent_stack,
96
+ &mut tokens,
97
+ &mut line,
98
+ &mut column
99
+ );
100
+ }
101
+ ':' => {
102
+ handle_colon_lexer(
103
+ ch,
104
+ &mut chars,
105
+ &mut current_indent,
106
+ &mut indent_stack,
107
+ &mut tokens,
108
+ &mut line,
109
+ &mut column
110
+ );
111
+ }
112
+ '=' => {
113
+ handle_equal_lexer(
114
+ ch,
115
+ &mut chars,
116
+ &mut current_indent,
117
+ &mut indent_stack,
118
+ &mut tokens,
119
+ &mut line,
120
+ &mut column
121
+ );
122
+ }
123
+ '{' => {
124
+ handle_lbrace_lexer(
125
+ ch,
126
+ &mut chars,
127
+ &mut current_indent,
128
+ &mut indent_stack,
129
+ &mut tokens,
130
+ &mut line,
131
+ &mut column
132
+ );
133
+ }
134
+ '}' => {
135
+ handle_rbrace_lexer(
136
+ ch,
137
+ &mut chars,
138
+ &mut current_indent,
139
+ &mut indent_stack,
140
+ &mut tokens,
141
+ &mut line,
142
+ &mut column
143
+ );
144
+ }
145
+ '.' => {
146
+ handle_dot_lexer(
147
+ ch,
148
+ &mut chars,
149
+ &mut current_indent,
150
+ &mut indent_stack,
151
+ &mut tokens,
152
+ &mut line,
153
+ &mut column
154
+ );
155
+ }
156
+ '@' => {
157
+ handle_at_lexer(
158
+ ch,
159
+ &mut chars,
160
+ &mut current_indent,
161
+ &mut indent_stack,
162
+ &mut tokens,
163
+ &mut line,
164
+ &mut column
165
+ );
166
+ }
167
+ '\"' | '\'' => {
168
+ handle_string_lexer(
169
+ ch,
170
+ &mut chars,
171
+ &mut current_indent,
172
+ &mut indent_stack,
173
+ &mut tokens,
174
+ &mut line,
175
+ &mut column
176
+ );
177
+ }
178
+ c if c.is_ascii_digit() => {
179
+ handle_number_lexer(
180
+ c,
181
+ &mut chars,
182
+ &mut current_indent,
183
+ &mut indent_stack,
184
+ &mut tokens,
185
+ &mut line,
186
+ &mut column
187
+ );
188
+ }
189
+ c if c.is_ascii_alphabetic() => {
190
+ handle_identifier_lexer(
191
+ c,
192
+ &mut chars,
193
+ &mut current_indent,
194
+ &mut indent_stack,
195
+ &mut tokens,
196
+ &mut line,
197
+ &mut column
198
+ );
199
+ }
200
+ _ => {
201
+ // Ignore unknown char
202
+ }
203
+ }
204
+ }
205
+
206
+ while indent_stack.len() > 1 {
207
+ indent_stack.pop();
208
+ current_indent = *indent_stack.last().unwrap();
209
+ tokens.push(Token {
210
+ kind: TokenKind::Dedent,
211
+ lexeme: String::new(),
212
+ line,
213
+ column,
214
+ indent: current_indent,
215
+ });
216
+ }
217
+
218
+ tokens.push(Token {
219
+ kind: TokenKind::EOF,
220
+ lexeme: String::new(),
221
+ line: line + 1,
222
+ column: 0,
223
+ indent: 0,
224
+ });
225
+
226
+ // NOTE: Debug only
227
+ // for token in &tokens {
228
+ // println!(
229
+ // "{:?} @ line {}, col {}, indent {}",
230
+ // token.kind,
231
+ // token.line,
232
+ // token.column,
233
+ // token.indent
234
+ // );
235
+ // }
236
+
237
+ tokens
238
+ }
@@ -1,23 +1,19 @@
1
- use crate::core::types::token::{Token, TokenKind};
1
+ use crate::core::lexer::token::{ Token, TokenKind };
2
2
 
3
3
  pub fn handle_newline_lexer(
4
- char: char,
4
+ ch: char,
5
5
  chars: &mut std::iter::Peekable<std::str::Chars>,
6
6
  tokens: &mut Vec<Token>,
7
7
  line: &mut usize,
8
8
  column: &mut usize,
9
9
  at_line_start: &mut bool,
10
- current_indent: &mut usize,
10
+ current_indent: &mut usize
11
11
  ) {
12
12
  tokens.push(Token {
13
13
  kind: TokenKind::Newline,
14
- lexeme: char.to_string(),
14
+ lexeme: ch.to_string(),
15
15
  line: *line,
16
- column: *column,
17
- indent: *current_indent,
16
+ column: 0,
17
+ indent: 0,
18
18
  });
19
-
20
- *line += 1;
21
- *column = 1;
22
- *at_line_start = true;
23
19
  }
@@ -1,4 +1,4 @@
1
- use crate::core::types::token::{Token, TokenKind};
1
+ use crate::core::lexer::token::{ Token, TokenKind };
2
2
 
3
3
  pub fn handle_number_lexer(
4
4
  char: char,
@@ -0,0 +1,66 @@
1
+ use crate::core::lexer::token::{Token, TokenKind};
2
+
3
+ pub fn handle_string_lexer(
4
+ ch: 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
+ let quote_char = ch;
13
+
14
+ // Position de départ du token
15
+ let start_column = *column;
16
+ let start_line = *line;
17
+
18
+ // Consommer le guillemet ouvrant
19
+ chars.next();
20
+ *column += 1;
21
+
22
+ let mut string_content = String::new();
23
+
24
+ while let Some(&next_ch) = chars.peek() {
25
+ if next_ch == quote_char {
26
+ chars.next(); // Consomme le guillemet fermant
27
+ *column += 1;
28
+ break;
29
+ } else if next_ch == '\\' {
30
+ chars.next(); // Consomme '\'
31
+ *column += 1;
32
+
33
+ if let Some(escaped) = chars.next() {
34
+ match escaped {
35
+ 'n' => string_content.push('\n'),
36
+ 't' => string_content.push('\t'),
37
+ '\\' => string_content.push('\\'),
38
+ '"' => string_content.push('"'),
39
+ '\'' => string_content.push('\''),
40
+ other => {
41
+ string_content.push('\\');
42
+ string_content.push(other);
43
+ }
44
+ }
45
+ *column += 1;
46
+ }
47
+ } else {
48
+ chars.next();
49
+ if next_ch == '\n' {
50
+ *line += 1;
51
+ *column = 1;
52
+ } else {
53
+ *column += 1;
54
+ }
55
+ string_content.push(next_ch);
56
+ }
57
+ }
58
+
59
+ tokens.push(Token {
60
+ kind: TokenKind::String,
61
+ lexeme: string_content,
62
+ indent: *current_indent,
63
+ line: start_line,
64
+ column: start_column,
65
+ });
66
+ }
@@ -1,14 +1,25 @@
1
- pub mod indent;
2
- pub mod identifier;
3
- pub mod number;
4
- pub mod at;
5
- pub mod dot;
6
- pub mod quote;
7
- pub mod brace;
8
- pub mod newline;
9
- pub mod comment;
10
- pub mod bracket;
11
- pub mod colon;
12
- pub mod equal;
13
-
14
- pub mod driver;
1
+ pub mod handler;
2
+ pub mod token;
3
+
4
+ use std::fs;
5
+ use crate::core::{ lexer::{ handler::handle_content_lexing, token::Token }, utils::path::normalize_path };
6
+
7
+ pub struct Lexer {}
8
+
9
+ impl Lexer {
10
+ pub fn new() -> Self {
11
+ Lexer {}
12
+ }
13
+
14
+ pub fn lex_tokens(&self, entrypoint: &str) -> Vec<Token> {
15
+ let path = normalize_path(entrypoint);
16
+
17
+ let file_content = fs
18
+ ::read_to_string(&path)
19
+ .expect("Failed to read the entrypoint file");
20
+
21
+ let tokens = handle_content_lexing(file_content);
22
+
23
+ tokens
24
+ }
25
+ }
@@ -0,0 +1,55 @@
1
+ use serde::{ Deserialize, Serialize };
2
+
3
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4
+ pub struct Token {
5
+ pub kind: TokenKind,
6
+ pub lexeme: String,
7
+ pub indent: usize,
8
+ pub line: usize,
9
+ pub column: usize,
10
+ }
11
+
12
+ impl Token {
13
+ pub fn is_error(&self) -> bool {
14
+ match &self.kind {
15
+ TokenKind::Error(_) => {
16
+ return true;
17
+ }
18
+ _ => {
19
+ return false;
20
+ }
21
+ };
22
+ }
23
+ }
24
+
25
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26
+ pub enum TokenKind {
27
+ At,
28
+ Tempo,
29
+ Bank,
30
+ Loop,
31
+ Identifier,
32
+ Map,
33
+ Array,
34
+ Number,
35
+ String,
36
+ Boolean,
37
+ Colon,
38
+ Comma,
39
+ Equals,
40
+ DoubleEquals,
41
+ Dot,
42
+ LBrace,
43
+ RBrace,
44
+ DbQuote,
45
+ Quote,
46
+ LBracket,
47
+ RBracket,
48
+ Newline,
49
+ Indent,
50
+ Dedent,
51
+ Comment,
52
+ Unknown,
53
+ Error(String),
54
+ EOF,
55
+ }
package/rust/core/mod.rs CHANGED
@@ -1,6 +1,9 @@
1
1
  pub mod lexer;
2
- pub mod parser;
3
2
  pub mod preprocessor;
3
+ pub mod store;
4
+ pub mod parser;
5
+ pub mod shared;
4
6
  pub mod debugger;
7
+ pub mod utils;
5
8
  pub mod builder;
6
- pub mod types;
9
+ pub mod error;
@@ -0,0 +1,166 @@
1
+ use crate::core::{
2
+ lexer::token::{ Token, TokenKind },
3
+ parser::{
4
+ handler::identifier::parse_identifier_token,
5
+ statement::{ Statement, StatementKind },
6
+ Parser,
7
+ },
8
+ shared::value::Value,
9
+ store::global::GlobalStore,
10
+ };
11
+ pub fn parse_at_token(parser: &mut Parser, _global_store: &mut GlobalStore) -> Statement {
12
+ parser.advance(); // consume '@'
13
+
14
+ let Some(token) = parser.peek_clone() else {
15
+ return Statement::unknown();
16
+ };
17
+
18
+ let keyword = token.lexeme.as_str();
19
+
20
+ match keyword {
21
+ "import" => {
22
+ parser.advance(); // consume 'import'
23
+
24
+ if !parser.match_token(TokenKind::LBrace) {
25
+ return Statement::error(token, "Expected '{{' after 'import'".to_string());
26
+ }
27
+
28
+ let mut names = Vec::new();
29
+ while let Some(token) = parser.peek() {
30
+ match &token.kind {
31
+ TokenKind::Identifier => {
32
+ names.push(token.lexeme.clone());
33
+ parser.advance();
34
+ }
35
+ TokenKind::Comma => {
36
+ parser.advance();
37
+ }
38
+ TokenKind::RBrace => {
39
+ parser.advance();
40
+ break;
41
+ }
42
+ _ => {
43
+ let message = format!(
44
+ "Unexpected token in import list: {:?}",
45
+ token.kind.clone()
46
+ );
47
+ return Statement::error(token.clone(), message);
48
+ }
49
+ }
50
+ }
51
+
52
+ let Some(from_token) = parser.peek_clone() else {
53
+ return Statement::error(token, "Expected 'from' after import list".to_string());
54
+ };
55
+
56
+ if from_token.lexeme != "from" {
57
+ return Statement::error(token, "Expected keyword 'from'".to_string());
58
+ }
59
+
60
+ parser.advance(); // consume 'from'
61
+
62
+ let Some(source_token) = parser.peek() else {
63
+ return Statement::error(token, "Expected string after 'from'".to_string());
64
+ };
65
+
66
+ if source_token.kind != TokenKind::String {
67
+ return Statement::error(token, "Expected string after 'from'".to_string());
68
+ }
69
+
70
+ let source = source_token.lexeme.clone();
71
+ parser.advance(); // consume string
72
+
73
+ Statement {
74
+ kind: StatementKind::Import { names, source },
75
+ value: Value::Null,
76
+ indent: token.indent,
77
+ line: token.line,
78
+ column: token.column,
79
+ }
80
+ }
81
+
82
+ "export" => {
83
+ parser.advance(); // consume 'export'
84
+
85
+ parser.advance(); // consume '{'
86
+
87
+ let names_tokens = parser.collect_until(|t| TokenKind::RBrace == t.kind);
88
+ let mut names: Vec<String> = Vec::new();
89
+
90
+ for token in names_tokens {
91
+ if token.kind == TokenKind::Identifier {
92
+ names.push(token.lexeme.clone());
93
+ } else if token.kind == TokenKind::Comma {
94
+ continue; // Ignore commas
95
+ } else if token.kind == TokenKind::RBrace {
96
+ break; // Stop at the closing brace
97
+ } else {
98
+ return Statement::error(token, "Unexpected token in export list".to_string());
99
+ }
100
+ }
101
+
102
+ Statement {
103
+ kind: StatementKind::Export {
104
+ names: names.clone(),
105
+ source: parser.current_module.clone(),
106
+ },
107
+ value: Value::Null,
108
+ indent: token.indent,
109
+ line: token.line,
110
+ column: token.column,
111
+ }
112
+ }
113
+
114
+ "load" => {
115
+ parser.advance(); // consume 'load'
116
+
117
+ // Exemple : @load "preset.mydeva"
118
+ let Some(path_token) = parser.peek() else {
119
+ return Statement::error(token, "Expected string after 'load'".to_string());
120
+ };
121
+
122
+ if path_token.kind != TokenKind::String {
123
+ return Statement::error(token, "Expected string after 'load'".to_string());
124
+ }
125
+
126
+ let path = path_token.lexeme.clone();
127
+
128
+ parser.advance(); // consume string
129
+ parser.advance(); // consume 'as'
130
+
131
+ let Some(as_token) = parser.peek_clone() else {
132
+ return Statement::error(
133
+ token,
134
+ "Expected 'as' after path in load statement".to_string()
135
+ );
136
+ };
137
+
138
+ if as_token.kind != TokenKind::Identifier {
139
+ return Statement::error(
140
+ token,
141
+ "Expected identifier after 'as' in load statement".to_string()
142
+ );
143
+ }
144
+
145
+ let alias = as_token.lexeme.clone();
146
+
147
+ parser.advance(); // consume identifier
148
+
149
+ Statement {
150
+ kind: StatementKind::Load {
151
+ source: path,
152
+ alias,
153
+ },
154
+ value: Value::Null,
155
+ indent: token.indent,
156
+ line: token.line,
157
+ column: token.column,
158
+ }
159
+ }
160
+
161
+ _ => {
162
+ let message = format!("Unknown keyword after '@' : {}", keyword);
163
+ Statement::error(token, message)
164
+ }
165
+ }
166
+ }
@@ -0,0 +1,38 @@
1
+ use crate::core::{
2
+ lexer::token::TokenKind,
3
+ parser::{ statement::{ Statement, StatementKind }, 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(bank_token, "Expected identifier or number after 'bank'".to_string());
29
+ };
30
+
31
+ Statement {
32
+ kind: StatementKind::Bank,
33
+ value: bank_value,
34
+ indent: bank_token.indent,
35
+ line: bank_token.line,
36
+ column: bank_token.column,
37
+ }
38
+ }