gdscript_highlighter.h 4.4 KB

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