Skip to content

Commit

Permalink
[C] Add support for binary file inclusion preprocessor directive (#4067)
Browse files Browse the repository at this point in the history
This adds support for the new #embed preprocessor directive that can
be used to directly include binary files into program variables without
the use of external code generators.

C++, Objective-C, and Objective-C++ are also updated because they derive
from the C syntax family as well.

This has already made it into recent C and C++ compilers and is also
part of the C23 standard.
  • Loading branch information
braewoods authored Oct 25, 2024
1 parent 4b503ad commit 8414d15
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion C++/C++.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ contexts:
- include: strings
- match: '\S+'
scope: string.unquoted.c++
- match: ^\s*(#\s*(?:include|include_next|import))\b
- match: ^\s*(#\s*(?:include|include_next|embed|import))\b
captures:
1: keyword.control.import.include.c++
push:
Expand Down
2 changes: 1 addition & 1 deletion C++/C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ contexts:
- include: strings
- match: '\S+'
scope: string.unquoted.c
- match: ^\s*(#\s*(?:include|include_next|import))\b
- match: ^\s*(#\s*(?:include|include_next|embed|import))\b
captures:
1: keyword.control.import.include.c
push:
Expand Down
5 changes: 5 additions & 0 deletions C++/syntax_test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@ func_call(foo
/* ^ punctuation.definition.string.end */
#endif

static const unsigned char image_png[] = {
#embed <image.png>
/* <- keyword.control.import.include */
};

#include<iostream>
/* <- keyword.control.import.include */
/* ^ punctuation.definition.string.begin */
Expand Down
2 changes: 1 addition & 1 deletion Objective-C/Objective-C++.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2165,7 +2165,7 @@ contexts:
- include: strings
- match: '\S+'
scope: string.unquoted.objc++
- match: ^\s*(#\s*(?:include|include_next))\b
- match: ^\s*(#\s*(?:include|include_next|embed))\b
captures:
1: keyword.control.import.include.objc++
push:
Expand Down
2 changes: 1 addition & 1 deletion Objective-C/Objective-C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ contexts:
- include: strings
- match: '\S+'
scope: string.unquoted.objc
- match: ^\s*(#\s*(?:include|include_next))\b
- match: ^\s*(#\s*(?:include|include_next|embed))\b
captures:
1: keyword.control.import.include.objc
push:
Expand Down
5 changes: 5 additions & 0 deletions Objective-C/syntax_test_objc.m
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,11 @@ - (void)debugOutput:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2)
/* ^ punctuation.definition.string.end */
#endif
static const unsigned char image_png[] = {
#embed <image.png>
/* <- keyword.control.import.include */
};
#include<iostream>
/* <- keyword.control.import.include */
/* ^ punctuation.definition.string.begin */
Expand Down

0 comments on commit 8414d15

Please sign in to comment.