gdscript_highlighter.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. Dictionary keywords;
  46. Dictionary member_keywords;
  47. enum Type {
  48. NONE,
  49. REGION,
  50. NODE_PATH,
  51. SYMBOL,
  52. NUMBER,
  53. FUNCTION,
  54. KEYWORD,
  55. MEMBER,
  56. IDENTIFIER,
  57. TYPE,
  58. };
  59. // colours
  60. Color font_color;
  61. Color symbol_color;
  62. Color function_color;
  63. Color function_definition_color;
  64. Color built_in_type_color;
  65. Color number_color;
  66. Color member_color;
  67. Color node_path_color;
  68. Color type_color;
  69. void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false);
  70. public:
  71. virtual void _update_cache() override;
  72. virtual Dictionary _get_line_syntax_highlighting(int p_line) override;
  73. virtual String _get_name() const override;
  74. virtual Array _get_supported_languages() const override;
  75. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  76. };
  77. #endif // GDSCRIPT_HIGHLIGHTER_H