@devaloop/devalang 0.0.1-beta.2 → 0.0.1-beta.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 +84 -81
- package/README.md +3 -2
- package/docs/CHANGELOG.md +41 -0
- package/docs/ROADMAP.md +3 -3
- package/examples/chain.deva +19 -0
- package/examples/plugin.deva +10 -10
- package/examples/routing.deva +23 -0
- package/out-tsc/bin/project-version.json +6 -0
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +8 -8
- package/out-tsc/scripts/version/copy-to-binary.d.ts +1 -0
- package/out-tsc/scripts/version/copy-to-binary.js +79 -0
- package/package.json +23 -10
- package/project-version.json +3 -3
- package/rust/bindings/Cargo.toml +9 -0
- package/rust/bindings/src/lib.rs +86 -0
- package/rust/cli/addon/commands.rs +35 -0
- package/rust/cli/addon/download.rs +234 -0
- package/rust/cli/addon/install.rs +33 -0
- package/rust/cli/addon/list.rs +224 -0
- package/rust/cli/addon/metadata.rs +124 -0
- package/rust/cli/addon/mod.rs +8 -0
- package/rust/cli/addon/remove.rs +271 -0
- package/rust/cli/addon/update.rs +305 -0
- package/rust/cli/{install/addon.rs → addon/utils.rs} +109 -118
- package/rust/cli/build/commands.rs +153 -153
- package/rust/cli/build/process.rs +165 -165
- package/rust/cli/check/mod.rs +208 -208
- package/rust/cli/discover/commands.rs +275 -253
- package/rust/cli/discover/config.rs +109 -111
- package/rust/cli/discover/fs.rs +19 -19
- package/rust/cli/discover/install.rs +214 -103
- package/rust/cli/discover/metadata.rs +48 -48
- package/rust/cli/discover/mod.rs +5 -5
- package/rust/cli/me/commands.rs +52 -0
- package/rust/cli/me/mod.rs +1 -0
- package/rust/cli/mod.rs +12 -12
- package/rust/cli/parser.rs +30 -69
- package/rust/cli/play/commands.rs +375 -375
- package/rust/cli/play/process.rs +159 -159
- package/rust/core/audio/engine/driver.rs +19 -2
- package/rust/core/audio/engine/export.rs +169 -169
- package/rust/core/audio/engine/mod.rs +56 -56
- package/rust/core/audio/engine/notes/dsp.rs +88 -85
- package/rust/core/audio/engine/notes/mod.rs +53 -44
- package/rust/core/audio/engine/notes/params.rs +294 -294
- package/rust/core/audio/engine/sample/insert.rs +148 -47
- package/rust/core/audio/engine/sample/mod.rs +40 -40
- package/rust/core/audio/engine/sample/padding.rs +170 -170
- package/rust/core/audio/evaluator/condition.rs +61 -61
- package/rust/core/audio/evaluator/numeric.rs +152 -152
- package/rust/core/audio/evaluator/rhs.rs +16 -16
- package/rust/core/audio/evaluator/string_expr.rs +94 -94
- package/rust/core/audio/interpreter/driver.rs +574 -574
- package/rust/core/audio/interpreter/mod.rs +2 -2
- package/rust/core/audio/interpreter/statements/arrow_call/interprete.rs +9 -5
- package/rust/core/audio/interpreter/statements/arrow_call/methods/chord.rs +398 -384
- package/rust/core/audio/interpreter/statements/arrow_call/methods/effects.rs +323 -0
- package/rust/core/audio/interpreter/statements/arrow_call/methods/mod.rs +1 -0
- package/rust/core/audio/interpreter/statements/arrow_call/methods/note.rs +66 -11
- package/rust/core/audio/interpreter/statements/arrow_call/mod.rs +3 -3
- package/rust/core/audio/interpreter/statements/arrow_call/types/arp.rs +192 -192
- package/rust/core/audio/interpreter/statements/arrow_call/types/mod.rs +24 -24
- package/rust/core/audio/interpreter/statements/arrow_call/types/pad.rs +116 -116
- package/rust/core/audio/interpreter/statements/arrow_call/types/pluck.rs +97 -97
- package/rust/core/audio/interpreter/statements/arrow_call/types/sub.rs +100 -100
- package/rust/core/audio/interpreter/statements/automate.rs +16 -16
- package/rust/core/audio/interpreter/statements/call.rs +31 -1
- package/rust/core/audio/interpreter/statements/condition.rs +72 -72
- package/rust/core/audio/interpreter/statements/function.rs +24 -24
- package/rust/core/audio/interpreter/statements/let_.rs +36 -36
- package/rust/core/audio/interpreter/statements/load.rs +17 -17
- package/rust/core/audio/interpreter/statements/loop_.rs +115 -115
- package/rust/core/audio/interpreter/statements/spawn.rs +51 -2
- package/rust/core/audio/interpreter/statements/trigger.rs +242 -239
- package/rust/core/audio/loader/trigger.rs +98 -98
- package/rust/core/audio/player.rs +70 -70
- package/rust/core/audio/special/mod.rs +9 -9
- package/rust/core/builder/mod.rs +129 -129
- package/rust/core/debugger/lexer.rs +27 -27
- package/rust/core/debugger/logs.rs +52 -52
- package/rust/core/debugger/preprocessor.rs +27 -27
- package/rust/core/debugger/store.rs +38 -38
- package/rust/core/lexer/driver.rs +59 -59
- package/rust/core/lexer/handler/arrow.rs +82 -82
- package/rust/core/lexer/handler/at.rs +21 -21
- package/rust/core/lexer/handler/brace.rs +41 -41
- package/rust/core/lexer/handler/colon.rs +21 -21
- package/rust/core/lexer/handler/comment.rs +30 -30
- package/rust/core/lexer/handler/dot.rs +21 -21
- package/rust/core/lexer/handler/driver.rs +337 -337
- package/rust/core/lexer/handler/identifier.rs +47 -47
- package/rust/core/lexer/handler/indent.rs +66 -66
- package/rust/core/lexer/handler/mod.rs +15 -15
- package/rust/core/lexer/handler/newline.rs +23 -23
- package/rust/core/lexer/handler/number.rs +31 -31
- package/rust/core/lexer/handler/operator.rs +46 -46
- package/rust/core/lexer/handler/parenthesis.rs +41 -41
- package/rust/core/lexer/handler/slash.rs +21 -21
- package/rust/core/lexer/handler/string.rs +63 -63
- package/rust/core/lexer/mod.rs +3 -3
- package/rust/core/mod.rs +9 -9
- package/rust/core/parser/driver/block.rs +111 -111
- package/rust/core/parser/driver/cursor.rs +82 -82
- package/rust/core/parser/driver/driver_impl.rs +21 -1
- package/rust/core/parser/driver/mod.rs +6 -6
- package/rust/core/parser/driver/parse_array.rs +120 -120
- package/rust/core/parser/driver/parse_map.rs +247 -223
- package/rust/core/parser/driver/parser.rs +160 -160
- package/rust/core/parser/handler/arrow_call.rs +65 -14
- package/rust/core/parser/handler/identifier/synth.rs +171 -135
- package/rust/core/parser/handler/mod.rs +9 -9
- package/rust/core/parser/handler/pattern.rs +24 -1
- package/rust/core/plugin/loader.rs +137 -137
- package/rust/core/plugin/mod.rs +2 -2
- package/rust/core/plugin/runner/non_wasm.rs +481 -297
- package/rust/core/plugin/runner/wasm32.rs +1 -0
- package/rust/core/preprocessor/loader/inject.rs +313 -278
- package/rust/core/preprocessor/loader/loader_helpers.rs +110 -110
- package/rust/core/preprocessor/loader/mod.rs +235 -235
- package/rust/core/preprocessor/module.rs +55 -55
- package/rust/core/preprocessor/processor/handlers.rs +107 -107
- package/rust/core/preprocessor/resolver/bank.rs +49 -49
- package/rust/core/preprocessor/resolver/call.rs +124 -124
- package/rust/core/preprocessor/resolver/condition.rs +95 -95
- package/rust/core/preprocessor/resolver/driver.rs +324 -324
- package/rust/core/preprocessor/resolver/function.rs +69 -69
- package/rust/core/preprocessor/resolver/group.rs +122 -122
- package/rust/core/preprocessor/resolver/let_.rs +32 -32
- package/rust/core/preprocessor/resolver/loop_.rs +318 -318
- package/rust/core/preprocessor/resolver/mod.rs +16 -16
- package/rust/core/preprocessor/resolver/pattern.rs +95 -83
- package/rust/core/preprocessor/resolver/spawn.rs +99 -99
- package/rust/core/preprocessor/resolver/synth.rs +54 -54
- package/rust/core/preprocessor/resolver/tempo.rs +48 -48
- package/rust/core/preprocessor/resolver/trigger.rs +116 -116
- package/rust/core/preprocessor/resolver/value.rs +176 -176
- package/rust/core/store/global.rs +57 -57
- package/rust/lib.rs +323 -323
- package/rust/macros/Cargo.toml +14 -0
- package/rust/macros/src/lib.rs +52 -0
- package/rust/main.rs +311 -142
- package/rust/types/Cargo.toml +1 -1
- package/rust/types/src/addons.rs +3 -1
- package/rust/types/src/config.rs +1 -3
- package/rust/utils/Cargo.toml +5 -2
- package/rust/utils/src/file.rs +397 -14
- package/rust/utils/src/path.rs +31 -2
- package/rust/utils/src/version.rs +38 -7
- package/rust/web/auth.rs +5 -0
- package/rust/web/forge.rs +5 -0
- package/rust/web/mod.rs +5 -3
- package/typescript/scripts/version/copy-to-binary.ts +82 -0
- package/rust/cli/bank/api.rs +0 -122
- package/rust/cli/bank/commands.rs +0 -306
- package/rust/cli/bank/mod.rs +0 -29
- package/rust/cli/install/bank.rs +0 -72
- package/rust/cli/install/commands.rs +0 -35
- package/rust/cli/install/mod.rs +0 -4
- package/rust/cli/install/plugin.rs +0 -80
|
@@ -1,135 +1,171 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use devalang_types::Value;
|
|
4
|
-
|
|
5
|
-
use crate::core::{
|
|
6
|
-
lexer::token::Token,
|
|
7
|
-
parser::{
|
|
8
|
-
driver::parser::Parser,
|
|
9
|
-
handler::dot::parse_dot_token,
|
|
10
|
-
statement::{Statement, StatementKind},
|
|
11
|
-
},
|
|
12
|
-
store::global::GlobalStore,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
pub fn parse_synth_token(
|
|
16
|
-
parser: &mut Parser,
|
|
17
|
-
_current_token: Token,
|
|
18
|
-
_global_store: &mut GlobalStore,
|
|
19
|
-
) -> Statement {
|
|
20
|
-
parser.advance(); // consume 'synth'
|
|
21
|
-
|
|
22
|
-
let Some(synth_token) = parser.previous_clone() else {
|
|
23
|
-
return Statement::unknown();
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Expect a provider
|
|
27
|
-
// Also accept a dot-led entity by delegating to the dot parser (e.g. .module.export)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
&& first_token.kind != crate::core::lexer::token::TokenKind::
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| crate::core::lexer::token::TokenKind::
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
|
|
3
|
+
use devalang_types::Value;
|
|
4
|
+
|
|
5
|
+
use crate::core::{
|
|
6
|
+
lexer::token::Token,
|
|
7
|
+
parser::{
|
|
8
|
+
driver::parser::Parser,
|
|
9
|
+
handler::dot::parse_dot_token,
|
|
10
|
+
statement::{Statement, StatementKind},
|
|
11
|
+
},
|
|
12
|
+
store::global::GlobalStore,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
pub fn parse_synth_token(
|
|
16
|
+
parser: &mut Parser,
|
|
17
|
+
_current_token: Token,
|
|
18
|
+
_global_store: &mut GlobalStore,
|
|
19
|
+
) -> Statement {
|
|
20
|
+
parser.advance(); // consume 'synth'
|
|
21
|
+
|
|
22
|
+
let Some(synth_token) = parser.previous_clone() else {
|
|
23
|
+
return Statement::unknown();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Expect a provider or waveform identifier (can be dotted: alias.synth)
|
|
27
|
+
// Also accept a dot-led entity by delegating to the dot parser (e.g. .module.export)
|
|
28
|
+
// Support optional explicit waveform after a dotted provider: `synth alias.synth saw {}`
|
|
29
|
+
let synth_waveform = if let Some(first_token) = parser.peek_clone() {
|
|
30
|
+
use crate::core::lexer::token::TokenKind;
|
|
31
|
+
|
|
32
|
+
if first_token.kind == TokenKind::Dot {
|
|
33
|
+
// Parse dot-entity and extract its entity string
|
|
34
|
+
let dot_stmt = parse_dot_token(parser, _global_store);
|
|
35
|
+
// Extract entity if the parsed statement is a Trigger
|
|
36
|
+
match dot_stmt.kind {
|
|
37
|
+
StatementKind::Trigger { entity, .. } => entity,
|
|
38
|
+
_ => String::new(),
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if first_token.kind != crate::core::lexer::token::TokenKind::Identifier
|
|
42
|
+
&& first_token.kind != crate::core::lexer::token::TokenKind::Number
|
|
43
|
+
&& first_token.kind != crate::core::lexer::token::TokenKind::Synth
|
|
44
|
+
{
|
|
45
|
+
return crate::core::parser::statement::error_from_token(
|
|
46
|
+
first_token.clone(),
|
|
47
|
+
"Expected identifier after 'synth'".to_string(),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Collect dotted parts on the same line
|
|
52
|
+
let mut parts: Vec<String> = Vec::new();
|
|
53
|
+
let current_line = first_token.line;
|
|
54
|
+
loop {
|
|
55
|
+
let Some(tok) = parser.peek_clone() else {
|
|
56
|
+
break;
|
|
57
|
+
};
|
|
58
|
+
if tok.line != current_line {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
match tok.kind {
|
|
62
|
+
crate::core::lexer::token::TokenKind::Identifier
|
|
63
|
+
| crate::core::lexer::token::TokenKind::Number
|
|
64
|
+
| crate::core::lexer::token::TokenKind::Synth => {
|
|
65
|
+
parts.push(tok.lexeme.clone());
|
|
66
|
+
parser.advance();
|
|
67
|
+
// If next isn't a dot on same line, stop
|
|
68
|
+
if let Some(next) = parser.peek_clone() {
|
|
69
|
+
if !(next.line == current_line
|
|
70
|
+
&& next.kind == crate::core::lexer::token::TokenKind::Dot)
|
|
71
|
+
{
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
crate::core::lexer::token::TokenKind::Dot => {
|
|
79
|
+
parser.advance();
|
|
80
|
+
}
|
|
81
|
+
_ => break,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The joined parts form either:
|
|
86
|
+
// - a simple waveform name (e.g. "sine")
|
|
87
|
+
// - a provider entity (e.g. "author.synth")
|
|
88
|
+
let first = parts.join(".");
|
|
89
|
+
|
|
90
|
+
// If this looks like a dotted provider, try to consume an optional explicit
|
|
91
|
+
// waveform identifier on the same line (e.g. `synth author.synth saw`). If none
|
|
92
|
+
// is provided, fall back to the original behaviour (use the joined string as
|
|
93
|
+
// the waveform identifier) to remain backward-compatible.
|
|
94
|
+
if first.contains('.') {
|
|
95
|
+
// peek next token on same line
|
|
96
|
+
if let Some(next_tok) = parser.peek_clone() {
|
|
97
|
+
if next_tok.line == current_line
|
|
98
|
+
&& matches!(
|
|
99
|
+
next_tok.kind,
|
|
100
|
+
crate::core::lexer::token::TokenKind::Identifier
|
|
101
|
+
| crate::core::lexer::token::TokenKind::Number
|
|
102
|
+
| crate::core::lexer::token::TokenKind::Synth
|
|
103
|
+
)
|
|
104
|
+
{
|
|
105
|
+
// consume waveform token
|
|
106
|
+
let waveform = next_tok.lexeme.clone();
|
|
107
|
+
parser.advance();
|
|
108
|
+
// store as "provider.waveform" style? keep only waveform for compatibility
|
|
109
|
+
waveform
|
|
110
|
+
} else {
|
|
111
|
+
// no explicit waveform -> use the provider string (old behaviour)
|
|
112
|
+
first
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
first
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
// simple waveform name
|
|
119
|
+
first
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
return crate::core::parser::statement::error_from_token(
|
|
124
|
+
synth_token,
|
|
125
|
+
"Expected identifier after 'synth'".to_string(),
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Skip formatting before optional parameters map
|
|
130
|
+
while parser.check_token(crate::core::lexer::token::TokenKind::Newline)
|
|
131
|
+
|| parser.check_token(crate::core::lexer::token::TokenKind::Indent)
|
|
132
|
+
|| parser.check_token(crate::core::lexer::token::TokenKind::Dedent)
|
|
133
|
+
|| parser.check_token(crate::core::lexer::token::TokenKind::Whitespace)
|
|
134
|
+
{
|
|
135
|
+
parser.advance();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Expect synth optional parameters map
|
|
139
|
+
let parameters = if let Some(params) = parser.parse_map_value() {
|
|
140
|
+
// If parameters are provided, we expect a map
|
|
141
|
+
if let Value::Map(map) = params {
|
|
142
|
+
map
|
|
143
|
+
} else {
|
|
144
|
+
return crate::core::parser::statement::error_from_token(
|
|
145
|
+
synth_token,
|
|
146
|
+
"Expected a map for synth parameters".to_string(),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
// If no parameters are provided, we can still create the statement with an empty map
|
|
151
|
+
HashMap::new()
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
Statement {
|
|
155
|
+
kind: StatementKind::Synth,
|
|
156
|
+
value: Value::Map(HashMap::from([
|
|
157
|
+
("entity".to_string(), Value::String("synth".to_string())),
|
|
158
|
+
(
|
|
159
|
+
"value".to_string(),
|
|
160
|
+
Value::Map(HashMap::from([
|
|
161
|
+
// Store waveform as identifier to allow resolution from variables/exports
|
|
162
|
+
("waveform".to_string(), Value::Identifier(synth_waveform)),
|
|
163
|
+
("parameters".to_string(), Value::Map(parameters)),
|
|
164
|
+
])),
|
|
165
|
+
),
|
|
166
|
+
])),
|
|
167
|
+
indent: synth_token.indent,
|
|
168
|
+
line: synth_token.line,
|
|
169
|
+
column: synth_token.column,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
pub mod arrow_call;
|
|
2
|
-
pub mod at;
|
|
3
|
-
pub mod bank;
|
|
4
|
-
pub mod condition;
|
|
5
|
-
pub mod dot;
|
|
6
|
-
pub mod identifier;
|
|
7
|
-
pub mod loop_;
|
|
8
|
-
pub mod pattern;
|
|
9
|
-
pub mod tempo;
|
|
1
|
+
pub mod arrow_call;
|
|
2
|
+
pub mod at;
|
|
3
|
+
pub mod bank;
|
|
4
|
+
pub mod condition;
|
|
5
|
+
pub mod dot;
|
|
6
|
+
pub mod identifier;
|
|
7
|
+
pub mod loop_;
|
|
8
|
+
pub mod pattern;
|
|
9
|
+
pub mod tempo;
|
|
@@ -52,6 +52,12 @@ pub fn parse_pattern_token(parser: &mut Parser, _global_store: &mut GlobalStore)
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// optional inline options map like { swing: 0.08 }
|
|
56
|
+
let mut options: Option<Value> = None;
|
|
57
|
+
if parser.check_token(TokenKind::LBrace) {
|
|
58
|
+
options = parser.parse_map_value();
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
// optional '=' and pattern string
|
|
56
62
|
let mut value: Value = Value::Null;
|
|
57
63
|
if parser.peek_is("=") {
|
|
@@ -59,9 +65,26 @@ pub fn parse_pattern_token(parser: &mut Parser, _global_store: &mut GlobalStore)
|
|
|
59
65
|
if let Some(tok3) = parser.peek_clone() {
|
|
60
66
|
if tok3.kind == TokenKind::String {
|
|
61
67
|
parser.advance();
|
|
62
|
-
|
|
68
|
+
let pat_str = Value::String(tok3.lexeme.clone());
|
|
69
|
+
if let Some(opts) = options {
|
|
70
|
+
// merge options map with pattern key
|
|
71
|
+
if let Value::Map(mut m) = opts {
|
|
72
|
+
m.insert("pattern".to_string(), pat_str);
|
|
73
|
+
value = Value::Map(m);
|
|
74
|
+
} else {
|
|
75
|
+
// unexpected, wrap into a map
|
|
76
|
+
let mut m = std::collections::HashMap::new();
|
|
77
|
+
m.insert("pattern".to_string(), pat_str);
|
|
78
|
+
value = Value::Map(m);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
value = Value::String(tok3.lexeme.clone());
|
|
82
|
+
}
|
|
63
83
|
}
|
|
64
84
|
}
|
|
85
|
+
} else if let Some(opts) = options {
|
|
86
|
+
// only options were provided, store them as the value
|
|
87
|
+
value = opts;
|
|
65
88
|
}
|
|
66
89
|
|
|
67
90
|
Statement {
|
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
use devalang_types::{plugin::PluginExport, plugin::PluginInfo as SharedPluginInfo};
|
|
2
|
-
use devalang_utils::path as path_utils;
|
|
3
|
-
use serde::Deserialize;
|
|
4
|
-
use toml::Value as TomlValue;
|
|
5
|
-
|
|
6
|
-
#[derive(Debug, Deserialize, Clone)]
|
|
7
|
-
struct LocalExportEntry {
|
|
8
|
-
pub name: String,
|
|
9
|
-
|
|
10
|
-
pub kind: String,
|
|
11
|
-
#[serde(default)]
|
|
12
|
-
pub default: Option<TomlValue>,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
#[derive(Debug, Deserialize, Clone)]
|
|
16
|
-
struct LocalPluginFile {
|
|
17
|
-
pub plugin: LocalPluginInfo,
|
|
18
|
-
#[serde(default)]
|
|
19
|
-
pub
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
#[derive(Debug, Deserialize, Clone)]
|
|
23
|
-
struct LocalPluginInfo {
|
|
24
|
-
pub name: String,
|
|
25
|
-
pub version: Option<String>,
|
|
26
|
-
pub description: Option<String>,
|
|
27
|
-
pub author: Option<String>,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pub fn load_plugin(author: &str, name: &str) -> Result<(SharedPluginInfo, Vec<u8>), String> {
|
|
31
|
-
let root = path_utils::get_deva_dir()?;
|
|
32
|
-
let plugin_dir_preferred = root.join("plugins").join(format!("{}.{}", author, name));
|
|
33
|
-
let toml_path_preferred = plugin_dir_preferred.join("plugin.toml");
|
|
34
|
-
let wasm_path_preferred_bg = plugin_dir_preferred.join(format!("{}_bg.wasm", name));
|
|
35
|
-
let wasm_path_preferred_plain = plugin_dir_preferred.join(format!("{}.wasm", name));
|
|
36
|
-
|
|
37
|
-
// Legacy layout (fallback): ./.deva/plugin/<author>/<name>/
|
|
38
|
-
let plugin_dir_fallback = root.join("plugins").join(author).join(name);
|
|
39
|
-
let toml_path_fallback = plugin_dir_fallback.join("plugin.toml");
|
|
40
|
-
let wasm_path_fallback_bg = plugin_dir_fallback.join(format!("{}_bg.wasm", name));
|
|
41
|
-
let wasm_path_fallback_plain = plugin_dir_fallback.join(format!("{}.wasm", name));
|
|
42
|
-
|
|
43
|
-
// Resolve actual paths to use
|
|
44
|
-
let (toml_path, wasm_path) = if toml_path_preferred.exists() && wasm_path_preferred_bg.exists()
|
|
45
|
-
{
|
|
46
|
-
(toml_path_preferred, wasm_path_preferred_bg)
|
|
47
|
-
} else if toml_path_preferred.exists() && wasm_path_preferred_plain.exists() {
|
|
48
|
-
(toml_path_preferred, wasm_path_preferred_plain)
|
|
49
|
-
} else if toml_path_fallback.exists() && wasm_path_fallback_bg.exists() {
|
|
50
|
-
(toml_path_fallback, wasm_path_fallback_bg)
|
|
51
|
-
} else if toml_path_fallback.exists() && wasm_path_fallback_plain.exists() {
|
|
52
|
-
(toml_path_fallback, wasm_path_fallback_plain)
|
|
53
|
-
} else {
|
|
54
|
-
// If either file is missing in both layouts, produce specific errors for missing files in preferred layout
|
|
55
|
-
if !toml_path_preferred.exists() {
|
|
56
|
-
return Err(format!(
|
|
57
|
-
"❌ Plugin file not found: {}",
|
|
58
|
-
toml_path_preferred.display()
|
|
59
|
-
));
|
|
60
|
-
}
|
|
61
|
-
if !wasm_path_preferred_bg.exists() && !wasm_path_preferred_plain.exists() {
|
|
62
|
-
return Err(format!(
|
|
63
|
-
"❌ Plugin wasm not found: '{}' or '{}'",
|
|
64
|
-
wasm_path_preferred_bg.display(),
|
|
65
|
-
wasm_path_preferred_plain.display()
|
|
66
|
-
));
|
|
67
|
-
}
|
|
68
|
-
unreachable!();
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
let toml_content = std::fs::read_to_string(&toml_path)
|
|
72
|
-
.map_err(|e| format!("Failed to read '{}': {}", toml_path.display(), e))?;
|
|
73
|
-
let plugin_file: LocalPluginFile = toml::from_str(&toml_content)
|
|
74
|
-
.map_err(|e| format!("Failed to parse '{}': {}", toml_path.display(), e))?;
|
|
75
|
-
|
|
76
|
-
let wasm_bytes = std::fs::read(&wasm_path)
|
|
77
|
-
.map_err(|e| format!("Failed to read '{}': {}", wasm_path.display(), e))?;
|
|
78
|
-
|
|
79
|
-
// Map local parsed plugin info to shared PluginInfo
|
|
80
|
-
let mut exports: Vec<PluginExport> = Vec::new();
|
|
81
|
-
for e in plugin_file.
|
|
82
|
-
exports.push(PluginExport {
|
|
83
|
-
name: e.name.clone(),
|
|
84
|
-
kind: e.kind.clone(),
|
|
85
|
-
default: e.default.clone(),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let info = SharedPluginInfo {
|
|
90
|
-
author: plugin_file
|
|
91
|
-
.plugin
|
|
92
|
-
.author
|
|
93
|
-
.unwrap_or_else(|| author.to_string()),
|
|
94
|
-
name: plugin_file.plugin.name.clone(),
|
|
95
|
-
version: plugin_file.plugin.version.clone(),
|
|
96
|
-
description: plugin_file.plugin.description.clone(),
|
|
97
|
-
exports,
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
Ok((info, wasm_bytes))
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/// Load a plugin from dot notation: "author.name"
|
|
104
|
-
pub fn load_plugin_from_dot(dot: &str) -> Result<(SharedPluginInfo, Vec<u8>), String> {
|
|
105
|
-
let mut parts = dot.split('.');
|
|
106
|
-
let author = parts
|
|
107
|
-
.next()
|
|
108
|
-
.ok_or_else(|| "Invalid plugin name, missing author".to_string())?;
|
|
109
|
-
let name = parts
|
|
110
|
-
.next()
|
|
111
|
-
.ok_or_else(|| "Invalid plugin name, missing name".to_string())?;
|
|
112
|
-
if parts.next().is_some() {
|
|
113
|
-
return Err("Invalid plugin name format, expected <author>.<name>".into());
|
|
114
|
-
}
|
|
115
|
-
load_plugin(author, name)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
pub fn load_plugin_from_uri(uri: &str) -> Result<(SharedPluginInfo, Vec<u8>), String> {
|
|
119
|
-
if !uri.starts_with("devalang://plugin/") {
|
|
120
|
-
return Err("Invalid plugin URI".into());
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Expect format: devalang://plugin/author.name
|
|
124
|
-
let payload = uri.trim_start_matches("devalang://plugin/");
|
|
125
|
-
let mut parts = payload.split('.');
|
|
126
|
-
let author = parts
|
|
127
|
-
.next()
|
|
128
|
-
.ok_or_else(|| "Invalid plugin URI, missing author".to_string())?;
|
|
129
|
-
let name = parts
|
|
130
|
-
.next()
|
|
131
|
-
.ok_or_else(|| "Invalid plugin URI, missing name".to_string())?;
|
|
132
|
-
if parts.next().is_some() {
|
|
133
|
-
return Err("Invalid plugin URI format, expected devalang://plugin/<author>.<name>".into());
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
load_plugin(author, name)
|
|
137
|
-
}
|
|
1
|
+
use devalang_types::{plugin::PluginExport, plugin::PluginInfo as SharedPluginInfo};
|
|
2
|
+
use devalang_utils::path as path_utils;
|
|
3
|
+
use serde::Deserialize;
|
|
4
|
+
use toml::Value as TomlValue;
|
|
5
|
+
|
|
6
|
+
#[derive(Debug, Deserialize, Clone)]
|
|
7
|
+
struct LocalExportEntry {
|
|
8
|
+
pub name: String,
|
|
9
|
+
// Local plugin.toml uses 'kind' to describe export type (e.g. "func", "number")
|
|
10
|
+
pub kind: String,
|
|
11
|
+
#[serde(default)]
|
|
12
|
+
pub default: Option<TomlValue>,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[derive(Debug, Deserialize, Clone)]
|
|
16
|
+
struct LocalPluginFile {
|
|
17
|
+
pub plugin: LocalPluginInfo,
|
|
18
|
+
#[serde(rename = "exports", default)]
|
|
19
|
+
pub exports: Vec<LocalExportEntry>,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[derive(Debug, Deserialize, Clone)]
|
|
23
|
+
struct LocalPluginInfo {
|
|
24
|
+
pub name: String,
|
|
25
|
+
pub version: Option<String>,
|
|
26
|
+
pub description: Option<String>,
|
|
27
|
+
pub author: Option<String>,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub fn load_plugin(author: &str, name: &str) -> Result<(SharedPluginInfo, Vec<u8>), String> {
|
|
31
|
+
let root = path_utils::get_deva_dir()?;
|
|
32
|
+
let plugin_dir_preferred = root.join("plugins").join(format!("{}.{}", author, name));
|
|
33
|
+
let toml_path_preferred = plugin_dir_preferred.join("plugin.toml");
|
|
34
|
+
let wasm_path_preferred_bg = plugin_dir_preferred.join(format!("{}_bg.wasm", name));
|
|
35
|
+
let wasm_path_preferred_plain = plugin_dir_preferred.join(format!("{}.wasm", name));
|
|
36
|
+
|
|
37
|
+
// Legacy layout (fallback): ./.deva/plugin/<author>/<name>/
|
|
38
|
+
let plugin_dir_fallback = root.join("plugins").join(author).join(name);
|
|
39
|
+
let toml_path_fallback = plugin_dir_fallback.join("plugin.toml");
|
|
40
|
+
let wasm_path_fallback_bg = plugin_dir_fallback.join(format!("{}_bg.wasm", name));
|
|
41
|
+
let wasm_path_fallback_plain = plugin_dir_fallback.join(format!("{}.wasm", name));
|
|
42
|
+
|
|
43
|
+
// Resolve actual paths to use
|
|
44
|
+
let (toml_path, wasm_path) = if toml_path_preferred.exists() && wasm_path_preferred_bg.exists()
|
|
45
|
+
{
|
|
46
|
+
(toml_path_preferred, wasm_path_preferred_bg)
|
|
47
|
+
} else if toml_path_preferred.exists() && wasm_path_preferred_plain.exists() {
|
|
48
|
+
(toml_path_preferred, wasm_path_preferred_plain)
|
|
49
|
+
} else if toml_path_fallback.exists() && wasm_path_fallback_bg.exists() {
|
|
50
|
+
(toml_path_fallback, wasm_path_fallback_bg)
|
|
51
|
+
} else if toml_path_fallback.exists() && wasm_path_fallback_plain.exists() {
|
|
52
|
+
(toml_path_fallback, wasm_path_fallback_plain)
|
|
53
|
+
} else {
|
|
54
|
+
// If either file is missing in both layouts, produce specific errors for missing files in preferred layout
|
|
55
|
+
if !toml_path_preferred.exists() {
|
|
56
|
+
return Err(format!(
|
|
57
|
+
"❌ Plugin file not found: {}",
|
|
58
|
+
toml_path_preferred.display()
|
|
59
|
+
));
|
|
60
|
+
}
|
|
61
|
+
if !wasm_path_preferred_bg.exists() && !wasm_path_preferred_plain.exists() {
|
|
62
|
+
return Err(format!(
|
|
63
|
+
"❌ Plugin wasm not found: '{}' or '{}'",
|
|
64
|
+
wasm_path_preferred_bg.display(),
|
|
65
|
+
wasm_path_preferred_plain.display()
|
|
66
|
+
));
|
|
67
|
+
}
|
|
68
|
+
unreachable!();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
let toml_content = std::fs::read_to_string(&toml_path)
|
|
72
|
+
.map_err(|e| format!("Failed to read '{}': {}", toml_path.display(), e))?;
|
|
73
|
+
let plugin_file: LocalPluginFile = toml::from_str(&toml_content)
|
|
74
|
+
.map_err(|e| format!("Failed to parse '{}': {}", toml_path.display(), e))?;
|
|
75
|
+
|
|
76
|
+
let wasm_bytes = std::fs::read(&wasm_path)
|
|
77
|
+
.map_err(|e| format!("Failed to read '{}': {}", wasm_path.display(), e))?;
|
|
78
|
+
|
|
79
|
+
// Map local parsed plugin info to shared PluginInfo
|
|
80
|
+
let mut exports: Vec<PluginExport> = Vec::new();
|
|
81
|
+
for e in plugin_file.exports.iter() {
|
|
82
|
+
exports.push(PluginExport {
|
|
83
|
+
name: e.name.clone(),
|
|
84
|
+
kind: e.kind.clone(),
|
|
85
|
+
default: e.default.clone(),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let info = SharedPluginInfo {
|
|
90
|
+
author: plugin_file
|
|
91
|
+
.plugin
|
|
92
|
+
.author
|
|
93
|
+
.unwrap_or_else(|| author.to_string()),
|
|
94
|
+
name: plugin_file.plugin.name.clone(),
|
|
95
|
+
version: plugin_file.plugin.version.clone(),
|
|
96
|
+
description: plugin_file.plugin.description.clone(),
|
|
97
|
+
exports,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Ok((info, wasm_bytes))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Load a plugin from dot notation: "author.name"
|
|
104
|
+
pub fn load_plugin_from_dot(dot: &str) -> Result<(SharedPluginInfo, Vec<u8>), String> {
|
|
105
|
+
let mut parts = dot.split('.');
|
|
106
|
+
let author = parts
|
|
107
|
+
.next()
|
|
108
|
+
.ok_or_else(|| "Invalid plugin name, missing author".to_string())?;
|
|
109
|
+
let name = parts
|
|
110
|
+
.next()
|
|
111
|
+
.ok_or_else(|| "Invalid plugin name, missing name".to_string())?;
|
|
112
|
+
if parts.next().is_some() {
|
|
113
|
+
return Err("Invalid plugin name format, expected <author>.<name>".into());
|
|
114
|
+
}
|
|
115
|
+
load_plugin(author, name)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
pub fn load_plugin_from_uri(uri: &str) -> Result<(SharedPluginInfo, Vec<u8>), String> {
|
|
119
|
+
if !uri.starts_with("devalang://plugin/") {
|
|
120
|
+
return Err("Invalid plugin URI".into());
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Expect format: devalang://plugin/author.name
|
|
124
|
+
let payload = uri.trim_start_matches("devalang://plugin/");
|
|
125
|
+
let mut parts = payload.split('.');
|
|
126
|
+
let author = parts
|
|
127
|
+
.next()
|
|
128
|
+
.ok_or_else(|| "Invalid plugin URI, missing author".to_string())?;
|
|
129
|
+
let name = parts
|
|
130
|
+
.next()
|
|
131
|
+
.ok_or_else(|| "Invalid plugin URI, missing name".to_string())?;
|
|
132
|
+
if parts.next().is_some() {
|
|
133
|
+
return Err("Invalid plugin URI format, expected devalang://plugin/<author>.<name>".into());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
load_plugin(author, name)
|
|
137
|
+
}
|
package/rust/core/plugin/mod.rs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
pub mod loader;
|
|
2
|
-
pub mod runner;
|
|
1
|
+
pub mod loader;
|
|
2
|
+
pub mod runner;
|