@devaloop/devalang 0.0.1-alpha.15 → 0.0.1-alpha.16-hotfix.0

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 (173) hide show
  1. package/.devalang +2 -0
  2. package/.github/workflows/ci.yml +92 -0
  3. package/Cargo.toml +60 -58
  4. package/README.md +1 -1
  5. package/docs/CHANGELOG.md +34 -1
  6. package/docs/CONTRIBUTING.md +101 -1
  7. package/docs/ROADMAP.md +1 -1
  8. package/docs/TODO.md +1 -1
  9. package/examples/automation.deva +1 -3
  10. package/examples/bank.deva +4 -4
  11. package/examples/events.deva +12 -0
  12. package/examples/function.deva +4 -4
  13. package/examples/index.deva +3 -5
  14. package/examples/loop.deva +5 -11
  15. package/examples/pattern.deva +8 -0
  16. package/examples/plugin.deva +12 -11
  17. package/examples/variables.deva +1 -1
  18. package/out-tsc/bin/index.js +51 -7
  19. package/out-tsc/index.js +3 -1
  20. package/out-tsc/scripts/postbuild.js +9 -10
  21. package/out-tsc/scripts/postinstall.js +49 -0
  22. package/package.json +12 -4
  23. package/project-version.json +3 -3
  24. package/rust/cli/bank.rs +462 -455
  25. package/rust/cli/build.rs +252 -199
  26. package/rust/cli/check.rs +221 -180
  27. package/rust/cli/driver.rs +297 -292
  28. package/rust/cli/generator.rs +1 -0
  29. package/rust/cli/init.rs +87 -79
  30. package/rust/cli/install.rs +35 -32
  31. package/rust/cli/login.rs +127 -134
  32. package/rust/cli/mod.rs +13 -11
  33. package/rust/cli/play.rs +1123 -218
  34. package/rust/cli/telemetry.rs +19 -0
  35. package/rust/cli/template.rs +69 -57
  36. package/rust/cli/update.rs +6 -4
  37. package/rust/common/api.rs +5 -5
  38. package/rust/common/mod.rs +3 -3
  39. package/rust/config/driver.rs +118 -94
  40. package/rust/config/loader.rs +165 -156
  41. package/rust/config/mod.rs +4 -2
  42. package/rust/config/settings.rs +91 -0
  43. package/rust/config/stats.rs +257 -0
  44. package/rust/core/audio/engine.rs +696 -659
  45. package/rust/core/audio/evaluator.rs +263 -132
  46. package/rust/core/audio/interpreter/arrow_call.rs +198 -187
  47. package/rust/core/audio/interpreter/call.rs +98 -95
  48. package/rust/core/audio/interpreter/condition.rs +70 -71
  49. package/rust/core/audio/interpreter/driver.rs +487 -231
  50. package/rust/core/audio/interpreter/function.rs +26 -21
  51. package/rust/core/audio/interpreter/let_.rs +38 -26
  52. package/rust/core/audio/interpreter/load.rs +18 -18
  53. package/rust/core/audio/interpreter/loop_.rs +113 -106
  54. package/rust/core/audio/interpreter/mod.rs +14 -14
  55. package/rust/core/audio/interpreter/sleep.rs +27 -28
  56. package/rust/core/audio/interpreter/spawn.rs +105 -102
  57. package/rust/core/audio/interpreter/tempo.rs +19 -16
  58. package/rust/core/audio/interpreter/trigger.rs +239 -210
  59. package/rust/core/audio/loader/mod.rs +1 -1
  60. package/rust/core/audio/loader/trigger.rs +100 -94
  61. package/rust/core/audio/mod.rs +7 -7
  62. package/rust/core/audio/player.rs +64 -64
  63. package/rust/core/audio/renderer.rs +56 -53
  64. package/rust/core/audio/special/easing.rs +189 -120
  65. package/rust/core/audio/special/env.rs +43 -41
  66. package/rust/core/audio/special/math.rs +102 -92
  67. package/rust/core/audio/special/mod.rs +9 -9
  68. package/rust/core/audio/special/modulator.rs +143 -120
  69. package/rust/core/builder/mod.rs +80 -85
  70. package/rust/core/debugger/lexer.rs +27 -27
  71. package/rust/core/debugger/mod.rs +24 -23
  72. package/rust/core/debugger/module.rs +55 -47
  73. package/rust/core/debugger/preprocessor.rs +27 -27
  74. package/rust/core/debugger/store.rs +40 -39
  75. package/rust/core/error/mod.rs +80 -69
  76. package/rust/core/lexer/handler/arrow.rs +82 -82
  77. package/rust/core/lexer/handler/at.rs +21 -21
  78. package/rust/core/lexer/handler/brace.rs +41 -41
  79. package/rust/core/lexer/handler/colon.rs +21 -21
  80. package/rust/core/lexer/handler/comment.rs +30 -30
  81. package/rust/core/lexer/handler/dot.rs +21 -21
  82. package/rust/core/lexer/handler/driver.rs +337 -292
  83. package/rust/core/lexer/handler/identifier.rs +46 -43
  84. package/rust/core/lexer/handler/indent.rs +66 -66
  85. package/rust/core/lexer/handler/mod.rs +16 -16
  86. package/rust/core/lexer/handler/newline.rs +23 -23
  87. package/rust/core/lexer/handler/number.rs +31 -31
  88. package/rust/core/lexer/handler/operator.rs +46 -46
  89. package/rust/core/lexer/handler/parenthesis.rs +41 -41
  90. package/rust/core/lexer/handler/slash.rs +21 -21
  91. package/rust/core/lexer/handler/string.rs +63 -63
  92. package/rust/core/lexer/mod.rs +54 -51
  93. package/rust/core/lexer/token.rs +97 -94
  94. package/rust/core/mod.rs +11 -11
  95. package/rust/core/parser/driver.rs +513 -490
  96. package/rust/core/parser/handler/arrow_call.rs +233 -227
  97. package/rust/core/parser/handler/at.rs +245 -162
  98. package/rust/core/parser/handler/bank.rs +94 -69
  99. package/rust/core/parser/handler/condition.rs +80 -74
  100. package/rust/core/parser/handler/dot.rs +143 -135
  101. package/rust/core/parser/handler/identifier/automate.rs +257 -194
  102. package/rust/core/parser/handler/identifier/call.rs +91 -88
  103. package/rust/core/parser/handler/identifier/emit.rs +66 -0
  104. package/rust/core/parser/handler/identifier/function.rs +100 -91
  105. package/rust/core/parser/handler/identifier/group.rs +85 -75
  106. package/rust/core/parser/handler/identifier/let_.rs +158 -143
  107. package/rust/core/parser/handler/identifier/mod.rs +54 -56
  108. package/rust/core/parser/handler/identifier/on.rs +98 -0
  109. package/rust/core/parser/handler/identifier/print.rs +52 -29
  110. package/rust/core/parser/handler/identifier/sleep.rs +36 -33
  111. package/rust/core/parser/handler/identifier/spawn.rs +91 -88
  112. package/rust/core/parser/handler/identifier/synth.rs +65 -63
  113. package/rust/core/parser/handler/loop_.rs +170 -89
  114. package/rust/core/parser/handler/mod.rs +8 -8
  115. package/rust/core/parser/handler/tempo.rs +53 -47
  116. package/rust/core/parser/mod.rs +4 -4
  117. package/rust/core/parser/statement.rs +142 -113
  118. package/rust/core/plugin/loader.rs +123 -48
  119. package/rust/core/plugin/mod.rs +2 -1
  120. package/rust/core/plugin/runner.rs +296 -0
  121. package/rust/core/preprocessor/loader.rs +515 -326
  122. package/rust/core/preprocessor/mod.rs +4 -4
  123. package/rust/core/preprocessor/module.rs +60 -58
  124. package/rust/core/preprocessor/processor.rs +99 -101
  125. package/rust/core/preprocessor/resolver/bank.rs +51 -48
  126. package/rust/core/preprocessor/resolver/call.rs +100 -101
  127. package/rust/core/preprocessor/resolver/condition.rs +97 -97
  128. package/rust/core/preprocessor/resolver/driver.rs +310 -280
  129. package/rust/core/preprocessor/resolver/function.rs +69 -68
  130. package/rust/core/preprocessor/resolver/group.rs +96 -91
  131. package/rust/core/preprocessor/resolver/let_.rs +32 -28
  132. package/rust/core/preprocessor/resolver/loop_.rs +320 -121
  133. package/rust/core/preprocessor/resolver/mod.rs +15 -15
  134. package/rust/core/preprocessor/resolver/spawn.rs +76 -73
  135. package/rust/core/preprocessor/resolver/synth.rs +56 -50
  136. package/rust/core/preprocessor/resolver/tempo.rs +50 -49
  137. package/rust/core/preprocessor/resolver/trigger.rs +113 -115
  138. package/rust/core/preprocessor/resolver/value.rs +81 -81
  139. package/rust/core/shared/duration.rs +9 -9
  140. package/rust/core/shared/mod.rs +3 -3
  141. package/rust/core/shared/value.rs +35 -32
  142. package/rust/core/store/function.rs +34 -34
  143. package/rust/core/store/global.rs +55 -38
  144. package/rust/core/store/mod.rs +5 -5
  145. package/rust/core/store/variable.rs +37 -34
  146. package/rust/core/utils/mod.rs +2 -2
  147. package/rust/core/utils/path.rs +37 -31
  148. package/rust/core/utils/validation.rs +35 -36
  149. package/rust/installer/addon.rs +84 -80
  150. package/rust/installer/bank.rs +62 -65
  151. package/rust/installer/mod.rs +5 -5
  152. package/rust/installer/plugin.rs +54 -55
  153. package/rust/installer/utils.rs +56 -56
  154. package/rust/lib.rs +156 -164
  155. package/rust/main.rs +250 -144
  156. package/rust/utils/error.rs +200 -51
  157. package/rust/utils/file.rs +38 -35
  158. package/rust/utils/first_usage.rs +76 -0
  159. package/rust/utils/logger.rs +195 -143
  160. package/rust/utils/mod.rs +9 -7
  161. package/rust/utils/signature.rs +19 -17
  162. package/rust/utils/spinner.rs +22 -19
  163. package/rust/utils/telemetry.rs +292 -0
  164. package/rust/utils/watcher.rs +34 -33
  165. package/templates/minimal/README.md +97 -121
  166. package/templates/welcome/README.md +97 -121
  167. package/typescript/bin/index.ts +19 -5
  168. package/typescript/index.ts +3 -1
  169. package/typescript/scripts/postbuild.ts +10 -6
  170. package/typescript/scripts/postinstall.ts +56 -0
  171. package/typescript/scripts/version/bump.ts +0 -1
  172. package/typescript/scripts/version/index.ts +0 -1
  173. package/out-tsc/bin/devalang.exe +0 -0
