godot
godot copied to clipboard
Fix highlighting of binary `%`, `&` and `^` and unary `+` and `-`
Used the Godot 2 theme below to highlight the fix with highlighting unary - and +:
| Before | After |
|---|---|
![]() |
![]() |
Bonus: Replaced instances of str.length() with line_length throughout the highlighter for consistency, also moved the StringName and NodePath logic next to each other (as it's ~identical)
Fixes #61646
Implements most of https://github.com/godotengine/godot-proposals/issues/4874
Supersedes PR #63044 (It only had the % highlighting fix)
Realized today this PR would put some highlighting bugs in the spotlight, even though it doesn't introduce them.

Ligatures are colored like their last character, and we already have a problematic case with ]# and <$. This PR introduces quite a few new problems. These ligatures aren't relevant to GDScript and should probably be broken up anyway. See https://github.com/godotengine/godot/issues/63605#issuecomment-1199105222
&& is a ligature and a binary op. Currently it's highlighted pink-white, which makes the ligature highlighted in white. With the PR it's colored white-pink, which makes the ligature colored in pink.
Figured out a good (in my opinion) fix to the second issue without using the tokenizer.

Added ~ to the rule since it's also a mathematical unary operator.
Caught up highlighting to handle all proper syntax around & and ^ without spacing. To the two people who would ever use such horrible syntax...

It's highlighted properly now! You're welcome.
In handling all these cases, the implementation became a bit messy, so I'm looking forward to a review.
Thank you and congrats on your first contribution to Godot Engine's source! 🎉

