Skip to content

Commit

Permalink
[C] Allow declaring a struct pointer in a struct
Browse files Browse the repository at this point in the history
Fixes sublimehq#1830

Signed-off-by: Raul E Rangel <[email protected]>
  • Loading branch information
Raul E Rangel committed Jan 31, 2019
1 parent 2c2772b commit 60b1ad7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 9 deletions.
2 changes: 1 addition & 1 deletion C++/C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ contexts:

data-structures:
# Detect variable type definitions using struct/enum/union followed by a tag
- match: '\b({{before_tag}})(?=\s+{{identifier}}\s+{{identifier}}\s*[=;\[])'
- match: '\b({{before_tag}})(?=\s+{{identifier}}\s+\**\s*{{identifier}}\s*[=;\[])'
scope: storage.type.c
- match: '\bstruct\b'
scope: storage.type.c
Expand Down
29 changes: 29 additions & 0 deletions C++/syntax_test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ struct foo MACRO {
/* ^ - entity.name */
}

struct UI_BoundingBox *position_p;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox * position_p1;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox **position_p2;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox ** position_p3;
/* ^ - entity.name */
/* ^ - entity.name */


// Partially-typed
struct foo
/* ^ entity.name */
Expand All @@ -324,6 +341,18 @@ struct UI_MenuBoxData
struct UI_BoundingBox position;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox *position_p;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox * position_p1;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox **position_p2;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox ** position_p3;
/* ^ - entity.name */
/* ^ - entity.name */
enum UI_BoxCharType borderType;
/* ^ - entity.name */
/* ^ - entity.name */
Expand Down
66 changes: 58 additions & 8 deletions C++/syntax_test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,56 @@ bool foo (bool run=true) {}
/* ^ entity.name.function */
};

struct UI_BoundingBox position;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox *position_p;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox * position_p2;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox **position_p2;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_BoundingBox ** position_p2;
/* ^ - entity.name */
/* ^ - entity.name */

struct UI_MenuBoxData
/* <- storage.type */
/* ^ entity.name.struct */
{
struct UI_BoundingBox position;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox *position_p;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox * position_p1;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox **position_p2;
/* ^ - entity.name */
/* ^ - entity.name */
struct UI_BoundingBox ** position_p3;
/* ^ - entity.name */
/* ^ - entity.name */
enum UI_BoxCharType borderType;
/* ^ - entity.name */
/* ^ - entity.name */
unsigned int paddingX;
unsigned int paddingY;
struct UI_ScrollBoxText boxContents[];
/* ^ - entity.name */
/* ^ - entity.name */
};


/////////////////////////////////////////////
// Strings
/////////////////////////////////////////////
Expand Down Expand Up @@ -478,7 +528,7 @@ template <typename T = float, int a = 3, bool b = true>
/* ^ meta.template constant.numeric */
/* ^ meta.template keyword.operator */
/* ^ meta.template constant.language */
struct Foo
struct Foo
{

/* <- meta.struct - meta.template */
Expand Down Expand Up @@ -515,7 +565,7 @@ template<class T, class U = T> class B { /* ... */ };
/* ^ - meta.template */
template <class ...Types> class C { /* ... */ };

// templates inside templates... it's templates all the way down
// templates inside templates... it's templates all the way down
template<template<class> class P> class X { /* ... */ };
/* ^ meta.template punctuation */
/* ^ meta.template meta.template punctuation */
Expand Down Expand Up @@ -615,28 +665,28 @@ int main() {

// Example from section 14.2/4 of
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf
struct X
struct X
{
template <std::size_t>
X* alloc();

template <std::size_t>
static X* adjust();
};
template <class T>
void f(T* p)
template <class T>
void f(T* p)
{
// Be optimistic: scope it as a template member function call anyway.
T* p1 = p->alloc<200>(); // ill-formed: < means less than

T* p2 = p->template alloc<200>(); // OK: < starts template argument list
/* ^ punctuation.accessor */
/* ^ storage.type - variable.other */
/* ^ variable.function */

// Be optimistic: scope it as a template member function call anyway.
T::adjust<100>(); // ill-formed: < means less than

T::template adjust<100>(); // OK: < starts template argument list
/* <- - variable.function */
/*^ punctuation.accessor */
Expand Down Expand Up @@ -1783,7 +1833,7 @@ class Foo {
/* ^ meta.method.constructor.initializer-list */
/* ^ - meta.function-call - variable.function */
private:
int var1, var2, var3, var4;
int var1, var2, var3, var4;
};

class X {
Expand Down

0 comments on commit 60b1ad7

Please sign in to comment.