Skip to content

Commit 60b1ad7

Browse files
author
Raul E Rangel
committed
[C] Allow declaring a struct pointer in a struct
Fixes sublimehq#1830 Signed-off-by: Raul E Rangel <[email protected]>
1 parent 2c2772b commit 60b1ad7

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

C++/C.sublime-syntax

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ contexts:
451451

452452
data-structures:
453453
# Detect variable type definitions using struct/enum/union followed by a tag
454-
- match: '\b({{before_tag}})(?=\s+{{identifier}}\s+{{identifier}}\s*[=;\[])'
454+
- match: '\b({{before_tag}})(?=\s+{{identifier}}\s+\**\s*{{identifier}}\s*[=;\[])'
455455
scope: storage.type.c
456456
- match: '\bstruct\b'
457457
scope: storage.type.c

C++/syntax_test_c.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,23 @@ struct foo MACRO {
313313
/* ^ - entity.name */
314314
}
315315

316+
struct UI_BoundingBox *position_p;
317+
/* ^ - entity.name */
318+
/* ^ - entity.name */
319+
320+
struct UI_BoundingBox * position_p1;
321+
/* ^ - entity.name */
322+
/* ^ - entity.name */
323+
324+
struct UI_BoundingBox **position_p2;
325+
/* ^ - entity.name */
326+
/* ^ - entity.name */
327+
328+
struct UI_BoundingBox ** position_p3;
329+
/* ^ - entity.name */
330+
/* ^ - entity.name */
331+
332+
316333
// Partially-typed
317334
struct foo
318335
/* ^ entity.name */
@@ -324,6 +341,18 @@ struct UI_MenuBoxData
324341
struct UI_BoundingBox position;
325342
/* ^ - entity.name */
326343
/* ^ - entity.name */
344+
struct UI_BoundingBox *position_p;
345+
/* ^ - entity.name */
346+
/* ^ - entity.name */
347+
struct UI_BoundingBox * position_p1;
348+
/* ^ - entity.name */
349+
/* ^ - entity.name */
350+
struct UI_BoundingBox **position_p2;
351+
/* ^ - entity.name */
352+
/* ^ - entity.name */
353+
struct UI_BoundingBox ** position_p3;
354+
/* ^ - entity.name */
355+
/* ^ - entity.name */
327356
enum UI_BoxCharType borderType;
328357
/* ^ - entity.name */
329358
/* ^ - entity.name */

C++/syntax_test_cpp.cpp

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,56 @@ bool foo (bool run=true) {}
237237
/* ^ entity.name.function */
238238
};
239239

240+
struct UI_BoundingBox position;
241+
/* ^ - entity.name */
242+
/* ^ - entity.name */
243+
244+
struct UI_BoundingBox *position_p;
245+
/* ^ - entity.name */
246+
/* ^ - entity.name */
247+
248+
struct UI_BoundingBox * position_p2;
249+
/* ^ - entity.name */
250+
/* ^ - entity.name */
251+
252+
struct UI_BoundingBox **position_p2;
253+
/* ^ - entity.name */
254+
/* ^ - entity.name */
255+
256+
struct UI_BoundingBox ** position_p2;
257+
/* ^ - entity.name */
258+
/* ^ - entity.name */
259+
260+
struct UI_MenuBoxData
261+
/* <- storage.type */
262+
/* ^ entity.name.struct */
263+
{
264+
struct UI_BoundingBox position;
265+
/* ^ - entity.name */
266+
/* ^ - entity.name */
267+
struct UI_BoundingBox *position_p;
268+
/* ^ - entity.name */
269+
/* ^ - entity.name */
270+
struct UI_BoundingBox * position_p1;
271+
/* ^ - entity.name */
272+
/* ^ - entity.name */
273+
struct UI_BoundingBox **position_p2;
274+
/* ^ - entity.name */
275+
/* ^ - entity.name */
276+
struct UI_BoundingBox ** position_p3;
277+
/* ^ - entity.name */
278+
/* ^ - entity.name */
279+
enum UI_BoxCharType borderType;
280+
/* ^ - entity.name */
281+
/* ^ - entity.name */
282+
unsigned int paddingX;
283+
unsigned int paddingY;
284+
struct UI_ScrollBoxText boxContents[];
285+
/* ^ - entity.name */
286+
/* ^ - entity.name */
287+
};
288+
289+
240290
/////////////////////////////////////////////
241291
// Strings
242292
/////////////////////////////////////////////
@@ -478,7 +528,7 @@ template <typename T = float, int a = 3, bool b = true>
478528
/* ^ meta.template constant.numeric */
479529
/* ^ meta.template keyword.operator */
480530
/* ^ meta.template constant.language */
481-
struct Foo
531+
struct Foo
482532
{
483533

484534
/* <- meta.struct - meta.template */
@@ -515,7 +565,7 @@ template<class T, class U = T> class B { /* ... */ };
515565
/* ^ - meta.template */
516566
template <class ...Types> class C { /* ... */ };
517567

518-
// templates inside templates... it's templates all the way down
568+
// templates inside templates... it's templates all the way down
519569
template<template<class> class P> class X { /* ... */ };
520570
/* ^ meta.template punctuation */
521571
/* ^ meta.template meta.template punctuation */
@@ -615,28 +665,28 @@ int main() {
615665

616666
// Example from section 14.2/4 of
617667
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf
618-
struct X
668+
struct X
619669
{
620670
template <std::size_t>
621671
X* alloc();
622672

623673
template <std::size_t>
624674
static X* adjust();
625675
};
626-
template <class T>
627-
void f(T* p)
676+
template <class T>
677+
void f(T* p)
628678
{
629679
// Be optimistic: scope it as a template member function call anyway.
630680
T* p1 = p->alloc<200>(); // ill-formed: < means less than
631-
681+
632682
T* p2 = p->template alloc<200>(); // OK: < starts template argument list
633683
/* ^ punctuation.accessor */
634684
/* ^ storage.type - variable.other */
635685
/* ^ variable.function */
636686

637687
// Be optimistic: scope it as a template member function call anyway.
638688
T::adjust<100>(); // ill-formed: < means less than
639-
689+
640690
T::template adjust<100>(); // OK: < starts template argument list
641691
/* <- - variable.function */
642692
/*^ punctuation.accessor */
@@ -1783,7 +1833,7 @@ class Foo {
17831833
/* ^ meta.method.constructor.initializer-list */
17841834
/* ^ - meta.function-call - variable.function */
17851835
private:
1786-
int var1, var2, var3, var4;
1836+
int var1, var2, var3, var4;
17871837
};
17881838

17891839
class X {

0 commit comments

Comments
 (0)