[Bf-blender-cvs] [81d5f15a2a7] master: Fix T61253: Wrong syntax highlighting when @ is used as multiplication
Jacques Lucke
noreply at git.blender.org
Mon Mar 11 16:15:50 CET 2019
Commit: 81d5f15a2a71eaa7c506b0b87706059b9c48d23a
Author: Jacques Lucke
Date: Mon Mar 11 16:14:46 2019 +0100
Branches: master
https://developer.blender.org/rB81d5f15a2a71eaa7c506b0b87706059b9c48d23a
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
===================================================================
M source/blender/editors/space_text/text_format_py.c
===================================================================
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)
More information about the Bf-blender-cvs
mailing list