1package g
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// GDScript lexer.
9var GDScript = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "GDScript",
12		Aliases:   []string{"gdscript", "gd"},
13		Filenames: []string{"*.gd"},
14		MimeTypes: []string{"text/x-gdscript", "application/x-gdscript"},
15	},
16	Rules{
17		"root": {
18			{`\n`, Text, nil},
19			{`^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil},
20			{`^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil},
21			{`[^\S\n]+`, Text, nil},
22			{`#.*$`, CommentSingle, nil},
23			{`[]{}:(),;[]`, Punctuation, nil},
24			{`\\\n`, Text, nil},
25			{`\\`, Text, nil},
26			{`(in|and|or|not)\b`, OperatorWord, nil},
27			{`!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||[-~+/*%=<>&^.!|$]`, Operator, nil},
28			Include("keywords"),
29			{`(def)((?:\s|\\\s)+)`, ByGroups(Keyword, Text), Push("funcname")},
30			{`(class)((?:\s|\\\s)+)`, ByGroups(Keyword, Text), Push("classname")},
31			Include("builtins"),
32			{`([rR]|[uUbB][rR]|[rR][uUbB])(""")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("tdqs")},
33			{`([rR]|[uUbB][rR]|[rR][uUbB])(''')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("tsqs")},
34			{`([rR]|[uUbB][rR]|[rR][uUbB])(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("dqs")},
35			{`([rR]|[uUbB][rR]|[rR][uUbB])(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("sqs")},
36			{`([uUbB]?)(""")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Combined("stringescape", "tdqs")},
37			{`([uUbB]?)(''')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Combined("stringescape", "tsqs")},
38			{`([uUbB]?)(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Combined("stringescape", "dqs")},
39			{`([uUbB]?)(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Combined("stringescape", "sqs")},
40			Include("name"),
41			Include("numbers"),
42		},
43		"keywords": {
44			{Words(``, `\b`,
45				`if`, `elif`, `else`, `for`, `do`,
46				`while`, `switch`, `case`, `break`, `continue`,
47				`pass`, `return`, `class`, `extends`, `tool`,
48				`signal`, `func`, `static`, `const`, `enum`,
49				`var`, `onready`, `export`, `setget`, `breakpoint`), Keyword, nil},
50		},
51		"builtins": {
52			{Words(`(?<!\.)`, `\b`,
53				`Color8`, `ColorN`, `abs`, `acos`, `asin`,
54				`assert`, `atan`, `atan2`, `bytes2var`, `ceil`,
55				`clamp`, `convert`, `cos`, `cosh`, `db2linear`,
56				`decimals`, `dectime`, `deg2rad`, `dict2inst`, `ease`,
57				`exp`, `floor`, `fmod`, `fposmod`, `funcref`,
58				`hash`, `inst2dict`, `instance_from_id`, `is_inf`, `is_nan`,
59				`lerp`, `linear2db`, `load`, `log`, `max`,
60				`min`, `nearest_po2`, `pow`, `preload`, `print`,
61				`print_stack`, `printerr`, `printraw`, `prints`, `printt`,
62				`rad2deg`, `rand_range`, `rand_seed`, `randf`, `randi`,
63				`randomize`, `range`, `round`, `seed`, `sign`,
64				`sin`, `sinh`, `sqrt`, `stepify`, `str`,
65				`str2var`, `tan`, `tanh`, `type_exist`, `typeof`,
66				`var2bytes`, `var2str`, `weakref`, `yield`,
67			), NameBuiltin, nil},
68			{`(?<!\.)(self|false|true|PI|NAN|INF)\b`, NameBuiltinPseudo, nil},
69			{Words(`(?<!\.)`, `\b`,
70				`AABB`, `AcceptDialog`, `AnimatedSprite`, `AnimatedSprite3D`, `Animation`, `AnimationPlayer`, `AnimationTreePlayer`, `Area`, `Area2D`, `Array`, `AtlasTexture`, `AudioServer`, `AudioServerSW`, `AudioStream`, `AudioStreamMPC`, `AudioStreamOGGVorbis`, `AudioStreamOpus`, `AudioStreamPlayback`, `AudioStreamSpeex`, `BackBufferCopy`, `BakedLight`, `BakedLightInstance`, `BakedLightSampler`, `BaseButton`, `BitMap`, `BoneAttachment`, `bool`, `BoxContainer`, `BoxShape`, `Button`, `ButtonArray`, `ButtonGroup`, `Camera`, `Camera2D`, `CanvasItem`, `CanvasItemMaterial`, `CanvasItemShader`, `CanvasItemShaderGraph`, `CanvasLayer`, `CanvasModulate`, `CapsuleShape`, `CapsuleShape2D`, `CenterContainer`, `CheckBox`, `CheckButton`, `CircleShape2D`, `CollisionObject`, `CollisionObject2D`, `CollisionPolygon`, `CollisionPolygon2D`, `CollisionShape`, `CollisionShape2D`, `Color`, `ColorArray`, `ColorPicker`, `ColorPickerButton`, `ColorRamp`, `ConcavePolygonShape`, `ConcavePolygonShape2D`, `ConeTwistJoint`, `ConfigFile`, `ConfirmationDialog`, `Container`, `Control`, `ConvexPolygonShape`, `ConvexPolygonShape2D`, `CubeMap`, `Curve2D`, `Curve3D`, `DampedSpringJoint2D`, `Dictionary`, `DirectionalLight`, `Directory`, `EditorFileDialog`, `EditorImportPlugin`, `EditorPlugin`, `EditorScenePostImport`, `EditorScript`, `Environment`, `EventPlayer`, `EventStream`, `EventStreamChibi`, `File`, `FileDialog`, `FixedMaterial`, `float`, `Font`, `FuncRef`, `GDFunctionState`, `GDNativeClass`, `GDScript`, `Generic6DOFJoint`, `Geometry`, `GeometryInstance`, `Globals`, `GraphEdit`, `GraphNode`, `GridContainer`, `GridMap`, `GrooveJoint2D`, `HBoxContainer`, `HButtonArray`, `HingeJoint`, `HScrollBar`, `HSeparator`, `HSlider`, `HSplitContainer`, `HTTPClient`, `Image`, `ImageTexture`, `ImmediateGeometry`, `Input`, `InputDefault`, `InputEvent`, `InputEventAction`, `InputEventJoystickButton`, `InputEventJoystickMotion`, `InputEventKey`, `InputEventMouseButton`, `InputEventMouseMotion`, `InputEventScreenDrag`, `InputEventScreenTouch`, `InputMap`, `InstancePlaceholder`, `int`, `IntArray`, `InterpolatedCamera`, `IP`, `IP_Unix`, `ItemList`, `Joint`, `Joint2D`, `KinematicBody`, `KinematicBody2D`, `Label`, `LargeTexture`, `Light`, `Light2D`, `LightOccluder2D`, `LineEdit`, `LineShape2D`, `MainLoop`, `MarginContainer`, `Marshalls`, `Material`, `MaterialShader`, `MaterialShaderGraph`, `Matrix3`, `Matrix32`, `MenuButton`, `Mesh`, `MeshDataTool`, `MeshInstance`, `MeshLibrary`, `MultiMesh`, `MultiMeshInstance`, `Mutex`, `Navigation`, `Navigation2D`, `NavigationMesh`, `NavigationMeshInstance`, `NavigationPolygon`, `NavigationPolygonInstance`, `Nil`, `Node`, `Node2D`, `NodePath`, `Object`, `OccluderPolygon2D`, `OmniLight`, `OptionButton`, `OS`, `PackedDataContainer`, `PackedDataContainerRef`, `PackedScene`, `PacketPeer`, `PacketPeerStream`, `PacketPeerUDP`, `Panel`, `PanelContainer`, `ParallaxBackground`, `ParallaxLayer`, `ParticleAttractor2D`, `Particles`, `Particles2D`, `Patch9Frame`, `Path`, `Path2D`, `PathFollow`, `PathFollow2D`, `PathRemap`, `PCKPacker`, `Performance`, `PHashTranslation`, `Physics2DDirectBodyState`, `Physics2DDirectBodyStateSW`, `Physics2DDirectSpaceState`, `Physics2DServer`, `Physics2DServerSW`, `Physics2DShapeQueryParameters`, `Physics2DShapeQueryResult`, `Physics2DTestMotionResult`, `PhysicsBody`, `PhysicsBody2D`, `PhysicsDirectBodyState`, `PhysicsDirectBodyStateSW`, `PhysicsDirectSpaceState`, `PhysicsServer`, `PhysicsServerSW`, `PhysicsShapeQueryParameters`, `PhysicsShapeQueryResult`, `PinJoint`, `PinJoint2D`, `Plane`, `PlaneShape`, `Polygon2D`, `PolygonPathFinder`, `Popup`, `PopupDialog`, `PopupMenu`, `PopupPanel`, `Portal`, `Position2D`, `Position3D`, `ProgressBar`, `ProximityGroup`, `Quad`, `Quat`, `Range`, `RawArray`, `RayCast`, `RayCast2D`, `RayShape`, `RayShape2D`, `RealArray`, `Rect2`, `RectangleShape2D`, `Reference`, `ReferenceFrame`, `RegEx`, `RemoteTransform2D`, `RenderTargetTexture`, `Resource`, `ResourceImportMetadata`, `ResourceInteractiveLoader`, `ResourceLoader`, `ResourcePreloader`, `ResourceSaver`, `RichTextLabel`, `RID`, `RigidBody`, `RigidBody2D`, `Room`, `RoomBounds`, `Sample`, `SampleLibrary`, `SamplePlayer`, `SamplePlayer2D`, `SceneState`, `SceneTree`, `Script`, `ScrollBar`, `ScrollContainer`, `SegmentShape2D`, `Semaphore`, `Separator`, `Shader`, `ShaderGraph`, `ShaderMaterial`, `Shape`, `Shape2D`, `Skeleton`, `Slider`, `SliderJoint`, `SoundPlayer2D`, `SoundRoomParams`, `Spatial`, `SpatialPlayer`, `SpatialSamplePlayer`, `SpatialSound2DServer`, `SpatialSound2DServerSW`, `SpatialSoundServer`, `SpatialSoundServerSW`, `SpatialStreamPlayer`, `SphereShape`, `SpinBox`, `SplitContainer`, `SpotLight`, `Sprite`, `Sprite3D`, `SpriteBase3D`, `SpriteFrames`, `StaticBody`, `StaticBody2D`, `StreamPeer`, `StreamPeerSSL`, `StreamPeerTCP`, `StreamPlayer`, `String`, `StringArray`, `StyleBox`, `StyleBoxEmpty`, `StyleBoxFlat`, `StyleBoxImageMask`, `StyleBoxTexture`, `SurfaceTool`, `TabContainer`, `Tabs`, `TCP_Server`, `TestCube`, `TextEdit`, `Texture`, `TextureButton`, `TextureFrame`, `TextureProgress`, `Theme`, `Thread`, `TileMap`, `TileSet`, `Timer`, `ToolButton`, `TouchScreenButton`, `Transform`, `Translation`, `TranslationServer`, `Tree`, `TreeItem`, `Tween`, `UndoRedo`, `VBoxContainer`, `VButtonArray`, `Vector2`, `Vector2Array`, `Vector3`, `Vector3Array`, `VehicleBody`, `VehicleWheel`, `VideoPlayer`, `VideoStream`, `VideoStreamTheora`, `Viewport`, `ViewportSprite`, `VisibilityEnabler`, `VisibilityEnabler2D`, `VisibilityNotifier`, `VisibilityNotifier2D`, `VisualInstance`, `VisualServer`, `VScrollBar`, `VSeparator`, `VSlider`, `VSplitContainer`, `WeakRef`, `WindowDialog`, `World`, `World2D`, `WorldEnvironment`, `XMLParser`, `YSort`), NameException, nil},
71		},
72		"numbers": {
73			{`(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?`, LiteralNumberFloat, nil},
74			{`\d+[eE][+-]?[0-9]+j?`, LiteralNumberFloat, nil},
75			{`0[xX][a-fA-F0-9]+`, LiteralNumberHex, nil},
76			{`\d+j?`, LiteralNumberInteger, nil},
77		},
78		"name": {
79			{`[a-zA-Z_]\w*`, Name, nil},
80		},
81		"funcname": {
82			{`[a-zA-Z_]\w*`, NameFunction, Pop(1)},
83			Default(Pop(1)),
84		},
85		"classname": {
86			{`[a-zA-Z_]\w*`, NameClass, Pop(1)},
87		},
88		"stringescape": {
89			{`\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})`, LiteralStringEscape, nil},
90		},
91		"strings-single": {
92			{`%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]`, LiteralStringInterpol, nil},
93			{`[^\\\'"%\n]+`, LiteralStringSingle, nil},
94			{`[\'"\\]`, LiteralStringSingle, nil},
95			{`%`, LiteralStringSingle, nil},
96		},
97		"strings-double": {
98			{`%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]`, LiteralStringInterpol, nil},
99			{`[^\\\'"%\n]+`, LiteralStringDouble, nil},
100			{`[\'"\\]`, LiteralStringDouble, nil},
101			{`%`, LiteralStringDouble, nil},
102		},
103		"dqs": {
104			{`"`, LiteralStringDouble, Pop(1)},
105			{`\\\\|\\"|\\\n`, LiteralStringEscape, nil},
106			Include("strings-double"),
107		},
108		"sqs": {
109			{`'`, LiteralStringSingle, Pop(1)},
110			{`\\\\|\\'|\\\n`, LiteralStringEscape, nil},
111			Include("strings-single"),
112		},
113		"tdqs": {
114			{`"""`, LiteralStringDouble, Pop(1)},
115			Include("strings-double"),
116			{`\n`, LiteralStringDouble, nil},
117		},
118		"tsqs": {
119			{`'''`, LiteralStringSingle, Pop(1)},
120			Include("strings-single"),
121			{`\n`, LiteralStringSingle, nil},
122		},
123	},
124))
125