syntax_highlighter.cpp 21 KB

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