Last active
May 16, 2025 04:22
-
-
Save codebrainz/2b1ef2285301fbb8104e2cab2f8c99b3 to your computer and use it in GitHub Desktop.
WIP Clang Format style file for c3lang
This file contains hidden or 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
# Treat C3 like C++ for clang-format | |
Language: Cpp | |
BasedOnStyle: LLVM | |
# Indentation & Tabs | |
UseTab: ForIndentation | |
TabWidth: 4 | |
IndentWidth: 4 | |
ContinuationIndentWidth: 8 | |
# Switch-Case Layout | |
IndentCaseLabels: true | |
#CaseIndentWidth: 1 | |
# Bracing & Single-Line Rules | |
BreakBeforeBraces: Allman | |
AllowShortIfStatementsOnASingleLine: WithoutElse | |
AllowShortFunctionsOnASingleLine: None | |
BreakAfterAttributes: Leave | |
#BreakBeforeAttributes: Leave | |
# Line Length & Wrapping | |
ColumnLimit: 120 | |
BinPackParameters: false | |
BinPackArguments: false | |
AllowAllArgumentsOnNextLine: false | |
PenaltyBreakBeforeFirstCallParameter: 50 | |
#PenaltyBreakBeforeFirstLambdaArrow: 50 | |
# Import/Include Handling | |
SortIncludes: false | |
IncludeIsMainRegex: "(?i)^(.*[/\\\\])?([^/\\\\]+)\\.c3$" | |
# C3-Specific Tokens | |
AttributeMacros: | |
- align | |
- benchmark | |
- bigendian | |
- builtin | |
- callconv | |
- compact | |
- const | |
- deprecated | |
- dynamic | |
- export | |
- extern | |
- finalizer | |
- if | |
- init | |
- inline | |
- link | |
- littleendian | |
- local | |
- maydiscard | |
- naked | |
- noalias | |
- nodiscard | |
- noinit | |
- noinline | |
- nopadding | |
- norecurse | |
- noreturn | |
- nosanitize | |
- nostrip | |
- obfuscate | |
- operator | |
- optional | |
- overlap | |
- packed | |
- private | |
- pure | |
- reflect | |
- section | |
- tag | |
- test | |
- unused | |
- used | |
- wasm | |
- winmain | |
- weak | |
StatementMacros: | |
- defer | |
- panic | |
# Formatter On/Off Pragmas | |
CommentPragmas: '^(//\\s*(?:c3|clang)-format-(?:off|on))' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me
clang-format is splitting some @ attributes, inserting a space between the @ and the keyword (ex. inline). I suspect it's because inline is a real c/c++ keyword, whereas in c3, it's an attribute
@inline
which becomes invalid when clang-format inserts whitespace after the @ChatGPT said:
ChatGPT o3
clang-format hard-codes its treatment of the Objective-C “@-keywords”.
If the token after the at-sign is one of the dozen keywords that Clang itself
recognises (
@interface
,@implementation
,@end
,@property
, …) it keepsthem glued together; otherwise it prints the two tokens separately, adding a
space between @ and the identifier to avoid the creation of an accidental
single token in C/C++ lexing. There is no style option that changes this
rule:
Because C3’s attributes (
@inline
,@naked
, …) are not recognisedkeywords, the formatter will always rewrite
to
and there is no YAML switch to stop it.
What you can do
Goal Work-around
Leave the attribute exactly as you wrote it Surround the region with the normal pragmas
// clang-format off / // clang-format on or any pattern you put in CommentPragmas.
Format the file but keep the attribute token intact Patch clang-format (add the C3 keywords to the Objective-C keyword table in TokenAnnotator.cpp and rebuild), or keep a fork that recognises C3.
Avoid touching the source at all Run clang-format only on C/C++ source and skip .c3 files (DisableFormat: true in a C3-specific section).
Until someone extends clang-format with first-class C3 support (or at least a
generic “leave
@identifier
alone” switch), disabling formatting around thoselines—or maintaining a small custom build—is the only reliable solution.