跳转到内容

语法参考

语法的事实来源是 docs/grammar.ebnf。本页总结当前语言表面,不是自动生 成的 parser 清单。

Vela 源文件使用 .vela。一个源文件可以包含 imports、attributes、consts、 VM/extern state declarations、functions、structs、enums、traits 和 impl blocks。

use game::reward as reward
#[event("monster.kill")]
fn on_kill(ctx: Context, player: Player) {
reward::grant(ctx, player, 10);
}

表达式语法覆盖 literals、arrays、maps、typed record literals、field access、indexing、calls、调用表达式后缀 .await、unary/binary operators、 ranges、lambdas、ifmatch 和 blocks。模块函数和脚本方法可以声明为 async fn

赋值目标必须是可赋值目标:identifier、field、index 或 host path proxy。 复合赋值和普通赋值使用相同写入边界。

matchfor binding 使用 patterns。语法支持 wildcard、literal、 binding、path、tuple-variant 和 record-variant patterns。

语法有意排除脚本侧泛型、脚本可见的 task/coroutine handle、手动 resume、 macro expansion、eval、classes、monkey patching 和 Rust-style borrow syntax。异步执行仍然是顺序的:.await 会挂起 async fn 直到调用完成, 但不会暴露脚本级并发。

Type hints 是 metadata contract 和分析输入。它们不会创建泛型类型,也不 会生成 monomorphized script functions。