@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,237 +1,14 @@
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 equal;
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
- }
14
+ pub mod arrow;
@@ -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
+ }
@@ -2,8 +2,9 @@ pub mod handler;
2
2
  pub mod token;
3
3
 
4
4
  use std::fs;
5
+ use std::path::{Path, PathBuf};
5
6
  use crate::core::{
6
- lexer::{ handler::handle_content_lexing, token::Token },
7
+ lexer::{ handler::driver::handle_content_lexing, token::Token },
7
8
  utils::path::normalize_path,
8
9
  };
9
10
 
@@ -20,11 +21,31 @@ impl Lexer {
20
21
 
21
22
  pub fn lex_tokens(&self, entrypoint: &str) -> Vec<Token> {
22
23
  let path = normalize_path(entrypoint);
24
+ let resolved_path = Self::resolve_entry_path(&path);
23
25
 
24
- let file_content = fs::read_to_string(&path).expect("Failed to read the entrypoint file");
26
+ let file_content =
27
+ fs::read_to_string(&resolved_path).expect("Failed to read the entrypoint file");
25
28
 
26
- let tokens = handle_content_lexing(file_content).expect("Failed to lex the content");
29
+ handle_content_lexing(file_content).expect("Failed to lex the content")
30
+ }
27
31
 
28
- tokens
32
+ fn resolve_entry_path(path: &str) -> String {
33
+ let candidate = Path::new(path);
34
+
35
+ if candidate.is_dir() {
36
+ let index_path = candidate.join("index.deva");
37
+ if index_path.exists() {
38
+ return index_path.to_string_lossy().replace("\\", "/");
39
+ } else {
40
+ panic!(
41
+ "Expected 'index.deva' in directory '{}', but it was not found",
42
+ path
43
+ );
44
+ }
45
+ } else if candidate.is_file() {
46
+ return path.to_string();
47
+ } else {
48
+ panic!("Provided entrypoint '{}' is not a valid file or directory", path);
49
+ }
29
50
  }
30
51
  }
@@ -24,31 +24,62 @@ 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
+ // ───── Instruments ─────
34
+ Synth,
35
+
36
+ // ───── Literals ─────
31
37
  Identifier,
32
- Map,
33
- Array,
34
38
  Number,
35
39
  String,
36
40
  Boolean,
41
+ Arrow,
42
+
43
+ // ───── Structures ─────
44
+ Map,
45
+ Array,
46
+
47
+ // ───── Symbols ─────
37
48
  Colon,
38
49
  Comma,
39
50
  Equals,
40
- DoubleEquals,
41
51
  Dot,
42
- LBrace,
43
- RBrace,
44
- DbQuote,
45
- Quote,
46
- LBracket,
47
- RBracket,
52
+
53
+ // ───── Operators ─────
54
+ DoubleEquals,
55
+ NotEquals,
56
+ GreaterEqual,
57
+ LessEqual,
58
+ Greater,
59
+ Less,
60
+
61
+ // ───── Brackets ─────
62
+ LBrace, // {
63
+ RBrace, // }
64
+ LBracket, // [
65
+ RBracket, // ]
66
+
67
+ // ───── Quotes ─────
68
+ Quote, // '
69
+ DbQuote, // "
70
+
71
+ // ───── Formatting ─────
48
72
  Newline,
49
73
  Indent,
50
74
  Dedent,
51
75
  Comment,
76
+
77
+ // ───── Conditions ─────
78
+ If,
79
+ Else,
80
+ ElseIf,
81
+
82
+ // ───── Special / Internal ─────
52
83
  Unknown,
53
84
  Error(String),
54
85
  EOF,