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

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 (51) hide show
  1. package/.devalang +9 -4
  2. package/Cargo.toml +54 -49
  3. package/README.md +59 -142
  4. package/docs/CHANGELOG.md +42 -1
  5. package/docs/ROADMAP.md +1 -1
  6. package/docs/TODO.md +1 -1
  7. package/examples/bank.deva +9 -0
  8. package/examples/duration.deva +9 -0
  9. package/examples/index.deva +0 -2
  10. package/out-tsc/bin/devalang.exe +0 -0
  11. package/package.json +1 -1
  12. package/project-version.json +3 -3
  13. package/rust/cli/bank.rs +455 -0
  14. package/rust/cli/build.rs +1 -1
  15. package/rust/cli/check.rs +1 -1
  16. package/rust/cli/driver.rs +280 -0
  17. package/rust/cli/install.rs +17 -0
  18. package/rust/cli/mod.rs +5 -200
  19. package/rust/cli/play.rs +1 -1
  20. package/rust/cli/update.rs +4 -0
  21. package/rust/common/cdn.rs +11 -0
  22. package/rust/common/mod.rs +1 -0
  23. package/rust/config/driver.rs +76 -0
  24. package/rust/config/loader.rs +98 -1
  25. package/rust/config/mod.rs +1 -15
  26. package/rust/core/audio/engine.rs +31 -3
  27. package/rust/core/audio/interpreter/arrow_call.rs +17 -4
  28. package/rust/core/audio/interpreter/trigger.rs +34 -1
  29. package/rust/core/audio/loader/trigger.rs +12 -0
  30. package/rust/core/lexer/handler/driver.rs +12 -1
  31. package/rust/core/lexer/handler/mod.rs +1 -0
  32. package/rust/core/lexer/handler/slash.rs +21 -0
  33. package/rust/core/lexer/token.rs +1 -0
  34. package/rust/core/parser/driver.rs +8 -0
  35. package/rust/core/parser/handler/arrow_call.rs +29 -4
  36. package/rust/core/parser/handler/dot.rs +103 -37
  37. package/rust/core/preprocessor/loader.rs +93 -14
  38. package/rust/core/preprocessor/resolver/driver.rs +5 -0
  39. package/rust/core/shared/bank.rs +21 -0
  40. package/rust/core/shared/duration.rs +1 -0
  41. package/rust/core/shared/mod.rs +2 -1
  42. package/rust/core/shared/value.rs +1 -0
  43. package/rust/installer/bank.rs +55 -0
  44. package/rust/installer/mod.rs +1 -0
  45. package/rust/lib.rs +1 -0
  46. package/rust/main.rs +62 -5
  47. package/rust/utils/installer.rs +56 -0
  48. package/rust/utils/mod.rs +2 -1
  49. package/docs/COMMANDS.md +0 -85
  50. package/docs/CONFIG.md +0 -30
  51. package/docs/SYNTAX.md +0 -230
