Update GDScript for Godot 4.x #3935
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I don't know if you're still accepting language PRs for v1, but I needed up-to-date GDSCript syntax highlighting, so I made the changes so it is compatible with Godot 4.x (this also removes some Godot 3.x-specific keywords).
Apart from the string and operators regex which I mostly reused as is, I overhauled the entire lexer taking inspiration from Godot's own pygments implementation for its official documentation. The following GDScript features are now available:
@export
and the like).$
and%
shorthands for nodepaths are highlighted asvariable
tokens.INF
,NAN
,PI
andTAU
arebuiltin-number
tokens aliased askeyword
,null
is included inbuiltin-pseudo
along withtrue
andfalse
, which are aliased asboolean
.From my testing, the only thing that does not highlight the way Godot does is class names, where Prism is not able to know they are classes, the rest should work fine.
For reference, here are comparison screenshots with the code in the example html file, in both Godot (using passivestar's theme with the CommitMonoNerd font (bold)) and an appropriately-themed Docusaurus page.
Edit: Closes #3752.