├── .gitmodules
├── .vscode
└── launch.json
├── Contributors.txt
├── LICENSE
├── README.md
├── dte
├── README.md
└── c3
├── emacs-legacy
├── README.md
└── c3-mode.el
├── iro
└── c3.iro
├── kakoune
└── c3.kak
├── kate
├── README.md
└── c3.xml
├── micro
└── c3.yaml
├── nano
├── README.md
└── c3.nanorc
├── neovim
├── LICENSE
├── README.md
├── lua
│ └── c3
│ │ └── init.lua
└── queries
│ └── c3
│ ├── folds.scm
│ ├── highlights.scm
│ ├── indents.scm
│ ├── injections.scm
│ └── unused_queries.scm
├── sublime-text
├── C3.sublime-build
├── C3.sublime-syntax
├── Comments.tmPreferences
├── README.md
├── Symbols.tmPreferences
├── SymbolsIgnore.tmPreferences
├── c3_toggle_comment.py
└── syntax_test_scopes.c3
└── vim
├── compiler
└── c3c.vim
├── ftdetect
└── c3.vim
├── ftplugin
└── c3.vim
└── syntax
└── c3.vim
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "emacs"]
2 | path = emacs
3 | url = https://github.com/c3lang/c3-ts-mode
4 | branch = main
5 | [submodule "zed"]
6 | path = zed
7 | url = https://github.com/AineeJames/c3-zed.git
8 | branch = main
9 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "name": "Run VSCode Extension",
6 | "type": "extensionHost",
7 | "request": "launch",
8 | "runtimeExecutable": "${execPath}",
9 | "args": [
10 | "--extensionDevelopmentPath=${workspaceFolder}"
11 | ]
12 | }
13 |
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/Contributors.txt:
--------------------------------------------------------------------------------
1 | The following contributors worked on these plugins in the C3C repository:
2 |
3 | dte: data-man
4 | Nano: André, data-man
5 | Kakoune: Hanna
6 | VsCode: Pyxel, Thsm
7 | Sublime Text: everlyy
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Christoffer Lernö and other contributors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Editor Plugins
2 | This repository contains editor plugins for syntax colouring in various
3 | editors.
4 |
5 | Currently available are:
6 | - [VS Code](https://github.com/c3lang/vscode-c3)
7 | - [Emacs 29+](https://github.com/c3lang/c3-ts-mode)
8 | - Emacs <= 28 (emacs-legacy)
9 | - [NeoVim](https://github.com/wstucco/c3.nvim)
10 | - Sublime Text
11 | - Nano
12 | - Kakoune
13 | - [Zed](https://github.com/AineeJames/c3-zed)
14 | - [Kate](https://kate-editor.org/get-it/)
15 |
16 | Please note that since the language is still undergoing revisions, these may or may not be completely
17 | current.
18 |
--------------------------------------------------------------------------------
/dte/README.md:
--------------------------------------------------------------------------------
1 |
2 | This `c3` file adds syntax highlighting support for C3 to [dte](https://craigbarnes.gitlab.io/dte/).
3 |
4 | It can be installed into `~/.dte/syntax`.
5 | And add `ft c3 c3 c3t` to the `~/.dte/syntax/rc` file.
6 |
--------------------------------------------------------------------------------
/dte/c3:
--------------------------------------------------------------------------------
1 | syntax .c3-multi-line-comment
2 |
3 | state comment
4 | char '*' star
5 | eat this
6 |
7 | state star comment
8 | char / END comment
9 | noeat comment
10 |
11 | syntax .c3-uchar4
12 |
13 | state 4left
14 | char 0-9a-fA-F 3left special
15 | eat END error
16 |
17 | state 3left
18 | char 0-9a-fA-F 2left special
19 | eat END error
20 |
21 | state 2left
22 | char 0-9a-fA-F 1left special
23 | eat END error
24 |
25 | state 1left
26 | char 0-9a-fA-F END special
27 | eat END error
28 |
29 | syntax .c3-uchar8
30 |
31 | state 8left
32 | char 0-9a-fA-F 7left special
33 | eat END error
34 |
35 | state 7left
36 | char 0-9a-fA-F 6left special
37 | eat END error
38 |
39 | state 6left
40 | char 0-9a-fA-F 5left special
41 | eat END error
42 |
43 | state 5left
44 | char 0-9a-fA-F .c3-uchar4:END special
45 | eat END error
46 |
47 | syntax .c3-esc
48 |
49 | state start special
50 | char "abfnrtv'\\\"" END special
51 | char 0-3 oct1
52 | char 4-7 oct2
53 | char x hex0
54 | char u .c3-uchar4:END special
55 | char U .c3-uchar8:END special
56 | # Anything but \n
57 | char -n "\n" END error
58 | # Don't eat \n
59 | noeat END
60 |
61 | state oct1 special
62 | char 0-7 oct2
63 | noeat END
64 |
65 | state oct2 special
66 | char 0-7 END special
67 | noeat END
68 |
69 | state hex0 special
70 | char 0-9a-fA-F hex1
71 | noeat END
72 |
73 | state hex1 special
74 | char 0-9a-fA-F hex2
75 | noeat END
76 |
77 | # In strings "\xaff" is an error but "\xafg" is not.
78 | # In chars both are errors.
79 | state hex2 special
80 | char 0-9a-fA-F END error
81 | noeat END
82 |
83 | syntax .c3-string
84 |
85 | state string
86 | char '"' END string
87 | # Avoid highlighting rest of the file again
88 | char "\n" END error
89 | char "\\" .c3-esc:this
90 | eat this
91 |
92 | syntax .c3-char
93 |
94 | state char
95 | char "'\n" END error
96 | char \\ .c3-esc:char-end
97 | eat char-end
98 |
99 | state char-end char
100 | char "'" END char
101 | eat END error
102 |
103 | syntax .c3-one-line-comment
104 |
105 | state comment
106 | char "\n" END
107 | char \\ backslash
108 | eat this
109 |
110 | state backslash comment
111 | # Multi-line comment?
112 | char "\n" comment
113 | noeat comment
114 |
115 | syntax c3
116 |
117 | state start code
118 | char " \t" this
119 | char # preproc
120 | char -b a-z_ ident-label
121 | char -b A-Z ident-upper-label
122 | noeat c3
123 |
124 | state preproc
125 | char " \t" this
126 | char -b a-zA-Z_ preproc-ident
127 | noeat preproc-misc
128 |
129 | state preproc-ident preproc
130 | char -b a-zA-Z0-9_ this
131 | bufis 'include' preproc-include
132 | inlist preproccond preproccond
133 | noeat preproc-misc
134 |
135 | state preproccond
136 | # Recolor to start of the line
137 | recolor preproccond 100
138 | noeat preproc-misc
139 |
140 | state preproc-misc preproc
141 | char "\n" start
142 | char "\\" preproc-cont
143 | char \" .c3-string:this
144 | char \' .c3-char:this
145 | str '/*' .c3-multi-line-comment:this
146 | str '//' .c3-one-line-comment:start
147 | eat this
148 |
149 | state preproc-include preproc
150 | char " \t" this
151 | char "\n" start
152 | char "\\" preproc-cont
153 | char '"' local-include
154 | # Not an error: #include DEFINE
155 | noeat preproc-misc
156 |
157 | state preproc-cont preproc
158 | char "\n" preproc-misc
159 | noeat preproc-misc
160 |
161 | state local-include string
162 | char '"' end-include string
163 | char "\n" start
164 | eat this
165 |
166 | state end-include preproc
167 | char "\n" start
168 | char " \t" this
169 | str '/*' .c3-multi-line-comment:this
170 | str '//' .c3-one-line-comment:start
171 | eat preproc-error
172 |
173 | state preproc-error error
174 | char "\n" start
175 | eat this
176 |
177 | state c3 code
178 | char -b a-z_ ident
179 | char -b A-Z ident-upper
180 | char 0 zero
181 | char 1-9 dec
182 | char . dot
183 | char \" .c3-string:this
184 | char \' .c3-char:this
185 | char "\n" start
186 | char ';' semicolon
187 | str '/*' .c3-multi-line-comment:this
188 | str '//' .c3-one-line-comment:start
189 | eat this
190 |
191 | state semicolon code
192 | char " \t" this
193 | char -b a-zA-Z_ ident-label
194 | noeat c3
195 |
196 | state ident-label ident
197 | char -b a-zA-Z0-9_ this
198 | char -b : label
199 | noeat -b ident
200 |
201 | state label
202 | recolor label
203 | noeat c3
204 |
205 | state ident
206 | char -b a-zA-Z0-9_ this
207 | inlist keywords c3
208 | inlist types c3
209 | inlist constants c3
210 | noeat c3
211 |
212 | state ident-upper ident
213 | char -b a-z class-name
214 | char -b A-Z0-9_ ident
215 | noeat c3
216 |
217 | state class-name
218 | recolor class-name
219 | char a-zA-Z0-9_ this
220 | noeat c3
221 |
222 | state ident-upper-label ident
223 | char -b a-z class-name-label
224 | char -b A-Z0-9_ ident-label
225 | char -b : label
226 | noeat c3
227 |
228 | state class-name-label class-name
229 | char -b a-zA-Z0-9_ this
230 | char -b : label
231 | noeat -b class-name
232 |
233 | state zero numeric
234 | char bB bin
235 | char xX hex
236 | char 0-7 oct
237 | char . float
238 | noeat check-suffix
239 |
240 | state oct numeric
241 | char 0-7 this
242 | noeat check-suffix
243 |
244 | state dec numeric
245 | char 0-9 this
246 | char eE exp
247 | char . float
248 | noeat check-suffix
249 |
250 | state bin numeric
251 | char 01 this
252 | noeat check-suffix
253 |
254 | state hex numeric
255 | char 0-9a-fA-F this
256 | noeat check-suffix
257 |
258 | state check-suffix error
259 | char -b a-zA-Z0-9_ this
260 | inlist numeric-suffix c3 numeric
261 | noeat c3
262 |
263 | state dot numeric
264 | char 0-9 float
265 | recolor code 1
266 | noeat c3
267 |
268 | state float numeric
269 | char 0-9 this
270 | char eE exp
271 | char fFlL float-suffix
272 | char a-zA-Z0-9_ error-ident
273 | noeat c3
274 |
275 | state float-suffix numeric
276 | char a-zA-Z0-9_ error-ident
277 | noeat c3
278 |
279 | state exp numeric
280 | char +- exp-digit
281 | char 0-9 exp-digit
282 | char a-zA-Z0-9_ error-ident
283 | noeat c3
284 |
285 | state exp-digit numeric
286 | char 0-9 this
287 | char a-zA-Z0-9_ error-ident
288 | noeat c3
289 |
290 | state error-ident error
291 | char a-zA-Z0-9_ this
292 | noeat c3
293 |
294 | list keywords \
295 | alias as asm assert break case catch const continue def default defer define do \
296 | else extern fn for foreach func if import macro module nextcase \
297 | null private return static switch tlocal try typeid var while
298 |
299 | list types \
300 | bitstruct bool anyerr char double enum fault float float16 float128 ichar \
301 | int int128 iptr iptrdiff isize long short struct uint uint128 ulong union \
302 | uptr uptrdiff ushort usize variant void
303 |
304 | list constants \
305 | null stdin stdout stderr false true
306 |
307 | list preproccond \
308 | elif else endif if ifdef ifndef
309 |
310 | list -i numeric-suffix \
311 | UL U L ul uL Ul u l
312 |
313 | default ident class-name
314 | default keyword keywords
315 | default preproc preproccond
316 | default type types
317 |
--------------------------------------------------------------------------------
/emacs-legacy/README.md:
--------------------------------------------------------------------------------
1 | This adds simple syntax highlighting for C3 in Emacs.
2 | Taken from [Alexey Kutepov's simpc-mode](https://github.com/rexim/simpc-mode)
3 |
4 | The current way to install is just by running `load-file` during startup.
5 |
--------------------------------------------------------------------------------
/emacs-legacy/c3-mode.el:
--------------------------------------------------------------------------------
1 | (require 'subr-x)
2 |
3 | (defvar c3-mode-syntax-table
4 | (let ((table (make-syntax-table)))
5 | ;; C/C++ style comments
6 | (modify-syntax-entry ?/ ". 124b" table)
7 | (modify-syntax-entry ?* ". 23" table)
8 | (modify-syntax-entry ?\n "> b" table)
9 | ;; Chars are the same as strings
10 | (modify-syntax-entry ?' "\"" table)
11 | ;; Treat <> as punctuation (needed to highlight C++ keywords
12 | ;; properly in template syntax)
13 | (modify-syntax-entry ?< "." table)
14 | (modify-syntax-entry ?> "." table)
15 | (modify-syntax-entry ?& "." table)
16 | (modify-syntax-entry ?% "." table)
17 | table))
18 |
19 | (defun c3-types ()
20 | '("void" "bool"
21 | "ichar" "char"
22 | ;; Integer types
23 | "short" "ushort" "int" "uint" "long" "ulong" "int128" "uint128"
24 | "iptr" "uptr"
25 | "isz" "usz"
26 | ;; Floating point types
27 | "float16" "float" "double" "float128"
28 | ;; Other types
29 | "any" "anyfault" "typeid"
30 | ;; C compatibility types
31 | "CChar" "CShort" "CUShort" "CInt" "CUInt" "CLong" "CULong" "CLongLong" "CULongLong" "CFloat" "CDouble" "CLongDouble"
32 | ;; CT types
33 | "$typefrom" "$tyypeof" "$vatype"
34 | ))
35 |
36 | (defun c3-keywords ()
37 | '("asm" "assert" "bitstruct"
38 | "break" "case" "catch"
39 | "const" "continue" "def"
40 | "default" "defer" "distinct"
41 | "do" "else" "enum"
42 | "extern" "false" "fault"
43 | "for" "foreach" "foreach_r"
44 | "fn" "tlocal" "if"
45 | "inline" "import" "macro"
46 | "module" "nextcase" "null"
47 | "return" "static" "struct"
48 | "switch" "true" "try"
49 | "union" "var" "while"
50 | "$alignof" "$assert" "$case"
51 | "$checks" "$default" "$defined"
52 | "$echo" "$else" "$endfor"
53 | "$endforeach" "$endif" "$endswitch"
54 | "$for" "$foreach" "$if"
55 | "$include" "$nameof" "$offsetof"
56 | "$qnameof" "$sizeof" "$stringify"
57 | "$vacount" "$vaconst" "$varef"
58 | "$vaarg" "$vaexpr" "$vasplat"
59 | ))
60 |
61 | (defun c3-font-lock-keywords ()
62 | (list
63 | `("#.*include \\(\\(<\\|\"\\).*\\(>\\|\"\\)\\)" . (1 font-lock-string-face))
64 | `(,(regexp-opt (c3-keywords) 'symbols) . font-lock-keyword-face)
65 | `(,(regexp-opt (c3-types) 'symbols) . font-lock-type-face)))
66 |
67 | (defun c3--space-prefix-len (line)
68 | (- (length line)
69 | (length (string-trim-left line))))
70 |
71 | (defun c3--previous-non-empty-line ()
72 | (save-excursion
73 | (forward-line -1)
74 | (while (and (not (bobp))
75 | (string-empty-p
76 | (string-trim-right
77 | (thing-at-point 'line t))))
78 | (forward-line -1))
79 | (thing-at-point 'line t)))
80 |
81 | (defun c3--desired-indentation ()
82 | (let ((cur-line (string-trim-right (thing-at-point 'line t)))
83 | (prev-line (string-trim-right (c3--previous-non-empty-line)))
84 | (indent-len 4))
85 | (cond
86 | ((and (string-suffix-p "{" prev-line)
87 | (string-prefix-p "}" (string-trim-left cur-line)))
88 | (c3--space-prefix-len prev-line))
89 | ((string-suffix-p "{" prev-line)
90 | (+ (c3--space-prefix-len prev-line) indent-len))
91 | ((string-prefix-p "}" (string-trim-left cur-line))
92 | (max (- (c3--space-prefix-len prev-line) indent-len) 0))
93 | (t (c3--space-prefix-len prev-line)))))
94 |
95 | (defun c3-indent-line ()
96 | (interactive)
97 | (when (not (bobp))
98 | (let* ((current-indentation
99 | (c3--space-prefix-len (thing-at-point 'line t)))
100 | (desired-indentation
101 | (c3--desired-indentation))
102 | (n (max (- (current-column) current-indentation) 0)))
103 | (indent-line-to desired-indentation)
104 | (forward-char n))))
105 |
106 | ;;;###autoload
107 | (define-derived-mode c3-mode prog-mode "Simple C3"
108 | "Simple major mode for C3."
109 | :syntax-table c3-mode-syntax-table
110 | (setq-local font-lock-defaults '(c3-font-lock-keywords))
111 | (setq-local indent-line-function 'c3-indent-line)
112 | (setq-local comment-start "// "))
113 |
114 | ;;;###autoload
115 | (add-to-list 'auto-mode-alist '("\\.c3\\'" . c3-mode))
116 | (add-to-list 'auto-mode-alist '("\\.c3i\\'" . c3-mode))
117 |
118 | (provide 'c3-mode)
119 |
--------------------------------------------------------------------------------
/iro/c3.iro:
--------------------------------------------------------------------------------
1 |
2 | name = C3
3 | file_extensions [] = c3;
4 |
5 | ################################################################
6 | ## Constants
7 | ################################################################
8 |
9 | __CONSTANT \= (_*[A-Z][A-Za-z0-9_]*)
10 | __IDENT \= _*[a-z][A-Za-z0-9_]*
11 | __TYPE \= _*[A-Z][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*
12 | __SCOPE \= ([a-z]+::)*
13 | __USERTYPE \= _*[A-Z][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*
14 | __BUILTIN_TYPE \= void|float|half|double|quad|long|ulong|int|short|char|uint|ushort|ichar|usize|isize|iptr|uptr|iptrdiff|uptrdiff
15 | ################################################################
16 | ## Styles
17 | ################################################################
18 |
19 | styles [] {
20 |
21 | .comment : style {
22 | color = #5F5A60
23 | italic = true
24 | ace_scope = comment
25 | textmate_scope = comment
26 | pygments_scope = Comment
27 | }
28 |
29 | .type : style {
30 | color = #AE81FF
31 | pygments_scope = Name.Class
32 | textmate_scope = entity.name.type
33 | }
34 |
35 | .string : style {
36 | color = #E6DB74
37 | pygments_scope = String.Double
38 | textmate_scope = string.quoted.double
39 | }
40 |
41 | .escaped_text : style {
42 | color = #AE81FF
43 | pygments_scope = String.Escape
44 | }
45 | .function_decl : style {
46 | color = #A6E22E
47 | pygments_scope = Name.Entity
48 | }
49 |
50 | .declare : style {
51 | color = #66D9EF
52 | pygments_scope = Keyword.Declaration
53 | }
54 |
55 |
56 | .function_call : style {
57 | color = #66D9EF
58 | pygments_scope = Name.Function
59 | }
60 |
61 | .type_builtin : style {
62 | color = #f92672
63 | ace_scope = keyword
64 | textmate_scope = keyword
65 | pygments_scope = Keyword.Type
66 | }
67 |
68 | .keyword_constant : style
69 | {
70 | color = #f92672
71 | ace_scope = keyword
72 | textmate_scope = keyword
73 | pygments_scope = Keyword.Constant
74 | }
75 |
76 | .keyword : style {
77 | color = #f92672
78 | ace_scope = keyword
79 | textmate_scope = keyword
80 | pygments_scope = Keyword
81 | }
82 |
83 | .constant : style {
84 | color = #AE81FF
85 | textmate_scope = constant
86 | pygments_scope = Name.Constant
87 | }
88 |
89 |
90 |
91 | .numeric : style {
92 | color = #AE81FF
93 | ace_scope = constant.numeric
94 | textmate_scope = constant.numeric
95 | pygments_scope = Number
96 | }
97 |
98 | .punctuation : style {
99 | color = #FD971F
100 | ace_scope = punctuation
101 | textmate_scope = punctuation
102 | pygments_scope = Punctuation
103 | }
104 |
105 | .compile_time : style {
106 | color = #908B25
107 | pygments_scope = Keyword.Pseudo
108 | }
109 |
110 | .variable : style {
111 | color = #f8f8f2
112 | background_color = #272822
113 | pygments_scope = Name
114 | }
115 |
116 |
117 | .text : style {
118 | color = #f8f8f2
119 | background_color = #272822
120 | ace_scope = text
121 | textmate_scope = text
122 | pygments_scope = String
123 | }
124 |
125 | .illegal : style {
126 | color = white
127 | background_color = red
128 | ace_scope = invalid
129 | textmate_scope = invalid
130 | pygments_scope = Generic.Error
131 | }
132 |
133 | }
134 |
135 | #################################################
136 | ## Parse contexts
137 | #################################################
138 |
139 | contexts [] {
140 |
141 | top_level : context {
142 | : include "parens";
143 | : include "comment";
144 | : include "constants";
145 | : include "ct_keywords";
146 | : include "decls";
147 | : include "path";
148 | : include "type";
149 | : include "keywords";
150 | : include "storage";
151 | : include "call";
152 | : include "identifier";
153 | : include "kw_operators";
154 | : include "operators";
155 | : pattern {
156 | regex \= ([\.\;])
157 | styles [] = .punctuation;
158 | }
159 | : pattern {
160 | regex \= ([\@])
161 | styles [] = .keyword;
162 | }
163 | }
164 |
165 | builtin_constants : context {
166 | : pattern {
167 | regex \= (true|false|null)
168 | styles [] = .keyword_constant;
169 | }
170 | }
171 | constants : context {
172 | : pattern {
173 | regex \= ($${__CONSTANT})
174 | styles [] = .constant;
175 | }
176 | }
177 | type : context {
178 | : pattern {
179 | regex \= ($${__SCOPE})?($${__USERTYPE})
180 | styles [] = .type;
181 | }
182 | : pattern {
183 | regex \= ($${__BUILTIN_TYPE})
184 | styles [] = .type_builtin;
185 | }
186 | }
187 | path : context {
188 | : pattern {
189 | regex \= ([a-z][a-z_0-9]*)(\s*)(::)
190 | styles [] = .text, .text, .keyword;
191 | }
192 | }
193 |
194 | call : context {
195 | : pattern {
196 | regex \= ($${__IDENT}\s*)(\()
197 | styles [] = .function_call, .text;
198 | }
199 | }
200 |
201 | keywords : context {
202 | : pattern {
203 | regex \= (import|for|foreach|foreach_r|return|else|if|default|switch|while|do|module|assert|distinct|break|nextcase|case|continue|defer)
204 | styles [] = .keyword;
205 | }
206 | }
207 | ct_keywords : context {
208 | : pattern {
209 | regex \= (\$[a-zA-Z][a-z_A-Z0-9]*)
210 | styles [] = .compile_time;
211 | }
212 | }
213 | storage : context {
214 | : pattern {
215 | regex \= (const|extern|static|private)
216 | styles [] = .keyword;
217 | }
218 | }
219 | identifier : context {
220 | : pattern {
221 | regex \= ($${__IDENT})
222 | styles [] = .variable;
223 | }
224 | }
225 |
226 | operators : context {
227 | : pattern {
228 | regex \= ([\*\=\/\%\<\>\,\:\^\&\!\|\~])
229 | styles [] = .text;
230 | }
231 | }
232 | kw_operators : context {
233 | : pattern {
234 | regex \= ([\+\-])
235 | styles [] = .text;
236 | }
237 | }
238 |
239 | parens : context {
240 | : pattern {
241 | regex \= ([\[\]\(\)\{\}])
242 | styles [] = .text;
243 | }
244 | }
245 |
246 | decls : context
247 | {
248 | : pattern {
249 | regex \= (fn\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
250 | styles [] = .declare, .text, .text, .type, .type_builtin, .function_decl;
251 | }
252 | : pattern {
253 | regex \= (fn\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
254 | styles [] = .declare, .text, .text, .type, .type_builtin, .function_decl;
255 | }
256 | : pattern {
257 | regex \= (enum|struct|errtype|union)(\s+)($${__USERTYPE})
258 | styles[] = .declare, .text, .function_decl;
259 | }
260 | : pattern {
261 | regex \= (struct|union|define)
262 | styles[] = .declare;
263 | }
264 | }
265 |
266 | nested_comment : context {
267 | : inline_push {
268 | regex \= (/\*)
269 | styles [] = .comment;
270 | : pop {
271 | regex \= (.*\*/)
272 | styles [] = .comment;
273 | }
274 | : include "nested_comment";
275 | }
276 | }
277 |
278 | comment : context {
279 | : pattern {
280 | regex \= (//.*)
281 | styles [] = .comment;
282 | }
283 | : include "nested_comment";
284 | }
285 |
286 |
287 | main : context {
288 |
289 |
290 | : include "top_level";
291 | : pattern {
292 | regex \= (bitstruct|typedef|define|def|extern|if|module|import|fn|struct|while|do|return|union|fault)
293 | styles [] = .keyword;
294 | }
295 |
296 | : include "numeric" ;
297 |
298 | : inline_push {
299 | regex \= (\{)
300 | styles [] = .punctuation;
301 | : pop {
302 | regex \= (\})
303 | styles [] = .punctuation;
304 | }
305 | : include "main" ;
306 | }
307 |
308 | : pattern {
309 | regex \= (;)
310 | styles [] = .punctuation;
311 | }
312 |
313 | : inline_push {
314 | regex \= (\")
315 | styles [] = .punctuation;
316 | : pop {
317 | regex \= (\")
318 | styles [] = .punctuation;
319 | }
320 | : pattern {
321 | regex \= (\\(?:\\|"))
322 | styles [] = .escaped_text;
323 | }
324 | : pattern {
325 | regex \= ([^"\\]+)
326 | styles [] = .string;
327 | }
328 | }
329 |
330 |
331 | : include "multi_line_comment" ;
332 |
333 | : pattern {
334 | regex \= (//.*)
335 | styles [] = .comment;
336 | }
337 |
338 | : pattern {
339 | regex \= ([^\s])
340 | styles [] = .illegal;
341 | }
342 |
343 | }
344 |
345 | #################################################
346 | ## End of Contexts
347 | #################################################
348 |
349 | ###########################################
350 | ## Numeric Context
351 | ###########################################
352 |
353 | numeric : context {
354 | : pattern {
355 | regex \= (\b\d+)
356 | styles [] = .numeric;
357 | }
358 | }
359 |
360 | ###########################################
361 | ## Multi Line Comment Context
362 | ###########################################
363 |
364 | multi_line_comment : context {
365 | description = multiline
366 | : inline_push {
367 | regex \= (/\*)
368 | styles [] = .comment;
369 | default_style = .comment
370 | : pop {
371 | regex \= (\*/)
372 | styles [] = .comment;
373 | }
374 | }
375 | }
376 |
377 | }
378 |
--------------------------------------------------------------------------------
/kakoune/c3.kak:
--------------------------------------------------------------------------------
1 | hook global BufCreate .*[.]c3[it]? %{
2 | set-option buffer filetype c3
3 | }
4 |
5 | hook -group c3-highlight global WinSetOption filetype=c3 %{
6 | require-module c3
7 |
8 | add-highlighter window/c3 ref c3
9 | hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/c3 }
10 | }
11 |
12 |
13 | provide-module c3 %{
14 |
15 | addhl shared/c3 regions
16 | addhl shared/c3/code default-region group
17 |
18 | addhl shared/c3/comment-line region '//' '$' fill comment
19 | addhl shared/c3/comment-block region -recurse '/\*' /\* \*/ fill comment
20 | addhl shared/c3/comment-doc region <\*(?!>) \*> fill comment
21 | addhl shared/c3/double-string region '"' (?
2 |
3 |
4 |
5 |
6 | - fn
7 |
8 |
9 | - switch
10 | - try
11 | - while
12 | - return
13 | - if
14 | - catch
15 | - continue
16 | - break
17 | - do
18 | - else
19 | - for
20 | - foreach
21 | - foreach_r
22 |
23 |
24 | - anyfault
25 | - typeid
26 | - assert
27 | - asm
28 | - bitstruct
29 | - case
30 | - const
31 | - def
32 | - default
33 | - defer
34 | - distinct
35 | - enum
36 | - extern
37 | - false
38 | - fault
39 | - tlocal
40 | - inline
41 | - import
42 | - macro
43 | - module
44 | - nextcase
45 | - null
46 | - static
47 | - true
48 | - struct
49 | - union
50 |
51 |
52 | - @align
53 | - @benchmark
54 | - @bigendian
55 | - @builtin
56 | - @cdecl
57 | - @deprecated
58 | - @dynamic
59 | - @export
60 | - @extern
61 | - @extname
62 | - @inline
63 | - @interface
64 | - @littleendian
65 | - @local
66 | - @maydiscard
67 | - @naked
68 | - @nodiscard
69 | - @noinit
70 | - @noinline
71 | - @noreturn
72 | - @nostrip
73 | - @obfuscate
74 | - @operator
75 | - @overlap
76 | - @packed
77 | - @priority
78 | - @private
79 | - @public
80 | - @pure
81 | - @reflect
82 | - @section
83 | - @stdcall
84 | - @test
85 | - @unused
86 | - @used
87 | - @veccall
88 | - @wasm
89 | - @weak
90 | - @winmain
91 |
92 |
93 | - var
94 | - void
95 | - bool
96 | - char
97 | - double
98 | - float
99 | - float16
100 | - int128
101 | - ichar
102 | - int
103 | - iptr
104 | - isz
105 | - long
106 | - short
107 | - uint128
108 | - uint
109 | - ulong
110 | - uptr
111 | - ushort
112 | - usz
113 | - float128
114 | - any
115 | - String
116 | - ZString
117 |
118 |
119 | - $alignof
120 | - $assert
121 | - $case
122 | - $default
123 | - $defined
124 | - $echo
125 | - $embed
126 | - $exec
127 | - $else
128 | - $endfor
129 | - $endforeach
130 | - $endif
131 | - $endswitch
132 | - $eval
133 | - $evaltype
134 | - $error
135 | - $extnameof
136 | - $for
137 | - $foreach
138 | - $if
139 | - $include
140 | - $nameof
141 | - $offsetof
142 | - $qnameof
143 | - $sizeof
144 | - $stringify
145 | - $switch
146 | - $typefrom
147 | - $typeof
148 | - $vacount
149 | - $vatype
150 | - $vaconst
151 | - $varef
152 | - $vaarg
153 | - $vaexpr
154 | - $vasplat
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
--------------------------------------------------------------------------------
/micro/c3.yaml:
--------------------------------------------------------------------------------
1 | filetype: c3
2 |
3 | detect:
4 | filename: "(\\.(c3)$)"
5 |
6 | rules:
7 | - identifier: "\\b[A-Z_][0-9A-Z_]+\\b"
8 | - type: "\\b[A-Z][A-Za-z_]+\\b"
9 | - identifier.constant: "\\b[A-Z_]+\\b"
10 | - identifer: "\\$[A-Za-z_][0-9A-Za-z_]+"
11 | - type: "\\b(void|bool|char|double|float|float16|bfloat|int128|ichar|int|iptr|isz|long|short|uint128|uint|ulong|uptr|ushort|usz|float128|any|anyfault|String)\\b"
12 | - type: "\\b(CChar|CShort|CUShort|CInt|CUInt|CLong|CULong|CLongLong|CULongLong|CLongDouble)\\b"
13 | - statement: "\\b(typeid|assert|asm|bitstruct|break|case|catch|const|continue|def|default|defer|distinct|do|else|enum|extern|fault|for|foreach|foreach_r|fn|tlocal|if|inline|import|macro|module|nextcase|null|interface|return|static|struct|switch|try|union|var|while)\\b"
14 | - statement: "(\\$\\$abs|\\$\\$any_make|\\$\\$atomic_load|\\$\\$atomic_store|\\$\\$atomic_fetch_exchange|\\$\\$atomic_fetch_add|\\$\\$atomic_fetch_sub|\\$\\$atomic_fetch_and|\\$\\$atomic_fetch_nand|\\$\\$atomic_fetch_or|\\$\\$atomic_fetch_xor|\\$\\$atomic_fetch_max|\\$\\$atomic_fetch_min|\\$\\$atomic_fetch_inc_wrap|\\$\\$atomic_fetch_dec_wrap|\\$\\$bitreverse|\\$\\$breakpoint|\\$\\$bswap|\\$\\$ceil|\\$\\$compare_exchange|\\$\\$copysign|\\$\\$cos|\\$\\$clz|\\$\\$ctz|\\$\\$add|\\$\\$div|\\$\\$mod|\\$\\$mul|\\$\\$neg|\\$\\$sub|\\$\\$exp|\\$\\$exp2|\\$\\$floor|\\$\\$fma|\\$\\$fmuladd|\\$\\$frameaddress|\\$\\$fshl|\\$\\$fshr|\\$\\$gather|\\$\\$get_rounding_mode|\\$\\$log|\\$\\$log10|\\$\\$log2|\\$\\$masked_load|\\$\\$masked_store|\\$\\$max|\\$\\$memcpy|\\$\\$memcpy_inline|\\$\\$memmove|\\$\\$memset|\\$\\$memset_inline|\\$\\$min|\\$\\$nearbyint|\\$\\$overflow_add|\\$\\$overflow_mul|\\$\\$overflow_sub|\\$\\$popcount|\\$\\$pow|\\$\\$pow_int|\\$\\$prefetch|\\$\\$reduce_add|\\$\\$reduce_and|\\$\\$reduce_fadd|\\$\\$reduce_fmul|\\$\\$reduce_max|\\$\\$reduce_min|\\$\\$reduce_mul|\\$\\$reduce_or|\\$\\$reduce_xor|\\$\\$reverse|\\$\\$returnaddress|\\$\\$rint|\\$\\$round|\\$\\$roundeven|\\$\\$sat_add|\\$\\$sat_shl|\\$\\$sat_sub|\\$\\$scatter|\\$\\$select|\\$\\$set_rounding_mode|\\$\\$str_hash|\\$\\$str_upper|\\$\\$str_lower|\\$\\$str_find|\\$\\$swizzle|\\$\\$swizzle2|\\$\\$sin|\\$\\$sqrt|\\$\\$syscall|\\$\\$sysclock|\\$\\$trap|\\$\\$trunc|\\$\\$unaligned_load|\\$\\$unaligned_store|\\$\\$unreachable|\\$\\$veccomplt|\\$\\$veccomple|\\$\\$veccompgt|\\$\\$veccompge|\\$\\$veccompeq|\\$\\$veccompne|\\$\\$volatile_load|\\$\\$volatile_store|\\$\\$wasm_memory_size|\\$\\$wasm_memory_grow|\\$\\$DATE|\\$\\$FILE|\\$\\$FILEPATH|\\$\\$FUNC|\\$\\$FUNCTION|\\$\\$LINE|\\$\\$LINE_RAW|\\$\\$MODULE|\\$\\$BENCHMARK_NAMES|\\$\\$BENCHMARK_FNS|\\$\\$TEST_NAMES|\\$\\$TEST_FNS|\\$\\$TIME)"
15 | - statement: "(\\$\\$expect_with_probability|\\$\\$expect)"
16 | - preproc: "(\\$alignof|\\$and|\\$append|\\$assert|\\$assignable|\\$case|\\$concat|\\$default|\\$defined|\\$echo|\\$else|\\$embed|\\$endfor|\\$endforeach|\\$endif|\\$endswitch|\\$eval|\\$evaltype|\\$error|\\$exec|\\$extnameof|\\$feature|\\$for|\\$foreach|\\$if|\\$include|\\$is_const|\\$nameof|\\$offsetof|\\$or|\\$qnameof|\\$sizeof|\\$stringify|\\$switch|\\$typefrom|\\$typeof|\\$vacount|\\$vatype|\\$vaconst|\\$varef|\\$vaarg|\\$vaexpr|\\$vasplat)"
17 | - preproc: "(@align|@benchmark|@bigendian|@builtin|@callconv|@compact|@const|@deprecated|@dynamic|@export|@extern|@finalizer|@if|@inline|@init|@link|@littleendian|@local|@maydiscard|@naked|@noalias|@nodiscard|@noinit|@noinline|@nopadding|@noreturn|@nostrip|@obfuscate|@operator|@optional|@overlap|@packed|@private|@public|@pure|@reflect|@safemacro|@section|@test|@unused|@used|@wasm|@weak|@winmain)"
18 | - symbol.operator: "[-+*/%=<>.:;,~&|^!?]\\b"
19 | - symbol.brackets: "[(){}]|\\[|\\]"
20 |
21 | # Integer Constants
22 | - constant.number: "(\\b([0-9_]+|0x[0-9A-Fa-f_]+|0b[01_]+)\\b)"
23 | # Decimal Floating Constants
24 | - constant.number: "(\\b([0-9_]+.[0-9]+)\\b)"
25 |
26 | - constant.bool: "(\\b(true|false|null)\\b)"
27 |
28 | - constant.string:
29 | start: "\""
30 | end: "\""
31 | skip: "\\\\."
32 | rules:
33 | - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"
34 |
35 | - constant.string:
36 | start: "'"
37 | end: "'"
38 | skip: "\\\\."
39 | rules:
40 | - error: "..+"
41 | - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"
42 |
43 | - comment:
44 | start: "//"
45 | end: "$"
46 | rules:
47 | - todo: "(TODO|XXX|FIXME):?"
48 |
49 | - comment:
50 | start: "/\\*"
51 | end: "\\*/"
52 | rules:
53 | - todo: "(TODO|XXX|FIXME):?"
54 |
55 | - comment.block:
56 | start: "<\\*"
57 | end: "\\*>"
58 | rules:
59 | - todo: "(TODO|XXX|FIXME):?"
60 |
--------------------------------------------------------------------------------
/nano/README.md:
--------------------------------------------------------------------------------
1 |
2 | This `.nanorc` file adds syntax highlighting support for C3 to `nano`.
3 |
4 | It can either be installed under `/usr/share/nano` or included into `~/.nanorc`.
5 |
--------------------------------------------------------------------------------
/nano/c3.nanorc:
--------------------------------------------------------------------------------
1 | ## C3 syntax highlighting support for nano
2 | ## https://github.com/c3lang/c3c
3 |
4 | syntax c3 "\.(c3|c3t)$"
5 |
6 | linter c3c -C compile
7 |
8 | comment "//"
9 |
10 | # Default color
11 | color white ".*"
12 |
13 | # Constants
14 | #color brightred "\<[A-Z_][0-9A-Z_]+\>"
15 |
16 | # Function names
17 | color magenta "\<[A-Za-z_]+\>\("
18 |
19 | # Macro names
20 | color red "@\w+"
21 |
22 | color normal "\(|\)"
23 |
24 | # Built-in properties
25 | # generated by "c3c --list-type-properties | sort"
26 | color green "\.(alignof|associated|elements|extnameof|inf|inner|is_eq|is_ordered|is_substruct|kindof|len|max|membersof|min|nameof|names|nan)"
27 | color green "\.(params|parentof|qnameof|returns|sizeof|values)"
28 |
29 | color brightblack ";|\.|,"
30 |
31 | # $$ Builtins
32 | # generated by "c3c --list-builtins | sort -V"
33 | color brightgreen "\$\$(BENCHMARK_FNS|BENCHMARK_NAMES|DATE|FILE|FILEPATH|FUNC|FUNCTION|LINE|LINE_RAW|MODULE|TEST_FNS|TEST_NAMES|TIME)"
34 | color brightgreen "\$\$(abs|add|any_make|atomic_fetch_add|atomic_fetch_and|atomic_fetch_dec_wrap|atomic_fetch_exchange|atomic_fetch_inc_wrap)"
35 | color brightgreen "\$\$(atomic_fetch_max|atomic_fetch_min|atomic_fetch_nand|atomic_fetch_or|atomic_fetch_sub|atomic_fetch_xor|atomic_load)"
36 | color brightgreen "\$\$(atomic_store|bitreverse|breakpoint|bswap|ceil|clz|compare_exchange|copysign|cos|ctz|div|exp|exp2|expect)"
37 | color brightgreen "\$\$(expect_with_probability|floor|fma|fmuladd|frameaddress|fshl|fshr|gather|get_rounding_mode|log|log2|log10|masked_load)"
38 | color brightgreen "\$\$(masked_store|max|memcpy|memcpy_inline|memmove|memset|memset_inline|min|mod|mul|nearbyint|neg|overflow_add|overflow_mul)"
39 | color brightgreen "\$\$(overflow_sub|popcount|pow|pow_int|prefetch|reduce_add|reduce_and|reduce_fadd|reduce_fmul|reduce_max|reduce_min|reduce_mul)"
40 | color brightgreen "\$\$(reduce_or|reduce_xor|returnaddress|reverse|rint|round|roundeven|sat_add|sat_shl|sat_sub|scatter|select|set_rounding_mode)"
41 | color brightgreen "\$\$(sin|sqrt|str_find|str_hash|str_lower|str_upper|sub|swizzle|swizzle2|syscall|sysclock|trap|trunc|unaligned_load)"
42 | color brightgreen "\$\$(unaligned_store|unreachable|veccompeq|veccompge|veccompgt|veccomple|veccomplt|veccompne|volatile_load|volatile_store)"
43 | color brightgreen "\$\$(wasm_memory_grow|wasm_memory_size)"
44 |
45 | # $ Keywords
46 | # generated by "c3c --list-keywords | sort -V"
47 | color brightyellow "\$\<(alignof|and|append|assert|assignable|case|concat|default|defined|echo|else|embed|endfor|endforeach|endif|endswitch)\>"
48 | color brightyellow "\$\<(eval|evaltype|error|exec|extnameof|feature|for|foreach|if|include|is_const|nameof|offsetof|or|qnameof|sizeof|stringify)\>"
49 | color brightyellow "\$\<(switch|typefrom|typeof|vacount|vatype|vaconst|varef|vaarg|vaexpr|vasplat)\>"
50 |
51 | color yellow "\<(asm|assert|bitstruct|break|case|catch|const|continue|def|default|defer|distinct|do|else)\>"
52 | color yellow "\<(enum|extern|false|fn|for|foreach|foreach_r|if|import|inline|interface)\>"
53 | color yellow "\<(macro|module|nextcase|null|return|static|struct|switch|tlocal|true|try|typeid|union)\>"
54 | color yellow "\<(var|while)\>"
55 |
56 | # Types
57 | color green "\<(any|anyfault|bfloat|bool|char|double|fault|float|float16|float128|ichar|int|int128|iptr|isz|long|short|uint|uint128|ulong|uptr|ushort|usz|void)\>"
58 |
59 | # @ Attributes
60 | # generated by "c3c --list-attributes | sort"
61 | color brightred "@\<(align|benchmark|bigendian|builtin|callconv|compact|deprecated|dynamic|export|extern|finalizer|if|inline|init|link|littleendian|local)\>"
62 | color brightred "@\<(maydiscard|naked|nodiscard|noinit|noinline|noinline|nopadding|noreturn|nostrip)\>"
63 | color brightred "@\<(obfuscate|operator|optional|overlap|packed|private|public|pure|reflect|safemacro|section|test|unused|used|wasm|weak|winmain)\>"
64 |
65 | # Operators
66 | # generated by "c3c --list-operators | sort"
67 |
68 | color brightblue ":|\?|\||\[\]|<=|>=|!=|<|>|\(|\)|\[|\]|\{|\}|\*|\+\+|\-\-|\=|\+|\-|&&|\^|\&|%|\/|~||!|!!|@|#"
69 |
70 | # Strings
71 | color brightblack "\"[^"]*\""
72 |
73 | # Everything down from here should stay in the current order
74 |
75 | # Comments
76 | color cyan "//.*"
77 | color cyan start="/\+" end="\+/"
78 | color cyan start="/\*" end="\*/"
79 |
80 | # Reminders
81 | color brightwhite,red "\<(FIXME|TODO|XXX)\>"
82 |
83 | # Trailing whitespace
84 | color ,green "[[:space:]]+$"
85 |
--------------------------------------------------------------------------------
/neovim/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Massimo Ronca
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/neovim/README.md:
--------------------------------------------------------------------------------
1 | # c3.nvim
2 | c3.nvim
3 |
4 |
5 | C3 neovim plugin
6 |
7 | ### Install
8 |
9 | ```lua
10 | -- lua/plugins/c3.lua
11 | return {
12 | {
13 | "wstucco/c3.nvim",
14 | config = function()
15 | require("c3")
16 | end,
17 | },
18 | }
19 | ```
--------------------------------------------------------------------------------
/neovim/lua/c3/init.lua:
--------------------------------------------------------------------------------
1 | return {
2 | -- Recommended configuration for C3
3 | setup = function()
4 | vim.filetype.add({
5 | extension = {
6 | c3 = "c3",
7 | c3i = "c3",
8 | c3t = "c3",
9 | },
10 | });
11 | end,
12 | recommended = {
13 | ft = "c3",
14 | root = { "project.json" },
15 | },
16 | {
17 | "nvim-treesitter/nvim-treesitter",
18 | opts = {
19 | ensure_installed = { "c3" },
20 | -- Add parser configurations
21 | parser_install_info = {
22 | c3 = {
23 | install_info = {
24 | url = "https://github.com/c3lang/tree-sitter-c3",
25 | files = { "src/parser.c", "src/scanner.c" },
26 | branch = "main",
27 | },
28 | sync_install = false, -- Set to true if you want to install synchronously
29 | auto_install = true, -- Automatically install when opening a file
30 | filetype = "c3", -- if filetype does not match the parser name
31 | },
32 | },
33 | highlight = {
34 | enable = true,
35 | additional_vim_regex_highlighting = false,
36 | },
37 | },
38 | },
39 | {
40 | "neovim/nvim-lspconfig",
41 | opts = {
42 | servers = {
43 | c3_lsp = {
44 | cmd = { "c3-lsp" },
45 | },
46 | },
47 | },
48 | },
49 | {
50 | "nvim-treesitter/nvim-treesitter-context", -- Optional: For better context display
51 | },
52 | {
53 | "nvim-treesitter/nvim-treesitter-refactor", -- Optional: For code refactoring features
54 | },
55 | }
56 |
--------------------------------------------------------------------------------
/neovim/queries/c3/folds.scm:
--------------------------------------------------------------------------------
1 | [
2 | ; Top-level declarations
3 | (bitstruct_declaration)
4 | (enum_declaration)
5 | (faultdef_declaration)
6 | (func_definition)
7 | (import_declaration)+
8 | (interface_declaration)
9 | (macro_declaration)
10 | (struct_declaration)
11 | ; Statements
12 | (asm_block_stmt)
13 | (case_stmt)
14 | (defer_stmt)
15 | (do_stmt)
16 | (for_stmt)
17 | (foreach_stmt)
18 | (if_stmt)
19 | (switch_stmt)
20 | (while_stmt)
21 | (ct_for_stmt)
22 | (ct_foreach_stmt)
23 | (ct_switch_stmt)
24 | (ct_case_stmt)
25 | (ct_if_stmt)
26 | (ct_else_stmt)
27 | ; Comments
28 | (block_comment)
29 | (doc_comment)
30 | ; Initializer list
31 | (initializer_list)
32 | ] @fold
33 |
34 | (compound_stmt
35 | (compound_stmt) @fold)
36 |
--------------------------------------------------------------------------------
/neovim/queries/c3/highlights.scm:
--------------------------------------------------------------------------------
1 | ; Punctuation
2 | [
3 | "("
4 | ")"
5 | "["
6 | "]"
7 | "{"
8 | "}"
9 | "[<"
10 | ">]"
11 | ] @punctuation.bracket
12 |
13 | [
14 | ";"
15 | ","
16 | ":"
17 | "::"
18 | ] @punctuation.delimiter
19 |
20 | ; Constant
21 | (const_ident) @constant
22 |
23 | [
24 | "true"
25 | "false"
26 | ] @boolean
27 |
28 | "null" @constant.builtin
29 |
30 | ; Variable
31 | [
32 | (ident)
33 | (ct_ident)
34 | (hash_ident)
35 | ] @variable
36 |
37 | ; 1) Member
38 | (field_expr
39 | field: (access_ident
40 | (ident) @variable.member))
41 |
42 | (struct_member_declaration
43 | (ident) @variable.member)
44 |
45 | (struct_member_declaration
46 | (identifier_list
47 | (ident) @variable.member))
48 |
49 | (bitstruct_member_declaration
50 | (ident) @variable.member)
51 |
52 | (initializer_list
53 | (initializer_element
54 | (param_path
55 | (param_path_element
56 | (access_ident (ident) @variable.member)))))
57 |
58 | ; 2) Parameter
59 | (param
60 | name: (_) @variable.parameter)
61 |
62 | (trailing_block_param
63 | (at_ident) @variable.parameter)
64 |
65 | (call_arg_list
66 | (call_arg
67 | name: (_) @variable.parameter))
68 |
69 | (enum_param
70 | (ident) @variable.parameter)
71 |
72 | ; Keyword (from `c3c --list-keywords`)
73 | [
74 | "alias"
75 | "asm"
76 | "attrdef"
77 | "catch"
78 | "defer"
79 | "try"
80 | "var"
81 | ] @keyword
82 |
83 | [
84 | "$alignof"
85 | "$assert"
86 | "$assignable"
87 | "$case"
88 | "$default"
89 | "$defined"
90 | "$echo"
91 | "$else"
92 | "$embed"
93 | "$endfor"
94 | "$endforeach"
95 | "$endif"
96 | "$endswitch"
97 | "$eval"
98 | "$evaltype"
99 | "$error"
100 | "$exec"
101 | "$extnameof"
102 | "$feature"
103 | "$for"
104 | "$foreach"
105 | "$if"
106 | "$include"
107 | "$is_const"
108 | "$nameof"
109 | "$offsetof"
110 | "$qnameof"
111 | "$sizeof"
112 | "$stringify"
113 | "$switch"
114 | "$typefrom"
115 | "$typeof"
116 | "$vacount"
117 | "$vatype"
118 | "$vaconst"
119 | "$vaarg"
120 | "$vaexpr"
121 | "$vasplat"
122 | ] @keyword.directive
123 |
124 | "assert" @keyword.debug
125 |
126 | "fn" @keyword.function
127 |
128 | "macro" @keyword.function
129 |
130 | "return" @keyword.return
131 |
132 | "import" @keyword.import
133 |
134 | "module" @keyword
135 |
136 | [
137 | "bitstruct"
138 | "enum"
139 | "faultdef"
140 | "interface"
141 | "struct"
142 | "typedef"
143 | "union"
144 | ] @keyword.type
145 |
146 | [
147 | "case"
148 | "default"
149 | "else"
150 | "if"
151 | "nextcase"
152 | "switch"
153 | ] @keyword.conditional
154 |
155 | [
156 | "break"
157 | "continue"
158 | "do"
159 | "for"
160 | "foreach"
161 | "foreach_r"
162 | "while"
163 | ] @keyword.repeat
164 |
165 | [
166 | "const"
167 | "extern"
168 | "inline"
169 | "static"
170 | "tlocal"
171 | ] @keyword.modifier
172 |
173 | ; Operator (from `c3c --list-operators`)
174 | [
175 | "&"
176 | "!"
177 | "~"
178 | "|"
179 | "^"
180 | "="
181 | ">"
182 | "/"
183 | "."
184 | "<"
185 | "-"
186 | "%"
187 | "+"
188 | "?"
189 | "*"
190 | "&&"
191 | "!!"
192 | "&="
193 | "|="
194 | "^="
195 | "/="
196 | ".."
197 | "?:"
198 | "=="
199 | ">="
200 | "=>"
201 | "<="
202 | "-="
203 | "--"
204 | "%="
205 | "*="
206 | "!="
207 | "||"
208 | "+="
209 | "++"
210 | "??"
211 | "<<"
212 | ">>"
213 | "..."
214 | "<<="
215 | ">>="
216 | "&&&"
217 | "+++"
218 | "|||"
219 | ] @operator
220 |
221 | (range_expr
222 | ":" @operator)
223 |
224 | (foreach_cond
225 | ":" @operator)
226 |
227 | (ct_foreach_cond
228 | ":" @operator)
229 |
230 | (ternary_expr
231 | [
232 | "?"
233 | ":"
234 | ] @keyword.conditional.ternary)
235 |
236 | (elvis_orelse_expr
237 | [
238 | "?:"
239 | "??"
240 | ] @keyword.conditional.ternary)
241 |
242 | ; Literal
243 | (integer_literal) @number
244 |
245 | (real_literal) @number.float
246 |
247 | (char_literal) @character
248 |
249 | (bytes_literal) @number
250 |
251 | ; String
252 | (string_literal) @string
253 |
254 | (raw_string_literal) @string
255 |
256 | ; Escape Sequence
257 | (escape_sequence) @string.escape
258 |
259 | ; Builtin (constants)
260 | (builtin_const) @constant.builtin
261 |
262 | ; Type Property (from `c3c --list-type-properties`)
263 | (type_access_expr
264 | (access_ident
265 | (ident) @variable.builtin
266 | (#any-of? @variable.builtin
267 | "alignof" "associated" "elements" "extnameof" "from_ordinal" "get" "inf" "is_eq" "is_ordered"
268 | "is_substruct" "len" "lookup" "lookup_field" "max" "membersof" "methodsof" "min" "nan" "inner"
269 | "kindof" "names" "nameof" "params" "paramsof" "parentof" "qnameof" "returns" "sizeof" "tagof"
270 | "has_tagof" "values" "typeid")))
271 |
272 | ; Label
273 | [
274 | (label)
275 | (label_target)
276 | ] @label
277 |
278 | ; Module
279 | (module_resolution
280 | (ident) @module)
281 |
282 | (module_declaration
283 | (path_ident
284 | (ident) @module))
285 |
286 | (import_declaration
287 | (path_ident
288 | (ident) @module))
289 |
290 | ; Attribute
291 | (attribute
292 | name: (at_ident) @attribute)
293 |
294 | (at_type_ident) @attribute
295 |
296 | (call_inline_attributes
297 | (at_ident) @attribute)
298 |
299 | (asm_block_stmt
300 | (at_ident) @attribute)
301 |
302 | ; Type
303 | [
304 | (type_ident)
305 | (ct_type_ident)
306 | ] @type
307 |
308 | (base_type_name) @type.builtin
309 |
310 | ; Function Definition
311 | (func_header
312 | name: (_) @function)
313 |
314 | (func_header
315 | method_type: (_)
316 | name: (_) @function.method)
317 |
318 | (macro_header
319 | name: (_) @function)
320 |
321 | (macro_header
322 | method_type: (_)
323 | name: (_) @function.method)
324 |
325 | ; Function Call
326 | (call_expr
327 | function: (ident_expr
328 | [
329 | (ident)
330 | (at_ident)
331 | ] @function.call))
332 |
333 | (call_expr
334 | function: (trailing_generic_expr
335 | argument: (ident_expr
336 | [
337 | (ident)
338 | (at_ident)
339 | ] @function.call)))
340 |
341 | ; Method call
342 | (call_expr
343 | function: (field_expr
344 | field: (access_ident
345 | [
346 | (ident)
347 | (at_ident)
348 | ] @function.method.call)))
349 |
350 | ; Method on type
351 | (call_expr
352 | function: (type_access_expr
353 | field: (access_ident
354 | [
355 | (ident)
356 | (at_ident)
357 | ] @function.method.call)))
358 |
359 | ; Builtin call
360 | (call_expr
361 | function: (builtin) @function.builtin)
362 |
363 | ; Asm
364 | (asm_instr
365 | [
366 | (ident)
367 | "int"
368 | ] @function.builtin)
369 |
370 | (asm_expr
371 | [
372 | (ct_ident)
373 | (ct_const_ident)
374 | ] @variable.builtin)
375 |
376 | ; Comment
377 | [
378 | (line_comment)
379 | (block_comment)
380 | ] @comment @spell
381 |
382 | (doc_comment) @comment.documentation
383 |
384 | (doc_comment_text) @spell
385 |
386 | (doc_comment_contract
387 | name: (_) @attribute)
388 |
389 | (doc_comment_contract
390 | parameter: [
391 | (ident)
392 | (ct_ident)
393 | (hash_ident)
394 | ] @variable.parameter
395 | (#set! priority 110))
396 |
397 | (doc_comment_contract
398 | [
399 | ":"
400 | "?"
401 | ] @comment.documentation
402 | (#set! priority 110))
403 |
404 | (doc_comment_contract
405 | description: (_) @comment.documentation
406 | (#set! priority 110))
407 |
--------------------------------------------------------------------------------
/neovim/queries/c3/indents.scm:
--------------------------------------------------------------------------------
1 | [
2 | (compound_stmt)
3 | (initializer_list)
4 | (implies_body)
5 | (struct_body)
6 | (bitstruct_body)
7 | (enum_body)
8 | (interface_body)
9 | (switch_body)
10 | (ct_if_stmt)
11 | (ct_for_stmt)
12 | (ct_foreach_stmt)
13 | (ct_switch_stmt)
14 | ] @indent.begin
15 |
16 | ([
17 | (case_stmt)
18 | (default_stmt)
19 | (ct_case_stmt)
20 | ] @indent.begin
21 | (#set! indent.immediate 1))
22 |
23 | (expr_stmt
24 | ";" @indent.end) @indent.begin
25 |
26 | (declaration
27 | ";" @indent.end) @indent.begin
28 |
29 | (const_declaration
30 | ";" @indent.end) @indent.begin
31 |
32 | (return_stmt
33 | ";" @indent.end) @indent.begin
34 |
35 | (faultdef_declaration
36 | ";" @indent.end) @indent.begin
37 |
38 | (macro_func_body
39 | ";" @indent.end)
40 |
41 | [
42 | ")"
43 | "}"
44 | "$endfor"
45 | "$endforeach"
46 | "$endswitch"
47 | "$endif"
48 | ] @indent.branch @indent.end
49 |
50 | "$else" @indent.branch
51 |
52 | ([
53 | (func_param_list)
54 | (macro_param_list)
55 | (enum_param_list)
56 | (attribute_param_list)
57 | (call_arg_list)
58 | (paren_cond)
59 | (for_cond)
60 | (foreach_cond)
61 | (paren_expr)
62 | ] @indent.align
63 | (#set! indent.open_delimiter "(")
64 | (#set! indent.close_delimiter ")"))
65 |
66 | [
67 | (block_comment)
68 | (doc_comment)
69 | (raw_string_literal)
70 | (bytes_literal)
71 | ] @indent.auto
72 |
73 | (string_literal) @indent.ignore
74 |
--------------------------------------------------------------------------------
/neovim/queries/c3/injections.scm:
--------------------------------------------------------------------------------
1 | ([
2 | (line_comment)
3 | (block_comment)
4 | ] @injection.content
5 | (#set! injection.language "comment"))
6 |
--------------------------------------------------------------------------------
/neovim/queries/c3/unused_queries.scm:
--------------------------------------------------------------------------------
1 | ;; 3) Declaration
2 | ; (declaration (identifier_list [(ident) (ct_ident)] @variable.declaration))
3 | ; (declaration name: [(ident) (ct_ident)] @variable.declaration)
4 | ; (var_declaration name: [(ident) (ct_ident)] @variable.declaration)
5 | ; (try_unwrap (ident) @variable.declaration)
6 | ; (catch_unwrap (ident) @variable.declaration)
7 |
8 | ; Assignment
9 | ; (assignment_expr left: (ident_expr (ident) @variable.member))
10 | ; (assignment_expr left: (field_expr field: (_) @variable.member))
11 | ; (assignment_expr left: (unary_expr operator: "*" @variable.member))
12 | ; (assignment_expr left: (subscript_expr ["[" "]"] @variable.member))
13 | ; (update_expr argument: (ident_expr ident: (ident) @variable.member))
14 | ; (update_expr argument: (field_expr field: (_) @variable.member))
15 | ; (update_expr argument: (unary_expr operator: "*" @variable.member))
16 | ; (update_expr argument: (subscript_expr ["[" "]"] @variable.member))
17 | ; (unary_expr operator: ["--" "++"] argument: (ident_expr (ident) @variable.member))
18 | ; (unary_expr operator: ["--" "++"] argument: (field_expr field: (access_ident (ident)) @variable.member))
19 | ; (unary_expr operator: ["--" "++"] argument: (subscript_expr ["[" "]"] @variable.member))
20 |
--------------------------------------------------------------------------------
/sublime-text/C3.sublime-build:
--------------------------------------------------------------------------------
1 | {
2 | "selector": "source.c3",
3 | "cmd": [
4 | "c3c",
5 | "build"
6 | ],
7 | "working_dir": "$folder",
8 | "file_regex": "^\\((.*.[cC]3t?):(\\d+):(\\d+)\\)",
9 | "variants": [
10 | {
11 | "name": "C3 build",
12 | "cmd": [
13 | "c3c",
14 | "build",
15 | ]
16 | },
17 | {
18 | "name": "C3 clean",
19 | "cmd": [
20 | "c3c",
21 | "clean",
22 | ]
23 | },
24 | {
25 | "name": "C3 test",
26 | "cmd": [
27 | "c3c",
28 | "test",
29 | ]
30 | },
31 | {
32 | "name": "C3 benchmark",
33 | "cmd": [
34 | "c3c",
35 | "benchmark",
36 | ]
37 | },
38 | {
39 | "name": "C3 Run",
40 | "cmd": [
41 | "c3c",
42 | "run",
43 | ]
44 | },
45 | ]
46 | }
47 |
--------------------------------------------------------------------------------
/sublime-text/C3.sublime-syntax:
--------------------------------------------------------------------------------
1 | %YAML 1.2
2 | ---
3 | # See http://www.sublimetext.com/docs/syntax.html
4 | file_extensions:
5 | - c3
6 | - c3i
7 | - c3t
8 |
9 | scope: source.c3
10 |
11 | variables:
12 | INT: '[0-9](_?[0-9])*'
13 | HINT: '[a-fA-F0-9](_?[a-fA-F0-9])*'
14 | OINT: '[0-7](_?[0-7])*'
15 | BINT: '[0-1](_?[0-1])*'
16 | INTTYPE: '(?:[ui](8|16|32|64|128)|[Uu][Ll]{0,2}|[Ll]{1,2})'
17 | REALTYPE: '(?:[f](8|16|32|64|128)?)'
18 | E: '[Ee][+-]?[0-9]+'
19 | P: '[Pp][+-]?[0-9]+'
20 | CONST: '(?:\b_*[A-Z][_A-Z0-9]*\b)'
21 | TYPE: '(?:\b_*[A-Z][_A-Z0-9]*[a-z][_a-zA-Z0-9]*\b)'
22 | IDENT: '(?:\b_*[a-z][_a-zA-Z0-9]*\b)'
23 | keyword: 'assert|asm|catch|inline|import|module|interface|try|var'
24 | control_keyword: 'break|case|continue|default|defer|do|else|for|foreach|foreach_r|if|nextcase|return|switch|while'
25 | ct_keyword: 'alignof|assert|assignable|default|defined|echo|embed|eval|error|exec|extnameof|feature|include|is_const|nameof|offsetof|qnameof|sizeof|stringify|vacount|vaconst|vaarg|vaexpr|vasplat'
26 | ct_control_keyword: 'case|else|endfor|endforeach|endif|endswitch|for|foreach|if|switch'
27 | base_type: 'void|bool|char|double|float|float16|int128|ichar|int|iptr|isz|long|short|uint128|uint|ulong|uptr|ushort|usz|float128|any|anyfault|typeid'
28 | attribute: 'align|benchmark|bigendian|builtin|callconv|compact|const|deprecated|dynamic|export|extern|finalizer|format|if|inline|init|link|littleendian|local|maydiscard|naked|noalias|nodiscard|noinit|noinline|nopadding|norecurse|noreturn|nosanitize|nostrip|obfuscate|operator|operator_r|operator_s|optional|overlap|packed|private|public|pure|reflect|safemacro|section|tag|test|unused|used|wasm|weak|winmain'
29 | TYPE_IDENT: '\b(?:{{base_type}})\b|\$?{{TYPE}}'
30 |
31 | contexts:
32 | main:
33 | - include: top_level
34 |
35 | prototype:
36 | - include: comments
37 |
38 | else_pop:
39 | - match: '(?=\S)'
40 | pop: true
41 |
42 | immediately_pop:
43 | - match: ''
44 | pop: true
45 |
46 | pop_on_semicolon:
47 | - match: ';'
48 | scope: punctuation.terminator.c3
49 | pop: true
50 |
51 | pop_on_colon:
52 | - match: ':'
53 | scope: punctuation.separator.c3
54 | pop: true
55 |
56 | pop_on_close_brace:
57 | - match: '\}'
58 | scope: punctuation.section.block.end.c3
59 | pop: true
60 |
61 | assign_right_expression:
62 | - match: '='
63 | scope: keyword.operator.assignment.c3
64 | set:
65 | - include: pop_on_semicolon
66 | - include: expression
67 |
68 | top_level:
69 | # Modifier
70 | - include: modifier_keywords
71 |
72 | - match: ';'
73 | scope: punctuation.terminator.c3
74 |
75 | # Compile Time Statements
76 | - match: '\$(?:assert|include|echo|exec)\b'
77 | scope: keyword.other.c3
78 | push:
79 | - include: pop_on_semicolon
80 | - include: expression
81 |
82 | # Module
83 | - match: '\bmodule\b'
84 | scope: keyword.declaration.module.c3
85 | push:
86 | - meta_scope: meta.module.c3
87 | - include: pop_on_semicolon
88 | - include: attribute
89 | - include: path
90 | - match: '{{IDENT}}'
91 | scope: meta.path.c3 entity.name.module.c3
92 | push: maybe_generic_params
93 |
94 | # Import
95 | - match: '\bimport\b'
96 | scope: keyword.control.import.c3
97 | push:
98 | - meta_scope: meta.import.c3
99 | - include: pop_on_semicolon
100 | - include: punctuation
101 | - include: attribute
102 | - include: path
103 | - match: '{{IDENT}}'
104 | scope: meta.path.c3
105 |
106 | # Function/Macro
107 | - match: '\b(?:fn|macro)\b'
108 | scope: keyword.declaratioFn.function.c3
109 | push: function
110 |
111 | # Alias
112 | - match: '\balias\b'
113 | scope: keyword.declaration.alias.c3
114 | push:
115 | - meta_scope: meta.alias.c3
116 | - include: pop_on_semicolon
117 | # Variable/function/macro/method/constant alias
118 | - match: '(@{{IDENT}})|({{IDENT}})|({{CONST}})'
119 | captures:
120 | 1: entity.name.function.c3
121 | 2: entity.name.alias.c3
122 | 3: entity.name.constant.c3
123 | set:
124 | - include: pop_on_semicolon
125 | - include: attribute
126 | - include: assign_right_expression
127 |
128 | # Type/function signature alias
129 | - match: '{{TYPE}}'
130 | branch_point:
131 | scope: entity.name.type.c3
132 | set:
133 | - include: pop_on_semicolon
134 | - include: attribute
135 | - include: assign_right_expression
136 |
137 | # Typedef
138 | - match: '\btypedef\b'
139 | scope: keyword.declaration.typedef.c3
140 | push:
141 | - meta_scope: meta.typedef.c3
142 | - include: pop_on_semicolon
143 | - match: '{{TYPE}}'
144 | #scope: storage.type.c3
145 | scope: entity.name.type.c3
146 | set:
147 | - include: pop_on_semicolon
148 | # Interface implementation
149 | - include: parens
150 | - include: attribute
151 | - include: assign_right_expression
152 |
153 | # Faultdef
154 | - match: '\bfaultdef\b'
155 | scope: keyword.declaration.faultdef.c3
156 | push:
157 | - meta_scope: meta.faultdef.c3
158 | - include: pop_on_semicolon
159 | - include: attribute
160 | - match: '{{CONST}}'
161 | scope: entity.name.constant.c3
162 | - match: ','
163 | scope: punctuation.separator.c3
164 |
165 | # Attrdef
166 | - match: '\battrdef\b'
167 | scope: keyword.declaration.attrdef.c3
168 | push:
169 | - meta_scope: meta.attrdef.c3
170 | - include: pop_on_semicolon
171 | - match: '@{{TYPE}}'
172 | scope: keyword.annotation.c3
173 | set:
174 | - include: pop_on_semicolon
175 | - include: parameters
176 | - include: attribute
177 | - match: '='
178 | scope: keyword.operator.assignment.c3
179 | set:
180 | - include: pop_on_semicolon
181 | - include: attribute
182 | - match: ','
183 | scope: punctuation.separator.c3
184 |
185 | # Struct/Bitstruct/Union (structlikes)
186 | - include: structlike
187 |
188 | # Enum
189 | - match: '\benum\b'
190 | scope: keyword.declaration.enum.c3
191 | push:
192 | - meta_scope: meta.enum.c3
193 | - match: '{{TYPE}}'
194 | scope: entity.name.enum.c3
195 | - include: attribute
196 | - match: ':'
197 | scope: punctuation.separator.c3
198 | push:
199 | - match: '(?=\{)'
200 | pop: true
201 | - match: '\binline\b'
202 | scope: storage.modifier.c3 # TODO
203 | - include: type_no_generics
204 | # Enum parameters
205 | - include: parameters
206 | - include: attribute
207 | # Enum body
208 | - match: '(?=\{)'
209 | set:
210 | - meta_include_prototype: false
211 | - match: '\{'
212 | scope: punctuation.section.block.begin.c3
213 | set:
214 | - meta_scope: meta.enum.body.c3 meta.block.c3
215 | - include: pop_on_close_brace
216 | - match: '='
217 | scope: keyword.operator.assignment.c3
218 | push:
219 | - match: '(?=,)'
220 | pop: true
221 | - include: expression
222 | - include: attribute
223 | - match: '{{CONST}}'
224 | scope: entity.name.constant.c3
225 | - match: ','
226 | scope: punctuation.separator.c3
227 |
228 |
229 | # Interface
230 | - match: '\binterface\b'
231 | scope: keyword.declaration.interface.c3
232 | push:
233 | - meta_scope: meta.interface.c3
234 | - match: '{{TYPE}}'
235 | scope: entity.name.interface.c3
236 | - include: attribute
237 | - match: ':'
238 | scope: punctuation.separator.c3
239 | push:
240 | - match: '(?=\{)'
241 | pop: true
242 | - include: punctuation
243 | - include: type_no_generics
244 | - match: '(?=\{)'
245 | set:
246 | - meta_include_prototype: false
247 | - match: '\{'
248 | scope: punctuation.section.block.begin.c3
249 | set:
250 | - meta_scope: meta.interface.body.c3 meta.block.c3
251 | - include: pop_on_close_brace
252 | - match: ';'
253 | scope: punctuation.terminator.c3
254 | - match: '\bfn\b'
255 | scope: keyword.declaration.function.c3
256 | push: function
257 |
258 | # Global
259 | - include: declaration
260 |
261 | function:
262 | - meta_scope: meta.function.c3
263 | - include: type
264 | - match: '\.'
265 | scope: punctuation.accessor.c3
266 | - match: '\@?{{IDENT}}'
267 | scope: entity.name.function.c3
268 | - match: '\('
269 | scope: meta.function.parameters.c3 meta.group.c3 punctuation.section.group.begin.c3
270 | set: [function_after_parameters, function_parameters_inner]
271 |
272 | function_parameters_inner:
273 | - meta_content_scope: meta.function.parameters.c3 meta.group.c3
274 | - match: '\)'
275 | scope: punctuation.section.group.end.c3
276 | pop: true
277 | # Parameters
278 | - include: type
279 | - include: punctuation
280 | - match: '\.\.\.'
281 | scope: keyword.operator.variadic.c3
282 | - match: '&'
283 | scope: keyword.operator.address.c3
284 | - match: '(?:(\$)|#)?{{IDENT}}'
285 | captures:
286 | 1: punctuation.definition.variable.c3
287 | scope: variable.parameter.c3
288 | push:
289 | - include: attribute
290 | - match: '\.\.\.'
291 | scope: keyword.operator.variadic.c3
292 | # Parameter with default value
293 | - match: '='
294 | scope: keyword.operator.assignment.c3
295 | set:
296 | - match: '(?=[,;)])'
297 | pop: true
298 | - include: expression
299 | - include: else_pop
300 | - match: ';'
301 | scope: punctuation.separator.c3
302 | push:
303 | - match: '(?=\))'
304 | pop: true
305 | # Trailing block param
306 | - match: '@{{IDENT}}'
307 | scope: entity.name.function.c3
308 | push:
309 | - match: '\('
310 | scope: meta.function.parameters.c3 meta.group.c3 punctuation.section.group.begin.c3
311 | set: function_parameters_inner
312 | - include: else_pop
313 |
314 | function_after_parameters:
315 | - meta_content_scope: meta.function.c3
316 | - include: attribute
317 | # Signature only
318 | - match: '(?=;)'
319 | pop: true
320 | # Function body
321 | - match: '\{'
322 | scope: punctuation.section.block.begin.c3
323 | push:
324 | - meta_scope: meta.block.c3
325 | - match: '\}'
326 | scope: punctuation.section.block.end.c3
327 | pop: 2
328 | - include: statements
329 |
330 | # Lambda body
331 | - match: '(?=\=>)'
332 | set:
333 | - meta_scope: meta.function.c3
334 | - match: '=>'
335 | scope: keyword.declaration.function.arrow.c3
336 | branch_point: function_arrow
337 | branch:
338 | - lambda_trailing_macro_body
339 | - lambda_expression
340 |
341 | func_macro_path_ident:
342 | - match: '::'
343 | scope: punctuation.accessor.c3
344 | - match: '\.'
345 | scope: punctuation.accessor.c3
346 | - include: path
347 | - match: '@?{{IDENT}}'
348 | scope: variable.function.c3
349 | push: maybe_generic_params
350 | - match: '{{TYPE}}'
351 | scope: storage.type.c3
352 |
353 | paren_func_macro_path_ident:
354 | - match: '\('
355 | push:
356 | - match: '\)'
357 | set: maybe_generic_params
358 | - include: paren_func_macro_path_ident
359 | - include: func_macro_path_ident
360 |
361 | macro_call_ident:
362 | - match: '\('
363 | set:
364 | - match: '\)'
365 | set: maybe_generic_params
366 | - include: paren_func_macro_path_ident
367 | - include: func_macro_path_ident
368 | - match: '(?=\S)'
369 | set:
370 | - include: func_macro_path_ident
371 | - include: else_pop
372 |
373 | macro_call_args_or_fail:
374 | - include: function_call_args
375 | - match: '(?=\S)'
376 | fail: function_arrow
377 |
378 | trailing_macro_body_or_fail:
379 | - match: '\{'
380 | scope: punctuation.section.block.begin.c3
381 | push:
382 | - meta_scope: meta.block.c3
383 | - match: '\}'
384 | scope: punctuation.section.block.end.c3
385 | set:
386 | - clear_scopes: 1
387 | # Expect a top level statement
388 | - match: '(?=[a-zA-Z_$;])'
389 | pop: 4
390 | - match: '(?=\S)'
391 | fail: function_arrow
392 | - include: statements
393 | - match: '(?=\S)'
394 | fail: function_arrow
395 |
396 | lambda_trailing_macro_body:
397 | - match: '(?=\S)'
398 | push: [trailing_macro_body_or_fail, maybe_attribute, macro_call_args_or_fail, macro_call_ident]
399 |
400 | lambda_expression:
401 | - match: '(?=[;,)])'
402 | pop: 2
403 | - include: expression
404 |
405 | structlike:
406 | - match: '\b(?:(struct|bitstruct)|(union))\b'
407 | captures:
408 | 1: keyword.declaration.struct.c3
409 | 2: keyword.declaration.union.c3
410 | push:
411 | - meta_scope: meta.struct.c3
412 | - match: '{{TYPE}}'
413 | scope: entity.name.struct.c3
414 | - match: '{{IDENT}}'
415 | scope: variable.other.member.c3
416 | - include: attribute
417 | - match: ':'
418 | scope: punctuation.separator.c3
419 | push:
420 | - match: '(?=\{)'
421 | pop: true
422 | - include: type_no_generics
423 | - include: attribute
424 | # Interface implementation
425 | - include: parens
426 | # Struct body
427 | - match: '(?=\{)'
428 | set:
429 | - meta_include_prototype: false
430 | - match: '\{'
431 | scope: punctuation.section.block.begin.c3
432 | set:
433 | - meta_scope: meta.struct.body.c3 meta.block.c3
434 | - include: pop_on_close_brace
435 | - include: structlike
436 | - include: modifier_keywords
437 | - include: type
438 | - match: '{{IDENT}}'
439 | scope: variable.other.member.c3
440 | - include: attribute
441 | - match: ';'
442 | scope: punctuation.terminator.c3
443 | # Bitstruct
444 | - match: ':'
445 | scope: punctuation.separator.c3
446 | push:
447 | - match: '(?=;)'
448 | pop: true
449 | - include: expression
450 |
451 | builtin:
452 | - match: '\$\$(?:{{CONST}}|{{IDENT}})'
453 | scope: keyword.builtin.c3
454 |
455 | keywords:
456 | - match: '\$(?:{{ct_keyword}})\b'
457 | scope: keyword.other.ct.c3
458 | - match: '\$(?:{{ct_control_keyword}})\b'
459 | scope: keyword.control.ct.c3
460 | - match: '\b(?:{{keyword}})\b'
461 | scope: keyword.other.c3
462 | - match: '\b(?:{{control_keyword}})\b'
463 | scope: keyword.control.c3
464 |
465 | modifier_keywords:
466 | - match: '\b(?:extern|static|tlocal|inline)\b'
467 | scope: storage.modifier.c3
468 |
469 | punctuation:
470 | # No semicolon here because we always match it separately
471 | - match: ','
472 | scope: punctuation.separator.c3
473 | - match: ':'
474 | scope: punctuation.separator.c3
475 | - match: ':(?!:)'
476 | scope: punctuation.separator.c3
477 | - match: '::|\.(?!\.\.)'
478 | scope: punctuation.accessor.c3
479 |
480 | constants:
481 | - match: '\b(true|false|null)\b'
482 | scope: constant.language.c3
483 | - match: '{{CONST}}'
484 | scope: constant.other.c3
485 | push: maybe_generic_params
486 |
487 | operators:
488 | - match: '&&&?|\|\|\|?'
489 | scope: keyword.operator.logical.c3
490 | - match: '!|\?[?:]?|\*|&|:'
491 | scope: keyword.operator.c3
492 | - match: '\.\.(?!\.)'
493 | scope: keyword.operator.range.c3
494 | - match: '\.\.\.'
495 | scope: keyword.operator.variadic.c3
496 | - match: '\+\+\+?|--'
497 | scope: keyword.operator.arithmetic.c3
498 | - match: '\+=|-=|\*=|/=|%=|&=|\|=|\^=|>>=|<<='
499 | scope: keyword.operator.assignment.augmented.c3
500 | - match: '<<|>>'
501 | scope: keyword.operator.arithmetic.c3
502 | - match: '<=|>=|==|<|>|\!='
503 | scope: keyword.operator.comparison.c3
504 | - match: '\+|\-|/|%|\||\^|~|!'
505 | scope: keyword.operator.arithmetic.c3
506 | - match: '='
507 | scope: keyword.operator.assignment.c3
508 |
509 | path:
510 | - match: '{{IDENT}}\s*(::)'
511 | captures:
512 | 1: punctuation.accessor.c3
513 | scope: meta.path.c3
514 |
515 | literals:
516 | - include: string_literal
517 | - include: char_literal
518 | - include: raw_string_literal
519 | - include: real_literal
520 | - include: integer_literal
521 | - include: bytes_literal
522 |
523 | char_literal:
524 | - match: "'"
525 | scope: punctuation.definition.string.begin.c3
526 | push:
527 | - meta_include_prototype: false
528 | - meta_scope: string.quoted.single.c3
529 | - match: '\\.'
530 | scope: constant.character.escape.c3
531 | - match: "'"
532 | scope: punctuation.definition.string.end.c3
533 | pop: true
534 |
535 | string_literal:
536 | - match: '"'
537 | scope: punctuation.definition.string.begin.c3
538 | push:
539 | - meta_include_prototype: false
540 | - meta_scope: string.quoted.double.c3
541 | - match: '\\([0abefnrtv''"\\]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})'
542 | scope: constant.character.escape.c3
543 | - match: '"'
544 | scope: punctuation.definition.string.end.c3
545 | pop: true
546 |
547 | raw_string_literal:
548 | - match: '`'
549 | scope: punctuation.definition.string.begin.c3
550 | push:
551 | - meta_include_prototype: false
552 | - meta_scope: string.quoted.other.c3
553 | - match: '``'
554 | scope: constant.character.escape.c3
555 | - match: '`'
556 | scope: punctuation.definition.string.end.c3
557 | pop: true
558 |
559 | real_literal:
560 | - match: '\b{{INT}}{{REALTYPE}}'
561 | scope: constant.numeric.float.c3
562 | - match: '\b(?:{{INT}}{{E}}|{{INT}}\.(?!\.)(?:{{INT}})?(?:{{E}})?){{REALTYPE}}?'
563 | scope: constant.numeric.float.c3
564 | - match: '\b(?:0[xX]{{HINT}}{{P}}|0[xX]{{HINT}}\.(?!\.)(?:{{HINT}})?(?:{{P}})?)'
565 | scope: constant.numeric.float.c3
566 |
567 | integer_literal:
568 | - match: '\b(?:0[xX]{{HINT}}|0[oO]{{OINT}}|0[bB]{{BINT}}|{{INT}}){{INTTYPE}}?'
569 | scope: constant.numeric.integer.c3
570 |
571 | bytes_literal:
572 | - match: "(x)([\"'`])"
573 | captures:
574 | 1: keyword.other.c3
575 | 2: punctuation.definition.string.begin.c3
576 | push:
577 | - meta_include_prototype: false
578 | - meta_scope: string.quoted.other.c3
579 | - match: "\\2"
580 | captures:
581 | 0: punctuation.definition.string.end.c3
582 | pop: true
583 | - match: '[\sfA-Fa-f0-9]+'
584 | scope: constant.numeric.integer.c3
585 | - match: "(b64)([\"'`])"
586 | captures:
587 | 1: keyword.other.c3
588 | push:
589 | - meta_include_prototype: false
590 | - meta_scope: string.quoted.other.c3
591 | - match: "\\2"
592 | captures:
593 | 0: punctuation.definition.string.end.c3
594 | pop: true
595 | - match: '[\sA-Za-z0-9+/=]+'
596 | scope: constant.numeric.integer.c3
597 |
598 | comments:
599 | - include: line_comment
600 | - include: block_comment
601 | - include: doc_comment
602 |
603 | line_comment:
604 | - match: '//'
605 | scope: punctuation.definition.comment.c3
606 | push: line_comment_body
607 |
608 | line_comment_body:
609 | - meta_include_prototype: false
610 | - meta_scope: comment.line.double-slash.c3
611 | - match: $
612 | pop: true
613 |
614 | block_comment:
615 | - match: '/\*'
616 | scope: punctuation.definition.comment.begin.c3
617 | push: block_comment_body
618 |
619 | block_comment_body:
620 | - meta_include_prototype: false
621 | - meta_scope: comment.block.c3
622 | - match: '/\*'
623 | scope: punctuation.definition.comment.begin.c3
624 | push: block_comment_body
625 | - match: '\*/'
626 | scope: punctuation.definition.comment.end.c3
627 | pop: true
628 |
629 | doc_comment:
630 | - match: '<\*'
631 | scope: punctuation.definition.comment.begin.c3
632 | push: doc_comment_body
633 |
634 | doc_comment_body:
635 | - meta_include_prototype: false
636 | - include: line_comment
637 | - include: block_comment
638 | - meta_scope: comment.block.documentation.c3
639 | - match: '\*>'
640 | scope: punctuation.definition.comment.end.c3
641 | pop: true
642 | - include: doc_comment_content
643 |
644 | doc_comment_content:
645 | - match: '@(param(\s*\[&?(in|out|inout)\])?|return\??|require|deprecated|ensure|pure)\s'
646 | scope: markup.bold
647 |
648 | type_parens:
649 | - match: '\('
650 | scope: punctuation.section.group.begin.c3
651 | push:
652 | - meta_scope: meta.group.c3
653 | - match: '\)'
654 | scope: punctuation.section.group.end.c3
655 | pop: 2
656 | - include: expression
657 |
658 | type_brackets:
659 | - match: '\['
660 | scope: punctuation.section.brackets.begin.c3
661 | push:
662 | - meta_scope: meta.brackets.c3
663 | - match: '\]'
664 | scope: punctuation.section.brackets.end.c3
665 | pop: 2
666 | - include: expression
667 |
668 | type:
669 | - include: path
670 | - match: '{{TYPE_IDENT}}'
671 | scope: storage.type.c3
672 | push: [maybe_type_suffix, maybe_generic_params]
673 | - match: '\$(?:typeof|typefrom|evaltype)\b'
674 | scope: storage.type.c3
675 | push: [maybe_type_suffix, type_parens]
676 | - match: '\$vatype\b'
677 | scope: storage.type.c3
678 | push: [maybe_type_suffix, type_brackets]
679 |
680 | type_no_generics:
681 | - include: path
682 | - match: '{{TYPE_IDENT}}'
683 | scope: storage.type.c3
684 | push: [maybe_type_suffix]
685 | - match: '\$(?:typeof|typefrom|evaltype)\b'
686 | scope: storage.type.c3
687 | push: [maybe_type_suffix, type_parens]
688 | - match: '\$vatype\b'
689 | scope: storage.type.c3
690 | push: [maybe_type_suffix, type_brackets]
691 |
692 | expect_type:
693 | - include: path
694 | - match: '{{TYPE_IDENT}}'
695 | scope: storage.type.c3
696 | set: [maybe_type_suffix, maybe_generic_params]
697 | - match: '\$(?:typeof|typefrom|evaltype)\b'
698 | scope: storage.type.c3
699 | set: [maybe_type_suffix, type_parens]
700 | - match: '\$vatype\b'
701 | scope: storage.type.c3
702 | set: [maybe_type_suffix, type_brackets]
703 |
704 | maybe_type_suffix:
705 | - meta_content_scope: meta.type_suffix.c3 # non-standard scope
706 | - match: '\*'
707 | scope: keyword.operator.c3
708 | - match: '\?'
709 | scope: keyword.operator.c3
710 | - include: brackets
711 | - include: else_pop
712 |
713 | attribute:
714 | - match: '@(?:{{attribute}}|{{TYPE}})'
715 | scope: keyword.annotation.c3
716 | push:
717 | - meta_scope: meta.annotation.c3
718 | - include: maybe_parens
719 |
720 | maybe_attribute:
721 | - match: '@(?:{{attribute}}|{{TYPE}})'
722 | scope: keyword.annotation.c3
723 | set:
724 | - meta_scope: meta.annotation.c3
725 | - include: maybe_parens
726 | - include: else_pop
727 |
728 | declaration:
729 | - match: '\bconst\b'
730 | scope: storage.modifier.c3
731 | push:
732 | - meta_scope: meta.declaration.c3
733 | - match: '(?={{CONST}})'
734 | set: [maybe_declaration_after_type]
735 | - match: '(?=\S)'
736 | set: [maybe_declaration_after_type, expect_type]
737 | - include: path
738 | - match: '(?={{TYPE_IDENT}}|\$(?:typeof|typefrom|vatype|evaltype)\b)'
739 | push: [maybe_declaration_after_type, expect_type]
740 | - match: '\bvar\b'
741 | scope: storage.type.c3
742 | push:
743 | - meta_scope: meta.declaration.c3
744 | - include: pop_on_semicolon
745 | - match: '(\$)?{{IDENT}}'
746 | captures:
747 | 1: punctuation.definition.variable.c3
748 | scope: variable.other.c3
749 | - match: '\$?{{TYPE}}'
750 | scope: storage.type.c3
751 | - include: attribute
752 | - include: assign_right_expression
753 | - include: else_pop
754 |
755 | maybe_declaration_after_type:
756 | - meta_scope: meta.declaration.c3
757 | - include: pop_on_semicolon
758 | - match: ','
759 | scope: punctuation.separator.c3
760 | - match: '(\$)?{{IDENT}}'
761 | captures:
762 | 1: punctuation.definition.variable.c3
763 | scope: variable.other.c3
764 | - match: '{{CONST}}'
765 | scope: entity.name.constant.c3
766 | - include: attribute
767 | - include: assign_right_expression
768 | - include: else_pop
769 |
770 | control_statements:
771 | # CT for
772 | - match: '\$for\b'
773 | scope: keyword.control.ct.c3
774 | push:
775 | - include: pop_on_colon
776 | - include: statements
777 | # CT foreach
778 | - match: '\$foreach\b'
779 | scope: keyword.control.ct.c3
780 | push:
781 | - match: '(\$){{IDENT}}'
782 | captures:
783 | 1: punctuation.definition.variable.c3
784 | scope: variable.other.c3
785 | - match: ','
786 | scope: punctuation.separator.c3
787 | - match: ':'
788 | scope: keyword.operator.c3
789 | set:
790 | - include: pop_on_colon
791 | - include: expression
792 | # for
793 | - match: '\bfor\b'
794 | scope: keyword.control.c3
795 | push:
796 | - match: '\('
797 | scope: punctuation.section.group.begin.c3
798 | set:
799 | - meta_scope: meta.group.c3
800 | - match: '\)'
801 | scope: punctuation.section.group.end.c3
802 | pop: true
803 | - include: statements
804 | # CT switch/case/default/if
805 | - match: '\$(?:switch|case|default|if)\b'
806 | scope: keyword.control.ct.c3
807 | push:
808 | - include: pop_on_colon
809 | - include: expression
810 | # case/default
811 | - match: '\b(?:case|default)\b'
812 | scope: keyword.control.c3
813 | push:
814 | - include: pop_on_colon
815 | - include: expression
816 |
817 | statements:
818 | - include: modifier_keywords
819 | - match: ';'
820 | scope: punctuation.terminator.c3
821 |
822 | - include: control_statements
823 |
824 | - include: declaration
825 | - include: expression
826 |
827 | variable:
828 | - match: '(??\]'
918 | scope: punctuation.section.brackets.end.c3
919 | pop: true
920 | - include: expression
921 |
922 | generic_params:
923 | - match: '\{'
924 | scope: punctuation.definition.generic.begin.c3
925 | push:
926 | - meta_scope: meta.generic.c3
927 | - match: '\}'
928 | scope: punctuation.definition.generic.end.c3
929 | pop: true
930 | - include: expression
931 |
932 | maybe_generic_params:
933 | - match: '\{'
934 | scope: punctuation.definition.generic.begin.c3
935 | push:
936 | - meta_scope: meta.generic.c3
937 | - match: '\}'
938 | scope: punctuation.definition.generic.end.c3
939 | pop: 2
940 | - include: expression
941 | - include: else_pop
942 |
943 | parameters:
944 | - match: '\('
945 | scope: punctuation.section.group.begin.c3
946 | push:
947 | - meta_scope: meta.parameters.c3 meta.group.c3
948 | - match: '\)'
949 | scope: punctuation.section.group.end.c3
950 | pop: true
951 |
952 | # Parameters
953 | - include: type
954 | - include: punctuation
955 | - match: '{{IDENT}}'
956 | scope: variable.parameter.c3
957 | push:
958 | - match: '(?=[;,)])'
959 | pop: true
960 | - include: attribute
961 | # Parameter with default value
962 | - match: '='
963 | scope: keyword.operator.assignment.c3
964 | set:
965 | - match: '(?=[;,)])'
966 | pop: true
967 | - include: expression
968 |
--------------------------------------------------------------------------------
/sublime-text/Comments.tmPreferences:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | scope
5 | source.c3
6 | settings
7 |
8 | shellVariables
9 |
10 |
11 | name
12 | TM_COMMENT_START
13 | value
14 | //
15 |
16 |
17 | name
18 | TM_COMMENT_START_2
19 | value
20 | /*
21 |
22 |
23 | name
24 | TM_COMMENT_END_2
25 | value
26 | */
27 |
28 |
29 | name
30 | TM_COMMENT_START_3
31 | value
32 |
33 |
34 |
35 | name
36 | TM_COMMENT_END_3
37 | value
38 | ]]>
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/sublime-text/README.md:
--------------------------------------------------------------------------------
1 | # Sublime Text Package
2 |
3 | Features:
4 | - Full syntax highlighting
5 | - Build tools with support for `build`, `test`, `benchmark`, `clean` anf `run`. The `c3c` executable must be in the PATH for this to work. Build errors are parsed.
6 |
7 | To use it put this ([../sublime-build](../sublime-text)) directory into your
8 | `Packages/User/` folder and rename it to e.g. `c3`. The `Packages/User/`
9 | directory has the following paths:
10 |
11 | - Linux: `~/.config/sublime-text/Packages/User/`
12 | - MacOS: `~/Library/Application Support/Sublime Text/Packages/User/`
13 | - Windows: `%APPDATA%\Roaming\Sublime Text\Packages\User\` (`C:\Users\\AppData\Roaming\Sublime Text\Packages\User\`)
14 |
15 | ## Contributing
16 |
17 | [./C3.sublime-build](./C3.sublime-build) adds C3's build system integration, see
18 | [Sublime Text Build System Reference](https://www.sublimetext.com/docs/build_systems.html)
19 |
20 |
21 | # Toggle Comment Fix for C3 Plugin in Sublime Text
22 | There is a known issue with the C3 plugin for Sublime Text where the "Toggle Comment" feature doesn't function properly. Until this issue is resolved, you can use this simple plugin to enable commenting of single-line or multi-line code in Sublime Text for C3 files.
23 |
24 | Installation Guide
25 | Step 1: Create the Plugin
26 | Open Sublime Text.
27 |
28 | Navigate to Tools > Developer > New Plugin....
29 |
30 | Replace the default code with the code from file c3_toggle_comment.py
31 |
32 | Save the file as c3_toggle_comment.py in the Packages/User directory.
33 |
34 | Step 2: Set Up Key Binding
35 | Press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the Command Palette.
36 |
37 | Type Preferences: Key Bindings and select it.
38 |
39 | In the user key bindings file that opens, add the following code inside the array brackets (make sure to add commas if necessary):
40 |
41 | {
42 | "keys": ["ctrl+/"],
43 | "command": "c3_toggle_comment",
44 | "context": [
45 | { "key": "selector", "operator": "equal", "operand": "source.c3" }
46 | ]
47 | }
48 |
49 | How to Use
50 | Toggle Comment: Open a C3 file and select the lines you want to comment or uncomment.
51 | Press Ctrl+/ to toggle comments on the selected lines.
52 | Additional Information
53 | This plugin is a temporary workaround until the issue with the original C3 plugin is fixed.
54 | Feel free to customize the key binding and the plugin code to suit your needs.
55 | Cheers!
--------------------------------------------------------------------------------
/sublime-text/Symbols.tmPreferences:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | scope
6 |
7 | entity.name.module.c3,
8 | entity.name.struct.c3,
9 | entity.name.interface.c3,
10 | source.c3 meta.declaration.c3 entity.name.constant.c3,
11 | meta.faultdef.c3 entity.name.constant.c3,
12 | meta.alias.c3 entity.name.constant.c3,
13 | meta.alias.c3 entity.name.alias.c3
14 |
15 | settings
16 |
17 | showInSymbolList
18 | 1
19 | showInIndexedSymbolList
20 | 1
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sublime-text/SymbolsIgnore.tmPreferences:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | scope
6 |
7 |
8 | source.c3 meta.function.c3 meta.block.c3,
9 | source.c3 meta.function.parameters.c3,
10 | source.c3 meta.interface.body.c3
11 |
12 | settings
13 |
14 | showInSymbolList
15 | 0
16 | showInIndexedSymbolList
17 | 0
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sublime-text/c3_toggle_comment.py:
--------------------------------------------------------------------------------
1 | import sublime
2 | import sublime_plugin
3 |
4 | class C3ToggleCommentCommand(sublime_plugin.TextCommand):
5 | def run(self, edit):
6 | for region in self.view.sel():
7 | if region.empty():
8 | # Toggle comment on the current line
9 | line = self.view.line(region)
10 | self.toggle_line_comment(edit, line)
11 | else:
12 | # Toggle comment on each line in the selected region
13 | self.toggle_region_comments(edit, region, edit)
14 |
15 | def toggle_line_comment(self, edit, line):
16 | text = self.view.substr(line)
17 |
18 | if text.startswith("//"):
19 | # Uncomment by removing // from the start of the line
20 | uncommented_text = text[2:]
21 | self.view.replace(edit, line, uncommented_text)
22 | else:
23 | # Comment by adding // at the start of the line
24 | commented_text = "//" + text
25 | self.view.replace(edit, line, commented_text)
26 |
27 | def toggle_region_comments(self, edit, region, view_edit):
28 | # Process each line in the selected region separately
29 | lines = self.view.split_by_newlines(region)
30 | all_commented = all(self.view.substr(line).startswith("//") for line in lines)
31 |
32 | # Collect the modified text for each line in sequence
33 | modified_text = []
34 |
35 | for line in lines:
36 | text = self.view.substr(line)
37 |
38 | if all_commented:
39 | # Uncomment each line by removing // only if it is at the start
40 | if text.startswith("//"):
41 | uncommented_text = text[2:]
42 | modified_text.append(uncommented_text)
43 | else:
44 | modified_text.append(text)
45 | else:
46 | # Comment each line by adding // at the start
47 | commented_text = "//" + text
48 | modified_text.append(commented_text)
49 |
50 | # Join all modified lines into a single block of text
51 | new_content = "\n".join(modified_text)
52 |
53 | # Replace the entire region with the modified block of text
54 | self.view.replace(view_edit, region, new_content)
55 |
--------------------------------------------------------------------------------
/sublime-text/syntax_test_scopes.c3:
--------------------------------------------------------------------------------
1 | // SYNTAX TEST "C3.sublime-syntax"
2 |
3 | /**
4 | * Comment Tests
5 | */
6 |
7 | // comment
8 | // <- comment.line.double-slash.c3 punctuation.definition.comment.c3
9 | // <- comment.line.double-slash.c3 punctuation.definition.comment.c3
10 | //^^^^^^^^ comment.line.double-slash.c3 - punctuation
11 |
12 | /**/
13 | // ^^ comment.block.c3 punctuation.definition.comment.begin.c3
14 | // ^^ comment.block.c3 punctuation.definition.comment.end.c3
15 |
16 | /*/**/*/
17 | // ^^ comment.block.c3 punctuation.definition.comment.begin.c3 - coment comment
18 | // ^^ comment.block.c3 comment.block.c3 punctuation.definition.comment.begin.c3
19 | // ^^ comment.block.c3 comment.block.c3 punctuation.definition.comment.end.c3
20 | // ^^ comment.block.c3 punctuation.definition.comment.end.c3 - coment comment
21 | // ^ - comment
22 |
23 | /**
24 | // ^ - comment
25 | // ^^^ comment.block.documentation.c3 punctuation.definition.comment.begin.c3
26 | // ^ comment.block.documentation.c3 - punctuation
27 | */
28 | // <- comment.block.documentation.c3
29 | // ^^ comment.block.documentation.c3 punctuation.definition.comment.end.c3
30 | // ^ - comment
31 |
32 | <* */ *>
33 | // ^^^^^^^^ comment.block.documentation.c3
34 | // ^^ punctuation.definition.comment.begin.c3
35 | // ^^ punctuation.definition.comment.end.c3
36 |
--------------------------------------------------------------------------------
/vim/compiler/c3c.vim:
--------------------------------------------------------------------------------
1 | if exists("c3c")
2 | finish
3 | endif
4 | let current_compiler = "c3c"
5 | CompilerSet makeprg=c3c
6 |
7 | let s:cpo_save = &cpo
8 | set cpo-=C
9 |
10 | setlocal errorformat=(%f:%l:%c)\ %m
11 |
12 | let &cpo = s:cpo_save
13 | unlet s:cpo_save
14 |
15 | "vim: ft=vim
16 |
--------------------------------------------------------------------------------
/vim/ftdetect/c3.vim:
--------------------------------------------------------------------------------
1 | autocmd BufNewFile,BufRead *.c3 setfiletype c3
2 |
--------------------------------------------------------------------------------
/vim/ftplugin/c3.vim:
--------------------------------------------------------------------------------
1 | set commentstring=//%s
2 | setlocal shiftwidth=4
3 | setlocal tabstop=4
4 |
--------------------------------------------------------------------------------
/vim/syntax/c3.vim:
--------------------------------------------------------------------------------
1 | if exists("b:current_syntax")
2 | finish
3 | endif
4 |
5 | syn match c3Identifier display "\v<_*[a-z][A-Za-z0-9_]*>"
6 | syn match c3Function display "\zs\(\w*\)*\s*\ze("
7 | syn match c3Macro display "@\zs\(\w*\)*\s*\ze("
8 | syn match c3UserType display "_*[A-Z][a-zA-Z0-9_]\+"
9 | syn match c3UserAttr display "@_*[A-Z][a-zA-Z0-9_]\+"
10 | syn match c3GlobalConst display "_*[A-Z][A-Z0-9_]\+"
11 | syn match c3Label display "^\s*_*[A-Z][A-Z0-9_]\+:"
12 | syn match c3ComptimeId display "\v\$<_*[a-z][A-Za-z0-9_]*>"
13 |
14 | syn match c3Number display "\v<0[Xx][0-9A-Fa-f](_*[0-9A-Fa-f])*>"
15 | syn match c3Number display "\v<0[Oo][0-7](_*[0-7])*>"
16 | syn match c3Number display "\v<0[Bb][01](_*[01])*>"
17 | syn match c3Number display "\v<[0-9](_*[0-9])*([iu](8|16|32|64|128)|([Uu][Ll]?|[Ll]))?>"
18 |
19 | syn match c3Float display "\v<[0-9](_*[0-9])*[Ee][+-]?[0-9]+(f(8|16|32|64|128))?>"
20 | syn match c3Float display "\v<0[Xx][0-9A-Fa-f](_*[0-9A-Fa-f])*[Pp][+-]?[0-9]+(f(8|16|32|64|128))?>"
21 | syn match c3Float display "\v<[0-9](_*[0-9])*\.[0-9](_*[0-9])*([Ee][+-]?[0-9]+)?(f(8|16|32|64|128))?>"
22 | syn match c3Float display "\v<0[Xx][0-9A-Fa-f](_*[0-9A-Fa-f])*\.[0-9A-Fa-f](_*[0-9A-Fa-f])*([Pp][+-]?[0-9]+)?(f(8|16|32|64|128))?>"
23 |
24 | syn match c3Operator display "\v\.\.\.?"
25 | syn match c3Operator display "\v(\<\<|\>\>|[<>=!+*/%&~^|-])\=?"
26 | syn match c3Operator display "\v\+\+|--|\&\&|\|\||\?\?|::|\?:|\=>|[\[]<|>[\]]|\$\$"
27 |
28 | syn match c3Delimiter display "\v[;,:\{\}\(\)\[\].?]"
29 |
30 | syn match c3HexBytes display "\v"
46 | syn match c3Contract contained "\v<\@ensure>"
47 | syn match c3Contract contained "\v<\@param\s+\[(in|out|inout)\]"
48 | syn match c3Contract contained "\v<\@pure>"
49 |
50 | syn keyword c3Todo todo Todo TODO contained
51 |
52 | " TODO: Comment nesting
53 |
54 | syn keyword c3Keyword
55 | \ if else
56 | \ try catch
57 | \ defer return
58 | \ switch case nextcase default
59 | \ cast asm
60 | \ def alias faultdef typedef fn enum macro fault struct bitstruct interface
61 | \ module import
62 |
63 | syn keyword c3Repeat
64 | \ do while while
65 | \ for foreach foreach_r
66 | \ continue break
67 |
68 | syn keyword c3Specifier extern inline static tlocal
69 | syn keyword c3Specifier var const
70 |
71 | syn keyword c3BuiltinType typeid errtype void any anyfault bool
72 | syn keyword c3BuiltinType ichar short int long int128 isz iptr
73 | syn keyword c3BuiltinType char ushort uint ulong uint128 usz uptr
74 | syn keyword c3BuiltinType float16 float double float128
75 | syn keyword c3BuiltinType String ZString WString DString
76 |
77 | syn keyword c3Null null
78 | syn keyword c3Boolean true false
79 |
80 | syn match c3BuiltinAttr display "\v\@align"
81 | syn match c3BuiltinAttr display "\v\@benchmark"
82 | syn match c3BuiltinAttr display "\v\@bigendian"
83 | syn match c3BuiltinAttr display "\v\@builtin"
84 | syn match c3BuiltinAttr display "\v\@callconv"
85 | syn match c3BuiltinAttr display "\v\@deprecated"
86 | syn match c3BuiltinAttr display "\v\@dynamic"
87 | syn match c3BuiltinAttr display "\v\@export"
88 | syn match c3BuiltinAttr display "\v\@extern"
89 | syn match c3BuiltinAttr display "\v\@if"
90 | syn match c3BuiltinAttr display "\v\@inline"
91 | syn match c3BuiltinAttr display "\v\@interface"
92 | syn match c3BuiltinAttr display "\v\@littleendian"
93 | syn match c3BuiltinAttr display "\v\@local"
94 | syn match c3BuiltinAttr display "\v\@maydiscard"
95 | syn match c3BuiltinAttr display "\v\@naked"
96 | syn match c3BuiltinAttr display "\v\@nodiscard"
97 | syn match c3BuiltinAttr display "\v\@noinit"
98 | syn match c3BuiltinAttr display "\v\@noreturn"
99 | syn match c3BuiltinAttr display "\v\@nostrip"
100 | syn match c3BuiltinAttr display "\v\@obfuscate"
101 | syn match c3BuiltinAttr display "\v\@operator"
102 | syn match c3BuiltinAttr display "\v\@optional"
103 | syn match c3BuiltinAttr display "\v\@overlap"
104 | syn match c3BuiltinAttr display "\v\@priority"
105 | syn match c3BuiltinAttr display "\v\@private"
106 | syn match c3BuiltinAttr display "\v\@public"
107 | syn match c3BuiltinAttr display "\v\@pure"
108 | syn match c3BuiltinAttr display "\v\@reflect"
109 | syn match c3BuiltinAttr display "\v\@section"
110 | syn match c3BuiltinAttr display "\v\@test"
111 | syn match c3BuiltinAttr display "\v\@used"
112 | syn match c3BuiltinAttr display "\v\@unused"
113 |
114 | syn match c3ComptimeKw display "\$and"
115 | syn match c3ComptimeKw display "\$assert"
116 | syn match c3ComptimeKw display "\$case"
117 | syn match c3ComptimeKw display "\$default"
118 | syn match c3ComptimeKw display "\$echo"
119 | syn match c3ComptimeKw display "\$else"
120 | syn match c3ComptimeKw display "\$error"
121 | syn match c3ComptimeKw display "\$endfor"
122 | syn match c3ComptimeKw display "\$endforeach"
123 | syn match c3ComptimeKw display "\$endif"
124 | syn match c3ComptimeKw display "\$endswitch"
125 | syn match c3ComptimeKw display "\$for"
126 | syn match c3ComptimeKw display "\$foreach"
127 | syn match c3ComptimeKw display "\$if"
128 | syn match c3ComptimeKw display "\$switch"
129 | syn match c3ComptimeKw display "\$typef"
130 | syn match c3ComptimeKw display "\$vaarg"
131 | syn match c3ComptimeKw display "\$vaconst"
132 | syn match c3ComptimeKw display "\$vacount"
133 | syn match c3ComptimeKw display "\$varef"
134 | syn match c3ComptimeKw display "\$vatype"
135 |
136 | hi def link c3Number Number
137 | hi def link c3Float Number
138 | hi def link c3Identifier Identifier
139 | hi def link c3ComptimeId Identifier
140 |
141 | if hlexists('@namespace')
142 | hi def link c3UserAttr @namespace
143 | hi def link c3BuiltinAttr @namespace
144 | else
145 | hi def link c3UserAttr Special
146 | hi def link c3BuiltinAttr Special
147 | endif
148 |
149 | hi def link c3Function Function
150 | hi def link c3Function Macro
151 | hi def link c3BuiltinType Type
152 | hi def link c3Label Label
153 | hi def link c3UserType Type
154 | hi def link c3Keyword Keyword
155 | hi def link c3ComptimeKw Keyword
156 | hi def link c3Specifier StorageClass
157 | hi def link c3Repeat Repeat
158 | hi def link c3Boolean Boolean
159 | hi def link c3Null Boolean
160 | hi def link c3GlobalConst Constant
161 | hi def link c3String String
162 | hi def link c3HexBytes String
163 | hi def link c3Base64 String
164 | hi def link c3Operator Operator
165 | hi def link c3Delimiter Delimiter
166 | hi def link c3Comment Comment
167 | hi def link c3Contract Comment
168 |
169 | let b:current_syntax = "c3"
170 |
171 |
--------------------------------------------------------------------------------