gdscript_highlighter.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*************************************************************************/
  2. /* gdscript_highlighter.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. Map<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. ANNOTATION,
  52. SYMBOL,
  53. NUMBER,
  54. FUNCTION,
  55. KEYWORD,
  56. MEMBER,
  57. IDENTIFIER,
  58. TYPE,
  59. };
  60. // colours
  61. Color font_color;
  62. Color symbol_color;
  63. Color function_color;
  64. Color function_definition_color;
  65. Color built_in_type_color;
  66. Color number_color;
  67. Color member_color;
  68. Color node_path_color;
  69. Color annotation_color;
  70. Color type_color;
  71. void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false);
  72. public:
  73. virtual void _update_cache() override;
  74. virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;
  75. virtual String _get_name() const override;
  76. virtual Array _get_supported_languages() const override;
  77. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  78. };
  79. #endif // GDSCRIPT_HIGHLIGHTER_H