diff options
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 26 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_format.h | 29 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_format_osl.c | 42 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_format_py.c | 44 |
4 files changed, 76 insertions, 65 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 01df223630a..01adf6a4107 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -117,33 +117,33 @@ static void txt_format_text(SpaceText *st) static void format_draw_color(char formatchar) { switch (formatchar) { - case '_': /* Whitespace */ + case FMT_TYPE_WHITESPACE: break; - case '!': /* Symbols */ + case FMT_TYPE_SYMBOL: UI_ThemeColorBlend(TH_TEXT, TH_BACK, 0.5f); break; - case '#': /* Comments */ + case FMT_TYPE_COMMENT: UI_ThemeColor(TH_SYNTAX_C); break; - case 'n': /* Numerals */ + case FMT_TYPE_NUMERAL: UI_ThemeColor(TH_SYNTAX_N); break; - case 'l': /* Strings */ + case FMT_TYPE_STRING: UI_ThemeColor(TH_SYNTAX_L); break; - case 'd': /* Preprocessor directive */ + case FMT_TYPE_DIRECTIVE: UI_ThemeColor(TH_SYNTAX_D); break; - case 'v': /* Specials: class, def */ + case FMT_TYPE_SPECIAL: UI_ThemeColor(TH_SYNTAX_V); break; - case 'r': /* Reserved keywords */ + case FMT_TYPE_RESERVED: UI_ThemeColor(TH_SYNTAX_R); break; - case 'b': /* Keywords: for, print, etc. */ + case FMT_TYPE_KEYWORD: UI_ThemeColor(TH_SYNTAX_B); break; - case 'q': /* Other text (identifiers) */ + case FMT_TYPE_DEFAULT: default: UI_ThemeColor(TH_TEXT); break; @@ -1174,7 +1174,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar) stack = 0; /* Don't highlight backets if syntax HL is off or bracket in string or comment. */ - if (!linep->format || linep->format[fc] == 'l' || linep->format[fc] == '#') + if (!linep->format || linep->format[fc] == FMT_TYPE_STRING || linep->format[fc] == FMT_TYPE_COMMENT) return; if (b > 0) { @@ -1183,7 +1183,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar) c += BLI_str_utf8_size_safe(linep->line + c); while (linep) { while (c < linep->len) { - if (linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') { + if (linep->format && linep->format[fc] != FMT_TYPE_STRING && linep->format[fc] != FMT_TYPE_COMMENT) { b = text_check_bracket(linep->line[c]); if (b == find) { if (stack == 0) { @@ -1212,7 +1212,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar) if (c > 0) c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c); while (linep) { while (fc >= 0) { - if (linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') { + if (linep->format && linep->format[fc] != FMT_TYPE_STRING && linep->format[fc] != FMT_TYPE_COMMENT) { b = text_check_bracket(linep->line[c]); if (b == find) { if (stack == 0) { diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h index e5c3db4f121..99cd20149cf 100644 --- a/source/blender/editors/space_text/text_format.h +++ b/source/blender/editors/space_text/text_format.h @@ -69,23 +69,30 @@ typedef struct TextFormatType { /* Formats the specified line. If do_next is set, the process will move on to * the succeeding line if it is affected (eg. multiline strings). Format strings * may contain any of the following characters: - * '_' Whitespace - * '#' Comment text - * '!' Punctuation and other symbols - * 'n' Numerals - * 'l' String letters - * 'd' Decorator / Preprocessor directive - * 'v' Special variables (class, def) - * 'r' Reserved keywords currently not in use, but still prohibited (OSL -> switch e.g.) - * 'b' Built-in names (print, for, etc.) - * 'q' Other text (identifiers, etc.) + * * It is terminated with a null-terminator '\0' followed by a continuation - * flag indicating whether the line is part of a multi-line string. */ + * flag indicating whether the line is part of a multi-line string. + * + * See: FMT_TYPE_ enums below + */ void (*format_line)(SpaceText *st, TextLine *line, int do_next); const char **ext; /* NULL terminated extensions */ } TextFormatType; +enum { + FMT_TYPE_WHITESPACE = '_', /* Whitespace */ + FMT_TYPE_COMMENT = '#', /* Comment text */ + FMT_TYPE_SYMBOL = '!', /* Punctuation and other symbols */ + FMT_TYPE_NUMERAL = 'n', /* Numerals */ + FMT_TYPE_STRING = 'l', /* String letters */ + FMT_TYPE_DIRECTIVE = 'd', /* Decorator / Preprocessor directive */ + FMT_TYPE_SPECIAL = 'v', /* Special variables (class, def) */ + FMT_TYPE_RESERVED = 'r', /* Reserved keywords currently not in use, but still prohibited (OSL -> switch e.g.) */ + FMT_TYPE_KEYWORD = 'b', /* Built-in names (return, for, etc.) */ + FMT_TYPE_DEFAULT = 'q', /* Regular text (identifiers, etc.) */ +}; + TextFormatType *ED_text_format_get(Text *text); void ED_text_format_register(TextFormatType *tft); diff --git a/source/blender/editors/space_text/text_format_osl.c b/source/blender/editors/space_text/text_format_osl.c index 3896daf9809..433ff0a035b 100644 --- a/source/blender/editors/space_text/text_format_osl.c +++ b/source/blender/editors/space_text/text_format_osl.c @@ -232,23 +232,23 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n else if (cont) { /* C-Style comments */ if (cont & FMT_CONT_COMMENT_CXX) { - *fmt = '#'; + *fmt = FMT_TYPE_COMMENT; } else if (cont & FMT_CONT_COMMENT_C) { if (*str == '*' && *(str + 1) == '/') { - *fmt = '#'; fmt++; str++; - *fmt = '#'; + *fmt = FMT_TYPE_COMMENT; fmt++; str++; + *fmt = FMT_TYPE_COMMENT; cont = FMT_CONT_NOP; } else { - *fmt = '#'; + *fmt = FMT_TYPE_COMMENT; } /* Handle other comments */ } else { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; if (*str == find) cont = 0; - *fmt = 'l'; + *fmt = FMT_TYPE_STRING; } str += BLI_str_utf8_size_safe(str) - 1; @@ -258,44 +258,46 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n /* Deal with comments first */ if (*str == '/' && *(str + 1) == '/') { cont = FMT_CONT_COMMENT_CXX; - *fmt = '#'; + *fmt = FMT_TYPE_COMMENT; } /* C-Style (multi-line) comments */ else if (*str == '/' && *(str + 1) == '*') { cont = FMT_CONT_COMMENT_C; - *fmt = '#'; fmt++; str++; - *fmt = '#'; + *fmt = FMT_TYPE_COMMENT; fmt++; str++; + *fmt = FMT_TYPE_COMMENT; } else if (*str == '"' || *str == '\'') { /* Strings */ find = *str; cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE; - *fmt = 'l'; + *fmt = FMT_TYPE_STRING; } /* Whitespace (all ws. has been converted to spaces) */ else if (*str == ' ') { - *fmt = '_'; + *fmt = FMT_TYPE_WHITESPACE; } /* Numbers (digits not part of an identifier and periods followed by digits) */ - else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) { - *fmt = 'n'; + else if ((prev != FMT_TYPE_DEFAULT && text_check_digit(*str)) || + (*str == '.' && text_check_digit(*(str + 1)))) + { + *fmt = FMT_TYPE_NUMERAL; } /* Punctuation */ else if ((*str != '#') && text_check_delim(*str)) { - *fmt = '!'; + *fmt = FMT_TYPE_SYMBOL; } /* Identifiers and other text (no previous ws. or delims. so text continues) */ - else if (prev == 'q') { + else if (prev == FMT_TYPE_DEFAULT) { str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; + *fmt = FMT_TYPE_DEFAULT; } /* Not ws, a digit, punct, or continuing text. Must be new, check for special words */ else { /* Special vars(v) or built-in keywords(b) */ - if ((i = txtfmt_osl_find_specialvar(str)) != -1) prev = 'v'; - else if ((i = txtfmt_osl_find_builtinfunc(str)) != -1) prev = 'b'; - else if ((i = txtfmt_osl_find_reserved(str)) != -1) prev = 'r'; - else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = 'd'; + if ((i = txtfmt_osl_find_specialvar(str)) != -1) prev = FMT_TYPE_SPECIAL; + else if ((i = txtfmt_osl_find_builtinfunc(str)) != -1) prev = FMT_TYPE_KEYWORD; + else if ((i = txtfmt_osl_find_reserved(str)) != -1) prev = FMT_TYPE_RESERVED; + else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = FMT_TYPE_DIRECTIVE; if (i > 0) { memset(fmt, prev, i); @@ -303,7 +305,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n } else { str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; + *fmt = FMT_TYPE_DEFAULT; } } } diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index 4f8f277f6da..02b67c32052 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -204,8 +204,8 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne if (cont & FMT_CONT_TRIPLE) { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; if (*str == find && *(str + 1) == find && *(str + 2) == find) { - *fmt = 'l'; fmt++; str++; - *fmt = 'l'; fmt++; str++; + *fmt = FMT_TYPE_STRING; fmt++; str++; + *fmt = FMT_TYPE_STRING; fmt++; str++; cont = FMT_CONT_NOP; } /* Handle other strings */ @@ -215,14 +215,14 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne if (*str == find) cont = FMT_CONT_NOP; } - *fmt = 'l'; + *fmt = FMT_TYPE_STRING; str += BLI_str_utf8_size_safe(str) - 1; } /* Not in a string... */ else { /* Deal with comments first */ - if (prev == '#' || *str == '#') { - *fmt = '#'; + if (prev == FMT_TYPE_COMMENT || *str == '#') { + *fmt = FMT_TYPE_COMMENT; str += BLI_str_utf8_size_safe(str) - 1; } else if (*str == '"' || *str == '\'') { @@ -230,46 +230,48 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne find = *str; cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE; if (*(str + 1) == find && *(str + 2) == find) { - *fmt = 'l'; fmt++; str++; - *fmt = 'l'; fmt++; str++; + *fmt = FMT_TYPE_STRING; fmt++; str++; + *fmt = FMT_TYPE_STRING; fmt++; str++; cont |= FMT_CONT_TRIPLE; } - *fmt = 'l'; + *fmt = FMT_TYPE_STRING; } /* Whitespace (all ws. has been converted to spaces) */ else if (*str == ' ') { - *fmt = '_'; + *fmt = FMT_TYPE_WHITESPACE; } /* Numbers (digits not part of an identifier and periods followed by digits) */ - else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) { - *fmt = 'n'; + else if ((prev != FMT_TYPE_DEFAULT && text_check_digit(*str)) || + (*str == '.' && text_check_digit(*(str + 1)))) + { + *fmt = FMT_TYPE_NUMERAL; } /* Booleans */ - else if (prev != 'q' && (i = txtfmt_py_find_bool(str)) != -1) { + else if (prev != FMT_TYPE_DEFAULT && (i = txtfmt_py_find_bool(str)) != -1) { if (i > 0) { - memset(fmt, 'n', i); + memset(fmt, FMT_TYPE_NUMERAL, i); i--; fmt += i; str += i; } else { str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; + *fmt = FMT_TYPE_DEFAULT; } } /* Punctuation */ else if ((*str != '@') && text_check_delim(*str)) { - *fmt = '!'; + *fmt = FMT_TYPE_SYMBOL; } /* Identifiers and other text (no previous ws. or delims. so text continues) */ - else if (prev == 'q') { + else if (prev == FMT_TYPE_DEFAULT) { str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; + *fmt = FMT_TYPE_DEFAULT; } /* Not ws, a digit, punct, or continuing text. Must be new, check for special words */ else { /* Special vars(v) or built-in keywords(b) */ - if ((i = txtfmt_py_find_specialvar(str)) != -1) prev = 'v'; - else if ((i = txtfmt_py_find_builtinfunc(str)) != -1) prev = 'b'; - else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = 'v'; /* could have a new color for this */ + if ((i = txtfmt_py_find_specialvar(str)) != -1) prev = FMT_TYPE_SPECIAL; + else if ((i = txtfmt_py_find_builtinfunc(str)) != -1) prev = FMT_TYPE_KEYWORD; + else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = FMT_TYPE_SPECIAL; /* could have a new color for this */ if (i > 0) { memset(fmt, prev, i); @@ -277,7 +279,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne } else { str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; + *fmt = FMT_TYPE_DEFAULT; } } } |