gdscript_highlighter.h 4.5 KB

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