-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add c3 language support to helix #11521
base: master
Are you sure you want to change the base?
Changes from 3 commits
b929979
5d567dc
ce99422
b39b3e5
1873b02
b7b8d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,323 @@ | ||
;; NOTE In this file later patterns are assumed to have priority! | ||
|
||
;; Punctuation | ||
["(" ")" "[" "]" "{" "}" "(<" ">)" "[<" ">]" "{|" "|}"] @punctuation.bracket | ||
[";" "," ":" "::"] @punctuation.delimiter | ||
|
||
;; Constant | ||
(const_ident) @constant | ||
["true" "false"] @boolean | ||
["null"] @constant.builtin | ||
|
||
;; Variable | ||
[(ident) (ct_ident)] @variable | ||
;; 1) Member | ||
(field_expr field: (access_ident (ident) @variable.member)) | ||
(struct_member_declaration (ident) @variable.member) | ||
(struct_member_declaration (identifier_list (ident) @variable.member)) | ||
(bitstruct_member_declaration (ident) @variable.member) | ||
(initializer_list (arg (param_path (param_path_element (ident) @variable.member)))) | ||
;; 2) Parameter | ||
(parameter name: (_) @variable.parameter) | ||
(call_invocation (arg (param_path (param_path_element [(ident) (ct_ident)] @variable.parameter)))) | ||
(enum_param_declaration (ident) @variable.parameter) | ||
;; 3) Declaration | ||
(global_declaration (ident) @variable.declaration) | ||
(local_decl_after_type name: [(ident) (ct_ident)] @variable.declaration) | ||
(var_decl name: [(ident) (ct_ident)] @variable.declaration) | ||
(try_unwrap (ident) @variable.declaration) | ||
(catch_unwrap (ident) @variable.declaration) | ||
|
||
;; Keyword (from `c3c --list-keywords`) | ||
[ | ||
"assert" | ||
"asm" | ||
"catch" | ||
"defer" | ||
"try" | ||
"var" | ||
] @keyword | ||
|
||
[ | ||
"$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" | ||
] @keyword.directive | ||
|
||
"fn" @keyword.function | ||
"macro" @keyword.function | ||
"return" @keyword.return | ||
"import" @keyword.import | ||
"module" @keyword.module | ||
|
||
[ | ||
"bitstruct" | ||
"def" | ||
"distinct" | ||
"enum" | ||
"fault" | ||
"interface" | ||
"struct" | ||
"union" | ||
] @keyword.type | ||
|
||
[ | ||
"case" | ||
"default" | ||
"else" | ||
"if" | ||
"nextcase" | ||
"switch" | ||
] @keyword.conditional | ||
|
||
[ | ||
"break" | ||
"continue" | ||
"do" | ||
"for" | ||
"foreach" | ||
"foreach_r" | ||
"while" | ||
] @keyword.repeat | ||
|
||
[ | ||
"const" | ||
"extern" | ||
"inline" | ||
"static" | ||
"tlocal" | ||
] @keyword.modifier | ||
|
||
;; Operator (from `c3c --list-operators`) | ||
[ | ||
"&" | ||
"!" | ||
"~" | ||
"|" | ||
"^" | ||
;; ":" | ||
;; "," | ||
;; ";" | ||
"=" | ||
">" | ||
"/" | ||
"." | ||
;; "#" | ||
"<" | ||
;; "{" | ||
;; "[" | ||
;; "(" | ||
"-" | ||
"%" | ||
"+" | ||
"?" | ||
;; "}" | ||
;; "]" | ||
;; ")" | ||
"*" | ||
;; "_" | ||
"&&" | ||
;; "->" | ||
"!!" | ||
"&=" | ||
"|=" | ||
"^=" | ||
"/=" | ||
".." | ||
"?:" | ||
"==" | ||
">=" | ||
"=>" | ||
"<=" | ||
;; "{|" | ||
;; "(<" | ||
;; "[<" | ||
"-=" | ||
"--" | ||
"%=" | ||
"*=" | ||
"!=" | ||
"||" | ||
"+=" | ||
"++" | ||
;; "|}" | ||
;; ">)" | ||
;; ">]" | ||
"??" | ||
;; "::" | ||
"<<" | ||
">>" | ||
"..." | ||
"<<=" | ||
">>=" | ||
] @operator | ||
|
||
(range_expr ":" @operator) | ||
(foreach_cond ":" @operator) | ||
|
||
(ternary_expr | ||
[ | ||
"?" | ||
":" | ||
] @keyword.conditional.ternary) | ||
|
||
(elvis_orelse_expr | ||
[ | ||
"?:" | ||
"??" | ||
] @keyword.conditional.ternary) | ||
|
||
;; Literal | ||
(integer_literal) @number | ||
(real_literal) @number.float | ||
(char_literal) @character | ||
(bytes_literal) @number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the scopes in this file need fixing https://docs.helix-editor.com/themes.html#syntax-highlighting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good way to debug these scopes ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the |
||
|
||
;; String | ||
(string_literal) @string | ||
(raw_string_literal) @string | ||
|
||
;; Escape Sequence | ||
(escape_sequence) @string.escape | ||
|
||
;; Builtin (constants) | ||
((builtin) @constant.builtin (#match? @constant.builtin "_*[A-Z][_A-Z0-9]*")) | ||
|
||
;; Type Property (from `c3c --list-type-properties`) | ||
(type_access_expr (access_ident [(ident) "typeid"] @variable.builtin | ||
(#any-of? @variable.builtin | ||
"alignof" | ||
"associated" | ||
"elements" | ||
"extnameof" | ||
"inf" | ||
"is_eq" | ||
"is_ordered" | ||
"is_substruct" | ||
"len" | ||
"max" | ||
"membersof" | ||
"min" | ||
"nan" | ||
"inner" | ||
"kindof" | ||
"names" | ||
"nameof" | ||
"params" | ||
"parentof" | ||
"qnameof" | ||
"returns" | ||
"sizeof" | ||
"values" | ||
;; Extra token | ||
"typeid"))) | ||
|
||
;; Label | ||
[ | ||
(label) | ||
(label_target) | ||
] @label | ||
|
||
;; Module | ||
(module_resolution (ident) @module) | ||
(module (path_ident (ident) @module)) | ||
(import_declaration (path_ident (ident) @module)) | ||
|
||
;; Attribute | ||
(attribute name: (_) @attribute) | ||
(define_attribute name: (_) @attribute) | ||
(call_inline_attributes (at_ident) @attribute) | ||
(asm_block_stmt (at_ident) @attribute) | ||
|
||
;; Type | ||
[ | ||
(type_ident) | ||
(ct_type_ident) | ||
] @type | ||
(base_type_name) @type.builtin | ||
|
||
;; Function Definition | ||
(func_header name: (_) @function) | ||
(func_header method_type: (_) name: (_) @function.method) | ||
;; NOTE macro_declaration can also have a func_header | ||
(macro_header name: (_) @function) | ||
(macro_header method_type: (_) name: (_) @function.method) | ||
|
||
;; Function Call | ||
(call_expr function: [(ident) (at_ident)] @function.call) | ||
(call_expr function: [(builtin)] @function.builtin.call) | ||
(call_expr function: (module_ident_expr ident: (_) @function.call)) | ||
(call_expr function: (trailing_generic_expr argument: (module_ident_expr ident: (_) @function.call))) | ||
(call_expr function: (field_expr field: (access_ident [(ident) (at_ident)] @function.method.call))) ; NOTE Ambiguous, could be calling a method or function pointer | ||
;; Method on type | ||
(call_expr function: (type_access_expr field: (access_ident [(ident) (at_ident)] @function.method.call))) | ||
|
||
;; Assignment | ||
;; (assignment_expr left: (ident) @variable.member) | ||
;; (assignment_expr left: (module_ident_expr (ident) @variable.member)) | ||
;; (assignment_expr left: (field_expr field: (_) @variable.member)) | ||
;; (assignment_expr left: (unary_expr operator: "*" @variable.member)) | ||
;; (assignment_expr left: (subscript_expr ["[" "]"] @variable.member)) | ||
|
||
;; (update_expr argument: (ident) @variable.member) | ||
;; (update_expr argument: (module_ident_expr ident: (ident) @variable.member)) | ||
;; (update_expr argument: (field_expr field: (_) @variable.member)) | ||
;; (update_expr argument: (unary_expr operator: "*" @variable.member)) | ||
;; (update_expr argument: (subscript_expr ["[" "]"] @variable.member)) | ||
|
||
;; (unary_expr operator: ["--" "++"] argument: (ident) @variable.member) | ||
;; (unary_expr operator: ["--" "++"] argument: (module_ident_expr (ident) @variable.member)) | ||
;; (unary_expr operator: ["--" "++"] argument: (field_expr field: (access_ident (ident)) @variable.member)) | ||
;; (unary_expr operator: ["--" "++"] argument: (subscript_expr ["[" "]"] @variable.member)) | ||
|
||
;; Asm | ||
(asm_instr [(ident) "int"] @function.builtin) | ||
(asm_expr [(ct_ident) (ct_const_ident)] @variable.builtin) | ||
|
||
;; Comment | ||
[ | ||
(line_comment) | ||
(block_comment) | ||
] @comment @spell | ||
|
||
(doc_comment) @comment.documentation @spell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key can be omitted since by default it matches the name of the language