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#ifndef GDSCRIPT_HIGHLIGHTER_H
32#define GDSCRIPT_HIGHLIGHTER_H
33
34#include "editor/plugins/script_editor_plugin.h"
35#include "scene/gui/text_edit.h"
36
37class GDScriptSyntaxHighlighter : public EditorSyntaxHighlighter {
38 GDCLASS(GDScriptSyntaxHighlighter, EditorSyntaxHighlighter)
39
40private:
41 struct ColorRegion {
42 Color color;
43 String start_key;
44 String end_key;
45 bool line_only = false;
46 };
47 Vector<ColorRegion> color_regions;
48 HashMap<int, int> color_region_cache;
49
50 HashMap<StringName, Color> class_names;
51 HashMap<StringName, Color> reserved_keywords;
52 HashMap<StringName, Color> member_keywords;
53 HashSet<StringName> global_functions;
54
55 enum Type {
56 NONE,
57 REGION,
58 NODE_PATH,
59 NODE_REF,
60 ANNOTATION,
61 STRING_NAME,
62 SYMBOL,
63 NUMBER,
64 FUNCTION,
65 SIGNAL,
66 KEYWORD,
67 MEMBER,
68 IDENTIFIER,
69 TYPE,
70 };
71
72 // Colors.
73 Color font_color;
74 Color symbol_color;
75 Color function_color;
76 Color global_function_color;
77 Color function_definition_color;
78 Color built_in_type_color;
79 Color number_color;
80 Color member_color;
81 Color node_path_color;
82 Color node_ref_color;
83 Color annotation_color;
84 Color string_name_color;
85 Color type_color;
86
87 enum CommentMarkerLevel {
88 COMMENT_MARKER_CRITICAL,
89 COMMENT_MARKER_WARNING,
90 COMMENT_MARKER_NOTICE,
91 COMMENT_MARKER_MAX,
92 };
93 Color comment_marker_colors[COMMENT_MARKER_MAX];
94 HashMap<String, CommentMarkerLevel> comment_markers;
95
96 void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false);
97
98public:
99 virtual void _update_cache() override;
100 virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;
101
102 virtual String _get_name() const override;
103 virtual PackedStringArray _get_supported_languages() const override;
104
105 virtual Ref<EditorSyntaxHighlighter> _create() const override;
106};
107
108#endif // GDSCRIPT_HIGHLIGHTER_H
109