@devaloop/devalang 0.0.1-alpha.1 → 0.0.1-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devalang +9 -0
- package/Cargo.toml +15 -6
- package/README.md +79 -81
- package/docs/CHANGELOG.md +213 -0
- package/docs/ROADMAP.md +11 -8
- package/docs/TODO.md +32 -29
- package/examples/bank.deva +9 -0
- package/examples/condition.deva +20 -0
- package/examples/duration.deva +9 -0
- package/examples/group.deva +12 -0
- package/examples/index.deva +12 -5
- package/examples/loop.deva +16 -0
- package/examples/samples/hat-808.wav +0 -0
- package/examples/synth.deva +14 -0
- package/examples/variables.deva +9 -0
- package/out-tsc/bin/devalang.exe +0 -0
- package/out-tsc/scripts/version/fetch.js +1 -5
- package/package.json +5 -4
- package/project-version.json +3 -3
- package/rust/cli/bank.rs +455 -0
- package/rust/cli/build.rs +114 -28
- package/rust/cli/check.rs +96 -103
- package/rust/cli/driver.rs +280 -0
- package/rust/cli/init.rs +79 -0
- package/rust/cli/install.rs +17 -0
- package/rust/cli/mod.rs +8 -1
- package/rust/cli/play.rs +193 -0
- package/rust/cli/template.rs +57 -0
- package/rust/cli/update.rs +4 -0
- package/rust/common/cdn.rs +11 -0
- package/rust/common/mod.rs +1 -0
- package/rust/config/driver.rs +76 -0
- package/rust/config/loader.rs +110 -0
- package/rust/config/mod.rs +2 -0
- package/rust/core/audio/engine.rs +242 -0
- package/rust/core/audio/evaluator.rs +31 -0
- package/rust/core/audio/interpreter/arrow_call.rs +142 -0
- package/rust/core/audio/interpreter/call.rs +70 -0
- package/rust/core/audio/interpreter/condition.rs +69 -0
- package/rust/core/audio/interpreter/driver.rs +236 -0
- package/rust/core/audio/interpreter/let_.rs +19 -0
- package/rust/core/audio/interpreter/load.rs +18 -0
- package/rust/core/audio/interpreter/loop_.rs +67 -0
- package/rust/core/audio/interpreter/mod.rs +12 -0
- package/rust/core/audio/interpreter/sleep.rs +36 -0
- package/rust/core/audio/interpreter/spawn.rs +84 -0
- package/rust/core/audio/interpreter/tempo.rs +16 -0
- package/rust/core/audio/interpreter/trigger.rs +102 -0
- package/rust/core/audio/loader/mod.rs +1 -0
- package/rust/core/audio/loader/trigger.rs +64 -0
- package/rust/core/audio/mod.rs +6 -0
- package/rust/core/audio/player.rs +54 -0
- package/rust/core/audio/renderer.rs +54 -0
- package/rust/core/builder/mod.rs +70 -27
- package/rust/core/debugger/lexer.rs +27 -0
- package/rust/core/debugger/mod.rs +13 -49
- package/rust/core/debugger/preprocessor.rs +27 -0
- package/rust/core/debugger/store.rs +25 -0
- package/rust/core/error/mod.rs +60 -0
- package/rust/core/lexer/handler/arrow.rs +31 -0
- package/rust/core/lexer/handler/at.rs +21 -0
- package/rust/core/lexer/handler/brace.rs +41 -0
- package/rust/core/lexer/handler/colon.rs +21 -0
- package/rust/core/lexer/handler/comment.rs +30 -0
- package/rust/core/lexer/handler/dot.rs +21 -0
- package/rust/core/lexer/handler/driver.rs +241 -0
- package/rust/core/lexer/handler/identifier.rs +41 -0
- package/rust/core/lexer/handler/indent.rs +52 -0
- package/rust/core/lexer/handler/mod.rs +15 -0
- package/rust/core/lexer/handler/newline.rs +23 -0
- package/rust/core/lexer/handler/number.rs +31 -0
- package/rust/core/lexer/handler/operator.rs +44 -0
- package/rust/core/lexer/handler/slash.rs +21 -0
- package/rust/core/lexer/handler/string.rs +63 -0
- package/rust/core/lexer/mod.rs +37 -319
- package/rust/core/lexer/token.rs +87 -0
- package/rust/core/mod.rs +6 -2
- package/rust/core/parser/driver.rs +339 -0
- package/rust/core/parser/handler/arrow_call.rs +151 -0
- package/rust/core/parser/handler/at.rs +162 -0
- package/rust/core/parser/handler/bank.rs +41 -0
- package/rust/core/parser/handler/condition.rs +74 -0
- package/rust/core/parser/handler/dot.rs +178 -0
- package/rust/core/parser/handler/identifier/call.rs +41 -0
- package/rust/core/parser/handler/identifier/group.rs +75 -0
- package/rust/core/parser/handler/identifier/let_.rs +133 -0
- package/rust/core/parser/handler/identifier/mod.rs +51 -0
- package/rust/core/parser/handler/identifier/sleep.rs +33 -0
- package/rust/core/parser/handler/identifier/spawn.rs +41 -0
- package/rust/core/parser/handler/identifier/synth.rs +65 -0
- package/rust/core/parser/handler/loop_.rs +72 -0
- package/rust/core/parser/handler/mod.rs +8 -0
- package/rust/core/parser/handler/tempo.rs +47 -0
- package/rust/core/parser/mod.rs +3 -200
- package/rust/core/parser/statement.rs +96 -0
- package/rust/core/preprocessor/loader.rs +308 -0
- package/rust/core/preprocessor/mod.rs +2 -24
- package/rust/core/preprocessor/module.rs +42 -56
- package/rust/core/preprocessor/processor.rs +76 -0
- package/rust/core/preprocessor/resolver/bank.rs +41 -51
- package/rust/core/preprocessor/resolver/call.rs +123 -0
- package/rust/core/preprocessor/resolver/condition.rs +92 -0
- package/rust/core/preprocessor/resolver/driver.rs +232 -0
- package/rust/core/preprocessor/resolver/group.rs +61 -0
- package/rust/core/preprocessor/resolver/let_.rs +31 -0
- package/rust/core/preprocessor/resolver/loop_.rs +76 -67
- package/rust/core/preprocessor/resolver/mod.rs +12 -111
- package/rust/core/preprocessor/resolver/spawn.rs +58 -0
- package/rust/core/preprocessor/resolver/synth.rs +50 -0
- package/rust/core/preprocessor/resolver/tempo.rs +40 -61
- package/rust/core/preprocessor/resolver/trigger.rs +90 -154
- package/rust/core/preprocessor/resolver/value.rs +78 -0
- package/rust/core/shared/bank.rs +21 -0
- package/rust/core/shared/duration.rs +9 -0
- package/rust/core/shared/mod.rs +3 -0
- package/rust/core/shared/value.rs +29 -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/path.rs +31 -0
- package/rust/core/utils/validation.rs +37 -0
- package/rust/installer/bank.rs +55 -0
- package/rust/installer/mod.rs +1 -0
- package/rust/lib.rs +162 -1
- package/rust/main.rs +104 -31
- package/rust/utils/file.rs +35 -0
- package/rust/utils/installer.rs +56 -0
- package/rust/utils/logger.rs +108 -34
- package/rust/utils/mod.rs +5 -3
- package/rust/utils/{loader.rs → spinner.rs} +2 -0
- package/rust/utils/watcher.rs +33 -0
- package/templates/minimal/.devalang +5 -0
- package/templates/minimal/README.md +202 -0
- package/templates/minimal/src/index.deva +2 -0
- package/templates/welcome/.devalang +5 -0
- package/templates/welcome/README.md +202 -0
- package/templates/welcome/samples/kick-808.wav +0 -0
- package/templates/welcome/src/index.deva +13 -0
- package/templates/welcome/src/variables.deva +5 -0
- package/typescript/scripts/version/fetch.ts +1 -6
- package/docs/COMMANDS.md +0 -31
- package/docs/SYNTAX.md +0 -148
- package/examples/exported.deva +0 -7
- package/rust/audio/mod.rs +0 -1
- package/rust/cli/new.rs +0 -1
- package/rust/core/parser/at.rs +0 -142
- package/rust/core/parser/bank.rs +0 -42
- package/rust/core/parser/dot.rs +0 -107
- 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/types/cli.rs +0 -160
- package/rust/core/types/mod.rs +0 -7
- 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/path.rs +0 -46
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
|
|
3
|
+
use crate::core::{
|
|
4
|
+
lexer::{ token::TokenKind },
|
|
5
|
+
parser::{ statement::{ Statement, StatementKind }, driver::Parser },
|
|
6
|
+
shared::value::Value,
|
|
7
|
+
store::global::GlobalStore,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
pub fn parse_loop_token(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
|
|
11
|
+
parser.advance(); // consume 'loop'
|
|
12
|
+
let Some(loop_token) = parser.previous_clone() else {
|
|
13
|
+
return Statement::unknown();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let Some(iterator_token) = parser.peek_clone() else {
|
|
17
|
+
return Statement::error(loop_token, "Expected number or identifier after 'loop'".to_string());
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
let iterator_value = match iterator_token.kind {
|
|
21
|
+
TokenKind::Number => {
|
|
22
|
+
let val = iterator_token.lexeme.parse::<f32>().unwrap_or(1.0);
|
|
23
|
+
parser.advance();
|
|
24
|
+
Value::Number(val)
|
|
25
|
+
}
|
|
26
|
+
TokenKind::Identifier => {
|
|
27
|
+
let val = iterator_token.lexeme.clone();
|
|
28
|
+
parser.advance();
|
|
29
|
+
Value::Identifier(val)
|
|
30
|
+
}
|
|
31
|
+
_ => {
|
|
32
|
+
return Statement::error(
|
|
33
|
+
iterator_token.clone(),
|
|
34
|
+
"Expected a number or identifier as loop count".to_string()
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Expect colon
|
|
40
|
+
let Some(colon_token) = parser.peek_clone() else {
|
|
41
|
+
return Statement::error(iterator_token.clone(), "Expected ':' after loop count".to_string());
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if colon_token.kind != TokenKind::Colon {
|
|
45
|
+
let message = format!("Expected ':' after loop count, got {:?}", colon_token.kind);
|
|
46
|
+
return Statement::error(colon_token.clone(), message);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
parser.advance(); // consume ':'
|
|
50
|
+
|
|
51
|
+
// Collect body
|
|
52
|
+
let tokens = parser.collect_until(|t| t.kind == TokenKind::Dedent || t.kind == TokenKind::EOF);
|
|
53
|
+
let loop_body = parser.parse_block(tokens.clone(), global_store);
|
|
54
|
+
|
|
55
|
+
if let Some(token) = parser.peek() {
|
|
56
|
+
if token.kind == TokenKind::Dedent {
|
|
57
|
+
parser.advance();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let mut value_map = HashMap::new();
|
|
62
|
+
value_map.insert("iterator".to_string(), iterator_value);
|
|
63
|
+
value_map.insert("body".to_string(), Value::Block(loop_body.clone()));
|
|
64
|
+
|
|
65
|
+
Statement {
|
|
66
|
+
kind: StatementKind::Loop,
|
|
67
|
+
value: Value::Map(value_map),
|
|
68
|
+
indent: loop_token.indent,
|
|
69
|
+
line: loop_token.line,
|
|
70
|
+
column: loop_token.column,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
use crate::core::{
|
|
2
|
+
lexer::token::TokenKind,
|
|
3
|
+
parser::{ statement::{ Statement, StatementKind }, driver::Parser },
|
|
4
|
+
shared::value::Value,
|
|
5
|
+
store::global::GlobalStore,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
pub fn parse_tempo_token(parser: &mut Parser, _global_store: &mut GlobalStore) -> Statement {
|
|
9
|
+
parser.advance(); // consume 'bpm'
|
|
10
|
+
|
|
11
|
+
let Some(tempo_token) = parser.previous_clone() else {
|
|
12
|
+
return Statement::unknown();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Expect a number or identifier
|
|
16
|
+
let Some(value_token) = parser.peek_clone() else {
|
|
17
|
+
return Statement::error(
|
|
18
|
+
tempo_token,
|
|
19
|
+
"Expected a number or identifier after 'bpm'".to_string()
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let value = match value_token.kind {
|
|
24
|
+
TokenKind::Number => {
|
|
25
|
+
parser.advance();
|
|
26
|
+
Value::Number(value_token.lexeme.parse().unwrap_or(0.0))
|
|
27
|
+
}
|
|
28
|
+
TokenKind::Identifier => {
|
|
29
|
+
parser.advance();
|
|
30
|
+
Value::Identifier(value_token.lexeme.clone())
|
|
31
|
+
}
|
|
32
|
+
_ => {
|
|
33
|
+
return Statement::error(
|
|
34
|
+
value_token.clone(),
|
|
35
|
+
format!("Expected a number or identifier after 'bpm', got {:?}", value_token.kind)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Statement {
|
|
41
|
+
kind: StatementKind::Tempo,
|
|
42
|
+
value,
|
|
43
|
+
indent: tempo_token.indent,
|
|
44
|
+
line: tempo_token.line,
|
|
45
|
+
column: tempo_token.column,
|
|
46
|
+
}
|
|
47
|
+
}
|
package/rust/core/parser/mod.rs
CHANGED
|
@@ -1,201 +1,4 @@
|
|
|
1
|
-
pub mod
|
|
2
|
-
pub mod variable;
|
|
3
|
-
pub mod at;
|
|
4
|
-
pub mod dot;
|
|
5
|
-
pub mod bank;
|
|
6
|
-
pub mod loop_;
|
|
7
|
-
pub mod tempo;
|
|
1
|
+
pub mod driver;
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
parser::{
|
|
12
|
-
at::parse_at,
|
|
13
|
-
bank::parse_bank,
|
|
14
|
-
dot::parse_dot,
|
|
15
|
-
identifer::parse_identifier,
|
|
16
|
-
loop_::parse_loop,
|
|
17
|
-
tempo::parse_tempo,
|
|
18
|
-
},
|
|
19
|
-
preprocessor::resolver::resolve_statement,
|
|
20
|
-
types::{
|
|
21
|
-
module::Module,
|
|
22
|
-
parser::Parser,
|
|
23
|
-
statement::{ Statement, StatementKind, StatementResolved },
|
|
24
|
-
store::{ GlobalStore },
|
|
25
|
-
token::{ Token, TokenKind },
|
|
26
|
-
variable::VariableValue,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
utils::logger::log_message,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
pub fn parse_without_resolving(
|
|
33
|
-
tokens: Vec<Token>,
|
|
34
|
-
mut parser: &mut Parser,
|
|
35
|
-
global_store: &mut GlobalStore
|
|
36
|
-
) -> Vec<Statement> {
|
|
37
|
-
let mut statements = Vec::new();
|
|
38
|
-
|
|
39
|
-
while !parser.is_eof() {
|
|
40
|
-
let mut error_statement = Statement {
|
|
41
|
-
kind: StatementKind::Error,
|
|
42
|
-
value: VariableValue::Null,
|
|
43
|
-
line: parser.peek().map_or(0, |t| t.line),
|
|
44
|
-
column: parser.peek().map_or(0, |t| t.column),
|
|
45
|
-
indent: parser.peek().map_or(0, |t| t.indent),
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
match parser.peek().map(|t| t.kind.clone()) {
|
|
49
|
-
Some(TokenKind::Identifier) => {
|
|
50
|
-
match parse_identifier(&mut parser, global_store) {
|
|
51
|
-
Ok(statement) => statements.push(statement),
|
|
52
|
-
Err(e) => {
|
|
53
|
-
error_statement.value = VariableValue::Text(e.to_string());
|
|
54
|
-
statements.push(error_statement);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
Some(TokenKind::Bank) => {
|
|
60
|
-
match parse_bank(&mut parser, global_store) {
|
|
61
|
-
Ok(statement) => statements.push(statement),
|
|
62
|
-
Err(e) => {
|
|
63
|
-
error_statement.value = VariableValue::Text(e.to_string());
|
|
64
|
-
statements.push(error_statement);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
Some(TokenKind::At) => {
|
|
70
|
-
match parse_at(&mut parser) {
|
|
71
|
-
Ok(statement) => statements.push(statement),
|
|
72
|
-
Err(e) => {
|
|
73
|
-
error_statement.value = VariableValue::Text(e.to_string());
|
|
74
|
-
statements.push(error_statement);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
Some(TokenKind::Dot) => {
|
|
80
|
-
match parse_dot(&mut parser, global_store) {
|
|
81
|
-
Ok(statement) => statements.push(statement),
|
|
82
|
-
Err(e) => {
|
|
83
|
-
error_statement.value = VariableValue::Text(e.to_string());
|
|
84
|
-
statements.push(error_statement);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
Some(TokenKind::Loop) => {
|
|
90
|
-
match parse_loop(&mut parser, global_store) {
|
|
91
|
-
Ok(statement) => statements.push(statement),
|
|
92
|
-
Err(e) => {
|
|
93
|
-
error_statement.value = VariableValue::Text(e.to_string());
|
|
94
|
-
statements.push(error_statement);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Some(TokenKind::Tempo) => {
|
|
100
|
-
match parse_tempo(&mut parser, global_store) {
|
|
101
|
-
Ok(statement) => statements.push(statement),
|
|
102
|
-
Err(e) => {
|
|
103
|
-
error_statement.value = VariableValue::Text(e.to_string());
|
|
104
|
-
statements.push(error_statement);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
| Some(TokenKind::LBrace)
|
|
110
|
-
| Some(TokenKind::RBrace)
|
|
111
|
-
| Some(TokenKind::LBracket)
|
|
112
|
-
| Some(TokenKind::RBracket)
|
|
113
|
-
| Some(TokenKind::DbQuote)
|
|
114
|
-
| Some(TokenKind::Quote)
|
|
115
|
-
| Some(TokenKind::Number)
|
|
116
|
-
| Some(TokenKind::String)
|
|
117
|
-
| Some(TokenKind::Newline)
|
|
118
|
-
| Some(TokenKind::Indent)
|
|
119
|
-
| Some(TokenKind::Dedent) => {
|
|
120
|
-
parser.next();
|
|
121
|
-
}
|
|
122
|
-
Some(_) => {
|
|
123
|
-
parser.next();
|
|
124
|
-
}
|
|
125
|
-
None => {
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
statements
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
pub fn parse_without_resolving_with_module(tokens: Vec<Token>, module: &Module) -> Vec<Statement> {
|
|
135
|
-
let mut parser = Parser::new(tokens.clone());
|
|
136
|
-
|
|
137
|
-
parser.current_module = module.path.clone();
|
|
138
|
-
|
|
139
|
-
let mut global_store = GlobalStore::new();
|
|
140
|
-
global_store.insert_module(module.path.clone(), module.clone());
|
|
141
|
-
|
|
142
|
-
let statements = parse_without_resolving(tokens, &mut parser, &mut global_store);
|
|
143
|
-
|
|
144
|
-
let mut updated_module = module.clone();
|
|
145
|
-
updated_module.statements = statements.clone();
|
|
146
|
-
|
|
147
|
-
let mut errors: Vec<String> = Vec::new();
|
|
148
|
-
|
|
149
|
-
statements.iter().for_each(|statement| {
|
|
150
|
-
match &statement.kind {
|
|
151
|
-
StatementKind::Error => {
|
|
152
|
-
let error_message = match &statement.value {
|
|
153
|
-
VariableValue::Text(text) => text.clone(),
|
|
154
|
-
_ => "Unknown error".to_string(),
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
errors.push(format!(
|
|
158
|
-
"Error in module '{}': {} at line {}, column {}",
|
|
159
|
-
updated_module.path,
|
|
160
|
-
error_message,
|
|
161
|
-
statement.line,
|
|
162
|
-
statement.column
|
|
163
|
-
));
|
|
164
|
-
|
|
165
|
-
log_message(&format!("Error: {}", error_message), "ERROR");
|
|
166
|
-
}
|
|
167
|
-
_ => {}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
if errors.len() > 0 {
|
|
172
|
-
log_message(&format!("{} error(s) found. Parsing stopped.", errors.len()), "INFO");
|
|
173
|
-
|
|
174
|
-
statements
|
|
175
|
-
} else {
|
|
176
|
-
statements
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
pub fn parse_with_resolving_with_module(
|
|
181
|
-
tokens: Vec<Token>,
|
|
182
|
-
module: &Module
|
|
183
|
-
) -> Vec<StatementResolved> {
|
|
184
|
-
let mut parser = Parser::new(tokens.clone());
|
|
185
|
-
|
|
186
|
-
parser.current_module = module.path.clone();
|
|
187
|
-
|
|
188
|
-
let mut global_store = GlobalStore::new();
|
|
189
|
-
global_store.insert_module(module.path.clone(), module.clone());
|
|
190
|
-
|
|
191
|
-
let statements = parse_without_resolving(tokens, &mut parser, &mut global_store);
|
|
192
|
-
|
|
193
|
-
let mut resolved_statements = Vec::new();
|
|
194
|
-
|
|
195
|
-
for statement in statements {
|
|
196
|
-
let resolved_statement = resolve_statement(&statement, &mut module.clone());
|
|
197
|
-
resolved_statements.push(resolved_statement);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return resolved_statements;
|
|
201
|
-
}
|
|
3
|
+
pub mod statement;
|
|
4
|
+
pub mod handler;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
use serde::{ Deserialize, Serialize };
|
|
2
|
+
use crate::core::{ lexer::token::Token, shared::{ duration::Duration, value::Value } };
|
|
3
|
+
|
|
4
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
5
|
+
pub struct Statement {
|
|
6
|
+
pub kind: StatementKind,
|
|
7
|
+
pub value: Value,
|
|
8
|
+
pub indent: usize,
|
|
9
|
+
pub line: usize,
|
|
10
|
+
pub column: usize,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
impl Statement {
|
|
14
|
+
pub fn unknown() -> Self {
|
|
15
|
+
Statement {
|
|
16
|
+
kind: StatementKind::Unknown,
|
|
17
|
+
value: Value::Null,
|
|
18
|
+
indent: 0,
|
|
19
|
+
line: 0,
|
|
20
|
+
column: 0,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fn error(token: Token, message: String) -> Self {
|
|
25
|
+
Statement {
|
|
26
|
+
kind: StatementKind::Error { message },
|
|
27
|
+
value: Value::Null,
|
|
28
|
+
indent: token.indent,
|
|
29
|
+
line: token.line,
|
|
30
|
+
column: token.column,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq)]
|
|
36
|
+
pub enum StatementKind {
|
|
37
|
+
// ───── Core Instructions ─────
|
|
38
|
+
Tempo,
|
|
39
|
+
Bank,
|
|
40
|
+
Load {
|
|
41
|
+
source: String,
|
|
42
|
+
alias: String,
|
|
43
|
+
},
|
|
44
|
+
Let {
|
|
45
|
+
name: String,
|
|
46
|
+
},
|
|
47
|
+
ArrowCall {
|
|
48
|
+
target: String,
|
|
49
|
+
method: String,
|
|
50
|
+
args: Vec<Value>,
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// ───── Instruments ─────
|
|
54
|
+
Synth,
|
|
55
|
+
|
|
56
|
+
// ───── Playback / Scheduling ─────
|
|
57
|
+
Trigger {
|
|
58
|
+
entity: String,
|
|
59
|
+
duration: Duration,
|
|
60
|
+
},
|
|
61
|
+
Sleep,
|
|
62
|
+
Call,
|
|
63
|
+
Spawn,
|
|
64
|
+
Loop,
|
|
65
|
+
|
|
66
|
+
// ───── Structure & Logic ─────
|
|
67
|
+
Group,
|
|
68
|
+
|
|
69
|
+
// ───── Module System ─────
|
|
70
|
+
Include(String),
|
|
71
|
+
Export {
|
|
72
|
+
names: Vec<String>,
|
|
73
|
+
source: String,
|
|
74
|
+
},
|
|
75
|
+
Import {
|
|
76
|
+
names: Vec<String>,
|
|
77
|
+
source: String,
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
// ───── Conditions ─────
|
|
81
|
+
If,
|
|
82
|
+
Else,
|
|
83
|
+
ElseIf,
|
|
84
|
+
|
|
85
|
+
// ───── Internal / Utility ─────
|
|
86
|
+
Comment,
|
|
87
|
+
Indent,
|
|
88
|
+
Dedent,
|
|
89
|
+
NewLine,
|
|
90
|
+
|
|
91
|
+
// ───── Error Handling ─────
|
|
92
|
+
Unknown,
|
|
93
|
+
Error {
|
|
94
|
+
message: String,
|
|
95
|
+
},
|
|
96
|
+
}
|