@@ -1,27 +1,27 @@
1
- use std::{ collections::HashMap, fs::create_dir_all };
2
- use crate::core::{ debugger::Debugger, lexer::token::Token };
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 preprocessor;
2
- pub mod lexer;
3
- pub mod store;
4
- pub mod module;
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()).expect("Failed to write to file");
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 std::{ fs::create_dir_all };
2
- use crate::core::{
3
- debugger::Debugger,
4
- store::{ function::FunctionTable, variable::VariableTable },
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.split('/').last().unwrap_or("index").replace(".deva", "");
15
-
16
- let log_directory = format!("{}/logs/modules/{}", output_dir, module_name);
17
- create_dir_all(&log_directory).expect("Failed to create log directory");
18
-
19
- for (var_name, var_data) in &variable_table.variables {
20
- content.push_str(&format!("{:?} = {:?}\n", var_name, var_data));
21
- }
22
-
23
- content.push_str("\n");
24
-
25
- debugger.write_log_file(&log_directory, "variables.log", &content);
26
- }
27
-
28
- pub fn write_module_function_log_file(
29
- output_dir: &str,
30
- module_path: &str,
31
- function_table: &FunctionTable
32
- ) {
33
- let debugger = Debugger::new();
34
- let mut content = String::new();
35
- let module_name = module_path.split('/').last().unwrap_or("index").replace(".deva", "");
36
-
37
- let log_directory = format!("{}/logs/modules/{}", output_dir, module_name);
38
- create_dir_all(&log_directory).expect("Failed to create log directory");
39
-
40
- for (func_name, func_data) in &function_table.functions {
41
- content.push_str(&format!("{:?} = {:?}\n", func_name, func_data));
42
- }
43
-
44
- content.push_str("\n");
45
-
46
- debugger.write_log_file(&log_directory, "functions.log", &content);
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 std::{ collections::HashMap, fs::create_dir_all };
2
- use crate::core::{ debugger::Debugger, parser::statement::Statement };
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 std::{ fs::create_dir_all };
2
- use crate::core::{
3
- debugger::Debugger,
4
- store::{ function::FunctionTable, variable::VariableTable },
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
- &format!("'{}' = [{:?}] => {:?}\n", function.name, function.parameters, function.body)
33
- );
34
- }
35
-
36
- content.push_str("\n");
37
-
38
- debugger.write_log_file(&log_directory, file_name, &content);
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
+ }
@@ -1,69 +1,80 @@
1
- use crate::core::parser::{ statement::{ Statement, StatementKind }, driver::Parser };
2
- use serde::{Serialize, Deserialize};
3
-
4
- pub struct ErrorHandler {
5
- errors: Vec<Error>,
6
- }
7
-
8
- #[derive(Serialize, Deserialize, Clone)]
9
- pub struct ErrorResult {
10
- pub message: String,
11
- pub line: usize,
12
- pub column: usize,
13
- }
14
-
15
- #[derive(Clone)]
16
- pub struct Error {
17
- pub message: String,
18
- pub line: usize,
19
- pub column: usize,
20
- }
21
-
22
- impl ErrorHandler {
23
- pub fn new() -> Self {
24
- Self { errors: Vec::new() }
25
- }
26
-
27
- pub fn add_error(&mut self, message: String, line: usize, column: usize) {
28
- let error_statement = Error {
29
- message,
30
- line,
31
- column,
32
- };
33
- self.errors.push(error_statement);
34
- }
35
-
36
- pub fn has_errors(&self) -> bool {
37
- !self.errors.is_empty()
38
- }
39
-
40
- pub fn get_errors(&self) -> &Vec<Error> {
41
- &self.errors
42
- }
43
-
44
- pub fn clear_errors(&mut self) {
45
- self.errors.clear();
46
- }
47
-
48
- pub fn detect_from_statements(&mut self, _parser: &mut Parser, statements: &[Statement]) {
49
- for stmt in statements {
50
- match &stmt.kind {
51
- StatementKind::Unknown => {
52
- self.add_error(
53
- "Unknown statement".to_string(),
54
- stmt.line,
55
- stmt.column
56
- );
57
- }
58
- StatementKind::Error { message } => {
59
- self.add_error(
60
- message.clone(),
61
- stmt.line,
62
- stmt.column
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::{ 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
- }
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
+ }