Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
140 stars 1 forks source link

NodePath syntax #53

Closed Mercerenies closed 1 year ago

Mercerenies commented 2 years ago

In GDScript, we can write @"a/b" to construct a NodePath which is pre-parsed. Should we expose this functionality to GDLisp? We could probably use the same exact @ syntax. Currently, @ is only valid in GDLisp followed by a symbol, and it translates to self:, so it wouldn't conflict with existing usage. Alternatively, we could make @" start a string literal of a different kind and just have the lexer deal with it.

On the other hand, in the spirit of not introducing more syntax, we could make an ordinary function NodePath (i.e. very similar to the built-in GDScript one of the same name) and then provide an optimization that can convert it to a string literal if given a literal argument.

Mercerenies commented 1 year ago

Closed by 924afff. We decided to go the route of not introducing more syntax. NodePath is a function in GDLisp whose call magic is capable of converting to the @"..." syntax if given a literal string.

The only downside to this is that call magic applies before optimizations, so if an optimization simplifies a NodePath call into taking a string literal, then it won't get compiled down. We could make an optimization that does the same at a later stage, but I'm not losing much sleep over it.