rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.63k stars 174 forks source link

Object definition syntax #861

Closed VinnyVicious closed 3 months ago

VinnyVicious commented 3 months ago

In order to define an object, Rhai uses #{. Could this be changed to just {? If not, how is the language structured to deal with such syntax customizations?

schungx commented 3 months ago

Not easily, because Rhai uses a recursive-descent parser, which means that the first token must always be deterministic.

Since Rhai allows any statements block as an expression (JavaScript doesn't), so there is no way to easily distinguish whether { is the beginning of a hash literal or the beginning of a statements block.

VinnyVicious commented 3 months ago

Understood, that makes total sense. Thank you for the detailed explanation!