godot-gdscript-toolkit
godot-gdscript-toolkit copied to clipboard
Casting a parenthetical expr trips up the grammar
In the following code gdformat fails to parse:
var segments: int = (int)(abs_normalized / 22.5)
The output is as follows:
./Scripts/Utils.gd:
var segments: int = (int) (abs_normalized / 22.5)
^
Unexpected token Token('LPAR', '(') at line 13, column 29.
Expected one of:
* IN
* "-="
* "+="
* AMPERSAND
* ">>="
* AS
* "=="
* EQUAL
* _NL
* "|="
* "*="
* LESSTHAN
* VBAR
* AND
* ">="
* MINUS
* PLUS
* "**"
* SLASH
* DOT
* OR
* "!="
* SEMICOLON
* "&="
* LSQB
* ">>"
* STAR
* "||"
* NOT
* PERCENT
* "<="
* "<<="
* _DEDENT
* IS
* "/="
* "&&"
* "**="
* "%="
* MORETHAN
* "<<"
* IF
* "^="
* CIRCUMFLEX
Previous tokens: [Token('RPAR', ')')]
This is not implemented currently - either it's a relatively new syntax or it was overlooked.
Thanks for the quick triage -- I actually came to say that I have no idea what's going on 😀.
My background is pretty deep but distinctly not-gdscript so I thought (type)(expr) was valid and my project was working when run. At some point godot cleared a cache though and I started getting weird errors that I traced back to (plausibly) this being invalid grammar / not parsing.
Per https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#casting x as y seems to be the only valid cast syntax so I'm going to preemptively close this and be somewhat confused at what was going on yesterday.
To me it looks like that syntax works in Godot. Anyway - I'll reopen this issue and do deep analysis of Godot behavior in that case.
I've confirmed this syntax is not supported in Godot 4.