ClueLang / Clue

C/Rust like programming language that compiles into Lua code
https://crates.io/crates/clue
MIT License
340 stars 15 forks source link

Make parentheses optional for function calls with single parameter string/table #139

Open Lyrth opened 10 months ago

Lyrth commented 10 months ago

Lua supports function calls without parentheses for specific kinds of literals:

-- equivalent to my_func("str")
local a = my_func "str"

-- equivalent to other_func({1, 2})
local b = other_func {1, 2}

Clue could support no-parentheses string calls just fine, and could probably make it work with special strings too (like raw). Although, the table param call will be problematic since code blocks also use { }.

On the other hand, method calls (class::method()) could support single table params as the call can't be confused with a expression + block combination. Slightly useful for class-related structures:

local p = Vec3::new { -4, 2.2, 0 }
Maiori44 commented 10 months ago

calls without () for strings would be fine, but {} could easily get ambiguous so I'm not sure if it's even possible even if methods wouldn't have this issue, I'd rather not have it work with just methods