@devaloop/devalang 0.0.1-alpha.15 → 0.0.1-alpha.16
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/.devalang +2 -0
- package/.github/workflows/ci.yml +92 -0
- package/Cargo.toml +60 -58
- package/README.md +1 -1
- package/docs/CHANGELOG.md +34 -1
- package/docs/CONTRIBUTING.md +101 -1
- package/docs/ROADMAP.md +1 -1
- package/docs/TODO.md +1 -1
- package/examples/automation.deva +1 -3
- package/examples/bank.deva +4 -4
- package/examples/events.deva +12 -0
- package/examples/function.deva +4 -4
- package/examples/index.deva +3 -5
- package/examples/loop.deva +5 -11
- package/examples/pattern.deva +8 -0
- package/examples/plugin.deva +12 -11
- package/examples/variables.deva +1 -1
- package/out-tsc/bin/index.js +51 -7
- package/out-tsc/index.js +3 -1
- package/out-tsc/scripts/postbuild.js +9 -10
- package/out-tsc/scripts/postinstall.js +49 -0
- package/package.json +12 -4
- package/project-version.json +3 -3
- package/rust/cli/bank.rs +462 -455
- package/rust/cli/build.rs +252 -199
- package/rust/cli/check.rs +221 -180
- package/rust/cli/driver.rs +297 -292
- package/rust/cli/generator.rs +1 -0
- package/rust/cli/init.rs +87 -79
- package/rust/cli/install.rs +35 -32
- package/rust/cli/login.rs +127 -134
- package/rust/cli/mod.rs +13 -11
- package/rust/cli/play.rs +1123 -218
- package/rust/cli/telemetry.rs +19 -0
- package/rust/cli/template.rs +69 -57
- package/rust/cli/update.rs +6 -4
- package/rust/common/api.rs +5 -5
- package/rust/common/mod.rs +3 -3
- package/rust/config/driver.rs +118 -94
- package/rust/config/loader.rs +165 -156
- package/rust/config/mod.rs +4 -2
- package/rust/config/settings.rs +91 -0
- package/rust/config/stats.rs +257 -0
- package/rust/core/audio/engine.rs +696 -659
- package/rust/core/audio/evaluator.rs +263 -132
- package/rust/core/audio/interpreter/arrow_call.rs +198 -187
- package/rust/core/audio/interpreter/call.rs +98 -95
- package/rust/core/audio/interpreter/condition.rs +70 -71
- package/rust/core/audio/interpreter/driver.rs +487 -231
- package/rust/core/audio/interpreter/function.rs +26 -21
- package/rust/core/audio/interpreter/let_.rs +38 -26
- package/rust/core/audio/interpreter/load.rs +18 -18
- package/rust/core/audio/interpreter/loop_.rs +113 -106
- package/rust/core/audio/interpreter/mod.rs +14 -14
- package/rust/core/audio/interpreter/sleep.rs +27 -28
- package/rust/core/audio/interpreter/spawn.rs +105 -102
- package/rust/core/audio/interpreter/tempo.rs +19 -16
- package/rust/core/audio/interpreter/trigger.rs +239 -210
- package/rust/core/audio/loader/mod.rs +1 -1
- package/rust/core/audio/loader/trigger.rs +100 -94
- package/rust/core/audio/mod.rs +7 -7
- package/rust/core/audio/player.rs +64 -64
- package/rust/core/audio/renderer.rs +56 -53
- package/rust/core/audio/special/easing.rs +189 -120
- package/rust/core/audio/special/env.rs +43 -41
- package/rust/core/audio/special/math.rs +102 -92
- package/rust/core/audio/special/mod.rs +9 -9
- package/rust/core/audio/special/modulator.rs +143 -120
- package/rust/core/builder/mod.rs +80 -85
- package/rust/core/debugger/lexer.rs +27 -27
- package/rust/core/debugger/mod.rs +24 -23
- package/rust/core/debugger/module.rs +55 -47
- package/rust/core/debugger/preprocessor.rs +27 -27
- package/rust/core/debugger/store.rs +40 -39
- package/rust/core/error/mod.rs +80 -69
- package/rust/core/lexer/handler/arrow.rs +82 -82
- package/rust/core/lexer/handler/at.rs +21 -21
- package/rust/core/lexer/handler/brace.rs +41 -41
- package/rust/core/lexer/handler/colon.rs +21 -21
- package/rust/core/lexer/handler/comment.rs +30 -30
- package/rust/core/lexer/handler/dot.rs +21 -21
- package/rust/core/lexer/handler/driver.rs +337 -292
- package/rust/core/lexer/handler/identifier.rs +46 -43
- package/rust/core/lexer/handler/indent.rs +66 -66
- package/rust/core/lexer/handler/mod.rs +16 -16
- package/rust/core/lexer/handler/newline.rs +23 -23
- package/rust/core/lexer/handler/number.rs +31 -31
- package/rust/core/lexer/handler/operator.rs +46 -46
- package/rust/core/lexer/handler/parenthesis.rs +41 -41
- package/rust/core/lexer/handler/slash.rs +21 -21
- package/rust/core/lexer/handler/string.rs +63 -63
- package/rust/core/lexer/mod.rs +54 -51
- package/rust/core/lexer/token.rs +97 -94
- package/rust/core/mod.rs +11 -11
- package/rust/core/parser/driver.rs +513 -490
- package/rust/core/parser/handler/arrow_call.rs +233 -227
- package/rust/core/parser/handler/at.rs +245 -162
- package/rust/core/parser/handler/bank.rs +94 -69
- package/rust/core/parser/handler/condition.rs +80 -74
- package/rust/core/parser/handler/dot.rs +143 -135
- package/rust/core/parser/handler/identifier/automate.rs +257 -194
- package/rust/core/parser/handler/identifier/call.rs +91 -88
- package/rust/core/parser/handler/identifier/emit.rs +66 -0
- package/rust/core/parser/handler/identifier/function.rs +100 -91
- package/rust/core/parser/handler/identifier/group.rs +85 -75
- package/rust/core/parser/handler/identifier/let_.rs +158 -143
- package/rust/core/parser/handler/identifier/mod.rs +54 -56
- package/rust/core/parser/handler/identifier/on.rs +98 -0
- package/rust/core/parser/handler/identifier/print.rs +52 -29
- package/rust/core/parser/handler/identifier/sleep.rs +36 -33
- package/rust/core/parser/handler/identifier/spawn.rs +91 -88
- package/rust/core/parser/handler/identifier/synth.rs +65 -63
- package/rust/core/parser/handler/loop_.rs +170 -89
- package/rust/core/parser/handler/mod.rs +8 -8
- package/rust/core/parser/handler/tempo.rs +53 -47
- package/rust/core/parser/mod.rs +4 -4
- package/rust/core/parser/statement.rs +142 -113
- package/rust/core/plugin/loader.rs +123 -48
- package/rust/core/plugin/mod.rs +2 -1
- package/rust/core/plugin/runner.rs +296 -0
- package/rust/core/preprocessor/loader.rs +515 -326
- package/rust/core/preprocessor/mod.rs +4 -4
- package/rust/core/preprocessor/module.rs +60 -58
- package/rust/core/preprocessor/processor.rs +99 -101
- package/rust/core/preprocessor/resolver/bank.rs +51 -48
- package/rust/core/preprocessor/resolver/call.rs +100 -101
- package/rust/core/preprocessor/resolver/condition.rs +97 -97
- package/rust/core/preprocessor/resolver/driver.rs +310 -280
- package/rust/core/preprocessor/resolver/function.rs +69 -68
- package/rust/core/preprocessor/resolver/group.rs +96 -91
- package/rust/core/preprocessor/resolver/let_.rs +32 -28
- package/rust/core/preprocessor/resolver/loop_.rs +320 -121
- package/rust/core/preprocessor/resolver/mod.rs +15 -15
- package/rust/core/preprocessor/resolver/spawn.rs +76 -73
- package/rust/core/preprocessor/resolver/synth.rs +56 -50
- package/rust/core/preprocessor/resolver/tempo.rs +50 -49
- package/rust/core/preprocessor/resolver/trigger.rs +113 -115
- package/rust/core/preprocessor/resolver/value.rs +81 -81
- package/rust/core/shared/duration.rs +9 -9
- package/rust/core/shared/mod.rs +3 -3
- package/rust/core/shared/value.rs +35 -32
- package/rust/core/store/function.rs +34 -34
- package/rust/core/store/global.rs +55 -38
- package/rust/core/store/mod.rs +5 -5
- package/rust/core/store/variable.rs +37 -34
- package/rust/core/utils/mod.rs +2 -2
- package/rust/core/utils/path.rs +37 -31
- package/rust/core/utils/validation.rs +35 -36
- package/rust/installer/addon.rs +84 -80
- package/rust/installer/bank.rs +62 -65
- package/rust/installer/mod.rs +5 -5
- package/rust/installer/plugin.rs +54 -55
- package/rust/installer/utils.rs +56 -56
- package/rust/lib.rs +156 -164
- package/rust/main.rs +250 -144
- package/rust/utils/error.rs +200 -51
- package/rust/utils/file.rs +38 -35
- package/rust/utils/first_usage.rs +76 -0
- package/rust/utils/logger.rs +195 -143
- package/rust/utils/mod.rs +9 -7
- package/rust/utils/signature.rs +19 -17
- package/rust/utils/spinner.rs +22 -19
- package/rust/utils/telemetry.rs +292 -0
- package/rust/utils/watcher.rs +34 -33
- package/templates/minimal/README.md +97 -121
- package/templates/welcome/README.md +97 -121
- package/typescript/bin/index.ts +19 -5
- package/typescript/index.ts +3 -1
- package/typescript/scripts/postbuild.ts +10 -6
- package/typescript/scripts/postinstall.ts +56 -0
- package/typescript/scripts/version/bump.ts +0 -1
- package/typescript/scripts/version/index.ts +0 -1
- package/out-tsc/bin/devalang.exe +0 -0
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
use
|
|
2
|
-
use
|
|
3
|
-
|
|
4
|
-
pub fn write_lexer_log_file(
|
|
5
|
-
output_dir: &str,
|
|
6
|
-
file_name: &str,
|
|
7
|
-
modules: HashMap<String, Vec<Token
|
|
8
|
-
) {
|
|
9
|
-
let debugger = Debugger::new();
|
|
10
|
-
let mut content = String::new();
|
|
11
|
-
|
|
12
|
-
let log_directory = format!("{}/logs", output_dir);
|
|
13
|
-
|
|
14
|
-
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
15
|
-
|
|
16
|
-
for (path, tokens) in modules {
|
|
17
|
-
content.push_str(&format!("--- Resolved Tokens for {} ---\n", path));
|
|
18
|
-
|
|
19
|
-
for token in tokens {
|
|
20
|
-
content.push_str(&format!("{:?}\n", token));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
content.push_str("\n");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
debugger.write_log_file(&log_directory, file_name, &content);
|
|
27
|
-
}
|
|
1
|
+
use crate::core::{debugger::Debugger, lexer::token::Token};
|
|
2
|
+
use std::{collections::HashMap, fs::create_dir_all};
|
|
3
|
+
|
|
4
|
+
pub fn write_lexer_log_file(
|
|
5
|
+
output_dir: &str,
|
|
6
|
+
file_name: &str,
|
|
7
|
+
modules: HashMap<String, Vec<Token>>,
|
|
8
|
+
) {
|
|
9
|
+
let debugger = Debugger::new();
|
|
10
|
+
let mut content = String::new();
|
|
11
|
+
|
|
12
|
+
let log_directory = format!("{}/logs", output_dir);
|
|
13
|
+
|
|
14
|
+
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
15
|
+
|
|
16
|
+
for (path, tokens) in modules {
|
|
17
|
+
content.push_str(&format!("--- Resolved Tokens for {} ---\n", path));
|
|
18
|
+
|
|
19
|
+
for token in tokens {
|
|
20
|
+
content.push_str(&format!("{:?}\n", token));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
content.push_str("\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
debugger.write_log_file(&log_directory, file_name, &content);
|
|
27
|
+
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
pub mod
|
|
2
|
-
pub mod
|
|
3
|
-
pub mod
|
|
4
|
-
pub mod
|
|
5
|
-
|
|
6
|
-
use std::io::Write;
|
|
7
|
-
|
|
8
|
-
pub struct Debugger {}
|
|
9
|
-
|
|
10
|
-
impl Debugger {
|
|
11
|
-
pub fn new() -> Self {
|
|
12
|
-
Debugger {}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
pub fn write_log_file(&self, path: &str, filename: &str, content: &str) {
|
|
16
|
-
std::fs::create_dir_all(path).expect("Failed to create directory");
|
|
17
|
-
|
|
18
|
-
let file_path = format!("{}/{}", path, filename);
|
|
19
|
-
let mut file = std::fs::File::create(file_path).expect("Failed to create file");
|
|
20
|
-
|
|
21
|
-
file.write_all(content.as_bytes())
|
|
22
|
-
|
|
23
|
-
}
|
|
1
|
+
pub mod lexer;
|
|
2
|
+
pub mod module;
|
|
3
|
+
pub mod preprocessor;
|
|
4
|
+
pub mod store;
|
|
5
|
+
|
|
6
|
+
use std::io::Write;
|
|
7
|
+
|
|
8
|
+
pub struct Debugger {}
|
|
9
|
+
|
|
10
|
+
impl Debugger {
|
|
11
|
+
pub fn new() -> Self {
|
|
12
|
+
Debugger {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pub fn write_log_file(&self, path: &str, filename: &str, content: &str) {
|
|
16
|
+
std::fs::create_dir_all(path).expect("Failed to create directory");
|
|
17
|
+
|
|
18
|
+
let file_path = format!("{}/{}", path, filename);
|
|
19
|
+
let mut file = std::fs::File::create(file_path).expect("Failed to create file");
|
|
20
|
+
|
|
21
|
+
file.write_all(content.as_bytes())
|
|
22
|
+
.expect("Failed to write to file");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,47 +1,55 @@
|
|
|
1
|
-
use
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
pub fn write_module_variable_log_file(
|
|
8
|
-
output_dir: &str,
|
|
9
|
-
module_path: &str,
|
|
10
|
-
variable_table: &VariableTable
|
|
11
|
-
) {
|
|
12
|
-
let debugger = Debugger::new();
|
|
13
|
-
let mut content = String::new();
|
|
14
|
-
let module_name = module_path
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
use crate::core::{
|
|
2
|
+
debugger::Debugger,
|
|
3
|
+
store::{function::FunctionTable, variable::VariableTable},
|
|
4
|
+
};
|
|
5
|
+
use std::fs::create_dir_all;
|
|
6
|
+
|
|
7
|
+
pub fn write_module_variable_log_file(
|
|
8
|
+
output_dir: &str,
|
|
9
|
+
module_path: &str,
|
|
10
|
+
variable_table: &VariableTable,
|
|
11
|
+
) {
|
|
12
|
+
let debugger = Debugger::new();
|
|
13
|
+
let mut content = String::new();
|
|
14
|
+
let module_name = module_path
|
|
15
|
+
.split('/')
|
|
16
|
+
.last()
|
|
17
|
+
.unwrap_or("index")
|
|
18
|
+
.replace(".deva", "");
|
|
19
|
+
|
|
20
|
+
let log_directory = format!("{}/logs/modules/{}", output_dir, module_name);
|
|
21
|
+
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
22
|
+
|
|
23
|
+
for (var_name, var_data) in &variable_table.variables {
|
|
24
|
+
content.push_str(&format!("{:?} = {:?}\n", var_name, var_data));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
content.push_str("\n");
|
|
28
|
+
|
|
29
|
+
debugger.write_log_file(&log_directory, "variables.log", &content);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub fn write_module_function_log_file(
|
|
33
|
+
output_dir: &str,
|
|
34
|
+
module_path: &str,
|
|
35
|
+
function_table: &FunctionTable,
|
|
36
|
+
) {
|
|
37
|
+
let debugger = Debugger::new();
|
|
38
|
+
let mut content = String::new();
|
|
39
|
+
let module_name = module_path
|
|
40
|
+
.split('/')
|
|
41
|
+
.last()
|
|
42
|
+
.unwrap_or("index")
|
|
43
|
+
.replace(".deva", "");
|
|
44
|
+
|
|
45
|
+
let log_directory = format!("{}/logs/modules/{}", output_dir, module_name);
|
|
46
|
+
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
47
|
+
|
|
48
|
+
for (func_name, func_data) in &function_table.functions {
|
|
49
|
+
content.push_str(&format!("{:?} = {:?}\n", func_name, func_data));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
content.push_str("\n");
|
|
53
|
+
|
|
54
|
+
debugger.write_log_file(&log_directory, "functions.log", &content);
|
|
55
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
use
|
|
2
|
-
use
|
|
3
|
-
|
|
4
|
-
pub fn write_preprocessor_log_file(
|
|
5
|
-
output_dir: &str,
|
|
6
|
-
file_name: &str,
|
|
7
|
-
modules: HashMap<String, Vec<Statement
|
|
8
|
-
) {
|
|
9
|
-
let debugger = Debugger::new();
|
|
10
|
-
let mut content = String::new();
|
|
11
|
-
|
|
12
|
-
let log_directory = format!("{}/logs", output_dir);
|
|
13
|
-
|
|
14
|
-
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
15
|
-
|
|
16
|
-
for (path, stmts) in modules {
|
|
17
|
-
content.push_str(&format!("--- Resolved Statements for {} ---\n", path));
|
|
18
|
-
|
|
19
|
-
for stmt in stmts {
|
|
20
|
-
content.push_str(&format!("{:?}\n", stmt));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
content.push_str("\n");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
debugger.write_log_file(&log_directory, file_name, &content);
|
|
27
|
-
}
|
|
1
|
+
use crate::core::{debugger::Debugger, parser::statement::Statement};
|
|
2
|
+
use std::{collections::HashMap, fs::create_dir_all};
|
|
3
|
+
|
|
4
|
+
pub fn write_preprocessor_log_file(
|
|
5
|
+
output_dir: &str,
|
|
6
|
+
file_name: &str,
|
|
7
|
+
modules: HashMap<String, Vec<Statement>>,
|
|
8
|
+
) {
|
|
9
|
+
let debugger = Debugger::new();
|
|
10
|
+
let mut content = String::new();
|
|
11
|
+
|
|
12
|
+
let log_directory = format!("{}/logs", output_dir);
|
|
13
|
+
|
|
14
|
+
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
15
|
+
|
|
16
|
+
for (path, stmts) in modules {
|
|
17
|
+
content.push_str(&format!("--- Resolved Statements for {} ---\n", path));
|
|
18
|
+
|
|
19
|
+
for stmt in stmts {
|
|
20
|
+
content.push_str(&format!("{:?}\n", stmt));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
content.push_str("\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
debugger.write_log_file(&log_directory, file_name, &content);
|
|
27
|
+
}
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
use
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
pub fn write_variables_log_file(output_dir: &str, file_name: &str, variables: VariableTable) {
|
|
8
|
-
let debugger = Debugger::new();
|
|
9
|
-
let mut content = String::new();
|
|
10
|
-
|
|
11
|
-
let log_directory = format!("{}/logs", output_dir);
|
|
12
|
-
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
13
|
-
|
|
14
|
-
for (var_name, var_data) in variables.variables {
|
|
15
|
-
content.push_str(&format!("{:?} = {:?}\n", var_name, var_data));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
content.push_str("\n");
|
|
19
|
-
|
|
20
|
-
debugger.write_log_file(&log_directory, file_name, &content);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
pub fn write_function_log_file(output_dir: &str, file_name: &str, functions: FunctionTable) {
|
|
24
|
-
let debugger = Debugger::new();
|
|
25
|
-
let mut content = String::new();
|
|
26
|
-
|
|
27
|
-
let log_directory = format!("{}/logs", output_dir);
|
|
28
|
-
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
29
|
-
|
|
30
|
-
for (_index, function) in functions.functions {
|
|
31
|
-
content.push_str(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
use crate::core::{
|
|
2
|
+
debugger::Debugger,
|
|
3
|
+
store::{function::FunctionTable, variable::VariableTable},
|
|
4
|
+
};
|
|
5
|
+
use std::fs::create_dir_all;
|
|
6
|
+
|
|
7
|
+
pub fn write_variables_log_file(output_dir: &str, file_name: &str, variables: VariableTable) {
|
|
8
|
+
let debugger = Debugger::new();
|
|
9
|
+
let mut content = String::new();
|
|
10
|
+
|
|
11
|
+
let log_directory = format!("{}/logs", output_dir);
|
|
12
|
+
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
13
|
+
|
|
14
|
+
for (var_name, var_data) in variables.variables {
|
|
15
|
+
content.push_str(&format!("{:?} = {:?}\n", var_name, var_data));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
content.push_str("\n");
|
|
19
|
+
|
|
20
|
+
debugger.write_log_file(&log_directory, file_name, &content);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
pub fn write_function_log_file(output_dir: &str, file_name: &str, functions: FunctionTable) {
|
|
24
|
+
let debugger = Debugger::new();
|
|
25
|
+
let mut content = String::new();
|
|
26
|
+
|
|
27
|
+
let log_directory = format!("{}/logs", output_dir);
|
|
28
|
+
create_dir_all(&log_directory).expect("Failed to create log directory");
|
|
29
|
+
|
|
30
|
+
for (_index, function) in functions.functions {
|
|
31
|
+
content.push_str(&format!(
|
|
32
|
+
"'{}' = [{:?}] => {:?}\n",
|
|
33
|
+
function.name, function.parameters, function.body
|
|
34
|
+
));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
content.push_str("\n");
|
|
38
|
+
|
|
39
|
+
debugger.write_log_file(&log_directory, file_name, &content);
|
|
40
|
+
}
|
package/rust/core/error/mod.rs
CHANGED
|
@@ -1,69 +1,80 @@
|
|
|
1
|
-
use crate::core::parser::{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
pub
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pub
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
pub
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
use crate::core::parser::{
|
|
2
|
+
driver::Parser,
|
|
3
|
+
statement::{Statement, StatementKind},
|
|
4
|
+
};
|
|
5
|
+
use serde::{Deserialize, Serialize};
|
|
6
|
+
|
|
7
|
+
pub struct ErrorHandler {
|
|
8
|
+
errors: Vec<Error>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
12
|
+
pub enum Severity {
|
|
13
|
+
Warning,
|
|
14
|
+
Critical,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
|
18
|
+
pub struct StackFrame {
|
|
19
|
+
pub module: Option<String>,
|
|
20
|
+
pub context: Option<String>,
|
|
21
|
+
pub line: usize,
|
|
22
|
+
pub column: usize,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
26
|
+
pub struct ErrorResult {
|
|
27
|
+
pub message: String,
|
|
28
|
+
pub line: usize,
|
|
29
|
+
pub column: usize,
|
|
30
|
+
pub severity: Severity,
|
|
31
|
+
pub stack: Vec<StackFrame>,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[derive(Clone)]
|
|
35
|
+
pub struct Error {
|
|
36
|
+
pub message: String,
|
|
37
|
+
pub line: usize,
|
|
38
|
+
pub column: usize,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl ErrorHandler {
|
|
42
|
+
pub fn new() -> Self {
|
|
43
|
+
Self { errors: Vec::new() }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn add_error(&mut self, message: String, line: usize, column: usize) {
|
|
47
|
+
let error_statement = Error {
|
|
48
|
+
message,
|
|
49
|
+
line,
|
|
50
|
+
column,
|
|
51
|
+
};
|
|
52
|
+
self.errors.push(error_statement);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
pub fn has_errors(&self) -> bool {
|
|
56
|
+
!self.errors.is_empty()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
pub fn get_errors(&self) -> &Vec<Error> {
|
|
60
|
+
&self.errors
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pub fn clear_errors(&mut self) {
|
|
64
|
+
self.errors.clear();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub fn detect_from_statements(&mut self, _parser: &mut Parser, statements: &[Statement]) {
|
|
68
|
+
for stmt in statements {
|
|
69
|
+
match &stmt.kind {
|
|
70
|
+
StatementKind::Unknown => {
|
|
71
|
+
self.add_error("Unknown statement".to_string(), stmt.line, stmt.column);
|
|
72
|
+
}
|
|
73
|
+
StatementKind::Error { message } => {
|
|
74
|
+
self.add_error(message.clone(), stmt.line, stmt.column);
|
|
75
|
+
}
|
|
76
|
+
_ => {}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
use crate::core::lexer::token::{
|
|
2
|
-
|
|
3
|
-
pub fn handle_arrow_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
|
-
// If next char is '>', this is an arrow '->'.
|
|
13
|
-
if let Some(&c) = chars.peek() {
|
|
14
|
-
if c == '>' {
|
|
15
|
-
let mut arrow_call = ch.to_string();
|
|
16
|
-
chars.next();
|
|
17
|
-
arrow_call.push(c);
|
|
18
|
-
*column += 1;
|
|
19
|
-
|
|
20
|
-
tokens.push(Token {
|
|
21
|
-
kind: TokenKind::Arrow,
|
|
22
|
-
lexeme: arrow_call,
|
|
23
|
-
line: *line,
|
|
24
|
-
column: *column,
|
|
25
|
-
indent: *current_indent,
|
|
26
|
-
});
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Otherwise, treat '-' as the start of a negative number if followed by digits.
|
|
32
|
-
let mut lexeme = String::from("-");
|
|
33
|
-
if let Some(&next) = chars.peek() {
|
|
34
|
-
if next.is_ascii_digit() {
|
|
35
|
-
// consume digits
|
|
36
|
-
while let Some(&d) = chars.peek() {
|
|
37
|
-
if d.is_ascii_digit() {
|
|
38
|
-
chars.next();
|
|
39
|
-
lexeme.push(d);
|
|
40
|
-
*column += 1;
|
|
41
|
-
} else {
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// optional decimal part
|
|
46
|
-
if let Some(&dot) = chars.peek() {
|
|
47
|
-
if dot == '.' {
|
|
48
|
-
chars.next();
|
|
49
|
-
lexeme.push(dot);
|
|
50
|
-
*column += 1;
|
|
51
|
-
while let Some(&d) = chars.peek() {
|
|
52
|
-
if d.is_ascii_digit() {
|
|
53
|
-
chars.next();
|
|
54
|
-
lexeme.push(d);
|
|
55
|
-
*column += 1;
|
|
56
|
-
} else {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
tokens.push(Token {
|
|
64
|
-
kind: TokenKind::Number,
|
|
65
|
-
lexeme,
|
|
66
|
-
line: *line,
|
|
67
|
-
column: *column,
|
|
68
|
-
indent: *current_indent,
|
|
69
|
-
});
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Fallback: lone '-' not part of '->' or a number; emit Unknown to avoid mis-parsing as Arrow
|
|
75
|
-
tokens.push(Token {
|
|
76
|
-
kind: TokenKind::Unknown,
|
|
77
|
-
lexeme: "-".to_string(),
|
|
78
|
-
line: *line,
|
|
79
|
-
column: *column,
|
|
80
|
-
indent: *current_indent,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
1
|
+
use crate::core::lexer::token::{Token, TokenKind};
|
|
2
|
+
|
|
3
|
+
pub fn handle_arrow_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
|
+
// If next char is '>', this is an arrow '->'.
|
|
13
|
+
if let Some(&c) = chars.peek() {
|
|
14
|
+
if c == '>' {
|
|
15
|
+
let mut arrow_call = ch.to_string();
|
|
16
|
+
chars.next();
|
|
17
|
+
arrow_call.push(c);
|
|
18
|
+
*column += 1;
|
|
19
|
+
|
|
20
|
+
tokens.push(Token {
|
|
21
|
+
kind: TokenKind::Arrow,
|
|
22
|
+
lexeme: arrow_call,
|
|
23
|
+
line: *line,
|
|
24
|
+
column: *column,
|
|
25
|
+
indent: *current_indent,
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Otherwise, treat '-' as the start of a negative number if followed by digits.
|
|
32
|
+
let mut lexeme = String::from("-");
|
|
33
|
+
if let Some(&next) = chars.peek() {
|
|
34
|
+
if next.is_ascii_digit() {
|
|
35
|
+
// consume digits
|
|
36
|
+
while let Some(&d) = chars.peek() {
|
|
37
|
+
if d.is_ascii_digit() {
|
|
38
|
+
chars.next();
|
|
39
|
+
lexeme.push(d);
|
|
40
|
+
*column += 1;
|
|
41
|
+
} else {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// optional decimal part
|
|
46
|
+
if let Some(&dot) = chars.peek() {
|
|
47
|
+
if dot == '.' {
|
|
48
|
+
chars.next();
|
|
49
|
+
lexeme.push(dot);
|
|
50
|
+
*column += 1;
|
|
51
|
+
while let Some(&d) = chars.peek() {
|
|
52
|
+
if d.is_ascii_digit() {
|
|
53
|
+
chars.next();
|
|
54
|
+
lexeme.push(d);
|
|
55
|
+
*column += 1;
|
|
56
|
+
} else {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
tokens.push(Token {
|
|
64
|
+
kind: TokenKind::Number,
|
|
65
|
+
lexeme,
|
|
66
|
+
line: *line,
|
|
67
|
+
column: *column,
|
|
68
|
+
indent: *current_indent,
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Fallback: lone '-' not part of '->' or a number; emit Unknown to avoid mis-parsing as Arrow
|
|
75
|
+
tokens.push(Token {
|
|
76
|
+
kind: TokenKind::Unknown,
|
|
77
|
+
lexeme: "-".to_string(),
|
|
78
|
+
line: *line,
|
|
79
|
+
column: *column,
|
|
80
|
+
indent: *current_indent,
|
|
81
|
+
});
|
|
82
|
+
}
|