Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions runtime/syntax/gdscript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,31 @@ rules:
# Built-in constants
- constant: "\\b(INF|NAN|PI|TAU)\\b"
- constant.bool: "\\b(null|true|false)\\b"
# Function calls
- identifier: "[a-zA-Z_0-9]+\\("
Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
Member

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...

# Built-in functions
- identifier: "\\b(abs|acos|asin|atan|atan2|ceil|clamp|convert|cos|cosh|db2linear|decimals|deg2rad|ease|exp|float|floor|fmod|fposmod|hash|int|isinf|isnan|lerp|linear2db|load|log|max|min|nearest_po2|pow|preload|print|printerr|printraw|prints|printt|rad2deg|rand_range|rand_seed|randomize|randi|randf|range|round|seed|sin|slerp|sqrt|str|str2var|tan|typeof|var2str|weakref)\\b"
# Built-in node names
- identifier: "\\b(AnimationPlayer|AnimationTreePlayer|Button|Control|Engine|HTTPClient|HTTPRequest|Input|InputEvent|MainLoop|Node|Node2D|OS|SceneTree|Spatial|StreamPeer|PacketPeer|PacketPeerUDP|Timer|Tween)\\b"
- identifier: "\\b(abs|acos|asin|atan|atan2|bool|ceil|clamp|convert|cos|cosh|db2linear|decimals|deg2rad|ease|exp|float|floor|fmod|fposmod|hash|int|isinf|isnan|lerp|linear2db|load|log|max|min|nearest_po2|pow|preload|print|printerr|printraw|prints|printt|rad2deg|rand_range|rand_seed|randomize|randi|randf|range|round|seed|sin|slerp|sqrt|str|str2var|tan|typeof|var2str|weakref)\\b"
# Types
- type: "\\b(AABB|Array|Basis|Color|Dictionary|NodePath|Object|Plane|PoolByteArray|PoolColorArray|PoolIntArray|PoolRealArray|PoolVector2Array|PoolVector3Array|Quat|Rect2|RID|String|Transform|Transform2D|Vector2|Vector3)\\b"
- type: "\\b(AABB|Array|Basis|Callable|Color|Dictionary|NodePath|Object|PackedByteArray|PackedColorArray|PackedFloat32Array|PackedFloat64Array|PackedInt32Array|PackedInt64Array|PackedVector2Array|PackedVector3Array|PackedVector4Array|Plane|PoolByteArray|PoolColorArray|PoolIntArray|PoolRealArray|PoolVector2Array|PoolVector3Array|Projection|Quat|Quaternion|Rect2|Rect2i|RID|Signal|String|StringName|Transform|Transform2D|Transform3D|Variant|Vector2|Vector2i|Vector3|Vector3i|Vector4|Vector4i|void)\\b"
# Class names (PascalCase)
- identifier: "\\b([A-Z][a-zA-Z0-9_]*)\\b"
# Constant names (CONSTANT_CASE)
- constant: "\\b([A-Z][A-Z0-9_]*)\\b"
# Definitions
- identifier: "func [a-zA-Z_0-9]+"
- identifier: "func\\s+[a-zA-Z_0-9]+"
# Annotations
- statement.meta: "@[A-Za-z_][A-Za-z0-9_]*\\b"
# Keywords
- statement: "\\b(and|as|assert|break|breakpoint|class|const|continue|elif|else|enum|export|extends|for|func|if|in|is|map|master|mastersync|match|not|onready|or|pass|remote|remotesync|return|self|setget|slave|slavesync|signal|sync|tool|var|while|yield)\\b"
- statement: "\\b(and|as|assert|await|break|breakpoint|class|class_name|const|continue|elif|else|enum|export|extends|for|func|get|if|in|is|map|master|mastersync|match|not|onready|or|pass|remote|remotesync|return|self|set|setget|slave|slavesync|signal|static|super|sync|tool|var|when|while|yield)\\b"
Comment thread
sockeye-d marked this conversation as resolved.

# Operators
- statement: "[.:;,+*|=!\\%@]|<|>|/|-|&"
- statement: "[.:;,+*|=!\\%]|<|>|/|-|&"

# Parentheses
- statement: "[(){}]|\\[|\\]"

# Numbers
- constant: "\\b[0-9]+\\b"
- constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b|'.'"

- comment:
start: "\"\"\""
end: "\"\"\""
rules:
- todo: "(TODO|XXX|FIXME):?"

- comment:
start: "'''"
end: "'''"
rules:
- todo: "(TODO|XXX|FIXME):?"
- constant.number: "-?\\b([0-9]?\\.[0-9]+|[0-9]+|0x[0-9a-fA-F]*)(e-?[0-9]+)?\\b"

- constant.string:
start: "\""
Expand All @@ -54,6 +47,18 @@ rules:
rules:
- constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})"

- constant.string:
start: "\"\"\""
end: "\"\"\""
rules:
- constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})"

- constant.string:
start: "\'\'\'"
end: "\'\'\'"
rules:
- constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})"

- comment:
start: "#"
end: "$"
Expand Down