@devaloop/devalang 0.0.1-beta.3 → 0.1.2
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/LICENSE +20 -20
- package/README.md +251 -221
- 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 +122 -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 +95 -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,70 +0,0 @@
|
|
|
1
|
-
use crate::core::{
|
|
2
|
-
lexer::token::TokenKind,
|
|
3
|
-
parser::{
|
|
4
|
-
driver::parser::Parser,
|
|
5
|
-
statement::{Statement, StatementKind},
|
|
6
|
-
},
|
|
7
|
-
store::global::GlobalStore,
|
|
8
|
-
};
|
|
9
|
-
use devalang_types::Value;
|
|
10
|
-
|
|
11
|
-
pub fn parse_emit_token(
|
|
12
|
-
parser: &mut Parser,
|
|
13
|
-
current: crate::core::lexer::token::Token,
|
|
14
|
-
_global_store: &mut GlobalStore,
|
|
15
|
-
) -> Statement {
|
|
16
|
-
parser.advance(); // consume 'emit'
|
|
17
|
-
|
|
18
|
-
let Some(ev) = parser.peek_clone() else {
|
|
19
|
-
return crate::core::parser::statement::error_from_token(
|
|
20
|
-
current,
|
|
21
|
-
"Expected event name after 'emit'".into(),
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
if ev.kind != TokenKind::Identifier {
|
|
25
|
-
return crate::core::parser::statement::error_from_token(
|
|
26
|
-
ev.clone(),
|
|
27
|
-
"Expected identifier as event name".into(),
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
let event_name = ev.lexeme.clone();
|
|
31
|
-
parser.advance(); // consume event name
|
|
32
|
-
|
|
33
|
-
// Optional payload on same line: number|string|identifier|map|array
|
|
34
|
-
let mut payload: Option<Value> = None;
|
|
35
|
-
if let Some(tok) = parser.peek_clone() {
|
|
36
|
-
if tok.line == ev.line {
|
|
37
|
-
let val = match tok.kind {
|
|
38
|
-
TokenKind::String => {
|
|
39
|
-
parser.advance();
|
|
40
|
-
Value::String(tok.lexeme.clone())
|
|
41
|
-
}
|
|
42
|
-
TokenKind::Number => {
|
|
43
|
-
parser.advance();
|
|
44
|
-
Value::Number(tok.lexeme.parse().unwrap_or(0.0))
|
|
45
|
-
}
|
|
46
|
-
TokenKind::Identifier => {
|
|
47
|
-
parser.advance();
|
|
48
|
-
Value::Identifier(tok.lexeme.clone())
|
|
49
|
-
}
|
|
50
|
-
TokenKind::LBrace => parser.parse_map_value().unwrap_or(Value::Null),
|
|
51
|
-
TokenKind::LBracket => parser.parse_array_value().unwrap_or(Value::Null),
|
|
52
|
-
_ => Value::Null,
|
|
53
|
-
};
|
|
54
|
-
if val != Value::Null {
|
|
55
|
-
payload = Some(val);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
Statement {
|
|
61
|
-
kind: StatementKind::Emit {
|
|
62
|
-
event: event_name,
|
|
63
|
-
payload: payload.clone(),
|
|
64
|
-
},
|
|
65
|
-
value: payload.unwrap_or(Value::Null),
|
|
66
|
-
indent: current.indent,
|
|
67
|
-
line: current.line,
|
|
68
|
-
column: current.column,
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
use devalang_types::Value;
|
|
2
|
-
|
|
3
|
-
use crate::core::{
|
|
4
|
-
lexer::token::TokenKind,
|
|
5
|
-
parser::{
|
|
6
|
-
driver::parser::Parser,
|
|
7
|
-
statement::{Statement, StatementKind},
|
|
8
|
-
},
|
|
9
|
-
store::global::GlobalStore,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
pub fn parse_function_token(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
|
|
13
|
-
parser.advance(); // consume 'fn'
|
|
14
|
-
|
|
15
|
-
let fn_token = match parser.previous_clone() {
|
|
16
|
-
Some(tok) => tok,
|
|
17
|
-
None => return Statement::unknown(),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
let name_token = match parser.peek_clone() {
|
|
21
|
-
Some(tok) => tok,
|
|
22
|
-
None => {
|
|
23
|
-
return crate::core::parser::statement::error_from_token(
|
|
24
|
-
fn_token,
|
|
25
|
-
"Expected function name after 'fn'".to_string(),
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if name_token.kind != TokenKind::Identifier {
|
|
31
|
-
return crate::core::parser::statement::error_from_token(
|
|
32
|
-
name_token.clone(),
|
|
33
|
-
"Expected function name to be an identifier".to_string(),
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let function_name = name_token.lexeme.clone();
|
|
38
|
-
parser.advance(); // consume function name
|
|
39
|
-
|
|
40
|
-
let mut parameters = Vec::new();
|
|
41
|
-
|
|
42
|
-
// Expect '('
|
|
43
|
-
if parser.peek_kind() != Some(TokenKind::LParen) {
|
|
44
|
-
return crate::core::parser::statement::error_from_token(
|
|
45
|
-
name_token.clone(),
|
|
46
|
-
"Expected '(' after function name".to_string(),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
parser.advance(); // consume '('
|
|
50
|
-
|
|
51
|
-
// Parse parameters until ')'
|
|
52
|
-
let tokens = parser.collect_until(|t| t.kind == TokenKind::RParen || t.kind == TokenKind::EOF);
|
|
53
|
-
for token in tokens {
|
|
54
|
-
if token.kind == TokenKind::Identifier {
|
|
55
|
-
parameters.push(token.lexeme.clone());
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if parser.peek_kind() == Some(TokenKind::RParen) {
|
|
60
|
-
parser.advance(); // consume ')'
|
|
61
|
-
} else {
|
|
62
|
-
return crate::core::parser::statement::error_from_token(
|
|
63
|
-
name_token.clone(),
|
|
64
|
-
"Expected ')' after parameters".to_string(),
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Expect colon
|
|
69
|
-
if parser.peek_kind() != Some(TokenKind::Colon) {
|
|
70
|
-
return crate::core::parser::statement::error_from_token(
|
|
71
|
-
name_token.clone(),
|
|
72
|
-
"Expected ':' after ')'".to_string(),
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
parser.advance(); // consume ':'
|
|
76
|
-
|
|
77
|
-
// Collect ALL tokens indented after this line until Dedent
|
|
78
|
-
let base_indent = fn_token.indent;
|
|
79
|
-
let mut body_tokens = Vec::new();
|
|
80
|
-
|
|
81
|
-
while let Some(tok) = parser.peek() {
|
|
82
|
-
if tok.kind == TokenKind::Dedent && tok.indent <= base_indent {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
if let Some(t) = parser.advance() {
|
|
86
|
-
body_tokens.push(t.clone());
|
|
87
|
-
} else {
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Parse those tokens into block statements
|
|
93
|
-
let body = parser.parse_block(body_tokens.clone(), global_store);
|
|
94
|
-
|
|
95
|
-
// Skip Dedent if present
|
|
96
|
-
if let Some(tok) = parser.peek() {
|
|
97
|
-
if tok.kind == TokenKind::Dedent {
|
|
98
|
-
parser.advance();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
Statement {
|
|
103
|
-
kind: StatementKind::Function {
|
|
104
|
-
name: function_name.clone(),
|
|
105
|
-
parameters: parameters.clone(),
|
|
106
|
-
body: body.clone(),
|
|
107
|
-
},
|
|
108
|
-
value: Value::Null,
|
|
109
|
-
indent: fn_token.indent,
|
|
110
|
-
line: fn_token.line,
|
|
111
|
-
column: fn_token.column,
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
use devalang_types::Value;
|
|
2
|
-
|
|
3
|
-
use crate::core::{
|
|
4
|
-
lexer::token::{Token, TokenKind},
|
|
5
|
-
parser::{
|
|
6
|
-
driver::parser::Parser,
|
|
7
|
-
statement::{Statement, StatementKind},
|
|
8
|
-
},
|
|
9
|
-
store::global::GlobalStore,
|
|
10
|
-
};
|
|
11
|
-
use std::collections::HashMap;
|
|
12
|
-
|
|
13
|
-
pub fn parse_group_token(
|
|
14
|
-
parser: &mut Parser,
|
|
15
|
-
current_token: Token,
|
|
16
|
-
global_store: &mut GlobalStore,
|
|
17
|
-
) -> Statement {
|
|
18
|
-
parser.advance(); // consume "group"
|
|
19
|
-
|
|
20
|
-
let Some(identifier_token) = parser.peek_clone() else {
|
|
21
|
-
return crate::core::parser::statement::error_from_token(
|
|
22
|
-
current_token,
|
|
23
|
-
"Expected identifier after 'group'".to_string(),
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if identifier_token.kind != TokenKind::Identifier && identifier_token.kind != TokenKind::String
|
|
28
|
-
{
|
|
29
|
-
return crate::core::parser::statement::error_from_token(
|
|
30
|
-
identifier_token,
|
|
31
|
-
"Expected valid identifier".to_string(),
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
parser.advance(); // consume identifier
|
|
36
|
-
|
|
37
|
-
let Some(colon_token) = parser.peek_clone() else {
|
|
38
|
-
return crate::core::parser::statement::error_from_token(
|
|
39
|
-
identifier_token,
|
|
40
|
-
"Expected ':' after group identifier".to_string(),
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
if colon_token.kind != TokenKind::Colon {
|
|
45
|
-
return crate::core::parser::statement::error_from_token(
|
|
46
|
-
colon_token.clone(),
|
|
47
|
-
"Expected ':' after group identifier".to_string(),
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
parser.advance(); // consume ':'
|
|
52
|
-
|
|
53
|
-
let base_indent = current_token.indent;
|
|
54
|
-
|
|
55
|
-
// Clone without consuming tokens
|
|
56
|
-
let mut index = parser.token_index;
|
|
57
|
-
let mut tokens_inside_group = Vec::new();
|
|
58
|
-
|
|
59
|
-
while index < parser.tokens.len() {
|
|
60
|
-
let token = parser.tokens[index].clone();
|
|
61
|
-
|
|
62
|
-
if token.indent <= base_indent && token.kind != TokenKind::Newline {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
tokens_inside_group.push(token);
|
|
67
|
-
index += 1;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Advance index once to skip the processed tokens
|
|
71
|
-
parser.token_index = index;
|
|
72
|
-
|
|
73
|
-
let body = parser.parse_block(tokens_inside_group, global_store);
|
|
74
|
-
|
|
75
|
-
let mut value_map = HashMap::new();
|
|
76
|
-
value_map.insert(
|
|
77
|
-
"identifier".to_string(),
|
|
78
|
-
Value::String(identifier_token.lexeme.clone()),
|
|
79
|
-
);
|
|
80
|
-
value_map.insert("body".to_string(), Value::Block(body));
|
|
81
|
-
|
|
82
|
-
Statement {
|
|
83
|
-
kind: StatementKind::Group,
|
|
84
|
-
value: Value::Map(value_map),
|
|
85
|
-
indent: current_token.indent,
|
|
86
|
-
line: current_token.line,
|
|
87
|
-
column: current_token.column,
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use crate::core::{
|
|
4
|
-
lexer::token::{Token, TokenKind},
|
|
5
|
-
parser::{
|
|
6
|
-
driver::parser::Parser,
|
|
7
|
-
handler::{dot::parse_dot_token, identifier::synth::parse_synth_token},
|
|
8
|
-
statement::{Statement, StatementKind},
|
|
9
|
-
},
|
|
10
|
-
store::global::GlobalStore,
|
|
11
|
-
};
|
|
12
|
-
use devalang_types::Value;
|
|
13
|
-
|
|
14
|
-
pub fn parse_let_token(
|
|
15
|
-
parser: &mut Parser,
|
|
16
|
-
current_token: Token,
|
|
17
|
-
global_store: &mut GlobalStore,
|
|
18
|
-
) -> Statement {
|
|
19
|
-
parser.advance(); // consume "let"
|
|
20
|
-
|
|
21
|
-
let identifier = if let Some(token) = parser.peek_clone() {
|
|
22
|
-
if token.kind == TokenKind::Identifier {
|
|
23
|
-
parser.advance();
|
|
24
|
-
token.lexeme.clone()
|
|
25
|
-
} else {
|
|
26
|
-
return crate::core::parser::statement::error_from_token(
|
|
27
|
-
token,
|
|
28
|
-
"Expected identifier after 'let'".to_string(),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
return crate::core::parser::statement::error_from_token(
|
|
33
|
-
current_token,
|
|
34
|
-
"Expected identifier after 'let'".to_string(),
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
if !parser.match_token(TokenKind::Equals) {
|
|
39
|
-
return crate::core::parser::statement::error_from_token(
|
|
40
|
-
current_token,
|
|
41
|
-
"Expected '=' after identifier".to_string(),
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// If RHS begins with '$' or contains expression tokens ('+', '-', '*', '/', '(', '['),
|
|
46
|
-
// collect the rest of the line as a raw expression string.
|
|
47
|
-
if let Some(tok) = parser.peek_clone() {
|
|
48
|
-
let line = tok.line;
|
|
49
|
-
if tok.lexeme.starts_with('$')
|
|
50
|
-
|| matches!(
|
|
51
|
-
tok.kind,
|
|
52
|
-
TokenKind::Identifier | TokenKind::Number | TokenKind::LParen | TokenKind::LBracket
|
|
53
|
-
)
|
|
54
|
-
{
|
|
55
|
-
// Collect tokens until end of the current line
|
|
56
|
-
let collected = parser.collect_until(|t| {
|
|
57
|
-
t.line != line || matches!(t.kind, TokenKind::Newline | TokenKind::EOF)
|
|
58
|
-
});
|
|
59
|
-
let mut text = String::new();
|
|
60
|
-
for t in collected.iter() {
|
|
61
|
-
if matches!(t.kind, TokenKind::Newline | TokenKind::EOF) {
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
text.push_str(&t.lexeme);
|
|
65
|
-
}
|
|
66
|
-
return Statement {
|
|
67
|
-
kind: StatementKind::Let { name: identifier },
|
|
68
|
-
value: Value::String(text.trim().to_string()),
|
|
69
|
-
indent: current_token.indent,
|
|
70
|
-
line: current_token.line,
|
|
71
|
-
column: current_token.column,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let value = match parser.peek_clone() {
|
|
77
|
-
Some(token) if token.kind == TokenKind::Dot => {
|
|
78
|
-
let dot_stmt = parse_dot_token(parser, global_store);
|
|
79
|
-
Value::Statement(Box::new(dot_stmt))
|
|
80
|
-
}
|
|
81
|
-
Some(token) if token.kind == TokenKind::Synth => {
|
|
82
|
-
let synth_stmt = parse_synth_token(parser, token.clone(), global_store);
|
|
83
|
-
Value::Statement(Box::new(synth_stmt))
|
|
84
|
-
}
|
|
85
|
-
Some(token) if token.kind == TokenKind::Identifier => {
|
|
86
|
-
parser.advance();
|
|
87
|
-
Value::Identifier(token.lexeme.clone())
|
|
88
|
-
}
|
|
89
|
-
Some(token) if token.kind == TokenKind::String => {
|
|
90
|
-
parser.advance();
|
|
91
|
-
Value::String(token.lexeme.clone())
|
|
92
|
-
}
|
|
93
|
-
Some(token) if token.kind == TokenKind::Number => {
|
|
94
|
-
parser.advance();
|
|
95
|
-
Value::Number(token.lexeme.parse().unwrap_or(0.0))
|
|
96
|
-
}
|
|
97
|
-
Some(token) if token.kind == TokenKind::Boolean => {
|
|
98
|
-
parser.advance();
|
|
99
|
-
Value::Boolean(token.lexeme.parse().unwrap_or(false))
|
|
100
|
-
}
|
|
101
|
-
Some(token) if token.kind == TokenKind::LBrace => {
|
|
102
|
-
parser.advance();
|
|
103
|
-
|
|
104
|
-
let mut map = HashMap::new();
|
|
105
|
-
|
|
106
|
-
while let Some(key_token) = parser.peek_clone() {
|
|
107
|
-
if key_token.kind == TokenKind::RBrace {
|
|
108
|
-
parser.advance(); // consume '}'
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if key_token.kind != TokenKind::Identifier {
|
|
113
|
-
return crate::core::parser::statement::error_from_token(
|
|
114
|
-
token,
|
|
115
|
-
"Expected key identifier in map".to_string(),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
parser.advance();
|
|
119
|
-
let key = key_token.lexeme.clone();
|
|
120
|
-
|
|
121
|
-
if !parser.match_token(TokenKind::Colon) {
|
|
122
|
-
let message = format!("Expected ':' after key '{}'", key);
|
|
123
|
-
return crate::core::parser::statement::error_from_token(token, message);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let val = match parser.peek_clone() {
|
|
127
|
-
Some(t) if t.kind == TokenKind::Number => {
|
|
128
|
-
parser.advance();
|
|
129
|
-
Value::Number(t.lexeme.parse().unwrap_or(0.0))
|
|
130
|
-
}
|
|
131
|
-
Some(t) if t.kind == TokenKind::String => {
|
|
132
|
-
parser.advance();
|
|
133
|
-
Value::String(t.lexeme.clone())
|
|
134
|
-
}
|
|
135
|
-
Some(t) if t.kind == TokenKind::Identifier => {
|
|
136
|
-
parser.advance();
|
|
137
|
-
Value::Identifier(t.lexeme.clone())
|
|
138
|
-
}
|
|
139
|
-
_ => Value::Null,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
if val == Value::Null {
|
|
143
|
-
let message = format!("Invalid value for key '{}'", key);
|
|
144
|
-
return crate::core::parser::statement::error_from_token(token, message);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
map.insert(key, val);
|
|
148
|
-
|
|
149
|
-
if let Some(t) = parser.peek() {
|
|
150
|
-
if t.kind == TokenKind::Comma {
|
|
151
|
-
parser.advance(); // skip comma
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
Value::Map(map)
|
|
157
|
-
}
|
|
158
|
-
_ => {
|
|
159
|
-
return crate::core::parser::statement::error_from_token(
|
|
160
|
-
current_token,
|
|
161
|
-
"Unhandled value type after '='".to_string(),
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
Statement {
|
|
167
|
-
kind: StatementKind::Let { name: identifier },
|
|
168
|
-
value,
|
|
169
|
-
indent: current_token.indent,
|
|
170
|
-
line: current_token.line,
|
|
171
|
-
column: current_token.column,
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
pub mod automate;
|
|
2
|
-
pub mod call;
|
|
3
|
-
pub mod emit;
|
|
4
|
-
pub mod function;
|
|
5
|
-
pub mod group;
|
|
6
|
-
pub mod let_;
|
|
7
|
-
pub mod on;
|
|
8
|
-
pub mod print;
|
|
9
|
-
pub mod sleep;
|
|
10
|
-
pub mod spawn;
|
|
11
|
-
pub mod synth;
|
|
12
|
-
|
|
13
|
-
use crate::core::{
|
|
14
|
-
parser::{
|
|
15
|
-
driver::parser::Parser,
|
|
16
|
-
handler::identifier::{
|
|
17
|
-
automate::parse_automate_token, call::parse_call_token, emit::parse_emit_token,
|
|
18
|
-
group::parse_group_token, let_::parse_let_token, on::parse_on_token,
|
|
19
|
-
print::parse_print_token, sleep::parse_sleep_token, spawn::parse_spawn_token,
|
|
20
|
-
synth::parse_synth_token,
|
|
21
|
-
},
|
|
22
|
-
statement::Statement,
|
|
23
|
-
},
|
|
24
|
-
store::global::GlobalStore,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
pub fn parse_identifier_token(parser: &mut Parser, global_store: &mut GlobalStore) -> Statement {
|
|
28
|
-
let Some(current_token) = parser.peek_clone() else {
|
|
29
|
-
return Statement::unknown();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
let current_token_clone = current_token.clone();
|
|
33
|
-
let current_token_lexeme = current_token_clone.lexeme.clone();
|
|
34
|
-
|
|
35
|
-
match current_token_lexeme.as_str() {
|
|
36
|
-
"let" => parse_let_token(parser, current_token_clone, global_store),
|
|
37
|
-
"group" => parse_group_token(parser, current_token_clone, global_store),
|
|
38
|
-
"call" => parse_call_token(parser, current_token_clone, global_store),
|
|
39
|
-
"spawn" => parse_spawn_token(parser, current_token_clone, global_store),
|
|
40
|
-
"sleep" => parse_sleep_token(parser, current_token_clone, global_store),
|
|
41
|
-
"synth" => parse_synth_token(parser, current_token_clone, global_store),
|
|
42
|
-
"automate" => parse_automate_token(parser, current_token_clone, global_store),
|
|
43
|
-
"print" => parse_print_token(parser, current_token_clone, global_store),
|
|
44
|
-
"on" => parse_on_token(parser, global_store),
|
|
45
|
-
"emit" => parse_emit_token(parser, current_token_clone, global_store),
|
|
46
|
-
_ => {
|
|
47
|
-
parser.advance(); // consume identifier
|
|
48
|
-
|
|
49
|
-
crate::core::parser::statement::error_from_token(
|
|
50
|
-
current_token_clone,
|
|
51
|
-
"Unexpected identifier".to_string(),
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
use devalang_types::Value;
|
|
2
|
-
|
|
3
|
-
use crate::core::{
|
|
4
|
-
lexer::token::TokenKind,
|
|
5
|
-
parser::{
|
|
6
|
-
driver::parser::Parser,
|
|
7
|
-
statement::{Statement, StatementKind},
|
|
8
|
-
},
|
|
9
|
-
store::global::GlobalStore,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
pub fn parse_on_token(parser: &mut Parser, _global_store: &mut GlobalStore) -> Statement {
|
|
13
|
-
// consume 'on'
|
|
14
|
-
let on_tok = match parser.peek_clone() {
|
|
15
|
-
Some(tok) => tok,
|
|
16
|
-
None => return Statement::unknown(),
|
|
17
|
-
};
|
|
18
|
-
parser.advance();
|
|
19
|
-
|
|
20
|
-
// Expect event name identifier
|
|
21
|
-
let event_tok = match parser.peek_clone() {
|
|
22
|
-
Some(tok) if tok.kind == TokenKind::Identifier => tok,
|
|
23
|
-
Some(other) => {
|
|
24
|
-
return crate::core::parser::statement::error_from_token(
|
|
25
|
-
other,
|
|
26
|
-
"Expected event name after 'on'".to_string(),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
None => {
|
|
30
|
-
return crate::core::parser::statement::error_from_token(
|
|
31
|
-
on_tok,
|
|
32
|
-
"Expected event name after 'on'".to_string(),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
let event_name = event_tok.lexeme.clone();
|
|
37
|
-
parser.advance();
|
|
38
|
-
|
|
39
|
-
// Optional parenthesized args on same line
|
|
40
|
-
let mut args: Option<Vec<Value>> = None;
|
|
41
|
-
if parser.peek_kind() == Some(TokenKind::LParen) {
|
|
42
|
-
parser.advance(); // '('
|
|
43
|
-
let mut collected: Vec<Value> = Vec::new();
|
|
44
|
-
// Collect tokens until ')', supporting numbers and identifiers separated by comma
|
|
45
|
-
while let Some(tok) = parser.peek_clone() {
|
|
46
|
-
match tok.kind {
|
|
47
|
-
TokenKind::RParen => {
|
|
48
|
-
parser.advance();
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
TokenKind::Number => {
|
|
52
|
-
parser.advance();
|
|
53
|
-
collected.push(Value::Number(tok.lexeme.parse().unwrap_or(0.0)));
|
|
54
|
-
}
|
|
55
|
-
TokenKind::Identifier => {
|
|
56
|
-
parser.advance();
|
|
57
|
-
collected.push(Value::Identifier(tok.lexeme));
|
|
58
|
-
}
|
|
59
|
-
TokenKind::Comma => {
|
|
60
|
-
parser.advance();
|
|
61
|
-
}
|
|
62
|
-
TokenKind::Whitespace | TokenKind::Newline => {
|
|
63
|
-
parser.advance();
|
|
64
|
-
}
|
|
65
|
-
_ => {
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if !collected.is_empty() {
|
|
71
|
-
args = Some(collected);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Expect ':' then block
|
|
76
|
-
if parser.peek_kind() != Some(TokenKind::Colon) {
|
|
77
|
-
return crate::core::parser::statement::error_from_token(
|
|
78
|
-
event_tok,
|
|
79
|
-
"Expected ':' after event name".to_string(),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
parser.advance(); // consume ':'
|
|
83
|
-
|
|
84
|
-
let base_indent = on_tok.indent;
|
|
85
|
-
let block_tokens = parser.collect_block_tokens(base_indent);
|
|
86
|
-
// Parse body within current store context
|
|
87
|
-
let body = parser.parse_block(block_tokens, _global_store);
|
|
88
|
-
|
|
89
|
-
let stmt = Statement {
|
|
90
|
-
kind: StatementKind::On {
|
|
91
|
-
event: event_name,
|
|
92
|
-
args,
|
|
93
|
-
body,
|
|
94
|
-
},
|
|
95
|
-
value: Value::Null,
|
|
96
|
-
indent: on_tok.indent,
|
|
97
|
-
line: on_tok.line,
|
|
98
|
-
column: on_tok.column,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// Register in global store for later emission
|
|
102
|
-
if let StatementKind::On { event, .. } = &stmt.kind {
|
|
103
|
-
_global_store.register_event_handler(event, stmt.clone());
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
stmt
|
|
107
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
use crate::core::{
|
|
2
|
-
lexer::token::{Token, TokenKind},
|
|
3
|
-
parser::{
|
|
4
|
-
driver::parser::Parser,
|
|
5
|
-
statement::{Statement, StatementKind},
|
|
6
|
-
},
|
|
7
|
-
store::global::GlobalStore,
|
|
8
|
-
};
|
|
9
|
-
use devalang_types::Value;
|
|
10
|
-
|
|
11
|
-
pub fn parse_print_token(
|
|
12
|
-
parser: &mut Parser,
|
|
13
|
-
current_token: Token,
|
|
14
|
-
_global_store: &mut GlobalStore,
|
|
15
|
-
) -> Statement {
|
|
16
|
-
// consume 'print'
|
|
17
|
-
parser.advance();
|
|
18
|
-
|
|
19
|
-
let collected = parser.collect_until(|t| matches!(t.kind, TokenKind::Newline | TokenKind::EOF));
|
|
20
|
-
// Accept: print <identifier|string|number|expression>
|
|
21
|
-
let value = if collected.len() == 1 {
|
|
22
|
-
match collected[0].kind {
|
|
23
|
-
TokenKind::Identifier => Value::Identifier(collected[0].lexeme.clone()),
|
|
24
|
-
TokenKind::String => Value::String(collected[0].lexeme.clone()),
|
|
25
|
-
TokenKind::Number => {
|
|
26
|
-
let n = collected[0].lexeme.parse::<f32>().unwrap_or(0.0);
|
|
27
|
-
Value::Number(n)
|
|
28
|
-
}
|
|
29
|
-
_ => Value::String(collected[0].lexeme.clone()),
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
// Join tokens with spaces to preserve readability for expressions/text
|
|
33
|
-
let text = collected
|
|
34
|
-
.iter()
|
|
35
|
-
.filter(|t| !matches!(t.kind, TokenKind::Newline | TokenKind::EOF))
|
|
36
|
-
.map(|t| t.lexeme.clone())
|
|
37
|
-
.collect::<Vec<_>>()
|
|
38
|
-
.join(" ");
|
|
39
|
-
Value::String(text.trim().to_string())
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
Statement {
|
|
43
|
-
kind: StatementKind::Print,
|
|
44
|
-
value,
|
|
45
|
-
indent: current_token.indent,
|
|
46
|
-
line: current_token.line,
|
|
47
|
-
column: current_token.column,
|
|
48
|
-
}
|
|
49
|
-
}
|