@@ -0,0 +1,280 @@
1
+ use clap::{ Parser, Subcommand };
2
+ use crate::utils::version::get_version;
3
+
4
+ #[derive(Parser)]
5
+ #[command(name = "devalang")]
6
+ #[command(author = "Devaloop")]
7
+ #[command(version = get_version())]
8
+ #[command(about = "🦊 Devalang – A programming language for music and sound.")]
9
+ pub struct Cli {
10
+ #[arg(long, global = true)]
11
+ /// Skips loading the configuration file.
12
+ pub no_config: bool,
13
+
14
+ #[command(subcommand)]
15
+ pub command: Commands,
16
+ }
17
+
18
+ #[derive(Subcommand)]
19
+ pub enum InstallCommand {
20
+ /// Installs a bank.
21
+ Bank {
22
+ name: String,
23
+ },
24
+ }
25
+
26
+ #[derive(Subcommand)]
27
+ pub enum TemplateCommand {
28
+ /// Lists all available templates for Devalang projects.
29
+ List,
30
+ /// Displays information about a specific template.
31
+ Info {
32
+ name: String,
33
+ },
34
+ }
35
+
36
+ #[derive(Subcommand)]
37
+ pub enum BankCommand {
38
+ /// Lists installed banks.
39
+ List,
40
+ /// Lists all available banks.
41
+ Available,
42
+ /// Displays information about a specific bank.
43
+ Info {
44
+ name: String,
45
+ },
46
+ /// Removes a bank.
47
+ Remove {
48
+ name: String,
49
+ },
50
+ /// Updates a specific or all banks.
51
+ Update {
52
+ name: Option<String>,
53
+ },
54
+ }
55
+
56
+ #[derive(Subcommand)]
57
+ pub enum Commands {
58
+ /// Create a new Devalang project.
59
+ ///
60
+ /// ### Arguments
61
+ /// - `name` - The name of the project to create.
62
+ /// - `template` - The template to use for the project. Defaults to "default".
63
+ ///
64
+ /// ### Example
65
+ /// ```bash
66
+ /// devalang init --name my_project --template default
67
+ ///
68
+ Init {
69
+ #[arg(short, long)]
70
+ /// The optional name (directory) of the project to create.
71
+ name: Option<String>,
72
+
73
+ #[arg(short, long)]
74
+ /// The template to use for the project.
75
+ ///
76
+ /// ### Default value
77
+ /// - `default`
78
+ ///
79
+ template: Option<String>,
80
+ },
81
+
82
+ /// Manage templates for Devalang projects.
83
+ ///
84
+ /// ### Subcommands
85
+ /// - `list` - Lists all available templates.
86
+ /// - `info <name>` - Displays information about a specific template.
87
+ ///
88
+ /// ### Example
89
+ /// ```bash
90
+ /// devalang template list
91
+ /// devalang template info my_template
92
+ /// ```bash
93
+ ///
94
+ Template {
95
+ #[command(subcommand)]
96
+ /// The template command to execute.
97
+ command: TemplateCommand,
98
+ },
99
+
100
+ /// Build the program and generate output files.
101
+ ///
102
+ /// ### Arguments
103
+ /// - `entry` - The entry point of the program to build. Defaults to "./src".
104
+ /// - `output` - The directory where the output files will be generated. Defaults to "./output".
105
+ /// - `watch` - Whether to watch for changes and rebuild. Defaults to "true".
106
+ ///
107
+ /// ### Example
108
+ /// ```bash
109
+ /// devalang build --entry ./src --output ./output --watch true
110
+ /// ```
111
+ ///
112
+ Build {
113
+ #[arg(short, long)]
114
+ /// The entry point of the program to build.
115
+ ///
116
+ entry: Option<String>,
117
+
118
+ #[arg(short, long)]
119
+ /// The directory where the output files will be generated.
120
+ ///
121
+ output: Option<String>,
122
+
123
+ #[arg(long, default_value_t = false)]
124
+ /// Whether to watch for changes and rebuild.
125
+ ///
126
+ /// ### Default value
127
+ /// - `false`
128
+ ///
129
+ watch: bool,
130
+
131
+ #[arg(long, default_value = "real-time")]
132
+ /// The mode of compilation.
133
+ ///
134
+ /// ### Default value
135
+ /// - `real-time`
136
+ ///
137
+ /// ### Possible values
138
+ /// - `real-time` - Compiles files as soon as possible.
139
+ /// - `batch` - Compiles files one by one.
140
+ /// - `check` - Analyzes the code without compiling it.
141
+ ///
142
+ compilation_mode: String,
143
+
144
+ #[arg(short, long, default_value_t = false)]
145
+ /// Whether to print debug information.
146
+ ///
147
+ /// ### Default value
148
+ /// - `false`
149
+ ///
150
+ debug: bool,
151
+
152
+ #[arg(short, long, default_value_t = false)]
153
+ /// Whether to compress the output files.
154
+ ///
155
+ /// ### Default value
156
+ /// - `false`
157
+ ///
158
+ compress: bool,
159
+ },
160
+
161
+ /// Analyze the program for errors and warnings.
162
+ ///
163
+ /// ### Arguments
164
+ /// - `entry` - The entry point of the program to analyze. Defaults to "./src".
165
+ /// - `output` - The directory where the output files will be generated. Defaults to "./output".
166
+ /// - `watch` - Whether to watch for changes and re-analyze. Defaults to "true".
167
+ /// - `compilation_mode` - The mode of compilation. Defaults to "real-time".
168
+ /// - `debug` - Whether to print debug information. Defaults to "false".
169
+ ///
170
+ Check {
171
+ #[arg(short, long)]
172
+ /// The entry point of the program to analyze.
173
+ entry: Option<String>,
174
+
175
+ #[arg(short, long)]
176
+ /// The directory where the output files will be generated.
177
+ output: Option<String>,
178
+
179
+ #[arg(long, default_value_t = false)]
180
+ /// Whether to watch for changes and re-analyze.
181
+ ///
182
+ /// ### Default value
183
+ /// - `false`
184
+ ///
185
+ watch: bool,
186
+
187
+ #[arg(short, long, default_value = "real-time")]
188
+ /// The mode of compilation.
189
+ ///
190
+ /// ### Default value
191
+ /// - `real-time`
192
+ ///
193
+ /// ### Possible values
194
+ /// - `real-time` - Analyzes files as soon as possible.
195
+ /// - `batch` - Analyzes files one by one.
196
+ /// - `check` - Analyzes the code without compiling it.
197
+ ///
198
+ compilation_mode: String,
199
+
200
+ #[arg(short, long, default_value_t = false)]
201
+ /// Whether to print debug information.
202
+ ///
203
+ /// ### Default value
204
+ /// - `false`
205
+ ///
206
+ debug: bool,
207
+ },
208
+
209
+ /// Play the program and generate output files.
210
+ ///
211
+ /// ### Arguments
212
+ /// - `entry` - The entry point of the program to play. Defaults to "./src".
213
+ /// - `output` - The directory where the output files will be generated. Defaults to "./output".
214
+ /// - `watch` - Whether to watch for changes and re-play. Defaults to "false".
215
+ /// - `repeat` - Whether to replay the program after it finishes. Defaults to "false".
216
+ ///
217
+ Play {
218
+ #[arg(short, long)]
219
+ /// The entry point of the program to play.
220
+ entry: Option<String>,
221
+
222
+ #[arg(short, long)]
223
+ /// The directory where the output files will be generated.
224
+ output: Option<String>,
225
+
226
+ #[arg(long, default_value_t = false)]
227
+ /// Whether to watch for changes and re-play.
228
+ ///
229
+ /// ### Default value
230
+ /// - `false`
231
+ ///
232
+ watch: bool,
233
+
234
+ #[arg(long, default_value_t = false)]
235
+ /// Whether to replay the program after it finishes.
236
+ ///
237
+ /// ### Default value
238
+ /// - `false`
239
+ ///
240
+ repeat: bool,
241
+ },
242
+
243
+ /// Update the Devalang CLI to the latest version.
244
+ ///
245
+ /// ### Arguments
246
+ /// - `only` - Selects what to update (separated by commas). Defaults to updating all components.
247
+ ///
248
+ Update {
249
+ // #[arg(long, default_value_t = false)]
250
+ /// Whether to allow updates when the working directory is dirty.
251
+ // allow_dirty: bool,
252
+
253
+ #[arg(long, default_value = "")]
254
+ /// Selects what to update (separated by commas).
255
+ only: Option<String>,
256
+ },
257
+
258
+ /// Install templates, banks, or plugins.
259
+ ///
260
+ /// ### Subcommands
261
+ /// - `template` - Installs a template.
262
+ /// - `bank` - Installs a bank.
263
+ /// - `plugin` - Installs a plugin.
264
+ ///
265
+ Install {
266
+ #[command(subcommand)]
267
+ command: InstallCommand,
268
+ },
269
+
270
+ /// Manage banks for Devalang projects.
271
+ ///
272
+ /// ### Subcommands
273
+ /// - `list` - Lists all available banks.
274
+ /// - `info <name>` - Displays information about a specific bank.
275
+ ///
276
+ Bank {
277
+ #[command(subcommand)]
278
+ command: BankCommand,
279
+ },
280
+ }
@@ -0,0 +1,17 @@
1
+ use crate::installer::bank::install_bank;
2
+
3
+ #[cfg(feature = "cli")]
4
+ pub async fn handle_install_bank_command(name: String) -> Result<(), String> {
5
+ let deva_dir = std::path::Path::new("./.deva/");
6
+
7
+ println!("⬇️ Installing bank '{}'...", name);
8
+ println!("📂 Target directory: {}", deva_dir.display());
9
+
10
+ if let Err(e) = install_bank(name.as_str(), deva_dir).await {
11
+ eprintln!("❌ Error installing bank '{}': {}", name, e);
12
+ } else {
13
+ println!("✅ Bank '{}' installed successfully!", name);
14
+ }
15
+
16
+ Ok(())
17
+ }
package/rust/cli/mod.rs CHANGED
@@ -1,205 +1,10 @@
1
+ pub mod driver;
2
+
1
3
  pub mod check;
