@devaloop/devalang 0.0.1-alpha.16-hotfix.3 → 0.0.1-alpha.18

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 (239) hide show
  1. package/.cargo/config.toml +2 -0
  2. package/.devalang +10 -10
  3. package/.github/workflows/ci.yml +0 -1
  4. package/Cargo.toml +18 -2
  5. package/README.md +82 -34
  6. package/docs/CHANGELOG.md +91 -0
  7. package/docs/ROADMAP.md +7 -4
  8. package/docs/TODO.md +1 -1
  9. package/examples/index.deva +55 -35
  10. package/examples/pattern.deva +5 -5
  11. package/out-tsc/bin/index.d.ts +2 -0
  12. package/out-tsc/core/functions/index.d.ts +37 -0
  13. package/out-tsc/core/functions/index.js +76 -0
  14. package/out-tsc/core/index.d.ts +6 -0
  15. package/out-tsc/core/index.js +22 -0
  16. package/out-tsc/core/types/index.d.ts +4 -0
  17. package/out-tsc/core/types/index.js +20 -0
  18. package/out-tsc/core/types/plugin.d.ts +18 -0
  19. package/out-tsc/core/types/plugin.js +2 -0
  20. package/out-tsc/core/types/result.d.ts +27 -0
  21. package/out-tsc/core/types/result.js +2 -0
  22. package/out-tsc/core/types/statement.d.ts +106 -0
  23. package/out-tsc/core/types/statement.js +2 -0
  24. package/out-tsc/core/types/value.d.ts +43 -0
  25. package/out-tsc/core/types/value.js +2 -0
  26. package/out-tsc/index.d.ts +7 -0
  27. package/out-tsc/index.js +41 -2
  28. package/out-tsc/pkg/devalang_core.d.ts +7 -0
  29. package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
  30. package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
  31. package/out-tsc/scripts/copy-wasm-dts.js +73 -0
  32. package/out-tsc/scripts/postinstall.d.ts +1 -0
  33. package/out-tsc/scripts/postinstall.js +33 -23
  34. package/out-tsc/scripts/version/bump.d.ts +1 -0
  35. package/out-tsc/scripts/version/fetch.d.ts +1 -0
  36. package/out-tsc/scripts/version/index.d.ts +1 -0
  37. package/out-tsc/scripts/version/sync.d.ts +1 -0
  38. package/package.json +16 -4
  39. package/project-version.json +3 -3
  40. package/rust/cli/bank/api.rs +122 -0
  41. package/rust/cli/bank/commands.rs +275 -0
  42. package/rust/cli/bank/mod.rs +29 -0
  43. package/rust/cli/build/commands.rs +107 -0
  44. package/rust/cli/build/mod.rs +2 -0
  45. package/rust/cli/build/process.rs +146 -0
  46. package/rust/cli/{check.rs → check/mod.rs} +18 -31
  47. package/rust/cli/discover/commands.rs +253 -0
  48. package/rust/cli/discover/config.rs +111 -0
  49. package/rust/cli/discover/fs.rs +19 -0
  50. package/rust/cli/discover/install.rs +103 -0
  51. package/rust/cli/discover/metadata.rs +48 -0
  52. package/rust/cli/discover/mod.rs +5 -0
  53. package/rust/cli/{init.rs → init/commands.rs} +88 -87
  54. package/rust/cli/init/mod.rs +1 -0
  55. package/rust/cli/install/addon.rs +126 -0
  56. package/rust/cli/install/bank.rs +53 -0
  57. package/rust/cli/{install.rs → install/commands.rs} +9 -9
  58. package/rust/{installer → cli/install}/mod.rs +2 -3
  59. package/rust/cli/install/plugin.rs +61 -0
  60. package/rust/cli/{login.rs → login/commands.rs} +8 -11
  61. package/rust/cli/login/mod.rs +1 -0
  62. package/rust/cli/mod.rs +2 -2
  63. package/rust/cli/{driver.rs → parser.rs} +7 -2
  64. package/rust/cli/play/commands.rs +324 -0
  65. package/rust/cli/play/io.rs +17 -0
  66. package/rust/cli/play/mod.rs +5 -0
  67. package/rust/cli/play/process.rs +150 -0
  68. package/rust/cli/play/realtime.rs +91 -0
  69. package/rust/cli/play/utils.rs +23 -0
  70. package/rust/cli/{telemetry.rs → telemetry/commands.rs} +4 -4
  71. package/rust/cli/telemetry/event_creator.rs +80 -0
  72. package/rust/cli/telemetry/mod.rs +3 -0
  73. package/rust/cli/telemetry/send.rs +51 -0
  74. package/rust/cli/{template.rs → template/commands.rs} +1 -1
  75. package/rust/cli/template/mod.rs +1 -0
  76. package/rust/cli/{update.rs → update/commands.rs} +6 -6
  77. package/rust/cli/update/mod.rs +1 -0
  78. package/rust/config/driver.rs +57 -72
  79. package/rust/config/mod.rs +1 -2
  80. package/rust/config/ops.rs +26 -0
  81. package/rust/config/settings.rs +40 -42
  82. package/rust/core/audio/engine/helpers.rs +158 -0
  83. package/rust/core/audio/engine/mod.rs +7 -0
  84. package/rust/core/audio/engine/sample.rs +359 -0
  85. package/rust/core/audio/engine/synth.rs +325 -0
  86. package/rust/core/audio/evaluator.rs +68 -27
  87. package/rust/core/audio/interpreter/arrow_call.rs +113 -33
  88. package/rust/core/audio/interpreter/call.rs +232 -56
  89. package/rust/core/audio/interpreter/condition.rs +3 -2
  90. package/rust/core/audio/interpreter/driver.rs +206 -151
  91. package/rust/core/audio/interpreter/let_.rs +1 -1
  92. package/rust/core/audio/interpreter/load.rs +2 -1
  93. package/rust/core/audio/interpreter/loop_.rs +7 -6
  94. package/rust/core/audio/interpreter/sleep.rs +2 -1
  95. package/rust/core/audio/interpreter/spawn.rs +186 -54
  96. package/rust/core/audio/interpreter/tempo.rs +31 -10
  97. package/rust/core/audio/interpreter/trigger.rs +2 -2
  98. package/rust/core/audio/loader/trigger.rs +4 -7
  99. package/rust/core/audio/player.rs +6 -0
  100. package/rust/core/audio/renderer.rs +5 -7
  101. package/rust/core/audio/special/env.rs +3 -1
  102. package/rust/core/audio/special/math.rs +26 -6
  103. package/rust/core/audio/special/modulator.rs +2 -2
  104. package/rust/core/builder/mod.rs +9 -3
  105. package/rust/core/debugger/lexer.rs +1 -1
  106. package/rust/core/debugger/mod.rs +6 -0
  107. package/rust/core/debugger/module.rs +4 -4
  108. package/rust/core/debugger/preprocessor.rs +1 -1
  109. package/rust/core/debugger/store.rs +2 -2
  110. package/rust/core/error/mod.rs +189 -0
  111. package/rust/core/lexer/driver.rs +61 -0
  112. package/rust/core/lexer/handler/arrow.rs +1 -1
  113. package/rust/core/lexer/handler/at.rs +1 -1
  114. package/rust/core/lexer/handler/brace.rs +2 -2
  115. package/rust/core/lexer/handler/colon.rs +1 -1
  116. package/rust/core/lexer/handler/comment.rs +1 -1
  117. package/rust/core/lexer/handler/dot.rs +1 -1
  118. package/rust/core/lexer/handler/driver.rs +1 -1
  119. package/rust/core/lexer/handler/identifier.rs +4 -3
  120. package/rust/core/lexer/handler/mod.rs +1 -2
  121. package/rust/core/lexer/handler/number.rs +1 -1
  122. package/rust/core/lexer/handler/operator.rs +1 -1
  123. package/rust/core/lexer/handler/parenthesis.rs +2 -2
  124. package/rust/core/lexer/handler/slash.rs +1 -1
  125. package/rust/core/lexer/handler/string.rs +1 -1
  126. package/rust/core/lexer/mod.rs +1 -52
  127. package/rust/core/lexer/token.rs +91 -97
  128. package/rust/core/mod.rs +0 -1
  129. package/rust/core/parser/driver.rs +78 -22
  130. package/rust/core/parser/handler/arrow_call.rs +28 -8
  131. package/rust/core/parser/handler/at.rs +55 -21
  132. package/rust/core/parser/handler/bank.rs +14 -4
  133. package/rust/core/parser/handler/condition.rs +6 -3
  134. package/rust/core/parser/handler/dot.rs +5 -3
  135. package/rust/core/parser/handler/identifier/automate.rs +13 -16
  136. package/rust/core/parser/handler/identifier/call.rs +4 -4
  137. package/rust/core/parser/handler/identifier/emit.rs +9 -5
  138. package/rust/core/parser/handler/identifier/function.rs +20 -7
  139. package/rust/core/parser/handler/identifier/group.rs +11 -7
  140. package/rust/core/parser/handler/identifier/let_.rs +24 -9
  141. package/rust/core/parser/handler/identifier/mod.rs +6 -5
  142. package/rust/core/parser/handler/identifier/on.rs +16 -7
  143. package/rust/core/parser/handler/identifier/print.rs +6 -9
  144. package/rust/core/parser/handler/identifier/sleep.rs +12 -5
  145. package/rust/core/parser/handler/identifier/spawn.rs +4 -4
  146. package/rust/core/parser/handler/identifier/synth.rs +79 -9
  147. package/rust/core/parser/handler/loop_.rs +38 -13
  148. package/rust/core/parser/handler/mod.rs +1 -0
  149. package/rust/core/parser/handler/pattern.rs +74 -0
  150. package/rust/core/parser/handler/tempo.rs +9 -5
  151. package/rust/core/parser/mod.rs +0 -1
  152. package/rust/core/parser/statement.rs +6 -137
  153. package/rust/core/plugin/loader.rs +41 -27
  154. package/rust/core/plugin/runner.rs +68 -17
  155. package/rust/core/preprocessor/loader.rs +181 -99
  156. package/rust/core/preprocessor/processor.rs +9 -9
  157. package/rust/core/preprocessor/resolver/bank.rs +6 -8
  158. package/rust/core/preprocessor/resolver/call.rs +47 -23
  159. package/rust/core/preprocessor/resolver/condition.rs +6 -8
  160. package/rust/core/preprocessor/resolver/driver.rs +28 -28
  161. package/rust/core/preprocessor/resolver/function.rs +6 -6
  162. package/rust/core/preprocessor/resolver/group.rs +6 -8
  163. package/rust/core/preprocessor/resolver/loop_.rs +8 -10
  164. package/rust/core/preprocessor/resolver/mod.rs +1 -0
  165. package/rust/core/preprocessor/resolver/pattern.rs +75 -0
  166. package/rust/core/preprocessor/resolver/spawn.rs +45 -22
  167. package/rust/core/preprocessor/resolver/synth.rs +6 -8
  168. package/rust/core/preprocessor/resolver/tempo.rs +6 -8
  169. package/rust/core/preprocessor/resolver/trigger.rs +22 -19
  170. package/rust/core/preprocessor/resolver/value.rs +99 -4
  171. package/rust/core/store/export.rs +28 -28
  172. package/rust/core/store/function.rs +6 -0
  173. package/rust/core/store/global.rs +7 -1
  174. package/rust/core/store/import.rs +28 -28
  175. package/rust/core/store/variable.rs +16 -2
  176. package/rust/core/utils/mod.rs +0 -1
  177. package/rust/lib.rs +102 -9
  178. package/rust/main.rs +159 -45
  179. package/rust/types/Cargo.toml +11 -0
  180. package/rust/types/src/addons.rs +55 -0
  181. package/rust/types/src/ast.rs +202 -0
  182. package/rust/types/src/config.rs +74 -0
  183. package/rust/types/src/lib.rs +12 -0
  184. package/rust/types/src/telemetry.rs +85 -0
  185. package/rust/utils/Cargo.toml +26 -0
  186. package/rust/utils/{error.rs → src/error.rs} +186 -200
  187. package/rust/utils/src/file.rs +94 -0
  188. package/rust/utils/src/first_usage.rs +97 -0
  189. package/rust/utils/{mod.rs → src/lib.rs} +1 -1
  190. package/rust/utils/{logger.rs → src/logger.rs} +17 -12
  191. package/rust/utils/src/path.rs +88 -0
  192. package/rust/utils/src/signature.rs +41 -0
  193. package/rust/utils/{spinner.rs → src/spinner.rs} +3 -5
  194. package/rust/utils/src/version.rs +27 -0
  195. package/rust/utils/{watcher.rs → src/watcher.rs} +13 -1
  196. package/rust/web/cdn.rs +34 -0
  197. package/templates/minimal/README.md +98 -54
  198. package/templates/welcome/README.md +98 -54
  199. package/templates/welcome/src/index.deva +56 -8
  200. package/templates/welcome/src/variables.deva +2 -4
  201. package/tests/rust/TODO.md +0 -0
  202. package/tests/typescript/index.spec.ts +136 -0
  203. package/tests/typescript/playhead.spec.ts +36 -0
  204. package/tests/typescript/render_e2e.spec.ts +77 -0
  205. package/tsconfig.json +1 -1
  206. package/typescript/core/functions/index.ts +83 -0
  207. package/typescript/core/index.ts +6 -0
  208. package/typescript/core/types/index.ts +4 -0
  209. package/typescript/core/types/plugin.ts +19 -0
  210. package/typescript/core/types/result.ts +29 -0
  211. package/typescript/core/types/statement.ts +47 -0
  212. package/typescript/core/types/value.ts +29 -0
  213. package/typescript/index.ts +7 -2
  214. package/typescript/pkg/devalang_core.d.ts +4 -0
  215. package/typescript/scripts/copy-wasm-dts.ts +41 -0
  216. package/rust/cli/bank.rs +0 -462
  217. package/rust/cli/build.rs +0 -252
  218. package/rust/cli/play.rs +0 -1123
  219. package/rust/common/cdn.rs +0 -5
  220. package/rust/config/loader.rs +0 -165
  221. package/rust/config/stats.rs +0 -257
  222. package/rust/core/audio/engine.rs +0 -696
  223. package/rust/core/shared/bank.rs +0 -21
  224. package/rust/core/shared/duration.rs +0 -9
  225. package/rust/core/shared/mod.rs +0 -3
  226. package/rust/core/shared/value.rs +0 -35
  227. package/rust/core/utils/validation.rs +0 -35
  228. package/rust/installer/addon.rs +0 -84
  229. package/rust/installer/bank.rs +0 -62
  230. package/rust/installer/plugin.rs +0 -54
  231. package/rust/installer/utils.rs +0 -56
  232. package/rust/utils/file.rs +0 -38
  233. package/rust/utils/first_usage.rs +0 -83
  234. package/rust/utils/signature.rs +0 -19
  235. package/rust/utils/telemetry.rs +0 -292
  236. package/rust/utils/version.rs +0 -15
  237. /package/rust/{common → web}/api.rs +0 -0
  238. /package/rust/{common → web}/mod.rs +0 -0
  239. /package/rust/{common → web}/sso.rs +0 -0
