...

Source file src/github.com/alecthomas/chroma/lexers/g/gdscript.go

Documentation: github.com/alecthomas/chroma/lexers/g

     1  package g
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // GDScript lexer.
     9  var GDScript = internal.Register(MustNewLazyLexer(
    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  	gdscriptRules,
    17  ))
    18  
    19  func gdscriptRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`\n`, Text, nil},
    23  			{`^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil},
    24  			{`^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil},
    25  			{`[^\S\n]+`, Text, nil},
    26  			{`#.*$`, CommentSingle, nil},
    27  			{`[]{}:(),;[]`, Punctuation, nil},
    28  			{`\\\n`, Text, nil},
    29  			{`\\`, Text, nil},
    30  			{`(in|and|or|not)\b`, OperatorWord, nil},
    31  			{`!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||[-~+/*%=<>&^.!|$]`, Operator, nil},
    32  			Include("keywords"),
    33  			{`(def)((?:\s|\\\s)+)`, ByGroups(Keyword, Text), Push("funcname")},
    34  			{`(class)((?:\s|\\\s)+)`, ByGroups(Keyword, Text), Push("classname")},
    35  			Include("builtins"),
    36  			{`([rR]|[uUbB][rR]|[rR][uUbB])(""")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("tdqs")},
    37  			{`([rR]|[uUbB][rR]|[rR][uUbB])(''')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("tsqs")},
    38  			{`([rR]|[uUbB][rR]|[rR][uUbB])(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("dqs")},
    39  			{`([rR]|[uUbB][rR]|[rR][uUbB])(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("sqs")},
    40  			{`([uUbB]?)(""")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Combined("stringescape", "tdqs")},
    41  			{`([uUbB]?)(''')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Combined("stringescape", "tsqs")},
    42  			{`([uUbB]?)(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Combined("stringescape", "dqs")},
    43  			{`([uUbB]?)(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Combined("stringescape", "sqs")},
    44  			Include("name"),
    45  			Include("numbers"),
    46  		},
    47  		"keywords": {
    48  			{Words(``, `\b`,
    49  				`if`, `elif`, `else`, `for`, `do`,
    50  				`while`, `switch`, `case`, `break`, `continue`,
    51  				`pass`, `return`, `class`, `extends`, `tool`,
    52  				`signal`, `func`, `static`, `const`, `enum`,
    53  				`var`, `onready`, `export`, `setget`, `breakpoint`), Keyword, nil},
    54  		},
    55  		"builtins": {
    56  			{Words(`(?<!\.)`, `\b`,
    57  				`Color8`, `ColorN`, `abs`, `acos`, `asin`,
    58  				`assert`, `atan`, `atan2`, `bytes2var`, `ceil`,
    59  				`clamp`, `convert`, `cos`, `cosh`, `db2linear`,
    60  				`decimals`, `dectime`, `deg2rad`, `dict2inst`, `ease`,
    61  				`exp`, `floor`, `fmod`, `fposmod`, `funcref`,
    62  				`hash`, `inst2dict`, `instance_from_id`, `is_inf`, `is_nan`,
    63  				`lerp`, `linear2db`, `load`, `log`, `max`,
    64  				`min`, `nearest_po2`, `pow`, `preload`, `print`,
    65  				`print_stack`, `printerr`, `printraw`, `prints`, `printt`,
    66  				`rad2deg`, `rand_range`, `rand_seed`, `randf`, `randi`,
    67  				`randomize`, `range`, `round`, `seed`, `sign`,
    68  				`sin`, `sinh`, `sqrt`, `stepify`, `str`,
    69  				`str2var`, `tan`, `tanh`, `type_exist`, `typeof`,
    70  				`var2bytes`, `var2str`, `weakref`, `yield`,
    71  			), NameBuiltin, nil},
    72  			{`(?<!\.)(self|false|true|PI|NAN|INF)\b`, NameBuiltinPseudo, nil},
    73  			{Words(`(?<!\.)`, `\b`,
    74  				`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},
    75  		},
    76  		"numbers": {
    77  			{`(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?`, LiteralNumberFloat, nil},
    78  			{`\d+[eE][+-]?[0-9]+j?`, LiteralNumberFloat, nil},
    79  			{`0[xX][a-fA-F0-9]+`, LiteralNumberHex, nil},
    80  			{`\d+j?`, LiteralNumberInteger, nil},
    81  		},
    82  		"name": {
    83  			{`[a-zA-Z_]\w*`, Name, nil},
    84  		},
    85  		"funcname": {
    86  			{`[a-zA-Z_]\w*`, NameFunction, Pop(1)},
    87  			Default(Pop(1)),
    88  		},
    89  		"classname": {
    90  			{`[a-zA-Z_]\w*`, NameClass, Pop(1)},
    91  		},
    92  		"stringescape": {
    93  			{`\\([\\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},
    94  		},
    95  		"strings-single": {
    96  			{`%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]`, LiteralStringInterpol, nil},
    97  			{`[^\\\'"%\n]+`, LiteralStringSingle, nil},
    98  			{`[\'"\\]`, LiteralStringSingle, nil},
    99  			{`%`, LiteralStringSingle, nil},
   100  		},
   101  		"strings-double": {
   102  			{`%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]`, LiteralStringInterpol, nil},
   103  			{`[^\\\'"%\n]+`, LiteralStringDouble, nil},
   104  			{`[\'"\\]`, LiteralStringDouble, nil},
   105  			{`%`, LiteralStringDouble, nil},
   106  		},
   107  		"dqs": {
   108  			{`"`, LiteralStringDouble, Pop(1)},
   109  			{`\\\\|\\"|\\\n`, LiteralStringEscape, nil},
   110  			Include("strings-double"),
   111  		},
   112  		"sqs": {
   113  			{`'`, LiteralStringSingle, Pop(1)},
   114  			{`\\\\|\\'|\\\n`, LiteralStringEscape, nil},
   115  			Include("strings-single"),
   116  		},
   117  		"tdqs": {
   118  			{`"""`, LiteralStringDouble, Pop(1)},
   119  			Include("strings-double"),
   120  			{`\n`, LiteralStringDouble, nil},
   121  		},
   122  		"tsqs": {
   123  			{`'''`, LiteralStringSingle, Pop(1)},
   124  			Include("strings-single"),
   125  			{`\n`, LiteralStringSingle, nil},
   126  		},
   127  	}
   128  }
   129  

View as plain text