2
4
  pub mod build;
3
5
  pub mod init;
4
6
  pub mod template;
5
7
  pub mod play;
6
-
7
- use clap::{ Parser, Subcommand };
8
- use crate::utils::version::get_version;
9
-
10
- #[derive(Parser)]
11
- #[command(name = "devalang")]
12
- #[command(author = "Devaloop")]
13
- #[command(version = get_version())]
14
- #[command(about = "🦊 Devalang – A programming language for music and sound.")]
15
- pub struct Cli {
16
- #[arg(long, global = true)]
17
- /// Skips loading the configuration file.
18
- pub no_config: bool,
19
-
20
- #[command(subcommand)]
21
- pub command: Commands,
22
- }
23
-
24
- #[derive(Subcommand)]
25
- pub enum TemplateCommand {
26
- /// Lists all available templates for Devalang projects.
27
- List,
28
- /// Displays information about a specific template.
29
- Info {
30
- name: String,
31
- },
32
- }
33
-
34
- #[derive(Subcommand)]
35
- pub enum Commands {
36
- /// Create a new Devalang project.
37
- ///
38
- /// ### Arguments
39
- /// - `name` - The name of the project to create.
40
- /// - `template` - The template to use for the project. Defaults to "default".
41
- ///
42
- /// ### Example
43
- /// ```bash
44
- /// devalang init --name my_project --template default
45
- ///
46
- Init {
47
- #[arg(short, long)]
48
- /// The optional name (directory) of the project to create.
49
- name: Option<String>,
50
-
51
- #[arg(short, long)]
52
- /// The template to use for the project.
53
- ///
54
- /// ### Default value
55
- /// - `default`
56
- ///
57
- template: Option<String>,
58
- },
59
-
60
- Template {
61
- #[command(subcommand)]
62
- /// The template command to execute.
63
- command: TemplateCommand,
64
- },
65
-
66
- /// Build the program and generate output files.
67
- ///
68
- /// ### Arguments
69
- /// - `entry` - The entry point of the program to build. Defaults to "./src".
70
- /// - `output` - The directory where the output files will be generated. Defaults to "./output".
71
- /// - `watch` - Whether to watch for changes and rebuild. Defaults to "true".
72
- ///
73
- /// ### Example
74
- /// ```bash
75
- /// devalang build --entry ./src --output ./output --watch true
76
- /// ```
77
- ///
78
- Build {
79
- #[arg(short, long)]
80
- /// The entry point of the program to build.
81
- ///
82
- entry: Option<String>,
83
-
84
- #[arg(short, long)]
85
- /// The directory where the output files will be generated.
86
- ///
87
- output: Option<String>,
88
-
89
- #[arg(long, default_value_t = false)]
90
- /// Whether to watch for changes and rebuild.
91
- ///
92
- /// ### Default value
93
- /// - `false`
94
- ///
95
- watch: bool,
96
-
97
- #[arg(long, default_value = "real-time")]
98
- /// The mode of compilation.
99
- ///
100
- /// ### Default value
101
- /// - `real-time`
102
- ///
103
- /// ### Possible values
104
- /// - `real-time` - Compiles files as soon as possible.
105
- /// - `batch` - Compiles files one by one.
106
- /// - `check` - Analyzes the code without compiling it.
107
- ///
108
- compilation_mode: String,
109
-
110
- #[arg(short, long, default_value_t = false)]
111
- /// Whether to print debug information.
112
- ///
113
- /// ### Default value
114
- /// - `false`
115
- ///
116
- debug: bool,
117
-
118
- #[arg(short, long, default_value_t = false)]
119
- /// Whether to compress the output files.
120
- ///
121
- /// ### Default value
122
- /// - `false`
123
- ///
124
- compress: bool,
125
- },
126
-
127
- /// Analyze the program for errors and warnings.
128
- ///
129
- /// ### Arguments
130
- /// - `entry` - The entry point of the program to analyze. Defaults to "./src".
131
- /// - `watch` - Whether to watch for changes and re-analyze. Defaults to "true".
132
- ///
133
- /// ### Example
134
- /// ```bash
135
- /// devalang check --entry ./src --watch true --compilation-mode real-time
136
- /// ```
137
- Check {
138
- #[arg(short, long)]
139
- /// The entry point of the program to analyze.
140
- ///
141
- entry: Option<String>,
142
-
143
- #[arg(short, long)]
144
- /// The directory where the output files will be generated.
145
- ///
146
- output: Option<String>,
147
-
148
- #[arg(long, default_value_t = false)]
149
- /// Whether to watch for changes and re-analyze.
150
- ///
151
- /// ### Default value
152
- /// - `false`
153
- ///
154
- watch: bool,
155
-
156
- #[arg(short, long, default_value = "real-time")]
157
- /// The mode of compilation.
158
- ///
159
- /// ### Default value
160
- /// - `real-time`
161
- ///
162
- /// ### Possible values
163
- /// - `real-time` - Analyzes files as soon as possible.
164
- /// - `batch` - Analyzes files one by one.
165
- /// - `check` - Analyzes the code without compiling it.
166
- ///
167
- compilation_mode: String,
168
-
169
- #[arg(short, long, default_value_t = false)]
170
- /// Whether to print debug information.
171
- ///
172
- /// ### Default value
173
- /// - `false`
174
- ///
175
- debug: bool,
176
- },
177
-
178
- Play {
179
- #[arg(short, long)]
180
- /// The entry point of the program to play.
181
- ///
182
- entry: Option<String>,
183
-
184
- #[arg(short, long)]
185
- /// The directory where the output files will be generated.
186
- ///
187
- output: Option<String>,
188
-
189
- #[arg(long, default_value_t = false)]
190
- /// Whether to watch for changes and re-play.
191
- ///
192
- /// ### Default value
193
- /// - `false`
194
- ///
195
- watch: bool,
196
-
197
- #[arg(long, default_value_t = false)]
198
- /// Whether to replay the program after it finishes.
199
- ///
200
- /// ### Default value
201
- /// - `false`
202
- ///
203
- repeat: bool,
204
- },
205
- }
8
+ pub mod install;
9
+ pub mod bank;
10
+ pub mod update;
package/rust/cli/play.rs CHANGED
@@ -1,5 +1,4 @@
1
1
  use crate::{
2
- config::Config,
3
2
  core::{
4
3
  builder::Builder,
5
4
  debugger::{ lexer::write_lexer_log_file, preprocessor::write_preprocessor_log_file },
@@ -7,6 +6,7 @@ use crate::{
7
6
  store::global::GlobalStore,
8
7
  utils::path::{ find_entry_file, normalize_path },
9
8
  },
9
+ config::driver::Config,
10
10
  utils::{ logger::{ LogLevel, Logger }, spinner::with_spinner, watcher::watch_directory },
11
11
  };
12
12
 
@@ -0,0 +1,4 @@
1
+ pub async fn handle_update_command(only: Option<String>) -> Result<(), Box<dyn std::error::Error>> {
2
+ println!("Updates are not yet implemented. This is a placeholder function.");
3
+ Ok(())
4
+ }
@@ -0,0 +1,11 @@
1
+ pub fn get_cdn_url() -> String {
2
+ let cdn_url = std::env
3
+ ::var("CDN_URL")
4
+ .unwrap_or_else(|_| "https://cdn.devalang.com".to_string());
5
+
6
+ if !cdn_url.ends_with('/') {
7
+ format!("{}/", cdn_url)
8
+ } else {
9
+ cdn_url
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ pub mod cdn;
@@ -0,0 +1,76 @@
1
+ use serde::{ Deserialize, Serialize };
2
+
3
+ #[derive(Debug, Deserialize, Clone, Serialize)]
4
+ pub struct Config {
5
+ pub defaults: ConfigDefaults,
6
+ pub banks: Option<Vec<BankEntry>>,
7
+ }
8
+
9
+ #[derive(Debug, Deserialize, Clone, Serialize)]
10
+ pub struct ConfigDefaults {
11
+ pub entry: Option<String>,
12
+ pub output: Option<String>,
13
+ pub watch: Option<bool>,
14
+ pub repeat: Option<bool>,
15
+ }
16
+
17
+ #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
18
+ pub struct BankEntry {
19
+ pub path: String,
20
+ pub version: Option<String>,
21
+ pub author: Option<String>,
22
+ }
23
+
24
+ impl Config {
25
+ pub fn new() -> Self {
26
+ Config {
27
+ defaults: ConfigDefaults {
28
+ entry: None,
29
+ output: None,
30
+ watch: None,
31
+ repeat: None,
32
+ },
33
+ banks: Some(Vec::new()),
34
+ }
35
+ }
36
+
37
+ pub fn with_defaults(
38
+ entry: Option<String>,
39
+ output: Option<String>,
40
+ watch: Option<bool>,
41
+ repeat: Option<bool>
42
+ ) -> Self {
43
+ Config {
44
+ defaults: ConfigDefaults {
45
+ entry,
46
+ output,
47
+ watch,
48
+ repeat,
49
+ },
50
+ banks: Some(Vec::new()),
51
+ }
52
+ }
53
+
54
+ pub fn from_string(config_string: &str) -> Result<(Self, String), String> {
55
+ let config: Config = toml
56
+ ::from_str(config_string)
57
+ .map_err(|e| format!("Failed to parse config string: {}", e))?;
58
+ let config_path = ".devalang".to_string();
59
+
60
+ Ok((config, config_path))
61
+ }
62
+
63
+ pub fn write(&self, new_config: &Config) -> Result<(), String> {
64
+ let config_path = ".devalang";
65
+
66
+ let content = toml
67
+ ::to_string(new_config)
68
+ .map_err(|e| format!("Failed to serialize config: {}", e))?;
69
+
70
+ std::fs
71
+ ::write(config_path, content)
72
+ .map_err(|e| format!("Failed to write config to file '{}': {}", config_path, e))?;
73
+
74
+ Ok(())
75
+ }
76
+ }