@@ -0,0 +1,74 @@
1
+ use serde::{Deserialize, Serialize};
2
+ use toml::Value as TomlValue;
3
+
4
+ use crate::TelemetrySettings;
5
+
6
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7
+ pub struct PluginExport {
8
+ pub name: String,
9
+ pub kind: String,
10
+ /// Optional default value provided by the plugin manifest (keeps toml::Value to preserve types)
11
+ #[serde(default)]
12
+ pub default: Option<TomlValue>,
13
+ }
14
+
15
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
16
+ pub struct PluginInfo {
17
+ pub author: String,
18
+ pub name: String,
19
+ /// Optional version string when available from a plugin file
20
+ #[serde(default)]
21
+ pub version: Option<String>,
22
+ /// Optional human-friendly description
23
+ #[serde(default)]
24
+ pub description: Option<String>,
25
+ pub exports: Vec<PluginExport>,
26
+ }
27
+
28
+ // --- Config types (centralised) ------------------------------------------
29
+
30
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
31
+ pub struct ProjectConfig {
32
+ pub defaults: ProjectConfigDefaults,
33
+ pub banks: Option<Vec<ProjectConfigBankEntry>>,
34
+ pub plugins: Option<Vec<ProjectConfigPluginEntry>>,
35
+ }
36
+
37
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
38
+ pub struct ProjectConfigDefaults {
39
+ pub entry: Option<String>,
40
+ pub output: Option<String>,
41
+ pub watch: Option<bool>,
42
+ pub repeat: Option<bool>,
43
+ pub debug: Option<bool>,
44
+ pub compress: Option<bool>,
45
+ }
46
+
47
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
48
+ pub struct ProjectConfigBankEntry {
49
+ pub path: String,
50
+ pub version: Option<String>,
51
+ }
52
+
53
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
54
+ pub struct ProjectConfigPluginEntry {
55
+ pub path: String,
56
+ pub version: Option<String>,
57
+ }
58
+
59
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
60
+ pub struct PluginEntry {
61
+ pub path: String,
62
+ #[serde(default)]
63
+ pub version: String,
64
+ #[serde(default)]
65
+ pub author: String,
66
+ #[serde(default)]
67
+ pub access: String,
68
+ }
69
+
70
+ #[derive(Serialize, Deserialize, Default, Debug)]
71
+ pub struct UserSettings {
72
+ pub session: String,
73
+ pub telemetry: TelemetrySettings,
74
+ }
@@ -0,0 +1,12 @@
1
+ //! Common shared types for Devalang
2
+
3
+ pub mod addons;
4
+ pub mod ast;
5
+ pub mod config;
6
+ pub mod telemetry;
7
+
8
+ // Re-exports for convenience
9
+ pub use addons::*;
10
+ pub use ast::*;
11
+ pub use config::*;
12
+ pub use telemetry::*;
@@ -0,0 +1,85 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
4
+ pub enum TelemetryErrorLevel {
5
+ #[default]
6
+ None,
7
+ Warning,
8
+ Critical,
9
+ }
10
+
11
+ #[derive(Debug)]
12
+ pub enum TelemetrySendError {
13
+ Http(String),
14
+ }
15
+
16
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
17
+ pub struct TelemetryProjectInfo {
18
+ pub config: Option<TelemetryProjectInfoConfig>,
19
+ pub stats: Option<TelemetryProjectInfoStats>,
20
+ }
21
+
22
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
23
+ pub struct TelemetryProjectInfoStats {
24
+ pub counts: TelemetryProjectInfoStatsCounts,
25
+ pub features: TelemetryProjectInfoStatsFeatures,
26
+ pub audio: TelemetryProjectInfoStatsAudio,
27
+ }
28
+
29
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
30
+ pub struct TelemetryProjectInfoStatsCounts {
31
+ pub nb_files: usize,
32
+ pub nb_modules: usize,
33
+ pub nb_lines: usize,
34
+ pub nb_banks: usize,
35
+ pub nb_plugins: usize,
36
+ }
37
+
38
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
39
+ pub struct TelemetryProjectInfoStatsFeatures {
40
+ pub uses_imports: bool,
41
+ pub uses_functions: bool,
42
+ pub uses_groups: bool,
43
+ pub uses_automations: bool,
44
+ pub uses_loops: bool,
45
+ }
46
+
47
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
48
+ pub struct TelemetryProjectInfoStatsAudio {
49
+ pub avg_bpm: Option<u32>,
50
+ pub has_synths: bool,
51
+ pub has_samples: bool,
52
+ }
53
+
54
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
55
+ pub struct TelemetryProjectInfoConfig {
56
+ pub entry_defined: bool,
57
+ pub output_defined: bool,
58
+ pub watch_defined: bool,
59
+ pub repeat_defined: bool,
60
+ pub debug_defined: bool,
61
+ pub compress_defined: bool,
62
+ }
63
+
64
+ #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
65
+ pub struct TelemetryEvent {
66
+ pub uuid: String,
67
+ pub cli_version: String,
68
+ pub os: String,
69
+ pub command: Vec<String>,
70
+ pub project_info: Option<TelemetryProjectInfo>,
71
+ pub error_level: TelemetryErrorLevel,
72
+ pub error_message: Option<String>,
73
+ pub exit_code: Option<i32>,
74
+ pub timestamp: String,
75
+ pub duration: u64,
76
+ pub success: bool,
77
+ }
78
+
79
+ #[derive(Serialize, Deserialize, Default, Debug)]
80
+ pub struct TelemetrySettings {
81
+ pub uuid: String,
82
+ pub stats: bool,
83
+ pub level: String,
84
+ pub enabled: bool,
85
+ }
@@ -0,0 +1,26 @@
1
+ [package]
2
+ name = "devalang_utils"
3
+ version = "0.0.1"
4
+ description = "Utility functions and types for Devalang"
5
+ license = "MIT"
6
+ authors = ["Devaloop <contact@devaloop.com>"]
7
+ edition = "2024"
8
+
9
+ [dependencies]
10
+ devalang_types = { path = "../types", version = "0.0.1" }
11
+ serde = { version = "1.0", features = ["derive"] }
12
+ serde_json = "1.0"
13
+ include_dir = "0.7"
14
+ notify = "6.1"
15
+ zip = "4.3.0"
16
+
17
+ [dependencies.crossterm]
18
+ version = "0.27"
19
+ optional = true
20
+
21
+ [dependencies.indicatif]
22
+ version = "0.17"
23
+ optional = true
24
+
25
+ [features]
26
+ cli = ["crossterm", "indicatif"]
@@ -1,200 +1,186 @@
1
- use super::logger::{LogLevel, Logger};
2
- use crate::core::{
3
- error::{ErrorResult, Severity, StackFrame},
4
- parser::statement::{Statement, StatementKind},
5
- shared::value::Value,
6
- };
7
- use std::collections::HashMap;
8
-
9
- /// Recursively collects errors from a list of statements.
10
- ///
11
- /// This function traverses the provided statements and aggregates any
12
- /// `Unknown` or explicit `Error` statements into a flat vector.
13
- /// It also descends into loop bodies to ensure nested errors are
14
- /// surfaced.
15
- pub fn collect_errors_recursively(statements: &[Statement]) -> Vec<ErrorResult> {
16
- let mut errors: Vec<ErrorResult> = Vec::new();
17
-
18
- for stmt in statements {
19
- match &stmt.kind {
20
- StatementKind::Unknown => {
21
- errors.push(ErrorResult {
22
- message: format!("Unknown statement at line {}:{}", stmt.line, stmt.column),
23
- line: stmt.line,
24
- column: stmt.column,
25
- severity: Severity::Warning,
26
- stack: vec![StackFrame {
27
- module: None,
28
- context: Some("Unknown".to_string()),
29
- line: stmt.line,
30
- column: stmt.column,
31
- }],
32
- });
33
- }
34
- StatementKind::Error { message } => {
35
- errors.push(ErrorResult {
36
- message: message.clone(),
37
- line: stmt.line,
38
- column: stmt.column,
39
- severity: Severity::Critical,
40
- stack: vec![StackFrame {
41
- module: None,
42
- context: Some("Error".to_string()),
43
- line: stmt.line,
44
- column: stmt.column,
45
- }],
46
- });
47
- }
48
- StatementKind::Loop => {
49
- if let Some(body_statements) = extract_loop_body_statements(&stmt.value) {
50
- let nested = collect_errors_recursively(body_statements);
51
- errors.extend(nested.into_iter().map(|mut e| {
52
- // push parent frame contextually for a basic callstack-like trace
53
- e.stack.insert(
54
- 0,
55
- StackFrame {
56
- module: None,
57
- context: Some("loop".to_string()),
58
- line: stmt.line,
59
- column: stmt.column,
60
- },
61
- );
62
- e
63
- }));
64
- }
65
- }
66
- _ => {}
67
- }
68
- }
69
-
70
- errors
71
- }
72
-
73
- fn extract_loop_body_statements(value: &Value) -> Option<&[Statement]> {
74
- if let Value::Map(map) = value {
75
- if let Some(Value::Block(statements)) = map.get("body") {
76
- return Some(statements);
77
- }
78
- }
79
- None
80
- }
81
-
82
- pub fn partition_errors(errors: Vec<ErrorResult>) -> (Vec<ErrorResult>, Vec<ErrorResult>) {
83
- let mut warnings = Vec::new();
84
- let mut criticals = Vec::new();
85
- for e in errors {
86
- match e.severity {
87
- Severity::Warning => warnings.push(e),
88
- Severity::Critical => criticals.push(e),
89
- }
90
- }
91
- (warnings, criticals)
92
- }
93
-
94
- pub fn log_errors_with_stack(prefix: &str, warnings: &[ErrorResult], criticals: &[ErrorResult]) {
95
- let logger = Logger::new();
96
- if !warnings.is_empty() {
97
- logger.log_message(
98
- LogLevel::Warning,
99
- &format!("{}: {} warning(s)", prefix, warnings.len()),
100
- );
101
- for w in warnings {
102
- logger.log_message(LogLevel::Warning, &format!("- {}", w.message));
103
- // Print primary location in path:line:col if available
104
- if let Some(frame) = w.stack.first() {
105
- let module = frame.module.clone().unwrap_or_default();
106
- logger.log_message(
107
- LogLevel::Debug,
108
- &format!(
109
- " ↳ {}:{}:{} {}",
110
- module,
111
- frame.line,
112
- frame.column,
113
- frame.context.clone().unwrap_or_default()
114
- ),
115
- );
116
- }
117
- // Print remaining frames if any
118
- if w.stack.len() > 1 {
119
- for (i, f) in w.stack.iter().enumerate().skip(1) {
120
- let module = f.module.clone().unwrap_or_default();
121
- logger.log_message(
122
- LogLevel::Debug,
123
- &format!(
124
- " #{} {}:{}:{} {}",
125
- i,
126
- module,
127
- f.line,
128
- f.column,
129
- f.context.clone().unwrap_or_default()
130
- ),
131
- );
132
- }
133
- }
134
- }
135
- }
136
- if !criticals.is_empty() {
137
- logger.log_message(
138
- LogLevel::Error,
139
- &format!("{}: {} critical error(s)", prefix, criticals.len()),
140
- );
141
- for c in criticals {
142
- logger.log_message(LogLevel::Error, &format!("- {}", c.message));
143
- if let Some(frame) = c.stack.first() {
144
- let module = frame.module.clone().unwrap_or_default();
145
- logger.log_message(
146
- LogLevel::Error,
147
- &format!(
148
- " ↳ {}:{}:{} {}",
149
- module,
150
- frame.line,
151
- frame.column,
152
- frame.context.clone().unwrap_or_default()
153
- ),
154
- );
155
- }
156
- if c.stack.len() > 1 {
157
- for (i, f) in c.stack.iter().enumerate().skip(1) {
158
- let module = f.module.clone().unwrap_or_default();
159
- logger.log_message(
160
- LogLevel::Error,
161
- &format!(
162
- " #{} {}:{}:{} {}",
163
- i,
164
- module,
165
- f.line,
166
- f.column,
167
- f.context.clone().unwrap_or_default()
168
- ),
169
- );
170
- }
171
- }
172
- }
173
- }
174
- }
175
-
176
- pub fn collect_all_errors_with_modules(
177
- modules: &HashMap<String, Vec<Statement>>,
178
- ) -> Vec<ErrorResult> {
179
- let mut all = Vec::new();
180
- for (module_path, stmts) in modules {
181
- let mut errs = collect_errors_recursively(stmts);
182
- for e in errs.iter_mut() {
183
- // ensure top frame carries the module path
184
- if e.stack.is_empty() {
185
- e.stack.push(StackFrame {
186
- module: Some(module_path.clone()),
187
- context: None,
188
- line: e.line,
189
- column: e.column,
190
- });
191
- } else {
192
- if e.stack[0].module.is_none() {
193
- e.stack[0].module = Some(module_path.clone());
194
- }
195
- }
196
- }
197
- all.extend(errs);
198
- }
199
- all
200
- }
1
+ use super::logger::{LogLevel, Logger};
2
+ use devalang_types::{ErrorResult, Severity, StackFrame, Statement, StatementKind, Value};
3
+ use std::collections::HashMap;
4
+
5
+ pub fn collect_errors_recursively(statements: &[Statement]) -> Vec<ErrorResult> {
6
+ let mut errors: Vec<ErrorResult> = Vec::new();
7
+
8
+ for stmt in statements {
9
+ match &stmt.kind {
10
+ StatementKind::Unknown => {
11
+ errors.push(ErrorResult {
12
+ message: format!("Unknown statement at line {}:{}", stmt.line, stmt.column),
13
+ line: stmt.line,
14
+ column: stmt.column,
15
+ severity: Severity::Warning,
16
+ stack: vec![StackFrame {
17
+ module: None,
18
+ context: Some("Unknown".to_string()),
19
+ line: stmt.line,
20
+ column: stmt.column,
21
+ }],
22
+ });
23
+ }
24
+ StatementKind::Error { message } => {
25
+ errors.push(ErrorResult {
26
+ message: message.clone(),
27
+ line: stmt.line,
28
+ column: stmt.column,
29
+ severity: Severity::Critical,
30
+ stack: vec![StackFrame {
31
+ module: None,
32
+ context: Some("Error".to_string()),
33
+ line: stmt.line,
34
+ column: stmt.column,
35
+ }],
36
+ });
37
+ }
38
+ StatementKind::Loop => {
39
+ if let Some(body_statements) = extract_loop_body_statements(&stmt.value) {
40
+ let nested = collect_errors_recursively(body_statements);
41
+ errors.extend(nested.into_iter().map(|mut e| {
42
+ e.stack.insert(
43
+ 0,
44
+ StackFrame {
45
+ module: None,
46
+ context: Some("loop".to_string()),
47
+ line: stmt.line,
48
+ column: stmt.column,
49
+ },
50
+ );
51
+ e
52
+ }));
53
+ }
54
+ }
55
+ _ => {}
56
+ }
57
+ }
58
+
59
+ errors
60
+ }
61
+
62
+ fn extract_loop_body_statements(value: &Value) -> Option<&[Statement]> {
63
+ if let Value::Map(map) = value {
64
+ if let Some(Value::Block(statements)) = map.get("body") {
65
+ return Some(statements);
66
+ }
67
+ }
68
+ None
69
+ }
70
+
71
+ pub fn partition_errors(errors: Vec<ErrorResult>) -> (Vec<ErrorResult>, Vec<ErrorResult>) {
72
+ let mut warnings = Vec::new();
73
+ let mut criticals = Vec::new();
74
+ for e in errors {
75
+ match e.severity {
76
+ Severity::Warning => warnings.push(e),
77
+ Severity::Critical => criticals.push(e),
78
+ }
79
+ }
80
+ (warnings, criticals)
81
+ }
82
+
83
+ pub fn log_errors_with_stack(prefix: &str, warnings: &[ErrorResult], criticals: &[ErrorResult]) {
84
+ let logger = Logger::new();
85
+ if !warnings.is_empty() {
86
+ logger.log_message(
87
+ LogLevel::Warning,
88
+ &format!("{}: {} warning(s)", prefix, warnings.len()),
89
+ );
90
+ for w in warnings {
91
+ logger.log_message(LogLevel::Warning, &format!("- {}", w.message));
92
+ if let Some(frame) = w.stack.first() {
93
+ let module = frame.module.clone().unwrap_or_default();
94
+ logger.log_message(
95
+ LogLevel::Debug,
96
+ &format!(
97
+ " ↳ {}:{}:{} {}",
98
+ module,
99
+ frame.line,
100
+ frame.column,
101
+ frame.context.clone().unwrap_or_default()
102
+ ),
103
+ );
104
+ }
105
+ if w.stack.len() > 1 {
106
+ for (i, f) in w.stack.iter().enumerate().skip(1) {
107
+ let module = f.module.clone().unwrap_or_default();
108
+ logger.log_message(
109
+ LogLevel::Debug,
110
+ &format!(
111
+ " #{} {}:{}:{} {}",
112
+ i,
113
+ module,
114
+ f.line,
115
+ f.column,
116
+ f.context.clone().unwrap_or_default()
117
+ ),
118
+ );
119
+ }
120
+ }
121
+ }
122
+ }
123
+ if !criticals.is_empty() {
124
+ logger.log_message(
125
+ LogLevel::Error,
126
+ &format!("{}: {} critical error(s)", prefix, criticals.len()),
127
+ );
128
+ for c in criticals {
129
+ logger.log_message(LogLevel::Error, &format!("- {}", c.message));
130
+ if let Some(frame) = c.stack.first() {
131
+ let module = frame.module.clone().unwrap_or_default();
132
+ logger.log_message(
133
+ LogLevel::Error,
134
+ &format!(
135
+ " ↳ {}:{}:{} {}",
136
+ module,
137
+ frame.line,
138
+ frame.column,
139
+ frame.context.clone().unwrap_or_default()
140
+ ),
141
+ );
142
+ }
143
+ if c.stack.len() > 1 {
144
+ for (i, f) in c.stack.iter().enumerate().skip(1) {
145
+ let module = f.module.clone().unwrap_or_default();
146
+ logger.log_message(
147
+ LogLevel::Error,
148
+ &format!(
149
+ " #{} {}:{}:{} {}",
150
+ i,
151
+ module,
152
+ f.line,
153
+ f.column,
154
+ f.context.clone().unwrap_or_default()
155
+ ),
156
+ );
157
+ }
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ pub fn collect_all_errors_with_modules(
164
+ modules: &HashMap<String, Vec<Statement>>,
165
+ ) -> Vec<ErrorResult> {
166
+ let mut all = Vec::new();
167
+ for (module_path, stmts) in modules {
168
+ let mut errs = collect_errors_recursively(stmts);
169
+ for e in errs.iter_mut() {
170
+ if e.stack.is_empty() {
171
+ e.stack.push(StackFrame {
172
+ module: Some(module_path.clone()),
173
+ context: None,
174
+ line: e.line,
175
+ column: e.column,
176
+ });
177
+ } else {
178
+ if e.stack[0].module.is_none() {
179
+ e.stack[0].module = Some(module_path.clone());
180
+ }
181
+ }
182
+ }
183
+ all.extend(errs);
184
+ }
185
+ all
186
+ }