@devaloop/devalang 0.0.1-alpha.7 → 0.0.1-alpha.8
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 +29 -10
- package/docs/CHANGELOG.md +22 -2
- package/docs/ROADMAP.md +2 -2
- package/docs/SYNTAX.md +41 -7
- package/docs/TODO.md +3 -3
- package/examples/condition.deva +24 -0
- package/examples/index.deva +4 -5
- package/examples/variables.deva +1 -1
- package/out-tsc/bin/devalang.exe +0 -0
- package/package.json +1 -1
- package/project-version.json +3 -3
- package/rust/cli/build.rs +6 -1
- package/rust/core/audio/evaluator.rs +31 -0
- package/rust/core/audio/interpreter/call.rs +42 -0
- package/rust/core/audio/interpreter/condition.rs +65 -0
- package/rust/core/audio/interpreter/driver.rs +204 -0
- package/rust/core/audio/interpreter/let_.rs +19 -0
- package/rust/core/audio/interpreter/load.rs +18 -0
- package/rust/core/audio/interpreter/loop_.rs +59 -0
- package/rust/core/audio/interpreter/mod.rs +11 -0
- package/rust/core/audio/interpreter/sleep.rs +36 -0
- package/rust/core/audio/interpreter/spawn.rs +65 -0
- package/rust/core/audio/interpreter/tempo.rs +16 -0
- package/rust/core/audio/interpreter/trigger.rs +69 -0
- package/rust/core/audio/loader/mod.rs +1 -0
- package/rust/core/audio/{loader.rs → loader/trigger.rs} +3 -1
- package/rust/core/audio/mod.rs +2 -1
- package/rust/core/audio/{render.rs → renderer.rs} +6 -2
- package/rust/core/builder/mod.rs +1 -1
- package/rust/core/debugger/lexer.rs +1 -1
- package/rust/core/debugger/mod.rs +1 -0
- package/rust/core/debugger/store.rs +25 -0
- package/rust/core/error/mod.rs +1 -1
- package/rust/core/lexer/handler/driver.rs +215 -0
- package/rust/core/lexer/handler/identifier.rs +2 -0
- package/rust/core/lexer/handler/mod.rs +3 -227
- package/rust/core/lexer/handler/operator.rs +44 -0
- package/rust/core/lexer/mod.rs +1 -1
- package/rust/core/lexer/token.rs +36 -9
- package/rust/core/parser/driver.rs +312 -0
- package/rust/core/parser/handler/at.rs +3 -7
- package/rust/core/parser/handler/bank.rs +5 -2
- package/rust/core/parser/handler/condition.rs +74 -0
- package/rust/core/parser/handler/dot.rs +1 -1
- package/rust/core/parser/handler/identifier.rs +38 -36
- package/rust/core/parser/handler/loop_.rs +1 -1
- package/rust/core/parser/handler/mod.rs +2 -1
- package/rust/core/parser/handler/tempo.rs +1 -1
- package/rust/core/parser/mod.rs +3 -237
- package/rust/core/parser/statement.rs +29 -36
- package/rust/core/preprocessor/loader.rs +7 -6
- package/rust/core/preprocessor/processor.rs +1 -1
- package/rust/core/preprocessor/resolver/call.rs +53 -0
- package/rust/core/preprocessor/resolver/condition.rs +66 -0
- package/rust/core/preprocessor/resolver/driver.rs +182 -0
- package/rust/core/preprocessor/resolver/group.rs +89 -84
- package/rust/core/preprocessor/resolver/mod.rs +5 -153
- package/rust/core/preprocessor/resolver/spawn.rs +53 -0
- package/rust/core/audio/interpreter.rs +0 -317
- package/rust/core/lexer/handler/equal.rs +0 -32
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
use crate::core::lexer::{
|
|
2
|
+
handler::{
|
|
3
|
+
at::handle_at_lexer, brace::{ handle_lbrace_lexer, handle_rbrace_lexer }, colon::handle_colon_lexer, comment::handle_comment_lexer, dot::handle_dot_lexer, identifier::handle_identifier_lexer, indent::handle_indent_lexer, newline::handle_newline_lexer, number::handle_number_lexer, operator::handle_operator_lexer, string::handle_string_lexer
|
|
4
|
+
},
|
|
5
|
+
token::{ Token, TokenKind },
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
fn advance_char<I: Iterator<Item = char>>(
|
|
9
|
+
chars: &mut std::iter::Peekable<I>,
|
|
10
|
+
line: &mut usize,
|
|
11
|
+
column: &mut usize
|
|
12
|
+
) -> Option<char> {
|
|
13
|
+
let c = chars.next()?;
|
|
14
|
+
if c == '\n' {
|
|
15
|
+
// Do not increment column on newline here
|
|
16
|
+
} else {
|
|
17
|
+
*column += 1;
|
|
18
|
+
}
|
|
19
|
+
Some(c)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub fn handle_content_lexing(content: String) -> Result<Vec<Token>, String> {
|
|
23
|
+
let mut tokens = Vec::new();
|
|
24
|
+
|
|
25
|
+
let mut line = 1;
|
|
26
|
+
let mut column = 1;
|
|
27
|
+
|
|
28
|
+
let mut indent_stack: Vec<usize> = vec![0];
|
|
29
|
+
let mut current_indent = 0;
|
|
30
|
+
let mut at_line_start = true;
|
|
31
|
+
|
|
32
|
+
let mut chars = content.chars().peekable();
|
|
33
|
+
|
|
34
|
+
while chars.peek().is_some() {
|
|
35
|
+
if at_line_start {
|
|
36
|
+
handle_indent_lexer(
|
|
37
|
+
&mut chars,
|
|
38
|
+
&mut current_indent,
|
|
39
|
+
&mut indent_stack,
|
|
40
|
+
&mut tokens,
|
|
41
|
+
&mut line,
|
|
42
|
+
&mut column
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
at_line_start = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let Some(ch) = advance_char(&mut chars, &mut line, &mut column) else {
|
|
49
|
+
break;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
match ch {
|
|
53
|
+
'\n' => {
|
|
54
|
+
handle_newline_lexer(
|
|
55
|
+
ch,
|
|
56
|
+
&mut chars,
|
|
57
|
+
&mut tokens,
|
|
58
|
+
&mut line,
|
|
59
|
+
&mut column,
|
|
60
|
+
&mut at_line_start,
|
|
61
|
+
&mut current_indent
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
' ' | '\t' => {
|
|
65
|
+
// Already handled by indent_lexer
|
|
66
|
+
}
|
|
67
|
+
'#' => {
|
|
68
|
+
handle_comment_lexer(
|
|
69
|
+
ch,
|
|
70
|
+
&mut chars,
|
|
71
|
+
&mut current_indent,
|
|
72
|
+
&mut indent_stack,
|
|
73
|
+
&mut tokens,
|
|
74
|
+
&mut line,
|
|
75
|
+
&mut column
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
':' => {
|
|
79
|
+
handle_colon_lexer(
|
|
80
|
+
ch,
|
|
81
|
+
&mut chars,
|
|
82
|
+
&mut current_indent,
|
|
83
|
+
&mut indent_stack,
|
|
84
|
+
&mut tokens,
|
|
85
|
+
&mut line,
|
|
86
|
+
&mut column
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
'=' | '!' | '<' | '>' => {
|
|
90
|
+
handle_operator_lexer(
|
|
91
|
+
ch,
|
|
92
|
+
&mut chars,
|
|
93
|
+
&mut current_indent,
|
|
94
|
+
&mut indent_stack,
|
|
95
|
+
&mut tokens,
|
|
96
|
+
&mut line,
|
|
97
|
+
&mut column
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
'{' => {
|
|
101
|
+
handle_lbrace_lexer(
|
|
102
|
+
ch,
|
|
103
|
+
&mut chars,
|
|
104
|
+
&mut current_indent,
|
|
105
|
+
&mut indent_stack,
|
|
106
|
+
&mut tokens,
|
|
107
|
+
&mut line,
|
|
108
|
+
&mut column
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
'}' => {
|
|
112
|
+
handle_rbrace_lexer(
|
|
113
|
+
ch,
|
|
114
|
+
&mut chars,
|
|
115
|
+
&mut current_indent,
|
|
116
|
+
&mut indent_stack,
|
|
117
|
+
&mut tokens,
|
|
118
|
+
&mut line,
|
|
119
|
+
&mut column
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
'.' => {
|
|
123
|
+
handle_dot_lexer(
|
|
124
|
+
ch,
|
|
125
|
+
&mut chars,
|
|
126
|
+
&mut current_indent,
|
|
127
|
+
&mut indent_stack,
|
|
128
|
+
&mut tokens,
|
|
129
|
+
&mut line,
|
|
130
|
+
&mut column
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
'@' => {
|
|
134
|
+
handle_at_lexer(
|
|
135
|
+
ch,
|
|
136
|
+
&mut chars,
|
|
137
|
+
&mut current_indent,
|
|
138
|
+
&mut indent_stack,
|
|
139
|
+
&mut tokens,
|
|
140
|
+
&mut line,
|
|
141
|
+
&mut column
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
'\"' | '\'' => {
|
|
145
|
+
handle_string_lexer(
|
|
146
|
+
ch,
|
|
147
|
+
&mut chars,
|
|
148
|
+
&mut current_indent,
|
|
149
|
+
&mut indent_stack,
|
|
150
|
+
&mut tokens,
|
|
151
|
+
&mut line,
|
|
152
|
+
&mut column
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
c if c.is_ascii_digit() => {
|
|
156
|
+
handle_number_lexer(
|
|
157
|
+
c,
|
|
158
|
+
&mut chars,
|
|
159
|
+
&mut current_indent,
|
|
160
|
+
&mut indent_stack,
|
|
161
|
+
&mut tokens,
|
|
162
|
+
&mut line,
|
|
163
|
+
&mut column
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
c if c.is_ascii_alphabetic() => {
|
|
167
|
+
handle_identifier_lexer(
|
|
168
|
+
c,
|
|
169
|
+
&mut chars,
|
|
170
|
+
&mut current_indent,
|
|
171
|
+
&mut indent_stack,
|
|
172
|
+
&mut tokens,
|
|
173
|
+
&mut line,
|
|
174
|
+
&mut column
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
_ => {
|
|
178
|
+
// Ignore unknown char
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
while indent_stack.len() > 1 {
|
|
184
|
+
indent_stack.pop();
|
|
185
|
+
current_indent = *indent_stack.last().unwrap();
|
|
186
|
+
tokens.push(Token {
|
|
187
|
+
kind: TokenKind::Dedent,
|
|
188
|
+
lexeme: String::new(),
|
|
189
|
+
line,
|
|
190
|
+
column,
|
|
191
|
+
indent: current_indent,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
tokens.push(Token {
|
|
196
|
+
kind: TokenKind::EOF,
|
|
197
|
+
lexeme: String::new(),
|
|
198
|
+
line: line + 1,
|
|
199
|
+
column: 0,
|
|
200
|
+
indent: 0,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// NOTE: Debug only
|
|
204
|
+
// for token in &tokens {
|
|
205
|
+
// println!(
|
|
206
|
+
// "{:?} @ line {}, col {}, indent {}",
|
|
207
|
+
// token.kind,
|
|
208
|
+
// token.line,
|
|
209
|
+
// token.column,
|
|
210
|
+
// token.indent
|
|
211
|
+
// );
|
|
212
|
+
// }
|
|
213
|
+
|
|
214
|
+
Ok(tokens)
|
|
215
|
+
}
|
|
@@ -1,237 +1,13 @@
|
|
|
1
|
+
pub mod driver;
|
|
2
|
+
|
|
1
3
|
pub mod at;
|
|
2
4
|
pub mod brace;
|
|
3
5
|
pub mod colon;
|
|
4
6
|
pub mod comment;
|
|
5
7
|
pub mod dot;
|
|
6
|
-
pub mod
|
|
8
|
+
pub mod operator;
|
|
7
9
|
pub mod identifier;
|
|
8
10
|
pub mod newline;
|
|
9
11
|
pub mod number;
|
|
10
12
|
pub mod indent;
|
|
11
13
|
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
|
-
// Do not increment column on newline here
|
|
38
|
-
} else {
|
|
39
|
-
*column += 1;
|
|
40
|
-
}
|
|
41
|
-
Some(c)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
pub fn handle_content_lexing(content: String) -> Result<Vec<Token>, String> {
|
|
45
|
-
let mut tokens = Vec::new();
|
|
46
|
-
|
|
47
|
-
let mut line = 1;
|
|
48
|
-
let mut column = 1;
|
|
49
|
-
|
|
50
|
-
let mut indent_stack: Vec<usize> = vec![0];
|
|
51
|
-
let mut current_indent = 0;
|
|
52
|
-
let mut at_line_start = true;
|
|
53
|
-
|
|
54
|
-
let mut chars = content.chars().peekable();
|
|
55
|
-
|
|
56
|
-
while chars.peek().is_some() {
|
|
57
|
-
if at_line_start {
|
|
58
|
-
handle_indent_lexer(
|
|
59
|
-
&mut chars,
|
|
60
|
-
&mut current_indent,
|
|
61
|
-
&mut indent_stack,
|
|
62
|
-
&mut tokens,
|
|
63
|
-
&mut line,
|
|
64
|
-
&mut column
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
at_line_start = false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let Some(ch) = advance_char(&mut chars, &mut line, &mut column) else {
|
|
71
|
-
break;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
match ch {
|
|
75
|
-
'\n' => {
|
|
76
|
-
handle_newline_lexer(
|
|
77
|
-
ch,
|
|
78
|
-
&mut chars,
|
|
79
|
-
&mut tokens,
|
|
80
|
-
&mut line,
|
|
81
|
-
&mut column,
|
|
82
|
-
&mut at_line_start,
|
|
83
|
-
&mut current_indent
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
' ' | '\t' => {
|
|
87
|
-
// Already handled by indent_lexer
|
|
88
|
-
}
|
|
89
|
-
'#' => {
|
|
90
|
-
handle_comment_lexer(
|
|
91
|
-
ch,
|
|
92
|
-
&mut chars,
|
|
93
|
-
&mut current_indent,
|
|
94
|
-
&mut indent_stack,
|
|
95
|
-
&mut tokens,
|
|
96
|
-
&mut line,
|
|
97
|
-
&mut column
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
':' => {
|
|
101
|
-
handle_colon_lexer(
|
|
102
|
-
ch,
|
|
103
|
-
&mut chars,
|
|
104
|
-
&mut current_indent,
|
|
105
|
-
&mut indent_stack,
|
|
106
|
-
&mut tokens,
|
|
107
|
-
&mut line,
|
|
108
|
-
&mut column
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
'=' => {
|
|
112
|
-
handle_equal_lexer(
|
|
113
|
-
ch,
|
|
114
|
-
&mut chars,
|
|
115
|
-
&mut current_indent,
|
|
116
|
-
&mut indent_stack,
|
|
117
|
-
&mut tokens,
|
|
118
|
-
&mut line,
|
|
119
|
-
&mut column
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
'{' => {
|
|
123
|
-
handle_lbrace_lexer(
|
|
124
|
-
ch,
|
|
125
|
-
&mut chars,
|
|
126
|
-
&mut current_indent,
|
|
127
|
-
&mut indent_stack,
|
|
128
|
-
&mut tokens,
|
|
129
|
-
&mut line,
|
|
130
|
-
&mut column
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
'}' => {
|
|
134
|
-
handle_rbrace_lexer(
|
|
135
|
-
ch,
|
|
136
|
-
&mut chars,
|
|
137
|
-
&mut current_indent,
|
|
138
|
-
&mut indent_stack,
|
|
139
|
-
&mut tokens,
|
|
140
|
-
&mut line,
|
|
141
|
-
&mut column
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
'.' => {
|
|
145
|
-
handle_dot_lexer(
|
|
146
|
-
ch,
|
|
147
|
-
&mut chars,
|
|
148
|
-
&mut current_indent,
|
|
149
|
-
&mut indent_stack,
|
|
150
|
-
&mut tokens,
|
|
151
|
-
&mut line,
|
|
152
|
-
&mut column
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
'@' => {
|
|
156
|
-
handle_at_lexer(
|
|
157
|
-
ch,
|
|
158
|
-
&mut chars,
|
|
159
|
-
&mut current_indent,
|
|
160
|
-
&mut indent_stack,
|
|
161
|
-
&mut tokens,
|
|
162
|
-
&mut line,
|
|
163
|
-
&mut column
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
'\"' | '\'' => {
|
|
167
|
-
handle_string_lexer(
|
|
168
|
-
ch,
|
|
169
|
-
&mut chars,
|
|
170
|
-
&mut current_indent,
|
|
171
|
-
&mut indent_stack,
|
|
172
|
-
&mut tokens,
|
|
173
|
-
&mut line,
|
|
174
|
-
&mut column
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
c if c.is_ascii_digit() => {
|
|
178
|
-
handle_number_lexer(
|
|
179
|
-
c,
|
|
180
|
-
&mut chars,
|
|
181
|
-
&mut current_indent,
|
|
182
|
-
&mut indent_stack,
|
|
183
|
-
&mut tokens,
|
|
184
|
-
&mut line,
|
|
185
|
-
&mut column
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
c if c.is_ascii_alphabetic() => {
|
|
189
|
-
handle_identifier_lexer(
|
|
190
|
-
c,
|
|
191
|
-
&mut chars,
|
|
192
|
-
&mut current_indent,
|
|
193
|
-
&mut indent_stack,
|
|
194
|
-
&mut tokens,
|
|
195
|
-
&mut line,
|
|
196
|
-
&mut column
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
_ => {
|
|
200
|
-
// Ignore unknown char
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
while indent_stack.len() > 1 {
|
|
206
|
-
indent_stack.pop();
|
|
207
|
-
current_indent = *indent_stack.last().unwrap();
|
|
208
|
-
tokens.push(Token {
|
|
209
|
-
kind: TokenKind::Dedent,
|
|
210
|
-
lexeme: String::new(),
|
|
211
|
-
line,
|
|
212
|
-
column,
|
|
213
|
-
indent: current_indent,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
tokens.push(Token {
|
|
218
|
-
kind: TokenKind::EOF,
|
|
219
|
-
lexeme: String::new(),
|
|
220
|
-
line: line + 1,
|
|
221
|
-
column: 0,
|
|
222
|
-
indent: 0,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// NOTE: Debug only
|
|
226
|
-
// for token in &tokens {
|
|
227
|
-
// println!(
|
|
228
|
-
// "{:?} @ line {}, col {}, indent {}",
|
|
229
|
-
// token.kind,
|
|
230
|
-
// token.line,
|
|
231
|
-
// token.column,
|
|
232
|
-
// token.indent
|
|
233
|
-
// );
|
|
234
|
-
// }
|
|
235
|
-
|
|
236
|
-
Ok(tokens)
|
|
237
|
-
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
use crate::core::lexer::token::{ Token, TokenKind };
|
|
2
|
+
|
|
3
|
+
pub fn handle_operator_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 next = chars.peek().copied();
|
|
13
|
+
|
|
14
|
+
let (kind, len) = match (ch, next) {
|
|
15
|
+
('=', Some('=')) => (TokenKind::DoubleEquals, 2),
|
|
16
|
+
('!', Some('=')) => (TokenKind::NotEquals, 2),
|
|
17
|
+
('>', Some('=')) => (TokenKind::GreaterEqual, 2),
|
|
18
|
+
('<', Some('=')) => (TokenKind::LessEqual, 2),
|
|
19
|
+
('=', _) => (TokenKind::Equals, 1),
|
|
20
|
+
('>', _) => (TokenKind::Greater, 1),
|
|
21
|
+
('<', _) => (TokenKind::Less, 1),
|
|
22
|
+
_ => {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if len == 2 {
|
|
28
|
+
chars.next(); // consume second char
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
tokens.push(Token {
|
|
32
|
+
kind,
|
|
33
|
+
lexeme: if len == 2 {
|
|
34
|
+
format!("{}{}", ch, next.unwrap())
|
|
35
|
+
} else {
|
|
36
|
+
ch.to_string()
|
|
37
|
+
},
|
|
38
|
+
line: *line,
|
|
39
|
+
column: *column,
|
|
40
|
+
indent: *current_indent,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
*column += len;
|
|
44
|
+
}
|
package/rust/core/lexer/mod.rs
CHANGED
package/rust/core/lexer/token.rs
CHANGED
|
@@ -24,31 +24,58 @@ impl Token {
|
|
|
24
24
|
|
|
25
25
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
26
26
|
pub enum TokenKind {
|
|
27
|
+
// ───── Keywords ─────
|
|
27
28
|
At,
|
|
28
29
|
Tempo,
|
|
29
30
|
Bank,
|
|
30
31
|
Loop,
|
|
32
|
+
|
|
33
|
+
// ───── Literals ─────
|
|
31
34
|
Identifier,
|
|
32
|
-
Map,
|
|
33
|
-
Array,
|
|
34
35
|
Number,
|
|
35
36
|
String,
|
|
36
37
|
Boolean,
|
|
38
|
+
|
|
39
|
+
// ───── Structures ─────
|
|
40
|
+
Map,
|
|
41
|
+
Array,
|
|
42
|
+
|
|
43
|
+
// ───── Symbols ─────
|
|
37
44
|
Colon,
|
|
38
45
|
Comma,
|
|
39
46
|
Equals,
|
|
40
|
-
DoubleEquals,
|
|
41
47
|
Dot,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
|
|
49
|
+
// ───── Operators ─────
|
|
50
|
+
DoubleEquals,
|
|
51
|
+
NotEquals,
|
|
52
|
+
GreaterEqual,
|
|
53
|
+
LessEqual,
|
|
54
|
+
Greater,
|
|
55
|
+
Less,
|
|
56
|
+
|
|
57
|
+
// ───── Brackets ─────
|
|
58
|
+
LBrace, // {
|
|
59
|
+
RBrace, // }
|
|
60
|
+
LBracket, // [
|
|
61
|
+
RBracket, // ]
|
|
62
|
+
|
|
63
|
+
// ───── Quotes ─────
|
|
64
|
+
Quote, // '
|
|
65
|
+
DbQuote, // "
|
|
66
|
+
|
|
67
|
+
// ───── Formatting ─────
|
|
48
68
|
Newline,
|
|
49
69
|
Indent,
|
|
50
70
|
Dedent,
|
|
51
71
|
Comment,
|
|
72
|
+
|
|
73
|
+
// ───── Conditions ─────
|
|
74
|
+
If,
|
|
75
|
+
Else,
|
|
76
|
+
ElseIf,
|
|
77
|
+
|
|
78
|
+
// ───── Special / Internal ─────
|
|
52
79
|
Unknown,
|
|
53
80
|
Error(String),
|
|
54
81
|
EOF,
|