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