@devaloop/devalang 0.0.1-alpha.2 → 0.0.1-alpha.3
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/Cargo.toml +46 -46
- package/README.md +7 -6
- package/docs/CHANGELOG.md +11 -6
- package/docs/ROADMAP.md +5 -1
- package/docs/TODO.md +6 -31
- package/examples/exported.deva +1 -1
- package/examples/index.deva +1 -0
- package/out-tsc/bin/devalang.exe +0 -0
- package/package.json +1 -2
- package/project-version.json +3 -3
- package/rust/cli/build.rs +57 -40
- package/rust/cli/check.rs +47 -111
- package/rust/cli/init.rs +1 -1
- package/rust/cli/mod.rs +174 -2
- package/rust/{utils/config.rs → config/loader.rs} +3 -2
- package/rust/{core/types/config.rs → config/mod.rs} +5 -5
- package/rust/core/builder/mod.rs +21 -27
- package/rust/core/debugger/lexer.rs +12 -0
- package/rust/core/debugger/mod.rs +12 -49
- package/rust/core/debugger/preprocessor.rs +23 -0
- package/rust/core/error/mod.rs +60 -0
- package/rust/core/lexer/{at.rs → handler/at.rs} +1 -1
- package/rust/core/lexer/{brace.rs → handler/brace.rs} +1 -1
- package/rust/core/lexer/{colon.rs → handler/colon.rs} +1 -1
- package/rust/core/lexer/{comment.rs → handler/comment.rs} +3 -3
- package/rust/core/lexer/{dot.rs → handler/dot.rs} +1 -1
- package/rust/core/lexer/{equal.rs → handler/equal.rs} +1 -1
- package/rust/core/lexer/{identifier.rs → handler/identifier.rs} +1 -1
- package/rust/core/lexer/{indent.rs → handler/indent.rs} +10 -5
- package/rust/core/lexer/handler/mod.rs +238 -0
- package/rust/core/lexer/{newline.rs → handler/newline.rs} +6 -10
- package/rust/core/lexer/{number.rs → handler/number.rs} +1 -1
- package/rust/core/lexer/handler/string.rs +66 -0
- package/rust/core/lexer/mod.rs +25 -14
- package/rust/core/lexer/token.rs +55 -0
- package/rust/core/mod.rs +5 -2
- package/rust/core/parser/handler/at.rs +166 -0
- package/rust/core/parser/handler/bank.rs +38 -0
- package/rust/core/parser/handler/dot.rs +112 -0
- package/rust/core/parser/handler/identifier.rs +134 -0
- package/rust/core/parser/handler/loop_.rs +55 -0
- package/rust/core/parser/handler/mod.rs +6 -0
- package/rust/core/parser/handler/tempo.rs +47 -0
- package/rust/core/parser/mod.rs +204 -166
- package/rust/core/parser/statement.rs +91 -0
- package/rust/core/preprocessor/loader.rs +105 -0
- package/rust/core/preprocessor/mod.rs +2 -24
- package/rust/core/preprocessor/module.rs +37 -56
- package/rust/core/preprocessor/processor.rs +41 -0
- package/rust/core/preprocessor/resolver.rs +372 -0
- package/rust/core/shared/duration.rs +8 -0
- package/rust/core/shared/mod.rs +2 -0
- package/rust/core/shared/value.rs +18 -0
- package/rust/core/store/export.rs +28 -0
- package/rust/core/store/global.rs +39 -0
- package/rust/core/store/import.rs +28 -0
- package/rust/core/store/mod.rs +4 -0
- package/rust/core/store/variable.rs +28 -0
- package/rust/core/utils/mod.rs +2 -0
- package/rust/core/utils/validation.rs +35 -0
- package/rust/lib.rs +0 -1
- package/rust/main.rs +17 -19
- package/rust/utils/logger.rs +69 -34
- package/rust/utils/mod.rs +3 -5
- package/templates/minimal/.devalang +1 -1
- package/templates/welcome/.devalang +1 -1
- package/rust/audio/mod.rs +0 -1
- package/rust/core/lexer/bracket.rs +0 -41
- package/rust/core/lexer/driver.rs +0 -286
- package/rust/core/lexer/quote.rs +0 -61
- package/rust/core/parser/at.rs +0 -142
- package/rust/core/parser/bank.rs +0 -42
- package/rust/core/parser/dot.rs +0 -137
- package/rust/core/parser/identifer.rs +0 -91
- package/rust/core/parser/loop_.rs +0 -62
- package/rust/core/parser/tempo.rs +0 -42
- package/rust/core/parser/variable.rs +0 -129
- package/rust/core/preprocessor/dependencies.rs +0 -54
- package/rust/core/preprocessor/resolver/at.rs +0 -24
- package/rust/core/preprocessor/resolver/bank.rs +0 -59
- package/rust/core/preprocessor/resolver/loop_.rs +0 -82
- package/rust/core/preprocessor/resolver/mod.rs +0 -113
- package/rust/core/preprocessor/resolver/tempo.rs +0 -70
- package/rust/core/preprocessor/resolver/trigger.rs +0 -176
- package/rust/core/types/cli.rs +0 -182
- package/rust/core/types/mod.rs +0 -8
- package/rust/core/types/module.rs +0 -41
- package/rust/core/types/parser.rs +0 -73
- package/rust/core/types/statement.rs +0 -105
- package/rust/core/types/store.rs +0 -116
- package/rust/core/types/token.rs +0 -83
- package/rust/core/types/variable.rs +0 -32
- package/rust/runner/executer.rs +0 -44
- package/rust/runner/mod.rs +0 -1
- /package/rust/{utils → core/utils}/path.rs +0 -0
- /package/rust/utils/{loader.rs → spinner.rs} +0 -0
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
use std::{ collections::{ HashSet, VecDeque }, fs };
|
|
2
|
-
|
|
3
|
-
pub fn collect_dependencies_recursively(entry_file: &str) -> Vec<String> {
|
|
4
|
-
let mut queue = VecDeque::new();
|
|
5
|
-
let mut loaded = HashSet::new();
|
|
6
|
-
|
|
7
|
-
queue.push_back(entry_file.to_string());
|
|
8
|
-
|
|
9
|
-
while let Some(file_ref) = queue.pop_front() {
|
|
10
|
-
if loaded.contains(&file_ref) {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let deps = get_direct_dependencies(&file_ref);
|
|
15
|
-
for dep in deps {
|
|
16
|
-
queue.push_back(dep.clone());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
loaded.insert(file_ref);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
loaded.into_iter().collect()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
fn get_direct_dependencies(file: &str) -> Vec<String> {
|
|
26
|
-
let content = match fs::read_to_string(file) {
|
|
27
|
-
Ok(c) => c,
|
|
28
|
-
Err(_) => {
|
|
29
|
-
eprintln!("⚠️ Unable to read file: {}", file);
|
|
30
|
-
return vec![];
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
let mut deps = Vec::new();
|
|
35
|
-
|
|
36
|
-
for line in content.lines() {
|
|
37
|
-
let line = line.trim();
|
|
38
|
-
|
|
39
|
-
if line.starts_with("@import") {
|
|
40
|
-
if let Some(from_index) = line.find("from") {
|
|
41
|
-
let after_from = line[from_index + 4..].trim();
|
|
42
|
-
if after_from.starts_with('"') || after_from.starts_with('\'') {
|
|
43
|
-
let delimiter = after_from.chars().next().unwrap();
|
|
44
|
-
if let Some(end_quote) = after_from[1..].find(delimiter) {
|
|
45
|
-
let path = &after_from[1..=end_quote];
|
|
46
|
-
deps.push(path.to_string());
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
deps
|
|
54
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
use crate::core::types::{
|
|
2
|
-
module::Module,
|
|
3
|
-
statement::{ Statement, StatementResolved, StatementResolvedValue },
|
|
4
|
-
variable::VariableValue,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
pub fn resolve_load_statement(
|
|
8
|
-
stmt: &Statement,
|
|
9
|
-
source: &str,
|
|
10
|
-
alias: &str,
|
|
11
|
-
module: &mut Module
|
|
12
|
-
) -> StatementResolved {
|
|
13
|
-
let source_string = source.to_string();
|
|
14
|
-
|
|
15
|
-
module.set_variable(alias.to_string(), VariableValue::Sample(source_string.clone()));
|
|
16
|
-
|
|
17
|
-
StatementResolved {
|
|
18
|
-
kind: stmt.kind.clone(),
|
|
19
|
-
value: StatementResolvedValue::Null,
|
|
20
|
-
indent: stmt.indent,
|
|
21
|
-
line: stmt.line,
|
|
22
|
-
column: stmt.column,
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
use crate::core::{parser::parse_with_resolving_with_module, types::{
|
|
2
|
-
module::Module,
|
|
3
|
-
statement::{ Statement, StatementKind, StatementResolved, StatementResolvedValue },
|
|
4
|
-
variable::VariableValue,
|
|
5
|
-
}};
|
|
6
|
-
|
|
7
|
-
pub fn resolve_bank_statement(stmt: &Statement, module: &Module) -> StatementResolved {
|
|
8
|
-
match &stmt.value {
|
|
9
|
-
VariableValue::Text(name) => {
|
|
10
|
-
if
|
|
11
|
-
let Some(value) = module.import_table.imports
|
|
12
|
-
.get(name)
|
|
13
|
-
.or_else(|| module.variable_table.variables.get(name))
|
|
14
|
-
{
|
|
15
|
-
let statement_value: StatementResolvedValue = match value {
|
|
16
|
-
VariableValue::Array(arr) => {
|
|
17
|
-
StatementResolvedValue::Array(
|
|
18
|
-
parse_with_resolving_with_module(arr.clone(), module)
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
VariableValue::Text(text) => StatementResolvedValue::String(text.clone()),
|
|
22
|
-
VariableValue::Number(num) => StatementResolvedValue::Number(*num),
|
|
23
|
-
VariableValue::Boolean(b) => StatementResolvedValue::Boolean(*b),
|
|
24
|
-
_ => {
|
|
25
|
-
eprintln!("⚠️ Unsupported variable type for Bank: {:?}", value);
|
|
26
|
-
StatementResolvedValue::Unknown
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
StatementResolved {
|
|
31
|
-
kind: StatementKind::Bank,
|
|
32
|
-
value: statement_value,
|
|
33
|
-
indent: stmt.indent,
|
|
34
|
-
line: stmt.line,
|
|
35
|
-
column: stmt.column,
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
eprintln!("⚠️ Bank variable '{}' not found", name);
|
|
39
|
-
StatementResolved {
|
|
40
|
-
kind: StatementKind::Bank,
|
|
41
|
-
value: StatementResolvedValue::Unknown,
|
|
42
|
-
indent: stmt.indent,
|
|
43
|
-
line: stmt.line,
|
|
44
|
-
column: stmt.column,
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
_ => {
|
|
49
|
-
eprintln!("⚠️ Invalid value type for Bank statement: {:?}", stmt.value);
|
|
50
|
-
StatementResolved {
|
|
51
|
-
kind: StatementKind::Bank,
|
|
52
|
-
value: StatementResolvedValue::Unknown,
|
|
53
|
-
indent: stmt.indent,
|
|
54
|
-
line: stmt.line,
|
|
55
|
-
column: stmt.column,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
use crate::core::{
|
|
2
|
-
parser::parse_without_resolving_with_module,
|
|
3
|
-
preprocessor::resolver::resolve_statement,
|
|
4
|
-
types::{
|
|
5
|
-
module::Module,
|
|
6
|
-
statement::{
|
|
7
|
-
Statement,
|
|
8
|
-
StatementIterator,
|
|
9
|
-
StatementKind,
|
|
10
|
-
StatementResolved,
|
|
11
|
-
StatementResolvedValue,
|
|
12
|
-
},
|
|
13
|
-
variable::VariableValue,
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
pub fn resolve_loop_statement(
|
|
18
|
-
loop_statement: &Statement,
|
|
19
|
-
iterator: StatementIterator,
|
|
20
|
-
module: &Module
|
|
21
|
-
) -> StatementResolved {
|
|
22
|
-
let mut resolved_iterator = StatementIterator::Unknown;
|
|
23
|
-
|
|
24
|
-
match iterator.clone() {
|
|
25
|
-
StatementIterator::Identifier(id) => {
|
|
26
|
-
if let Some(value) = module.variable_table.variables.get(&id) {
|
|
27
|
-
match value {
|
|
28
|
-
VariableValue::Array(arr) => {
|
|
29
|
-
resolved_iterator = StatementIterator::Array(
|
|
30
|
-
parse_without_resolving_with_module(arr.clone(), module)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
VariableValue::Number(num) => {
|
|
34
|
-
resolved_iterator = StatementIterator::Number(*num);
|
|
35
|
-
}
|
|
36
|
-
_ => {
|
|
37
|
-
eprintln!("⚠️ Unsupported variable type for loop iterator: {:?}", value);
|
|
38
|
-
resolved_iterator = StatementIterator::Unknown;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
eprintln!("⚠️ Loop iterator variable '{}' not found", id);
|
|
43
|
-
resolved_iterator = StatementIterator::Unknown;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
StatementIterator::Number(num) => {
|
|
47
|
-
resolved_iterator = StatementIterator::Number(num);
|
|
48
|
-
}
|
|
49
|
-
_ => {
|
|
50
|
-
resolved_iterator = iterator.clone();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let mut resolved_body: StatementResolvedValue = StatementResolvedValue::Unknown;
|
|
55
|
-
|
|
56
|
-
match &loop_statement.value {
|
|
57
|
-
VariableValue::Array(arr) => {
|
|
58
|
-
let raw_statements = parse_without_resolving_with_module(arr.clone(), &module.clone());
|
|
59
|
-
|
|
60
|
-
let mut resolved_statements = Vec::new();
|
|
61
|
-
|
|
62
|
-
for raw_stmt in raw_statements {
|
|
63
|
-
let resolved_stmt = resolve_statement(&raw_stmt, &mut module.clone());
|
|
64
|
-
resolved_statements.push(resolved_stmt);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
resolved_body = StatementResolvedValue::Array(resolved_statements);
|
|
68
|
-
}
|
|
69
|
-
_ => {
|
|
70
|
-
resolved_body = StatementResolvedValue::Unknown;
|
|
71
|
-
eprintln!("⚠️ Unsupported value type for loop body: {:?}", loop_statement.value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return StatementResolved {
|
|
76
|
-
kind: StatementKind::Loop { iterator: resolved_iterator },
|
|
77
|
-
value: resolved_body,
|
|
78
|
-
indent: loop_statement.indent,
|
|
79
|
-
line: loop_statement.line,
|
|
80
|
-
column: loop_statement.column,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
pub mod bank;
|
|
2
|
-
pub mod loop_;
|
|
3
|
-
pub mod tempo;
|
|
4
|
-
pub mod trigger;
|
|
5
|
-
pub mod at;
|
|
6
|
-
|
|
7
|
-
use crate::core::{
|
|
8
|
-
preprocessor::resolver::{
|
|
9
|
-
bank::resolve_bank_statement,
|
|
10
|
-
loop_::resolve_loop_statement,
|
|
11
|
-
tempo::resolve_tempo_statement,
|
|
12
|
-
trigger::resolve_trigger_statement,
|
|
13
|
-
at::{ resolve_load_statement },
|
|
14
|
-
},
|
|
15
|
-
types::{
|
|
16
|
-
module::Module,
|
|
17
|
-
parser::Parser,
|
|
18
|
-
statement::{ Statement, StatementKind, StatementResolved, StatementResolvedValue },
|
|
19
|
-
store::{ ExportTable, GlobalStore, ImportTable },
|
|
20
|
-
variable::VariableValue,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
pub fn resolve_exports(statements: &[Statement], parser: &Parser) -> ExportTable {
|
|
25
|
-
let mut export_table = parser.export_table.clone();
|
|
26
|
-
|
|
27
|
-
for stmt in statements {
|
|
28
|
-
if let StatementKind::Export = &stmt.kind {
|
|
29
|
-
if let VariableValue::Array(tokens) = &stmt.value {
|
|
30
|
-
for token in tokens {
|
|
31
|
-
let var_name = &token.lexeme;
|
|
32
|
-
if let Some(value) = parser.variable_table.variables.get(var_name) {
|
|
33
|
-
export_table.add_export(var_name.clone(), value.clone());
|
|
34
|
-
} else {
|
|
35
|
-
eprintln!("⚠️ Variable '{}' not found in scope, export skipped", var_name);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
eprintln!("⚠️ Unexpected value type in export: {:?}", stmt.value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export_table
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
pub fn resolve_imports(module: &mut Module, global_store: &GlobalStore) -> ImportTable {
|
|
48
|
-
let mut import_table = ImportTable::default();
|
|
49
|
-
|
|
50
|
-
for stmt in &module.statements {
|
|
51
|
-
if let StatementKind::Import { names, source } = &stmt.kind {
|
|
52
|
-
if let Some(from_module) = global_store.modules.get(source) {
|
|
53
|
-
for name in names {
|
|
54
|
-
if let Some(value) = from_module.export_table.exports.get(name) {
|
|
55
|
-
module.variable_table.variables.insert(name.clone(), value.clone());
|
|
56
|
-
import_table.add_import(name.clone(), value.clone());
|
|
57
|
-
} else {
|
|
58
|
-
eprintln!("⚠️ '{}' not found in exports of '{}'", name, source);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
eprintln!("⚠️ Module '{}' not found", source);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
import_table
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
pub fn resolve_statement(stmt: &Statement, module: &mut Module) -> StatementResolved {
|
|
71
|
-
match &stmt.kind {
|
|
72
|
-
StatementKind::Loop { iterator } => {
|
|
73
|
-
resolve_loop_statement(stmt, iterator.clone(), module)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
StatementKind::Trigger { entity, duration } => {
|
|
77
|
-
resolve_trigger_statement(stmt, entity.clone(), duration.clone(), module)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
StatementKind::Bank { .. } => { resolve_bank_statement(stmt, module) }
|
|
81
|
-
|
|
82
|
-
StatementKind::Tempo { .. } => { resolve_tempo_statement(stmt, module) }
|
|
83
|
-
|
|
84
|
-
StatementKind::Load { source, alias } => {
|
|
85
|
-
resolve_load_statement(stmt, source, alias, module)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// TODO Handle other statement kinds
|
|
89
|
-
|
|
90
|
-
StatementKind::Error => {
|
|
91
|
-
StatementResolved {
|
|
92
|
-
kind: StatementKind::Error,
|
|
93
|
-
value: match stmt.value {
|
|
94
|
-
VariableValue::Text(ref msg) => StatementResolvedValue::String(msg.clone()),
|
|
95
|
-
_ => StatementResolvedValue::Unknown,
|
|
96
|
-
},
|
|
97
|
-
indent: stmt.indent,
|
|
98
|
-
line: stmt.line,
|
|
99
|
-
column: stmt.column,
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_ => {
|
|
104
|
-
StatementResolved {
|
|
105
|
-
kind: StatementKind::Unknown,
|
|
106
|
-
value: StatementResolvedValue::Unknown,
|
|
107
|
-
indent: stmt.indent,
|
|
108
|
-
line: stmt.line,
|
|
109
|
-
column: stmt.column,
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
use crate::core::types::{module::Module, statement::{Statement, StatementKind, StatementResolved, StatementResolvedValue}, variable::VariableValue};
|
|
2
|
-
|
|
3
|
-
pub fn resolve_tempo_statement(
|
|
4
|
-
tempo_statement: &Statement,
|
|
5
|
-
module: &Module
|
|
6
|
-
) -> StatementResolved {
|
|
7
|
-
match &tempo_statement.value {
|
|
8
|
-
VariableValue::Number(num) => {
|
|
9
|
-
if *num > 0.0 {
|
|
10
|
-
StatementResolved {
|
|
11
|
-
kind: StatementKind::Tempo,
|
|
12
|
-
value: StatementResolvedValue::Number(*num),
|
|
13
|
-
indent: tempo_statement.indent,
|
|
14
|
-
line: tempo_statement.line,
|
|
15
|
-
column: tempo_statement.column,
|
|
16
|
-
}
|
|
17
|
-
} else {
|
|
18
|
-
eprintln!("⚠️ Invalid tempo value: {}", num);
|
|
19
|
-
StatementResolved {
|
|
20
|
-
kind: StatementKind::Tempo,
|
|
21
|
-
value: StatementResolvedValue::Unknown,
|
|
22
|
-
indent: tempo_statement.indent,
|
|
23
|
-
line: tempo_statement.line,
|
|
24
|
-
column: tempo_statement.column,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
VariableValue::Text(text) => {
|
|
29
|
-
if let Some(value) = module.variable_table.variables.get(text) {
|
|
30
|
-
let variable_value: StatementResolvedValue = match value {
|
|
31
|
-
VariableValue::Number(num) if *num > 0.0 => {
|
|
32
|
-
StatementResolvedValue::Number(*num)
|
|
33
|
-
}
|
|
34
|
-
VariableValue::Text(t) => StatementResolvedValue::String(t.clone()),
|
|
35
|
-
_ => {
|
|
36
|
-
eprintln!("⚠️ Unsupported variable type for Tempo: {:?}", value);
|
|
37
|
-
StatementResolvedValue::Unknown
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
StatementResolved {
|
|
42
|
-
kind: StatementKind::Tempo,
|
|
43
|
-
value: variable_value,
|
|
44
|
-
indent: tempo_statement.indent,
|
|
45
|
-
line: tempo_statement.line,
|
|
46
|
-
column: tempo_statement.column,
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
eprintln!("⚠️ Tempo variable '{}' not found", text);
|
|
50
|
-
StatementResolved {
|
|
51
|
-
kind: StatementKind::Tempo,
|
|
52
|
-
value: StatementResolvedValue::Unknown,
|
|
53
|
-
indent: tempo_statement.indent,
|
|
54
|
-
line: tempo_statement.line,
|
|
55
|
-
column: tempo_statement.column,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
_ => {
|
|
60
|
-
eprintln!("⚠️ Invalid value type for Tempo statement: {:?}", tempo_statement.value);
|
|
61
|
-
StatementResolved {
|
|
62
|
-
kind: StatementKind::Tempo,
|
|
63
|
-
value: StatementResolvedValue::Unknown,
|
|
64
|
-
indent: tempo_statement.indent,
|
|
65
|
-
line: tempo_statement.line,
|
|
66
|
-
column: tempo_statement.column,
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use crate::core::{
|
|
4
|
-
parser::parse_with_resolving_with_module,
|
|
5
|
-
types::{
|
|
6
|
-
module::Module,
|
|
7
|
-
statement::{ Statement, StatementKind, StatementResolved, StatementResolvedValue },
|
|
8
|
-
token::{ TokenDuration, TokenParamValue },
|
|
9
|
-
variable::VariableValue,
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
pub fn resolve_trigger_statement(
|
|
14
|
-
stmt: &Statement,
|
|
15
|
-
entity: String,
|
|
16
|
-
duration: TokenDuration,
|
|
17
|
-
module: &Module
|
|
18
|
-
) -> StatementResolved {
|
|
19
|
-
let mut entity_value = VariableValue::Unknown;
|
|
20
|
-
|
|
21
|
-
if let Some(value) = module.variable_table.variables.get(&entity) {
|
|
22
|
-
entity_value = value.clone();
|
|
23
|
-
} else {
|
|
24
|
-
entity_value = VariableValue::Text(entity.clone());
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let duration_raw_value = match duration {
|
|
28
|
-
TokenDuration::Auto => "auto",
|
|
29
|
-
TokenDuration::Infinite => "infinite",
|
|
30
|
-
TokenDuration::Number(n) => &n.to_string(),
|
|
31
|
-
TokenDuration::Identifier(ref id) => id.as_str(),
|
|
32
|
-
_ => "unknown",
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
let duration_variable_value = module.variable_table.variables.get(duration_raw_value);
|
|
36
|
-
let mut parsed_duration_value = TokenDuration::Unknown;
|
|
37
|
-
|
|
38
|
-
if duration_variable_value.is_some() {
|
|
39
|
-
parsed_duration_value = duration_variable_value
|
|
40
|
-
.as_ref()
|
|
41
|
-
.map_or(TokenDuration::Unknown, |value| {
|
|
42
|
-
match value {
|
|
43
|
-
VariableValue::Text(text) => TokenDuration::Identifier(text.clone()),
|
|
44
|
-
VariableValue::Number(num) => TokenDuration::Number(*num),
|
|
45
|
-
VariableValue::Boolean(_) => TokenDuration::Unknown,
|
|
46
|
-
_ => {
|
|
47
|
-
eprintln!("⚠️ Invalid duration type for Trigger: {:?}", value);
|
|
48
|
-
TokenDuration::Unknown
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
} else if let Ok(num) = duration_raw_value.parse::<f32>() {
|
|
53
|
-
parsed_duration_value = TokenDuration::Number(num);
|
|
54
|
-
} else if duration_raw_value == "auto" {
|
|
55
|
-
parsed_duration_value = TokenDuration::Auto;
|
|
56
|
-
} else if duration_raw_value == "infinite" {
|
|
57
|
-
parsed_duration_value = TokenDuration::Infinite;
|
|
58
|
-
} else {
|
|
59
|
-
eprintln!("⚠️ Invalid duration format: {}", duration_raw_value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
match &stmt.value {
|
|
63
|
-
VariableValue::Text(text) => {
|
|
64
|
-
if let Some(value) = module.variable_table.variables.get(text) {
|
|
65
|
-
let parsed_entity_value: StatementResolvedValue = match value {
|
|
66
|
-
VariableValue::Array(arr) => {
|
|
67
|
-
StatementResolvedValue::Array(
|
|
68
|
-
parse_with_resolving_with_module(arr.clone(), module)
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
VariableValue::Map(map) => {
|
|
72
|
-
let mut resolved_map = HashMap::new();
|
|
73
|
-
|
|
74
|
-
for (key, value) in map {
|
|
75
|
-
let resolved_value = match value {
|
|
76
|
-
TokenParamValue::String(text) =>
|
|
77
|
-
StatementResolvedValue::String(text.clone()),
|
|
78
|
-
TokenParamValue::Number(num) =>
|
|
79
|
-
StatementResolvedValue::Number(*num),
|
|
80
|
-
TokenParamValue::Boolean(b) => StatementResolvedValue::Boolean(*b),
|
|
81
|
-
_ => {
|
|
82
|
-
eprintln!(
|
|
83
|
-
"⚠️ Unsupported variable type for Trigger map: {:?}",
|
|
84
|
-
value
|
|
85
|
-
);
|
|
86
|
-
StatementResolvedValue::Unknown
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
resolved_map.insert(key.clone(), resolved_value);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
StatementResolvedValue::Map(resolved_map)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
| VariableValue::Text(_)
|
|
96
|
-
| VariableValue::Number(_)
|
|
97
|
-
| VariableValue::Boolean(_) => {
|
|
98
|
-
StatementResolvedValue::String(text.clone())
|
|
99
|
-
}
|
|
100
|
-
_ => {
|
|
101
|
-
eprintln!("⚠️ Unsupported variable type for Trigger entity: {:?}", value);
|
|
102
|
-
StatementResolvedValue::Unknown
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
StatementResolved {
|
|
107
|
-
kind: StatementKind::Trigger {
|
|
108
|
-
entity: entity.clone(),
|
|
109
|
-
duration: parsed_duration_value,
|
|
110
|
-
},
|
|
111
|
-
value: parsed_entity_value,
|
|
112
|
-
indent: stmt.indent,
|
|
113
|
-
line: stmt.line,
|
|
114
|
-
column: stmt.column,
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
eprintln!("⚠️ Trigger variable '{}' not found", text);
|
|
118
|
-
StatementResolved {
|
|
119
|
-
kind: StatementKind::Trigger {
|
|
120
|
-
entity: entity.clone(),
|
|
121
|
-
duration: parsed_duration_value,
|
|
122
|
-
},
|
|
123
|
-
value: StatementResolvedValue::Unknown,
|
|
124
|
-
indent: stmt.indent,
|
|
125
|
-
line: stmt.line,
|
|
126
|
-
column: stmt.column,
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
VariableValue::Map(map) => {
|
|
131
|
-
let mut resolved_map = HashMap::new();
|
|
132
|
-
|
|
133
|
-
// TODO Handle nested maps and arrays
|
|
134
|
-
|
|
135
|
-
StatementResolved {
|
|
136
|
-
kind: StatementKind::Trigger {
|
|
137
|
-
entity: entity.clone(),
|
|
138
|
-
duration: parsed_duration_value,
|
|
139
|
-
},
|
|
140
|
-
value: StatementResolvedValue::Map(resolved_map),
|
|
141
|
-
indent: stmt.indent,
|
|
142
|
-
line: stmt.line,
|
|
143
|
-
column: stmt.column,
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
VariableValue::Null => {
|
|
147
|
-
StatementResolved {
|
|
148
|
-
kind: StatementKind::Trigger {
|
|
149
|
-
entity: entity.clone(),
|
|
150
|
-
duration: parsed_duration_value,
|
|
151
|
-
},
|
|
152
|
-
value: StatementResolvedValue::Map(HashMap::new()),
|
|
153
|
-
indent: stmt.indent,
|
|
154
|
-
line: stmt.line,
|
|
155
|
-
column: stmt.column,
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// TODO Parse other parameters
|
|
160
|
-
|
|
161
|
-
_ => {
|
|
162
|
-
eprintln!("⚠️ Invalid value type for Trigger statement: {:?}", stmt.value);
|
|
163
|
-
|
|
164
|
-
StatementResolved {
|
|
165
|
-
kind: StatementKind::Trigger {
|
|
166
|
-
entity: entity.clone(),
|
|
167
|
-
duration: parsed_duration_value,
|
|
168
|
-
},
|
|
169
|
-
value: StatementResolvedValue::Unknown,
|
|
170
|
-
indent: stmt.indent,
|
|
171
|
-
line: stmt.line,
|
|
172
|
-
column: stmt.column,
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|