This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
462 additions
and
38 deletions.
There are no files selected for viewing
59 changes: 52 additions & 7 deletions
59
docker-images/syntax-highlighter/crates/scip-syntax/queries/c/scip-tags.scm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,56 @@ | ||
; Make use of @local | ||
|
||
(translation_unit (declaration (init_declarator declarator: (_) @descriptor.term))) | ||
(function_definition body: (_) @local) | ||
|
||
(enum_specifier name: (_) @descriptor.type body: (enumerator_list (enumerator name: (_) @descriptor.term)) @descriptor.scope) | ||
(parameter_list) @local | ||
|
||
(field_declaration declarator: [ | ||
(pointer_declarator (field_identifier) @descriptor.term) | ||
(field_identifier) @descriptor.term | ||
]) | ||
(function_definition (function_declarator declarator: (_) @descriptor.method)) | ||
(function_declarator declarator: (_) @descriptor.method @kind.function) | ||
|
||
(pointer_declarator declarator: ((identifier) @descriptor.term @kind.variable)) | ||
|
||
(init_declarator | ||
declarator: (identifier) @descriptor.term @kind.variable | ||
value: (_)) | ||
|
||
(array_declarator | ||
declarator: (identifier) @descriptor.term @kind.variable | ||
size: (_)) | ||
|
||
(declaration | ||
(type_qualifier)? | ||
declarator: ((identifier) @descriptor.term @kind.variable)) | ||
|
||
;; Enums | ||
(enum_specifier | ||
name: (_)? | ||
body: (enumerator_list | ||
(enumerator name: (_) @descriptor.term @kind.enummember))) ;; <-- capture enum kind | ||
|
||
(enum_specifier | ||
name: (type_identifier) @descriptor.type @kind.enum ;; <-- capture enum kind | ||
body: (_)) | ||
|
||
;; fields (inside structs, or unions, ...) | ||
(field_declaration_list | ||
(field_declaration declarator: [ | ||
(pointer_declarator (field_identifier) @descriptor.term @kind.field) | ||
(field_identifier) @descriptor.term @kind.field])) | ||
|
||
;; structs | ||
(struct_specifier | ||
name: (type_identifier) @descriptor.type @kind.struct ;; <-- capture struct kidn | ||
body: (_)) @scope | ||
|
||
;; typedefs | ||
(type_definition | ||
type: (_) | ||
declarator: (type_identifier) @descriptor.term @kind.typealias) | ||
|
||
;; macros | ||
(preproc_def | ||
name: (identifier) @descriptor.term @kind.macro) | ||
|
||
;; union | ||
(union_specifier | ||
name: (type_identifier) @descriptor.type @kind.union | ||
body: (_)) @scope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
...hlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_example.c.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
--- | ||
source: crates/scip-syntax/src/lib.rs | ||
expression: dumped | ||
--- | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
|
||
#define BUFSIZE 4096 | ||
// ^^^^^^^ definition(Macro) scip-ctags BUFSIZE. | ||
|
||
const char *name = "com.horsegraph.connection"; | ||
// ^^^^ definition(Variable) scip-ctags name. | ||
const char *author = "Petri & Thorsten"; | ||
// ^^^^^^ definition(Variable) scip-ctags author. | ||
const int count; | ||
// ^^^^^ definition(Variable) scip-ctags count. | ||
int count2; | ||
// ^^^^^^ definition(Variable) scip-ctags count2. | ||
const int age = 28; | ||
// ^^^ definition(Field) scip-ctags age. | ||
static uint sweet_sweet_numbers[5] = {23, 420, 69, 42, 7}; | ||
// ^^^^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags sweet_sweet_numbers. | ||
|
||
const int *ptr1 = &count; | ||
// ^^^^ definition(Variable) scip-ctags ptr1. | ||
const int **ptrptr1 = &ptr1; | ||
// ^^^^^^^ definition(Variable) scip-ctags ptrptr1. | ||
const int ***ptrptrptr1 = &ptrptr1; | ||
// ^^^^^^^^^^ definition(Variable) scip-ctags ptrptrptr1. | ||
|
||
enum { BLACK, RED }; | ||
// ^^^^^ definition(EnumMember) scip-ctags BLACK. | ||
// ^^^ definition(EnumMember) scip-ctags RED. | ||
|
||
enum animal { | ||
// ^^^^^^ definition(Enum) scip-ctags animal# | ||
ANIMAL_TOUCAN, | ||
// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_TOUCAN. | ||
ANIMAL_TIGER = 1, | ||
// ^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_TIGER. | ||
ANIMAL_TIGGER = ANIMAL_TIGER, | ||
// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_TIGGER. | ||
ANIMAL_HORSE, | ||
// ^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_HORSE. | ||
ANIMAL_GIRAFFE, | ||
// ^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_GIRAFFE. | ||
ANIMAL_GOPHER = 99, | ||
// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_GOPHER. | ||
ANIMAL_ORANGUTAN | ||
// ^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_ORANGUTAN. | ||
}; | ||
|
||
typedef enum instrument { | ||
// ^^^^^^^^^^ definition(Enum) scip-ctags instrument# | ||
INSTRUMENT_GUITAR, | ||
// ^^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags INSTRUMENT_GUITAR. | ||
INSTRUMENT_KEYTAR, | ||
// ^^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags INSTRUMENT_KEYTAR. | ||
INSTRUMENT_SITAR | ||
// ^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags INSTRUMENT_SITAR. | ||
} Instrument; | ||
// ^^^^^^^^^^ definition(TypeAlias) scip-ctags Instrument. | ||
|
||
union { | ||
char *hobby; | ||
// ^^^^^ definition(Field) scip-ctags hobby. | ||
int age; // <-- TODO: this will be tagged as a Constant because it's the same | ||
// ^^^ definition(Field) scip-ctags age. | ||
// symbol as the `const int age` above. | ||
} person; | ||
// ^^^^^^ definition(Variable) scip-ctags person. | ||
|
||
union object { | ||
// ^^^^^^ definition(Union) scip-ctags object# | ||
char *name; | ||
// ^^^^ definition(Field) scip-ctags object#name. | ||
int value; | ||
// ^^^^^ definition(Field) scip-ctags object#value. | ||
int age; | ||
// ^^^ definition(Field) scip-ctags object#age. | ||
} obj1, obj2, *obj3; | ||
// ^^^^ definition(Variable) scip-ctags obj1. | ||
// ^^^^ definition(Variable) scip-ctags obj2. | ||
// ^^^^ definition(Variable) scip-ctags obj3. | ||
|
||
const union object2 { | ||
// ^^^^^^^ definition(Union) scip-ctags object2# | ||
char name; | ||
// ^^^^ definition(Field) scip-ctags object2#name. | ||
} obj4; | ||
// ^^^^ definition(Variable) scip-ctags obj4. | ||
|
||
struct connection { | ||
// ^^^^^^^^^^ definition(Struct) scip-ctags connection# | ||
int complete; | ||
// ^^^^^^^^ definition(Field) scip-ctags connection#complete. | ||
int fd; | ||
// ^^ definition(Field) scip-ctags connection#fd. | ||
int bufsize; | ||
// ^^^^^^^ definition(Field) scip-ctags connection#bufsize. | ||
char *buffer; | ||
// ^^^^^^ definition(Field) scip-ctags connection#buffer. | ||
char *url; | ||
// ^^^ definition(Field) scip-ctags connection#url. | ||
}; | ||
|
||
typedef struct connection Connection; | ||
// ^^^^^^^^^^ definition(TypeAlias) scip-ctags Connection. | ||
|
||
typedef struct computer { | ||
// ^^^^^^^^ definition(Struct) scip-ctags computer# | ||
int cores; | ||
// ^^^^^ definition(Field) scip-ctags computer#cores. | ||
} Computer; | ||
// ^^^^^^^^ definition(TypeAlias) scip-ctags Computer. | ||
|
||
typedef struct { | ||
int number; | ||
// ^^^^^^ definition(Field) scip-ctags number. | ||
} NoName; | ||
// ^^^^^^ definition(TypeAlias) scip-ctags NoName. | ||
|
||
struct outer { | ||
// ^^^^^ definition(Struct) scip-ctags outer# | ||
struct inner { | ||
// ^^^^^ definition(Struct) scip-ctags outer#inner# | ||
int x; | ||
// ^ definition(Field) scip-ctags outer#inner#x. | ||
int y; | ||
// ^ definition(Field) scip-ctags outer#inner#y. | ||
} b; | ||
// ^ definition(Field) scip-ctags outer#b. | ||
}; | ||
|
||
// Prototype | ||
struct connection *new_connection(int fd); | ||
// ^^^^^^^^^^^^^^ definition(Function) scip-ctags new_connection(). | ||
// Implementation | ||
struct connection *new_connection(int fd) { | ||
// ^^^^^^^^^^^^^^ definition(Function) scip-ctags new_connection(). | ||
struct connection *c = malloc(sizeof(struct connection)); | ||
if (c == NULL) { | ||
return NULL; | ||
} | ||
|
||
c->url = NULL; | ||
c->complete = 0; | ||
c->fd = fd; | ||
|
||
c->buffer = calloc(BUFSIZE, sizeof(char)); | ||
if (c->buffer == NULL) { | ||
free(c); | ||
return NULL; | ||
} | ||
c->bufsize = BUFSIZE; | ||
|
||
return c; | ||
} | ||
|
||
static void free_connection(struct connection *c) { | ||
// ^^^^^^^^^^^^^^^ definition(Function) scip-ctags free_connection(). | ||
if (c->buffer) { | ||
free(c->buffer); | ||
} | ||
|
||
if (c->url) { | ||
free(c->url); | ||
} | ||
|
||
free(c); | ||
} | ||
|
||
// Prototype | ||
int returns_int(); | ||
// ^^^^^^^^^^^ definition(Function) scip-ctags returns_int(). | ||
// Implementation | ||
int returns_int() { return 12; } | ||
// ^^^^^^^^^^^ definition(Function) scip-ctags returns_int(). | ||
|
||
int main() { return 0; } | ||
// ^^^^ definition(Function) scip-ctags main(). | ||
|
||
int k_and_r(s, f) | ||
// ^^^^^^^ definition(Function) scip-ctags k_and_r(). | ||
char *s; | ||
// ^ definition(Variable) scip-ctags s. | ||
float f; | ||
// ^ definition(Variable) scip-ctags f. | ||
{ return 5; } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.