Skip to content

Conversation

@sockeye-d
Copy link

This removes export and related keywords from the list of keywords and adds a new rule for highlighting annotations

@Andriamanitra
Copy link
Contributor

I would rather keep old keywords around because someone could be editing code written for an old Godot version.

@sockeye-d
Copy link
Author

Finally got around to fixing this. I

  • added back the Godot 3 keywords
  • added the rest of Godot 4's Variant types
  • replaced the built-in node name highlighting with a more generic one that just highlights all words that start with an uppercase letter
  • Added a new highlighting rule for CONSTANT_CASE constants

Copy link
Contributor

@Andriamanitra Andriamanitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with two GDScript files I found on Github:

Triple quoted strings are missing handling for escaped characters, and I think it would make sense to make triple quoted strings into strings rather than comments (the documentation no longer mentions triple quoted strings as a way to create comments).

Other than that everything seems to look good.

Copy link
Contributor

@Andriamanitra Andriamanitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The triple quoted string highlighting actually needs to be above single quoted strings or the highlighting will see """x""" as three single quoted strings rather than one triple quoted string. 1 Check with syntax_test_gdscript.gd (it's easier to see what's going on while testing if you temporarily make triple quoted strings different color). You probably also need skip: "\\\\." to pass this test case:

var x = """ \""" """
var y = 123

Footnotes

  1. confusingly this is different than the situation we had earlier where the later rule was being applied on top of an earlier rule, that won't happen with groups with start/end.

@sockeye-d
Copy link
Author

I think this should fix that?

- constant: "\\b(INF|NAN|PI|TAU)\\b"
- constant.bool: "\\b(null|true|false)\\b"
# Function calls
- identifier: "[a-zA-Z_0-9]+\\("
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a function start with a number?
I assume that it is intentional to highlight the opening bracket, but not the closing, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bracket gets its color from statement later anyway so it doesn't matter. It's there just to limit the highlighting to function calls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the opening bracket just gets rehighlighted elsewhere. I couldn't figure out how to get a lookahead working so that was my next best option. I've fixed the function highlighting to check for word boundaries and handle numbers properly

Copy link
Collaborator

@JoeKar JoeKar Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that is not more than an unintended hack.
This should stop working after the highlighter is reworked, in which it builds kind of a tree.
Unless we improve the skip in that way in which it really was intended to work (provide a sort of a look ahead/around).

BTW:
Missed this one - identifier: "func\\s+[a-zA-Z_0-9]+"?

Copy link
Contributor

@Andriamanitra Andriamanitra Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that is not more than an unintended hack.
This should stop working after the highlighter is reworked, in which it builds kind of a tree.
Unless we improve the skip in that way in which it really was intended to work (provide a sort of a look ahead/around).

I'm pretty sure it's an intended hack. It is already in use in other syntaxes 1, some of which have been using it ever since the current highlighting system was introduced in 2fcb40d.

Footnotes

  1. Grepping for \\(" found kvlang, Lua, and PHP, and I'm pretty sure there are others that use the same trick for something slightly different

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, okay...doesn't make the intended rework easier, when rules are intended to overlap. 🤔
Dirty thing...

- constant: "\\b(INF|NAN|PI|TAU)\\b"
- constant.bool: "\\b(null|true|false)\\b"
# Function calls
- identifier: "\\b[a-zA-Z_][a-zA-Z_0-9]+\\("
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not * as in line 21 with [a-zA-Z_][a-zA-Z_0-9]*?
It should follow the same rule for the function name, at least I'd expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants