@devaloop/devalang 0.0.1-beta.3 → 0.1.1
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/README.md +182 -152
- package/out-tsc/api.d.ts +180 -0
- package/out-tsc/api.d.ts.map +1 -0
- package/out-tsc/api.js +286 -0
- package/out-tsc/api.js.map +1 -0
- package/out-tsc/bin/index.d.ts +12 -0
- package/out-tsc/bin/index.d.ts.map +1 -0
- package/out-tsc/bin/index.js +20 -54
- package/out-tsc/bin/index.js.map +1 -0
- package/out-tsc/examples/basic-usage.d.ts +8 -0
- package/out-tsc/examples/basic-usage.d.ts.map +1 -0
- package/out-tsc/examples/basic-usage.js +113 -0
- package/out-tsc/examples/basic-usage.js.map +1 -0
- package/out-tsc/index.d.ts +19 -5
- package/out-tsc/index.d.ts.map +1 -0
- package/out-tsc/index.js +24 -6
- package/out-tsc/index.js.map +1 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts +7 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts.map +1 -0
- package/out-tsc/scripts/copy-wasm-dts.js +36 -32
- package/out-tsc/scripts/copy-wasm-dts.js.map +1 -0
- package/out-tsc/scripts/postinstall.d.ts +1 -0
- package/out-tsc/scripts/postinstall.d.ts.map +1 -0
- package/out-tsc/scripts/postinstall.js +4 -1
- package/out-tsc/scripts/postinstall.js.map +1 -0
- package/out-tsc/scripts/version/bump.d.ts +5 -1
- package/out-tsc/scripts/version/bump.d.ts.map +1 -0
- package/out-tsc/scripts/version/bump.js +114 -44
- package/out-tsc/scripts/version/bump.js.map +1 -0
- package/out-tsc/scripts/version/fetch.d.ts +12 -1
- package/out-tsc/scripts/version/fetch.d.ts.map +1 -0
- package/out-tsc/scripts/version/fetch.js +68 -24
- package/out-tsc/scripts/version/fetch.js.map +1 -0
- package/out-tsc/scripts/version/index.d.ts +6 -0
- package/out-tsc/scripts/version/index.d.ts.map +1 -0
- package/out-tsc/scripts/version/index.js +44 -22
- package/out-tsc/scripts/version/index.js.map +1 -0
- package/out-tsc/scripts/version/sync.d.ts +5 -1
- package/out-tsc/scripts/version/sync.d.ts.map +1 -0
- package/out-tsc/scripts/version/sync.js +78 -29
- package/out-tsc/scripts/version/sync.js.map +1 -0
- package/out-tsc/types.d.ts +68 -0
- package/out-tsc/types.d.ts.map +1 -0
- package/out-tsc/{core/types/value.js → types.js} +4 -0
- package/out-tsc/types.js.map +1 -0
- package/out-tsc/wasm.d.ts +8 -0
- package/out-tsc/wasm.d.ts.map +1 -0
- package/out-tsc/{core/index.js → wasm.js} +9 -6
- package/out-tsc/wasm.js.map +1 -0
- package/package.json +42 -42
- package/.cargo/config.toml +0 -2
- package/.devalang +0 -9
- package/.github/workflows/ci.yml +0 -103
- package/Cargo.toml +0 -84
- package/docs/CHANGELOG.md +0 -622
- package/docs/CONTRIBUTING.md +0 -101
- package/docs/ROADMAP.md +0 -38
- package/docs/TODO.md +0 -71
- package/examples/automation.deva +0 -42
- package/examples/bank.deva +0 -7
- package/examples/bus.deva +0 -10
- package/examples/chain.deva +0 -19
- package/examples/condition.deva +0 -20
- package/examples/duration.deva +0 -9
- package/examples/effect.deva +0 -2
- package/examples/events.deva +0 -12
- package/examples/filter.deva +0 -11
- package/examples/function.deva +0 -15
- package/examples/group.deva +0 -12
- package/examples/index.deva +0 -63
- package/examples/lfo.deva +0 -9
- package/examples/loop.deva +0 -10
- package/examples/pattern.deva +0 -8
- package/examples/plugin.deva +0 -16
- package/examples/routing.deva +0 -23
- package/examples/samples/hat-808.wav +0 -0
- package/examples/samples/kick-808.wav +0 -0
- package/examples/synth.deva +0 -24
- package/examples/synth_types.deva +0 -17
- package/examples/variables.deva +0 -9
- package/out-tsc/bin/project-version.json +0 -6
- package/out-tsc/core/functions/index.d.ts +0 -42
- package/out-tsc/core/functions/index.js +0 -87
- package/out-tsc/core/index.d.ts +0 -6
- package/out-tsc/core/types/index.d.ts +0 -4
- package/out-tsc/core/types/index.js +0 -20
- package/out-tsc/core/types/plugin.d.ts +0 -18
- package/out-tsc/core/types/plugin.js +0 -2
- package/out-tsc/core/types/result.d.ts +0 -27
- package/out-tsc/core/types/result.js +0 -2
- package/out-tsc/core/types/statement.d.ts +0 -106
- package/out-tsc/core/types/statement.js +0 -2
- package/out-tsc/core/types/value.d.ts +0 -43
- package/out-tsc/pkg/devalang_core.d.ts +0 -15
- package/out-tsc/pkg/devalang_core.js +0 -65
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +0 -34
- package/out-tsc/scripts/version/copy-to-binary.d.ts +0 -1
- package/out-tsc/scripts/version/copy-to-binary.js +0 -79
- package/project-version.json +0 -6
- package/rust/bindings/Cargo.toml +0 -9
- package/rust/bindings/src/lib.rs +0 -86
- package/rust/cli/addon/commands.rs +0 -35
- package/rust/cli/addon/download.rs +0 -234
- package/rust/cli/addon/install.rs +0 -33
- package/rust/cli/addon/list.rs +0 -224
- package/rust/cli/addon/metadata.rs +0 -124
- package/rust/cli/addon/mod.rs +0 -8
- package/rust/cli/addon/remove.rs +0 -271
- package/rust/cli/addon/update.rs +0 -305
- package/rust/cli/addon/utils.rs +0 -109
- package/rust/cli/build/commands.rs +0 -153
- package/rust/cli/build/mod.rs +0 -2
- package/rust/cli/build/process.rs +0 -165
- package/rust/cli/check/mod.rs +0 -208
- package/rust/cli/discover/commands.rs +0 -275
- package/rust/cli/discover/config.rs +0 -109
- package/rust/cli/discover/fs.rs +0 -19
- package/rust/cli/discover/install.rs +0 -214
- package/rust/cli/discover/metadata.rs +0 -48
- package/rust/cli/discover/mod.rs +0 -5
- package/rust/cli/init/commands.rs +0 -88
- package/rust/cli/init/mod.rs +0 -1
- package/rust/cli/login/commands.rs +0 -124
- package/rust/cli/login/mod.rs +0 -1
- package/rust/cli/me/commands.rs +0 -52
- package/rust/cli/me/mod.rs +0 -1
- package/rust/cli/mod.rs +0 -12
- package/rust/cli/parser.rs +0 -320
- package/rust/cli/play/commands.rs +0 -375
- package/rust/cli/play/io.rs +0 -17
- package/rust/cli/play/mod.rs +0 -5
- package/rust/cli/play/process.rs +0 -159
- package/rust/cli/play/realtime.rs +0 -91
- package/rust/cli/play/utils.rs +0 -23
- package/rust/cli/telemetry/commands.rs +0 -22
- package/rust/cli/telemetry/event_creator.rs +0 -80
- package/rust/cli/telemetry/mod.rs +0 -3
- package/rust/cli/telemetry/send.rs +0 -51
- package/rust/cli/template/commands.rs +0 -69
- package/rust/cli/template/mod.rs +0 -1
- package/rust/cli/update/commands.rs +0 -6
- package/rust/cli/update/mod.rs +0 -1
- package/rust/config/driver.rs +0 -112
- package/rust/config/mod.rs +0 -3
- package/rust/config/ops.rs +0 -26
- package/rust/config/settings.rs +0 -101
- package/rust/core/audio/engine/driver.rs +0 -237
- package/rust/core/audio/engine/export.rs +0 -169
- package/rust/core/audio/engine/helpers.rs +0 -178
- package/rust/core/audio/engine/mod.rs +0 -56
- package/rust/core/audio/engine/notes/dsp.rs +0 -88
- package/rust/core/audio/engine/notes/mod.rs +0 -53
- package/rust/core/audio/engine/notes/params.rs +0 -294
- package/rust/core/audio/engine/sample/insert.rs +0 -300
- package/rust/core/audio/engine/sample/mod.rs +0 -40
- package/rust/core/audio/engine/sample/padding.rs +0 -170
- package/rust/core/audio/evaluator/condition.rs +0 -61
- package/rust/core/audio/evaluator/mod.rs +0 -9
- package/rust/core/audio/evaluator/numeric.rs +0 -152
- package/rust/core/audio/evaluator/rhs.rs +0 -16
- package/rust/core/audio/evaluator/string_expr.rs +0 -94
- package/rust/core/audio/interpreter/driver.rs +0 -574
- package/rust/core/audio/interpreter/mod.rs +0 -2
- package/rust/core/audio/interpreter/statements/arrow_call/interprete.rs +0 -179
- package/rust/core/audio/interpreter/statements/arrow_call/methods/chord.rs +0 -398
- package/rust/core/audio/interpreter/statements/arrow_call/methods/effects.rs +0 -323
- package/rust/core/audio/interpreter/statements/arrow_call/methods/mod.rs +0 -3
- package/rust/core/audio/interpreter/statements/arrow_call/methods/note.rs +0 -371
- package/rust/core/audio/interpreter/statements/arrow_call/mod.rs +0 -3
- package/rust/core/audio/interpreter/statements/arrow_call/types/arp.rs +0 -192
- package/rust/core/audio/interpreter/statements/arrow_call/types/mod.rs +0 -24
- package/rust/core/audio/interpreter/statements/arrow_call/types/pad.rs +0 -116
- package/rust/core/audio/interpreter/statements/arrow_call/types/pluck.rs +0 -97
- package/rust/core/audio/interpreter/statements/arrow_call/types/sub.rs +0 -100
- package/rust/core/audio/interpreter/statements/automate.rs +0 -16
- package/rust/core/audio/interpreter/statements/call.rs +0 -325
- package/rust/core/audio/interpreter/statements/condition.rs +0 -72
- package/rust/core/audio/interpreter/statements/function.rs +0 -24
- package/rust/core/audio/interpreter/statements/let_.rs +0 -36
- package/rust/core/audio/interpreter/statements/load.rs +0 -17
- package/rust/core/audio/interpreter/statements/loop_.rs +0 -115
- package/rust/core/audio/interpreter/statements/mod.rs +0 -12
- package/rust/core/audio/interpreter/statements/sleep.rs +0 -28
- package/rust/core/audio/interpreter/statements/spawn.rs +0 -302
- package/rust/core/audio/interpreter/statements/tempo.rs +0 -40
- package/rust/core/audio/interpreter/statements/trigger.rs +0 -242
- package/rust/core/audio/loader/mod.rs +0 -1
- package/rust/core/audio/loader/trigger.rs +0 -98
- package/rust/core/audio/mod.rs +0 -6
- package/rust/core/audio/player.rs +0 -70
- package/rust/core/audio/special/easing.rs +0 -189
- package/rust/core/audio/special/env.rs +0 -45
- package/rust/core/audio/special/math.rs +0 -134
- package/rust/core/audio/special/mod.rs +0 -9
- package/rust/core/audio/special/modulator.rs +0 -143
- package/rust/core/builder/mod.rs +0 -129
- package/rust/core/debugger/lexer.rs +0 -27
- package/rust/core/debugger/logs.rs +0 -52
- package/rust/core/debugger/mod.rs +0 -30
- package/rust/core/debugger/preprocessor.rs +0 -27
- package/rust/core/debugger/store.rs +0 -38
- package/rust/core/error/mod.rs +0 -269
- package/rust/core/lexer/driver.rs +0 -59
- package/rust/core/lexer/handler/arrow.rs +0 -82
- package/rust/core/lexer/handler/at.rs +0 -21
- package/rust/core/lexer/handler/brace.rs +0 -41
- package/rust/core/lexer/handler/colon.rs +0 -21
- package/rust/core/lexer/handler/comment.rs +0 -30
- package/rust/core/lexer/handler/dot.rs +0 -21
- package/rust/core/lexer/handler/driver.rs +0 -337
- package/rust/core/lexer/handler/identifier.rs +0 -47
- package/rust/core/lexer/handler/indent.rs +0 -66
- package/rust/core/lexer/handler/mod.rs +0 -15
- package/rust/core/lexer/handler/newline.rs +0 -23
- package/rust/core/lexer/handler/number.rs +0 -31
- package/rust/core/lexer/handler/operator.rs +0 -46
- package/rust/core/lexer/handler/parenthesis.rs +0 -41
- package/rust/core/lexer/handler/slash.rs +0 -21
- package/rust/core/lexer/handler/string.rs +0 -63
- package/rust/core/lexer/mod.rs +0 -3
- package/rust/core/lexer/token.rs +0 -91
- package/rust/core/mod.rs +0 -9
- package/rust/core/parser/driver/block.rs +0 -111
- package/rust/core/parser/driver/cursor.rs +0 -82
- package/rust/core/parser/driver/driver_impl.rs +0 -159
- package/rust/core/parser/driver/mod.rs +0 -6
- package/rust/core/parser/driver/parse_array.rs +0 -120
- package/rust/core/parser/driver/parse_map.rs +0 -247
- package/rust/core/parser/driver/parser.rs +0 -160
- package/rust/core/parser/handler/arrow_call.rs +0 -328
- package/rust/core/parser/handler/at.rs +0 -279
- package/rust/core/parser/handler/bank.rs +0 -104
- package/rust/core/parser/handler/condition.rs +0 -83
- package/rust/core/parser/handler/dot.rs +0 -148
- package/rust/core/parser/handler/identifier/automate.rs +0 -254
- package/rust/core/parser/handler/identifier/call.rs +0 -91
- package/rust/core/parser/handler/identifier/emit.rs +0 -70
- package/rust/core/parser/handler/identifier/function.rs +0 -113
- package/rust/core/parser/handler/identifier/group.rs +0 -89
- package/rust/core/parser/handler/identifier/let_.rs +0 -173
- package/rust/core/parser/handler/identifier/mod.rs +0 -55
- package/rust/core/parser/handler/identifier/on.rs +0 -107
- package/rust/core/parser/handler/identifier/print.rs +0 -49
- package/rust/core/parser/handler/identifier/sleep.rs +0 -96
- package/rust/core/parser/handler/identifier/spawn.rs +0 -91
- package/rust/core/parser/handler/identifier/synth.rs +0 -171
- package/rust/core/parser/handler/loop_.rs +0 -194
- package/rust/core/parser/handler/mod.rs +0 -9
- package/rust/core/parser/handler/pattern.rs +0 -97
- package/rust/core/parser/handler/tempo.rs +0 -105
- package/rust/core/parser/mod.rs +0 -3
- package/rust/core/parser/statement.rs +0 -10
- package/rust/core/plugin/loader.rs +0 -137
- package/rust/core/plugin/mod.rs +0 -2
- package/rust/core/plugin/runner/mod.rs +0 -11
- package/rust/core/plugin/runner/non_wasm.rs +0 -481
- package/rust/core/plugin/runner/wasm32.rs +0 -44
- package/rust/core/preprocessor/loader/inject.rs +0 -313
- package/rust/core/preprocessor/loader/loader_helpers.rs +0 -110
- package/rust/core/preprocessor/loader/mod.rs +0 -235
- package/rust/core/preprocessor/mod.rs +0 -4
- package/rust/core/preprocessor/module.rs +0 -55
- package/rust/core/preprocessor/processor/handlers.rs +0 -107
- package/rust/core/preprocessor/processor/mod.rs +0 -1
- package/rust/core/preprocessor/resolver/bank.rs +0 -49
- package/rust/core/preprocessor/resolver/call.rs +0 -124
- package/rust/core/preprocessor/resolver/condition.rs +0 -95
- package/rust/core/preprocessor/resolver/driver.rs +0 -324
- package/rust/core/preprocessor/resolver/function.rs +0 -69
- package/rust/core/preprocessor/resolver/group.rs +0 -122
- package/rust/core/preprocessor/resolver/let_.rs +0 -32
- package/rust/core/preprocessor/resolver/loop_.rs +0 -318
- package/rust/core/preprocessor/resolver/mod.rs +0 -16
- package/rust/core/preprocessor/resolver/pattern.rs +0 -95
- package/rust/core/preprocessor/resolver/spawn.rs +0 -99
- package/rust/core/preprocessor/resolver/synth.rs +0 -54
- package/rust/core/preprocessor/resolver/tempo.rs +0 -48
- package/rust/core/preprocessor/resolver/trigger.rs +0 -116
- package/rust/core/preprocessor/resolver/value.rs +0 -176
- package/rust/core/store/global.rs +0 -57
- package/rust/core/store/mod.rs +0 -1
- package/rust/lib.rs +0 -323
- package/rust/macros/Cargo.toml +0 -14
- package/rust/macros/src/lib.rs +0 -52
- package/rust/main.rs +0 -557
- package/rust/types/Cargo.toml +0 -11
- package/rust/types/src/addons.rs +0 -57
- package/rust/types/src/ast.rs +0 -202
- package/rust/types/src/config.rs +0 -82
- package/rust/types/src/lib.rs +0 -15
- package/rust/types/src/plugin.rs +0 -20
- package/rust/types/src/store.rs +0 -139
- package/rust/types/src/telemetry.rs +0 -85
- package/rust/utils/Cargo.toml +0 -29
- package/rust/utils/src/error.rs +0 -186
- package/rust/utils/src/file.rs +0 -477
- package/rust/utils/src/first_usage.rs +0 -97
- package/rust/utils/src/lib.rs +0 -9
- package/rust/utils/src/logger.rs +0 -200
- package/rust/utils/src/path.rs +0 -158
- package/rust/utils/src/signature.rs +0 -41
- package/rust/utils/src/spinner.rs +0 -20
- package/rust/utils/src/version.rs +0 -58
- package/rust/utils/src/watcher.rs +0 -46
- package/rust/web/api.rs +0 -5
- package/rust/web/auth.rs +0 -5
- package/rust/web/cdn.rs +0 -34
- package/rust/web/forge.rs +0 -5
- package/rust/web/mod.rs +0 -5
- package/rust/web/sso.rs +0 -5
- package/templates/minimal/.devalang +0 -5
- package/templates/minimal/README.md +0 -218
- package/templates/minimal/src/index.deva +0 -2
- package/templates/welcome/.devalang +0 -5
- package/templates/welcome/README.md +0 -218
- package/templates/welcome/samples/kick-808.wav +0 -0
- package/templates/welcome/src/index.deva +0 -61
- package/templates/welcome/src/variables.deva +0 -3
- package/tests/integration.rs +0 -21
- package/tests/rust/cli_check_build.rs +0 -21
- package/tests/rust/cli_help.rs +0 -12
- package/tests/rust/cli_template_list.rs +0 -10
- package/tests/rust/cli_version.rs +0 -11
- package/tests/typescript/index.spec.ts +0 -136
- package/tests/typescript/playhead.spec.ts +0 -36
- package/tests/typescript/render_e2e.spec.ts +0 -77
- package/tsconfig.json +0 -115
- package/typescript/bin/index.ts +0 -28
- package/typescript/core/functions/index.ts +0 -94
- package/typescript/core/index.ts +0 -6
- package/typescript/core/types/index.ts +0 -4
- package/typescript/core/types/plugin.ts +0 -19
- package/typescript/core/types/result.ts +0 -29
- package/typescript/core/types/statement.ts +0 -47
- package/typescript/core/types/value.ts +0 -29
- package/typescript/index.ts +0 -8
- package/typescript/pkg/devalang_core.d.ts +0 -4
- package/typescript/pkg/devalang_core.ts +0 -65
- package/typescript/scripts/copy-wasm-dts.ts +0 -41
- package/typescript/scripts/postinstall.ts +0 -85
- package/typescript/scripts/version/bump.ts +0 -44
- package/typescript/scripts/version/copy-to-binary.ts +0 -82
- package/typescript/scripts/version/fetch.ts +0 -18
- package/typescript/scripts/version/index.ts +0 -25
- package/typescript/scripts/version/sync.ts +0 -24
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
use crate::core::lexer::token::TokenKind;
|
|
2
|
-
use devalang_types::Value;
|
|
3
|
-
|
|
4
|
-
pub fn parse_array_value(
|
|
5
|
-
parser: &mut crate::core::parser::driver::parser::Parser,
|
|
6
|
-
) -> Option<Value> {
|
|
7
|
-
let logger = devalang_utils::logger::Logger::new();
|
|
8
|
-
use devalang_utils::logger::LogLevel;
|
|
9
|
-
if !parser.match_token(TokenKind::LBracket) {
|
|
10
|
-
return None;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let mut arr: Vec<Value> = Vec::new();
|
|
14
|
-
|
|
15
|
-
while !parser.check_token(TokenKind::RBracket) && !parser.is_eof() {
|
|
16
|
-
// Skip formatting tokens
|
|
17
|
-
while parser.check_token(TokenKind::Newline)
|
|
18
|
-
|| parser.check_token(TokenKind::Whitespace)
|
|
19
|
-
|| parser.check_token(TokenKind::Indent)
|
|
20
|
-
|| parser.check_token(TokenKind::Dedent)
|
|
21
|
-
|| parser.check_token(TokenKind::Comma)
|
|
22
|
-
{
|
|
23
|
-
parser.advance();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if parser.check_token(TokenKind::RBracket) {
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if let Some(token) = parser.peek_clone() {
|
|
31
|
-
let value = match token.kind {
|
|
32
|
-
TokenKind::String => {
|
|
33
|
-
parser.advance();
|
|
34
|
-
Value::String(token.lexeme.clone())
|
|
35
|
-
}
|
|
36
|
-
TokenKind::Number => {
|
|
37
|
-
// Support decimals and fraction literals (e.g., 1/4 -> Duration::Beat("1/4"))
|
|
38
|
-
let mut number_str = token.lexeme.clone();
|
|
39
|
-
parser.advance();
|
|
40
|
-
if let Some(dot) = parser.peek_clone() {
|
|
41
|
-
if dot.kind == TokenKind::Dot {
|
|
42
|
-
if let Some(next) = parser.peek_nth(1).cloned() {
|
|
43
|
-
if next.kind == TokenKind::Number {
|
|
44
|
-
parser.advance(); // consume dot
|
|
45
|
-
parser.advance(); // consume next number
|
|
46
|
-
number_str.push('.');
|
|
47
|
-
number_str.push_str(&next.lexeme);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Fraction form: number '/' number or identifier
|
|
54
|
-
if let Some(slash_tok) = parser.peek_clone() {
|
|
55
|
-
if slash_tok.kind == TokenKind::Slash {
|
|
56
|
-
// consume '/'
|
|
57
|
-
parser.advance();
|
|
58
|
-
if let Some(den_tok) = parser.peek_clone() {
|
|
59
|
-
match den_tok.kind {
|
|
60
|
-
TokenKind::Number | TokenKind::Identifier => {
|
|
61
|
-
let frac = format!("{}/{}", number_str, den_tok.lexeme);
|
|
62
|
-
parser.advance();
|
|
63
|
-
Value::Duration(devalang_types::Duration::Beat(frac))
|
|
64
|
-
}
|
|
65
|
-
_ => Value::Number(number_str.parse::<f32>().unwrap_or(0.0)),
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
Value::Number(number_str.parse::<f32>().unwrap_or(0.0))
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
Value::Number(number_str.parse::<f32>().unwrap_or(0.0))
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
Value::Number(number_str.parse::<f32>().unwrap_or(0.0))
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
TokenKind::Identifier => {
|
|
78
|
-
parser.advance();
|
|
79
|
-
Value::Identifier(token.lexeme.clone())
|
|
80
|
-
}
|
|
81
|
-
TokenKind::LBrace => {
|
|
82
|
-
// Allow inline maps inside arrays
|
|
83
|
-
if let Some(v) = crate::core::parser::driver::parse_map::parse_map_value(parser)
|
|
84
|
-
{
|
|
85
|
-
v
|
|
86
|
-
} else {
|
|
87
|
-
Value::Null
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
TokenKind::LBracket => {
|
|
91
|
-
// Nested arrays
|
|
92
|
-
if let Some(v) = parse_array_value(parser) {
|
|
93
|
-
v
|
|
94
|
-
} else {
|
|
95
|
-
Value::Null
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
_ => {
|
|
99
|
-
parser.advance();
|
|
100
|
-
Value::Null
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// Only push non-null (retain alignment with permissive parsing)
|
|
105
|
-
if value != Value::Null {
|
|
106
|
-
arr.push(value);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Optional trailing comma handled by the skipper at loop start
|
|
110
|
-
} else {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if !parser.match_token(TokenKind::RBracket) {
|
|
116
|
-
logger.log_message(LogLevel::Error, "Expected ']' at end of array");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
Some(Value::Array(arr))
|
|
120
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
use crate::core::lexer::token::TokenKind;
|
|
2
|
-
use devalang_types::Value;
|
|
3
|
-
|
|
4
|
-
pub fn parse_map_value(parser: &mut crate::core::parser::driver::parser::Parser) -> Option<Value> {
|
|
5
|
-
let logger = devalang_utils::logger::Logger::new();
|
|
6
|
-
use devalang_utils::logger::LogLevel;
|
|
7
|
-
if !parser.match_token(TokenKind::LBrace) {
|
|
8
|
-
return None;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
let mut map = std::collections::HashMap::new();
|
|
12
|
-
|
|
13
|
-
while !parser.check_token(TokenKind::RBrace) && !parser.is_eof() {
|
|
14
|
-
// Skip separators and formatting before the key
|
|
15
|
-
while parser.check_token(TokenKind::Newline)
|
|
16
|
-
|| parser.check_token(TokenKind::Whitespace)
|
|
17
|
-
|| parser.check_token(TokenKind::Indent)
|
|
18
|
-
|| parser.check_token(TokenKind::Dedent)
|
|
19
|
-
|| parser.check_token(TokenKind::Comma)
|
|
20
|
-
{
|
|
21
|
-
parser.advance();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Check if we are at the closing brace of the map
|
|
25
|
-
if parser.check_token(TokenKind::RBrace) {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let key = if let Some(token) = parser.advance() {
|
|
30
|
-
match token.kind {
|
|
31
|
-
TokenKind::Whitespace
|
|
32
|
-
| TokenKind::Indent
|
|
33
|
-
| TokenKind::Dedent
|
|
34
|
-
| TokenKind::Newline => {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
_ => token.lexeme.clone(),
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
break;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Skip newlines and whitespace before colon
|
|
44
|
-
while parser.check_token(TokenKind::Newline) || parser.check_token(TokenKind::Whitespace) {
|
|
45
|
-
parser.advance();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Accept both 'key: value' and short form 'key value' for convenience.
|
|
49
|
-
let mut saw_colon = false;
|
|
50
|
-
if parser.match_token(TokenKind::Colon) {
|
|
51
|
-
saw_colon = true;
|
|
52
|
-
} else {
|
|
53
|
-
// Peek to see if the next token looks like a value; if so, accept short form.
|
|
54
|
-
if let Some(peek) = parser.peek_clone() {
|
|
55
|
-
match peek.kind {
|
|
56
|
-
TokenKind::String
|
|
57
|
-
| TokenKind::Number
|
|
58
|
-
| TokenKind::Identifier
|
|
59
|
-
| TokenKind::LBracket
|
|
60
|
-
| TokenKind::LBrace => {
|
|
61
|
-
// short form accepted, do not consume here; value parsing will handle it
|
|
62
|
-
}
|
|
63
|
-
_ => {
|
|
64
|
-
logger.log_message(
|
|
65
|
-
LogLevel::Error,
|
|
66
|
-
&format!("Expected ':' after map key '{}'", key),
|
|
67
|
-
);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
logger.log_message(
|
|
73
|
-
LogLevel::Error,
|
|
74
|
-
&format!("Expected ':' after map key '{}'", key),
|
|
75
|
-
);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Skip separators and formatting before value
|
|
81
|
-
while parser.check_token(TokenKind::Newline)
|
|
82
|
-
|| parser.check_token(TokenKind::Whitespace)
|
|
83
|
-
|| parser.check_token(TokenKind::Indent)
|
|
84
|
-
|| parser.check_token(TokenKind::Dedent)
|
|
85
|
-
|| parser.check_token(TokenKind::Comma)
|
|
86
|
-
{
|
|
87
|
-
parser.advance();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let value = if let Some(token) = parser.peek_clone() {
|
|
91
|
-
match token.kind {
|
|
92
|
-
TokenKind::String => {
|
|
93
|
-
parser.advance();
|
|
94
|
-
Value::String(token.lexeme.clone())
|
|
95
|
-
}
|
|
96
|
-
TokenKind::Number => {
|
|
97
|
-
// Handle number, decimal number and optional fraction form (e.g., 1/4)
|
|
98
|
-
let mut number_str = token.lexeme.clone();
|
|
99
|
-
parser.advance(); // consume the first number
|
|
100
|
-
|
|
101
|
-
// decimal support: number '.' number
|
|
102
|
-
if let Some(dot_token) = parser.peek_clone() {
|
|
103
|
-
if dot_token.kind == TokenKind::Dot {
|
|
104
|
-
parser.advance(); // consume the dot
|
|
105
|
-
|
|
106
|
-
if let Some(decimal_token) = parser.peek_clone() {
|
|
107
|
-
if decimal_token.kind == TokenKind::Number {
|
|
108
|
-
parser.advance(); // consume the number after the dot
|
|
109
|
-
number_str.push('.');
|
|
110
|
-
number_str.push_str(&decimal_token.lexeme);
|
|
111
|
-
} else {
|
|
112
|
-
logger.log_message(
|
|
113
|
-
LogLevel::Error,
|
|
114
|
-
&format!(
|
|
115
|
-
"Expected number after dot, got {:?}",
|
|
116
|
-
decimal_token
|
|
117
|
-
),
|
|
118
|
-
);
|
|
119
|
-
return Some(Value::Null);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
logger.log_message(
|
|
123
|
-
LogLevel::Error,
|
|
124
|
-
"Expected number after dot, but reached EOF",
|
|
125
|
-
);
|
|
126
|
-
return Some(Value::Null);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Fraction support: number '/' number -> Duration::Beat("num/den")
|
|
132
|
-
if let Some(slash_tok) = parser.peek_clone() {
|
|
133
|
-
if slash_tok.kind == TokenKind::Slash {
|
|
134
|
-
// consume '/'
|
|
135
|
-
parser.advance();
|
|
136
|
-
if let Some(den_tok) = parser.peek_clone() {
|
|
137
|
-
match den_tok.kind {
|
|
138
|
-
TokenKind::Number | TokenKind::Identifier => {
|
|
139
|
-
let frac = format!("{}/{}", number_str, den_tok.lexeme);
|
|
140
|
-
parser.advance();
|
|
141
|
-
return Some(Value::Duration(
|
|
142
|
-
devalang_types::Duration::Beat(frac),
|
|
143
|
-
));
|
|
144
|
-
}
|
|
145
|
-
_ => {
|
|
146
|
-
logger.log_message(
|
|
147
|
-
LogLevel::Error,
|
|
148
|
-
&format!(
|
|
149
|
-
"Expected number or identifier after '/', got {:?}",
|
|
150
|
-
den_tok
|
|
151
|
-
),
|
|
152
|
-
);
|
|
153
|
-
return Some(Value::Null);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
logger.log_message(
|
|
158
|
-
LogLevel::Error,
|
|
159
|
-
"Expected denominator after '/', but reached EOF",
|
|
160
|
-
);
|
|
161
|
-
return Some(Value::Null);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
Value::Number(number_str.parse::<f32>().unwrap_or(0.0))
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
TokenKind::Identifier => {
|
|
170
|
-
// Support dotted identifiers in map values: alias.param or nested
|
|
171
|
-
let current_line = token.line;
|
|
172
|
-
let mut parts: Vec<String> = vec![token.lexeme.clone()];
|
|
173
|
-
parser.advance();
|
|
174
|
-
loop {
|
|
175
|
-
let Some(next) = parser.peek_clone() else {
|
|
176
|
-
break;
|
|
177
|
-
};
|
|
178
|
-
if next.line != current_line {
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
if next.kind == TokenKind::Dot {
|
|
182
|
-
// Consume '.' and the following identifier/number on same line
|
|
183
|
-
parser.advance(); // dot
|
|
184
|
-
if let Some(id2) = parser.peek_clone() {
|
|
185
|
-
if id2.line == current_line
|
|
186
|
-
&& (id2.kind == TokenKind::Identifier
|
|
187
|
-
|| id2.kind == TokenKind::Number)
|
|
188
|
-
{
|
|
189
|
-
parts.push(id2.lexeme.clone());
|
|
190
|
-
parser.advance(); // consume part
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
break;
|
|
195
|
-
} else {
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
Value::Identifier(parts.join("."))
|
|
200
|
-
}
|
|
201
|
-
TokenKind::LBracket => {
|
|
202
|
-
// Allow arrays as map values
|
|
203
|
-
if let Some(v) =
|
|
204
|
-
crate::core::parser::driver::parse_array::parse_array_value(parser)
|
|
205
|
-
{
|
|
206
|
-
v
|
|
207
|
-
} else {
|
|
208
|
-
Value::Null
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
TokenKind::LBrace => {
|
|
212
|
-
// Allow inline nested maps as map values
|
|
213
|
-
if let Some(v) = parse_map_value(parser) {
|
|
214
|
-
v
|
|
215
|
-
} else {
|
|
216
|
-
Value::Null
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
_ => {
|
|
220
|
-
logger.log_message(
|
|
221
|
-
LogLevel::Error,
|
|
222
|
-
&format!("Unexpected token in map value: {:?}", token),
|
|
223
|
-
);
|
|
224
|
-
Value::Null
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
Value::Null
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
map.insert(key, value);
|
|
232
|
-
|
|
233
|
-
// Optionally skip a trailing comma after the value
|
|
234
|
-
while parser.check_token(TokenKind::Comma)
|
|
235
|
-
|| parser.check_token(TokenKind::Whitespace)
|
|
236
|
-
|| parser.check_token(TokenKind::Newline)
|
|
237
|
-
{
|
|
238
|
-
parser.advance();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if !parser.match_token(TokenKind::RBrace) {
|
|
243
|
-
logger.log_message(LogLevel::Error, "Expected '}' at end of map");
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
Some(Value::Map(map))
|
|
247
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
use crate::core::{
|
|
2
|
-
lexer::token::{Token, TokenKind},
|
|
3
|
-
parser::statement::Statement,
|
|
4
|
-
store::global::GlobalStore,
|
|
5
|
-
};
|
|
6
|
-
use devalang_types::Value;
|
|
7
|
-
|
|
8
|
-
#[derive(Debug, Clone, PartialEq)]
|
|
9
|
-
pub struct Parser {
|
|
10
|
-
pub resolve_modules: bool,
|
|
11
|
-
pub tokens: Vec<Token>,
|
|
12
|
-
pub token_index: usize,
|
|
13
|
-
pub current_module: String,
|
|
14
|
-
pub previous: Option<Token>,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
impl Default for Parser {
|
|
18
|
-
fn default() -> Self {
|
|
19
|
-
Self::new()
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
impl Parser {
|
|
24
|
-
pub fn new() -> Self {
|
|
25
|
-
Parser {
|
|
26
|
-
resolve_modules: false,
|
|
27
|
-
tokens: Vec::new(),
|
|
28
|
-
token_index: 0,
|
|
29
|
-
current_module: String::new(),
|
|
30
|
-
previous: None,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
pub fn set_current_module(&mut self, module_path: String) {
|
|
35
|
-
self.current_module = module_path;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
pub fn advance(&mut self) -> Option<&Token> {
|
|
39
|
-
crate::core::parser::driver::cursor::advance_impl(self)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
pub fn peek_is(&self, expected: &str) -> bool {
|
|
43
|
-
crate::core::parser::driver::cursor::peek_is_impl(self, expected)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
pub fn peek_nth(&self, n: usize) -> Option<&Token> {
|
|
47
|
-
crate::core::parser::driver::cursor::peek_nth_impl(self, n)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
pub fn peek_nth_kind(&self, n: usize) -> Option<TokenKind> {
|
|
51
|
-
crate::core::parser::driver::cursor::peek_nth_kind_impl(self, n)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
pub fn advance_if(&mut self, kind: TokenKind) -> bool {
|
|
55
|
-
crate::core::parser::driver::cursor::advance_if_impl(self, kind)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
pub fn match_token(&mut self, kind: TokenKind) -> bool {
|
|
59
|
-
crate::core::parser::driver::cursor::match_token_impl(self, kind)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
pub fn previous_clone(&self) -> Option<Token> {
|
|
63
|
-
crate::core::parser::driver::cursor::previous_clone_impl(self)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
pub fn parse_block(
|
|
67
|
-
&self,
|
|
68
|
-
tokens: Vec<Token>,
|
|
69
|
-
global_store: &mut GlobalStore,
|
|
70
|
-
) -> Vec<Statement> {
|
|
71
|
-
crate::core::parser::driver::block::parse_block(self, tokens, global_store)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
pub fn parse_tokens(
|
|
75
|
-
&mut self,
|
|
76
|
-
tokens: Vec<Token>,
|
|
77
|
-
global_store: &mut GlobalStore,
|
|
78
|
-
) -> Vec<Statement> {
|
|
79
|
-
crate::core::parser::driver::driver_impl::parse_tokens_impl(self, tokens, global_store)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
pub fn check_token(&self, kind: TokenKind) -> bool {
|
|
83
|
-
crate::core::parser::driver::cursor::peek_impl(self).is_some_and(|t| t.kind == kind)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
pub fn peek_kind(&self) -> Option<TokenKind> {
|
|
87
|
-
crate::core::parser::driver::cursor::peek_impl(self).map(|t| t.kind.clone())
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
pub fn parse_map_value(&mut self) -> Option<Value> {
|
|
91
|
-
// Delegated to parse_map.rs
|
|
92
|
-
crate::core::parser::driver::parse_map::parse_map_value(self)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Parse an array value like [1, 2, 3] or ["a", b]
|
|
96
|
-
pub fn parse_array_value(&mut self) -> Option<Value> {
|
|
97
|
-
// delegated to parse_array.rs
|
|
98
|
-
crate::core::parser::driver::parse_array::parse_array_value(self)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
pub fn peek(&self) -> Option<&Token> {
|
|
102
|
-
self.tokens.get(self.token_index)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
pub fn peek_clone(&self) -> Option<Token> {
|
|
106
|
-
self.tokens.get(self.token_index).cloned()
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
pub fn expect(&mut self, kind: TokenKind) -> Result<&Token, String> {
|
|
110
|
-
let tok = self.advance().ok_or("Unexpected end of input")?;
|
|
111
|
-
if tok.kind == kind {
|
|
112
|
-
Ok(tok)
|
|
113
|
-
} else {
|
|
114
|
-
Err(format!("Expected {:?}, got {:?}", kind, tok.kind))
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
pub fn collect_block_tokens(&mut self, base_indent: usize) -> Vec<Token> {
|
|
119
|
-
crate::core::parser::driver::block::collect_block_tokens(self, base_indent)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
pub fn collect_until<F>(&mut self, condition: F) -> Vec<Token>
|
|
123
|
-
where
|
|
124
|
-
F: Fn(&Token) -> bool,
|
|
125
|
-
{
|
|
126
|
-
crate::core::parser::driver::block::collect_until(self, condition)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
pub fn is_eof(&self) -> bool {
|
|
130
|
-
self.token_index >= self.tokens.len()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
pub fn parse_block_until_next_else(
|
|
134
|
-
&mut self,
|
|
135
|
-
base_indent: usize,
|
|
136
|
-
global_store: &mut GlobalStore,
|
|
137
|
-
) -> Vec<Statement> {
|
|
138
|
-
crate::core::parser::driver::block::parse_block_until_next_else(
|
|
139
|
-
self,
|
|
140
|
-
base_indent,
|
|
141
|
-
global_store,
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
pub fn parse_condition_until_colon(&mut self) -> Option<Value> {
|
|
146
|
-
crate::core::parser::driver::driver_impl::parse_condition_until_colon_impl(self)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
pub fn parse_block_until_else_or_dedent(
|
|
150
|
-
&mut self,
|
|
151
|
-
base_indent: usize,
|
|
152
|
-
global_store: &mut GlobalStore,
|
|
153
|
-
) -> Vec<Statement> {
|
|
154
|
-
crate::core::parser::driver::block::parse_block_until_else_or_dedent(
|
|
155
|
-
self,
|
|
156
|
-
base_indent,
|
|
157
|
-
global_store,
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
}
|