diff --git a/C Improved.tmLanguage b/C Improved.tmLanguage
index 59a33d5..4351a36 100644
--- a/C Improved.tmLanguage
+++ b/C Improved.tmLanguage
@@ -43,10 +43,10 @@
include #special_block
include #typedef
- include #lex
-
include #type
+ include #lex
+
include #support-macro
include #function
include #support
@@ -102,10 +102,10 @@
patterns
include #typedef
- include #lex
-
include #type
+ include #lex
+
include #call
include #support
@@ -131,13 +131,13 @@
name meta.parens.c
patterns
+ include #type
+
include #lex
include #call
include #support
- include #type
-
include #block
include #parens
@@ -210,20 +210,21 @@
(?x)
(?: (?!\s*(?:[A-Za-z_({]|/[/*]|$))
| (?= \s*\b(?: [A-Za-z_]\w*+ ) (?= \s* [\[;] ) )
- | (?<!\})(?= \s*
+ | (?<!\})(?=
# Prefer function definition over an attribute defined
# through a macro, unless a block has been seen. That is:
# struct __packed __aligned(16) foo {...}; - function __aligned
# struct foo {...} __packed __aligned(16); - structure foo
- (?! \b__attribute__\b )
+ (?! \s* \b__attribute__\b )
- (?: (?<! (?<!\w) new
+ (?: ^
+ | (?<! (?<!\w) new
| (?<!\w) (?:else|enum) | (?<!\w) (?:class|union)
| (?<!\w) (?:struct|return|sizeof|typeof)
| (?<!\w) __typeof | (?<!\w) __typeof__ )
(?<= \w ) \s
- | # or type modifier / closing bracket before name
+ | # or type modifier / closing bracket before name
(?<= [^&]& | [*>)}\]] ) ) \s*
(?: [A-Za-z_]\w*+ | ::[^:] )++
@@ -248,7 +249,7 @@
include #block
include #parens
- match \b([A-Za-z_]\w*+)(?=(?:\s|/\*.*?\*/)*+\{)
+ match \b([A-Za-z_]\w*+)(?=(?:\s|/\*.*?\*/)*+(?:\{|(//.*)?\\?$))
captures
1 name entity.name.type.class.c entity.name.class.c
diff --git a/tests/test_struct.c b/tests/test_struct.c
new file mode 100644
index 0000000..66c2726
--- /dev/null
+++ b/tests/test_struct.c
@@ -0,0 +1,41 @@
+struct name { };
+
+struct name {
+};
+struct /* comment */ name /* comment */ { };
+
+struct name
+{ };
+struct name \
+{ };
+struct /* comment */ name // comment
+{ };
+
+/* type-definition inside parens and block. */
+void function(struct name {} arg);
+void function(struct /* comment */ name /* comment */ { } arg) {
+ struct name { };
+ struct name
+ { };
+ struct name \
+ { };
+ struct /* comment */ name // comment
+ { };
+}
+
+struct name *
+create_struct(void) { }
+
+
+/* FALSE POSITIVES */
+
+struct name
+create_struct(void);
+
+struct name
+create_struct(void) { }
+
+struct name // the compound meta block shouldn't span
+create_struct(void) { }
+
+struct __packed __aligned(16) name { }; // function __aligned