syntax_highlighter.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*************************************************************************/
  2. /* syntax_highlighter.cpp */
  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. #include "syntax_highlighter.h"
  31. #include "core/object/script_language.h"
  32. #include "scene/gui/text_edit.h"
  33. Dictionary SyntaxHighlighter::get_line_syntax_highlighting(int p_line) {
  34. if (highlighting_cache.has(p_line)) {
  35. return highlighting_cache[p_line];
  36. }
  37. Dictionary color_map;
  38. if (text_edit == nullptr) {
  39. return color_map;
  40. }
  41. if (!GDVIRTUAL_CALL(_get_line_syntax_highlighting, p_line, color_map)) {
  42. color_map = _get_line_syntax_highlighting_impl(p_line);
  43. }
  44. highlighting_cache[p_line] = color_map;
  45. return color_map;
  46. }
  47. void SyntaxHighlighter::_lines_edited_from(int p_from_line, int p_to_line) {
  48. if (highlighting_cache.size() < 1) {
  49. return;
  50. }
  51. int cache_size = highlighting_cache.back()->key();
  52. for (int i = MIN(p_from_line, p_to_line) - 1; i <= cache_size; i++) {
  53. if (highlighting_cache.has(i)) {
  54. highlighting_cache.erase(i);
  55. }
  56. }
  57. }
  58. void SyntaxHighlighter::clear_highlighting_cache() {
  59. highlighting_cache.clear();
  60. if (GDVIRTUAL_CALL(_clear_highlighting_cache)) {
  61. return;
  62. }
  63. _clear_highlighting_cache();
  64. }
  65. void SyntaxHighlighter::update_cache() {
  66. clear_highlighting_cache();
  67. if (text_edit == nullptr) {
  68. return;
  69. }
  70. if (GDVIRTUAL_CALL(_update_cache)) {
  71. return;
  72. }
  73. _update_cache();
  74. }
  75. void SyntaxHighlighter::set_text_edit(TextEdit *p_text_edit) {
  76. if (text_edit && ObjectDB::get_instance(text_edit_instance_id)) {
  77. text_edit->disconnect("lines_edited_from", callable_mp(this, &SyntaxHighlighter::_lines_edited_from));
  78. }
  79. text_edit = p_text_edit;
  80. if (p_text_edit == nullptr) {
  81. return;
  82. }
  83. text_edit_instance_id = text_edit->get_instance_id();
  84. text_edit->connect("lines_edited_from", callable_mp(this, &SyntaxHighlighter::_lines_edited_from));
  85. update_cache();
  86. }
  87. TextEdit *SyntaxHighlighter::get_text_edit() {
  88. return text_edit;
  89. }
  90. void SyntaxHighlighter::_bind_methods() {
  91. ClassDB::bind_method(D_METHOD("get_line_syntax_highlighting", "line"), &SyntaxHighlighter::get_line_syntax_highlighting);
  92. ClassDB::bind_method(D_METHOD("update_cache"), &SyntaxHighlighter::update_cache);
  93. ClassDB::bind_method(D_METHOD("clear_highlighting_cache"), &SyntaxHighlighter::clear_highlighting_cache);
  94. ClassDB::bind_method(D_METHOD("get_text_edit"), &SyntaxHighlighter::get_text_edit);
  95. GDVIRTUAL_BIND(_get_line_syntax_highlighting, "line")
  96. GDVIRTUAL_BIND(_clear_highlighting_cache)
  97. GDVIRTUAL_BIND(_update_cache)
  98. }
  99. ////////////////////////////////////////////////////////////////////////////////
  100. static bool _is_char(char32_t c) {
  101. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
  102. }
  103. static bool _is_hex_symbol(char32_t c) {
  104. return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
  105. }
  106. Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
  107. Dictionary color_map;
  108. bool prev_is_char = false;
  109. bool prev_is_number = false;
  110. bool in_keyword = false;
  111. bool in_word = false;
  112. bool in_function_name = false;
  113. bool in_member_variable = false;
  114. bool is_hex_notation = false;
  115. Color keyword_color;
  116. Color color;
  117. color_region_cache[p_line] = -1;
  118. int in_region = -1;
  119. if (p_line != 0) {
  120. int prev_region_line = p_line - 1;
  121. while (prev_region_line > 0 && !color_region_cache.has(prev_region_line)) {
  122. prev_region_line--;
  123. }
  124. for (int i = prev_region_line; i < p_line - 1; i++) {
  125. get_line_syntax_highlighting(i);
  126. }
  127. if (!color_region_cache.has(p_line - 1)) {
  128. get_line_syntax_highlighting(p_line - 1);
  129. }
  130. in_region = color_region_cache[p_line - 1];
  131. }
  132. const String &str = text_edit->get_line(p_line);
  133. const int line_length = str.length();
  134. Color prev_color;
  135. if (in_region != -1 && str.length() == 0) {
  136. color_region_cache[p_line] = in_region;
  137. }
  138. for (int j = 0; j < line_length; j++) {
  139. Dictionary highlighter_info;
  140. color = font_color;
  141. bool is_char = !is_symbol(str[j]);
  142. bool is_a_symbol = is_symbol(str[j]);
  143. bool is_number = (str[j] >= '0' && str[j] <= '9');
  144. /* color regions */
  145. if (is_a_symbol || in_region != -1) {
  146. int from = j;
  147. for (; from < line_length; from++) {
  148. if (str[from] == '\\') {
  149. from++;
  150. continue;
  151. }
  152. break;
  153. }
  154. if (from != line_length) {
  155. /* check if we are in entering a region */
  156. if (in_region == -1) {
  157. for (int c = 0; c < color_regions.size(); c++) {
  158. /* check there is enough room */
  159. int chars_left = line_length - from;
  160. int start_key_length = color_regions[c].start_key.length();
  161. int end_key_length = color_regions[c].end_key.length();
  162. if (chars_left < start_key_length) {
  163. continue;
  164. }
  165. /* search the line */
  166. bool match = true;
  167. const char32_t *start_key = color_regions[c].start_key.get_data();
  168. for (int k = 0; k < start_key_length; k++) {
  169. if (start_key[k] != str[from + k]) {
  170. match = false;
  171. break;
  172. }
  173. }
  174. if (!match) {
  175. continue;
  176. }
  177. in_region = c;
  178. from += start_key_length;
  179. /* check if it's the whole line */
  180. if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
  181. prev_color = color_regions[in_region].color;
  182. highlighter_info["color"] = color_regions[c].color;
  183. color_map[j] = highlighter_info;
  184. j = line_length;
  185. if (!color_regions[c].line_only) {
  186. color_region_cache[p_line] = c;
  187. }
  188. }
  189. break;
  190. }
  191. if (j == line_length) {
  192. continue;
  193. }
  194. }
  195. /* if we are in one find the end key */
  196. if (in_region != -1) {
  197. /* search the line */
  198. int region_end_index = -1;
  199. int end_key_length = color_regions[in_region].end_key.length();
  200. const char32_t *end_key = color_regions[in_region].end_key.get_data();
  201. for (; from < line_length; from++) {
  202. if (line_length - from < end_key_length) {
  203. break;
  204. }
  205. if (!is_symbol(str[from])) {
  206. continue;
  207. }
  208. if (str[from] == '\\') {
  209. from++;
  210. continue;
  211. }
  212. region_end_index = from;
  213. for (int k = 0; k < end_key_length; k++) {
  214. if (end_key[k] != str[from + k]) {
  215. region_end_index = -1;
  216. break;
  217. }
  218. }
  219. if (region_end_index != -1) {
  220. break;
  221. }
  222. }
  223. prev_color = color_regions[in_region].color;
  224. highlighter_info["color"] = color_regions[in_region].color;
  225. color_map[j] = highlighter_info;
  226. j = from + (end_key_length - 1);
  227. if (region_end_index == -1) {
  228. color_region_cache[p_line] = in_region;
  229. }
  230. in_region = -1;
  231. prev_is_char = false;
  232. prev_is_number = false;
  233. continue;
  234. }
  235. }
  236. }
  237. // Allow ABCDEF in hex notation.
  238. if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) {
  239. is_number = true;
  240. } else {
  241. is_hex_notation = false;
  242. }
  243. // Check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation.
  244. if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'f' || str[j] == 'e') && !in_word && prev_is_number && !is_number) {
  245. is_number = true;
  246. is_a_symbol = false;
  247. is_char = false;
  248. if (str[j] == 'x' && str[j - 1] == '0') {
  249. is_hex_notation = true;
  250. }
  251. }
  252. if (!in_word && _is_char(str[j]) && !is_number) {
  253. in_word = true;
  254. }
  255. if ((in_keyword || in_word) && !is_hex_notation) {
  256. is_number = false;
  257. }
  258. if (is_a_symbol && str[j] != '.' && in_word) {
  259. in_word = false;
  260. }
  261. if (!is_char) {
  262. in_keyword = false;
  263. }
  264. if (!in_keyword && is_char && !prev_is_char) {
  265. int to = j;
  266. while (to < line_length && !is_symbol(str[to])) {
  267. to++;
  268. }
  269. String word = str.substr(j, to - j);
  270. Color col = Color();
  271. if (keywords.has(word)) {
  272. col = keywords[word];
  273. } else if (member_keywords.has(word)) {
  274. col = member_keywords[word];
  275. for (int k = j - 1; k >= 0; k--) {
  276. if (str[k] == '.') {
  277. col = Color(); //member indexing not allowed
  278. break;
  279. } else if (str[k] > 32) {
  280. break;
  281. }
  282. }
  283. }
  284. if (col != Color()) {
  285. in_keyword = true;
  286. keyword_color = col;
  287. }
  288. }
  289. if (!in_function_name && in_word && !in_keyword) {
  290. int k = j;
  291. while (k < line_length && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
  292. k++;
  293. }
  294. // Check for space between name and bracket.
  295. while (k < line_length && (str[k] == '\t' || str[k] == ' ')) {
  296. k++;
  297. }
  298. if (str[k] == '(') {
  299. in_function_name = true;
  300. }
  301. }
  302. if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) {
  303. int k = j;
  304. while (k > 0 && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
  305. k--;
  306. }
  307. if (str[k] == '.') {
  308. in_member_variable = true;
  309. }
  310. }
  311. if (is_a_symbol) {
  312. in_function_name = false;
  313. in_member_variable = false;
  314. }
  315. if (in_keyword) {
  316. color = keyword_color;
  317. } else if (in_member_variable) {
  318. color = member_color;
  319. } else if (in_function_name) {
  320. color = function_color;
  321. } else if (is_a_symbol) {
  322. color = symbol_color;
  323. } else if (is_number) {
  324. color = number_color;
  325. }
  326. prev_is_char = is_char;
  327. prev_is_number = is_number;
  328. if (color != prev_color) {
  329. prev_color = color;
  330. highlighter_info["color"] = color;
  331. color_map[j] = highlighter_info;
  332. }
  333. }
  334. return color_map;
  335. }
  336. void CodeHighlighter::_clear_highlighting_cache() {
  337. color_region_cache.clear();
  338. }
  339. void CodeHighlighter::_update_cache() {
  340. font_color = text_edit->get_theme_color(SNAME("font_color"));
  341. }
  342. void CodeHighlighter::add_keyword_color(const String &p_keyword, const Color &p_color) {
  343. keywords[p_keyword] = p_color;
  344. clear_highlighting_cache();
  345. }
  346. void CodeHighlighter::remove_keyword_color(const String &p_keyword) {
  347. keywords.erase(p_keyword);
  348. clear_highlighting_cache();
  349. }
  350. bool CodeHighlighter::has_keyword_color(const String &p_keyword) const {
  351. return keywords.has(p_keyword);
  352. }
  353. Color CodeHighlighter::get_keyword_color(const String &p_keyword) const {
  354. ERR_FAIL_COND_V(!keywords.has(p_keyword), Color());
  355. return keywords[p_keyword];
  356. }
  357. void CodeHighlighter::set_keyword_colors(const Dictionary p_keywords) {
  358. keywords.clear();
  359. keywords = p_keywords;
  360. clear_highlighting_cache();
  361. }
  362. void CodeHighlighter::clear_keyword_colors() {
  363. keywords.clear();
  364. clear_highlighting_cache();
  365. }
  366. Dictionary CodeHighlighter::get_keyword_colors() const {
  367. return keywords;
  368. }
  369. void CodeHighlighter::add_member_keyword_color(const String &p_member_keyword, const Color &p_color) {
  370. member_keywords[p_member_keyword] = p_color;
  371. clear_highlighting_cache();
  372. }
  373. void CodeHighlighter::remove_member_keyword_color(const String &p_member_keyword) {
  374. member_keywords.erase(p_member_keyword);
  375. clear_highlighting_cache();
  376. }
  377. bool CodeHighlighter::has_member_keyword_color(const String &p_member_keyword) const {
  378. return member_keywords.has(p_member_keyword);
  379. }
  380. Color CodeHighlighter::get_member_keyword_color(const String &p_member_keyword) const {
  381. ERR_FAIL_COND_V(!member_keywords.has(p_member_keyword), Color());
  382. return member_keywords[p_member_keyword];
  383. }
  384. void CodeHighlighter::set_member_keyword_colors(const Dictionary &p_member_keywords) {
  385. member_keywords.clear();
  386. member_keywords = p_member_keywords;
  387. clear_highlighting_cache();
  388. }
  389. void CodeHighlighter::clear_member_keyword_colors() {
  390. member_keywords.clear();
  391. clear_highlighting_cache();
  392. }
  393. Dictionary CodeHighlighter::get_member_keyword_colors() const {
  394. return member_keywords;
  395. }
  396. void CodeHighlighter::add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only) {
  397. for (int i = 0; i < p_start_key.length(); i++) {
  398. ERR_FAIL_COND_MSG(!is_symbol(p_start_key[i]), "color regions must start with a symbol");
  399. }
  400. if (p_end_key.length() > 0) {
  401. for (int i = 0; i < p_end_key.length(); i++) {
  402. ERR_FAIL_COND_MSG(!is_symbol(p_end_key[i]), "color regions must end with a symbol");
  403. }
  404. }
  405. int at = 0;
  406. for (int i = 0; i < color_regions.size(); i++) {
  407. ERR_FAIL_COND_MSG(color_regions[i].start_key == p_start_key, "color region with start key '" + p_start_key + "' already exists.");
  408. if (p_start_key.length() < color_regions[i].start_key.length()) {
  409. at++;
  410. }
  411. }
  412. ColorRegion color_region;
  413. color_region.color = p_color;
  414. color_region.start_key = p_start_key;
  415. color_region.end_key = p_end_key;
  416. color_region.line_only = p_line_only || p_end_key == "";
  417. color_regions.insert(at, color_region);
  418. clear_highlighting_cache();
  419. }
  420. void CodeHighlighter::remove_color_region(const String &p_start_key) {
  421. for (int i = 0; i < color_regions.size(); i++) {
  422. if (color_regions[i].start_key == p_start_key) {
  423. color_regions.remove(i);
  424. break;
  425. }
  426. }
  427. clear_highlighting_cache();
  428. }
  429. bool CodeHighlighter::has_color_region(const String &p_start_key) const {
  430. for (int i = 0; i < color_regions.size(); i++) {
  431. if (color_regions[i].start_key == p_start_key) {
  432. return true;
  433. }
  434. }
  435. return false;
  436. }
  437. void CodeHighlighter::set_color_regions(const Dictionary &p_color_regions) {
  438. color_regions.clear();
  439. List<Variant> keys;
  440. p_color_regions.get_key_list(&keys);
  441. for (const Variant &E : keys) {
  442. String key = E;
  443. String start_key = key.get_slice(" ", 0);
  444. String end_key = key.get_slice_count(" ") > 1 ? key.get_slice(" ", 1) : String();
  445. add_color_region(start_key, end_key, p_color_regions[key], end_key == "");
  446. }
  447. clear_highlighting_cache();
  448. }
  449. void CodeHighlighter::clear_color_regions() {
  450. color_regions.clear();
  451. clear_highlighting_cache();
  452. }
  453. Dictionary CodeHighlighter::get_color_regions() const {
  454. Dictionary r_color_regions;
  455. for (int i = 0; i < color_regions.size(); i++) {
  456. ColorRegion region = color_regions[i];
  457. r_color_regions[region.start_key + (region.end_key.is_empty() ? "" : " " + region.end_key)] = region.color;
  458. }
  459. return r_color_regions;
  460. }
  461. void CodeHighlighter::_bind_methods() {
  462. ClassDB::bind_method(D_METHOD("add_keyword_color", "keyword", "color"), &CodeHighlighter::add_keyword_color);
  463. ClassDB::bind_method(D_METHOD("remove_keyword_color", "keyword"), &CodeHighlighter::remove_keyword_color);
  464. ClassDB::bind_method(D_METHOD("has_keyword_color", "keyword"), &CodeHighlighter::has_keyword_color);
  465. ClassDB::bind_method(D_METHOD("get_keyword_color", "keyword"), &CodeHighlighter::get_keyword_color);
  466. ClassDB::bind_method(D_METHOD("set_keyword_colors", "keywords"), &CodeHighlighter::set_keyword_colors);
  467. ClassDB::bind_method(D_METHOD("clear_keyword_colors"), &CodeHighlighter::clear_keyword_colors);
  468. ClassDB::bind_method(D_METHOD("get_keyword_colors"), &CodeHighlighter::get_keyword_colors);
  469. ClassDB::bind_method(D_METHOD("add_member_keyword_color", "member_keyword", "color"), &CodeHighlighter::add_member_keyword_color);
  470. ClassDB::bind_method(D_METHOD("remove_member_keyword_color", "member_keyword"), &CodeHighlighter::remove_member_keyword_color);
  471. ClassDB::bind_method(D_METHOD("has_member_keyword_color", "member_keyword"), &CodeHighlighter::has_member_keyword_color);
  472. ClassDB::bind_method(D_METHOD("get_member_keyword_color", "member_keyword"), &CodeHighlighter::get_member_keyword_color);
  473. ClassDB::bind_method(D_METHOD("set_member_keyword_colors", "member_keyword"), &CodeHighlighter::set_member_keyword_colors);
  474. ClassDB::bind_method(D_METHOD("clear_member_keyword_colors"), &CodeHighlighter::clear_member_keyword_colors);
  475. ClassDB::bind_method(D_METHOD("get_member_keyword_colors"), &CodeHighlighter::get_member_keyword_colors);
  476. ClassDB::bind_method(D_METHOD("add_color_region", "start_key", "end_key", "color", "line_only"), &CodeHighlighter::add_color_region, DEFVAL(false));
  477. ClassDB::bind_method(D_METHOD("remove_color_region", "start_key"), &CodeHighlighter::remove_color_region);
  478. ClassDB::bind_method(D_METHOD("has_color_region", "start_key"), &CodeHighlighter::has_color_region);
  479. ClassDB::bind_method(D_METHOD("set_color_regions", "color_regions"), &CodeHighlighter::set_color_regions);
  480. ClassDB::bind_method(D_METHOD("clear_color_regions"), &CodeHighlighter::clear_color_regions);
  481. ClassDB::bind_method(D_METHOD("get_color_regions"), &CodeHighlighter::get_color_regions);
  482. ClassDB::bind_method(D_METHOD("set_function_color", "color"), &CodeHighlighter::set_function_color);
  483. ClassDB::bind_method(D_METHOD("get_function_color"), &CodeHighlighter::get_function_color);
  484. ClassDB::bind_method(D_METHOD("set_number_color", "color"), &CodeHighlighter::set_number_color);
  485. ClassDB::bind_method(D_METHOD("get_number_color"), &CodeHighlighter::get_number_color);
  486. ClassDB::bind_method(D_METHOD("set_symbol_color", "color"), &CodeHighlighter::set_symbol_color);
  487. ClassDB::bind_method(D_METHOD("get_symbol_color"), &CodeHighlighter::get_symbol_color);
  488. ClassDB::bind_method(D_METHOD("set_member_variable_color", "color"), &CodeHighlighter::set_member_variable_color);
  489. ClassDB::bind_method(D_METHOD("get_member_variable_color"), &CodeHighlighter::get_member_variable_color);
  490. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "number_color"), "set_number_color", "get_number_color");
  491. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "symbol_color"), "set_symbol_color", "get_symbol_color");
  492. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "function_color"), "set_function_color", "get_function_color");
  493. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "member_variable_color"), "set_member_variable_color", "get_member_variable_color");
  494. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "keyword_colors"), "set_keyword_colors", "get_keyword_colors");
  495. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "member_keyword_colors"), "set_member_keyword_colors", "get_member_keyword_colors");
  496. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "color_regions"), "set_color_regions", "get_color_regions");
  497. }
  498. void CodeHighlighter::set_number_color(Color p_color) {
  499. number_color = p_color;
  500. clear_highlighting_cache();
  501. }
  502. Color CodeHighlighter::get_number_color() const {
  503. return number_color;
  504. }
  505. void CodeHighlighter::set_symbol_color(Color p_color) {
  506. symbol_color = p_color;
  507. clear_highlighting_cache();
  508. }
  509. Color CodeHighlighter::get_symbol_color() const {
  510. return symbol_color;
  511. }
  512. void CodeHighlighter::set_function_color(Color p_color) {
  513. function_color = p_color;
  514. clear_highlighting_cache();
  515. }
  516. Color CodeHighlighter::get_function_color() const {
  517. return function_color;
  518. }
  519. void CodeHighlighter::set_member_variable_color(Color p_color) {
  520. member_color = p_color;
  521. clear_highlighting_cache();
  522. }
  523. Color CodeHighlighter::get_member_variable_color() const {
  524. return member_color;
  525. }