gdscript_highlighter.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************/
  2. /* gdscript_highlighter.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. Color color;
  39. String start_key;
  40. String end_key;
  41. bool line_only = false;
  42. };
  43. Vector<ColorRegion> color_regions;
  44. HashMap<int, int> color_region_cache;
  45. HashMap<StringName, Color> keywords;
  46. HashMap<StringName, Color> member_keywords;
  47. enum Type {
  48. NONE,
  49. REGION,
  50. NODE_PATH,
  51. NODE_REF,
  52. ANNOTATION,
  53. STRING_NAME,
  54. SYMBOL,
  55. NUMBER,
  56. FUNCTION,
  57. SIGNAL,
  58. KEYWORD,
  59. MEMBER,
  60. IDENTIFIER,
  61. TYPE,
  62. };
  63. // colours
  64. Color font_color;
  65. Color symbol_color;
  66. Color function_color;
  67. Color function_definition_color;
  68. Color built_in_type_color;
  69. Color number_color;
  70. Color member_color;
  71. Color node_path_color;
  72. Color node_ref_color;
  73. Color annotation_color;
  74. Color string_name_color;
  75. Color type_color;
  76. void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false);
  77. public:
  78. virtual void _update_cache() override;
  79. virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;
  80. virtual String _get_name() const override;
  81. virtual Array _get_supported_languages() const override;
  82. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  83. };
  84. #endif // GDSCRIPT_HIGHLIGHTER_H