syntax_highlighter.cpp 21 KB

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