diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-03-11 18:14:46 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-03-11 18:15:46 +0300 |
commit | 81d5f15a2a71eaa7c506b0b87706059b9c48d23a (patch) | |
tree | 676c0b14b22343c7db62e98e41f1489b893137af | |
parent | a65b068f6eb31b7ca251075a8362b2098fecafd4 (diff) |
Fix T61253: Wrong syntax highlighting when @ is used as multiplication
This is obviously not a perfect solution. However, to do proper
highlighting a more advanced Python parser would be necessary.
I think this patch implements a good heuristic to differentiate
between the cases when `@` is used for a decorator vs for
multiplication.
When `@` is directly followed by an identifier, it is interpreted
as decorated. Otherwise not.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D4495
-rw-r--r-- | source/blender/editors/space_text/text_format_py.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index d7dc9d625f5..85c3c4220c0 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -116,18 +116,22 @@ static int txtfmt_py_find_specialvar(const char *string) static int txtfmt_py_find_decorator(const char *string) { - if (string[0] == '@') { - int i = 1; - /* Whitespace is ok '@ foo' */ - while (text_check_whitespace(string[i])) { - i++; - } - while (text_check_identifier(string[i])) { - i++; - } - return i; + if (string[0] != '@') { + return -1; + } + if (!text_check_identifier(string[1])) { + return -1; } - return -1; + /* Interpret as matrix multiplication when followed by whitespace. */ + if (text_check_whitespace(string[1])) { + return -1; + } + + int i = 1; + while (text_check_identifier(string[i])) { + i++; + } + return i; } static int txtfmt_py_find_bool(const char *string) |