Debian Codegraph @

modules/gdscript/editor/gdscript_highlighter.h

raw symbols SCIP
1 /**************************************************************************/
2 /* gdscript_highlighter.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "editor/script/script_editor_plugin.h"
34
35 class GDScriptSyntaxHighlighter : public EditorSyntaxHighlighter {
36 GDCLASS(GDScriptSyntaxHighlighter, EditorSyntaxHighlighter)
37
38 private:
39 struct ColorRegion {
40 enum Type {
41 TYPE_NONE,
42 TYPE_STRING, // `"` and `'`, optional prefix `&`, `^`, or `r`.
43 TYPE_MULTILINE_STRING, // `"""` and `'''`, optional prefix `r`.
44 TYPE_COMMENT, // `#` and `##`.
45 TYPE_CODE_REGION, // `#region` and `#endregion`.
46 };
47
48 Type type = TYPE_NONE;
49 Color color;
50 String start_key;
51 String end_key;
52 bool line_only = false;
53 bool r_prefix = false;
54 bool is_string = false; // `TYPE_STRING` or `TYPE_MULTILINE_STRING`.
55 bool is_comment = false; // `TYPE_COMMENT` or `TYPE_CODE_REGION`.
56 };
57 Vector<ColorRegion> color_regions;
58 HashMap<int, int> color_region_cache;
59
60 HashMap<StringName, Color> class_names;
61 HashMap<StringName, Color> reserved_keywords;
62 HashMap<StringName, Color> member_keywords;
63 HashSet<StringName> global_functions;
64
65 enum Type {
66 NONE,
67 REGION,
68 NODE_PATH,
69 NODE_REF,
70 ANNOTATION,
71 STRING_NAME,
72 SYMBOL,
73 NUMBER,
74 FUNCTION,
75 SIGNAL,
76 KEYWORD,
77 MEMBER,
78 IDENTIFIER,
79 TYPE,
80 };
81
82 // Colors.
83 Color font_color;
84 Color symbol_color;
85 Color function_color;
86 Color global_function_color;
87 Color function_definition_color;
88 Color built_in_type_color;
89 Color number_color;
90 Color member_variable_color;
91 Color string_color;
92 Color placeholder_color;
93 Color node_path_color;
94 Color node_ref_color;
95 Color annotation_color;
96 Color string_name_color;
97 Color type_color;
98
99 enum CommentMarkerLevel {
100 COMMENT_MARKER_CRITICAL,
101 COMMENT_MARKER_WARNING,
102 COMMENT_MARKER_NOTICE,
103 COMMENT_MARKER_MAX,
104 };
105 Color comment_marker_colors[COMMENT_MARKER_MAX];
106 HashMap<String, CommentMarkerLevel> comment_markers;
107
108 void add_color_region(ColorRegion::Type p_type, const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false, bool p_r_prefix = false);
109
110 public:
111 virtual void _update_cache() override;
112 virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;
113
114 virtual String _get_name() const override;
115 virtual PackedStringArray _get_supported_languages() const override;
116
117 virtual Ref<EditorSyntaxHighlighter> _create() const override;
118 };