diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/grammars/.gitkeep | 0 | ||||
-rw-r--r-- | runtime/queries/c/highlights.scm | 2 | ||||
-rw-r--r-- | runtime/queries/rust/highlights.scm | 483 | ||||
-rw-r--r-- | runtime/themes/dark_plus.toml | 80 |
4 files changed, 385 insertions, 180 deletions
diff --git a/runtime/grammars/.gitkeep b/runtime/grammars/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/runtime/grammars/.gitkeep diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 36fe47d9..258e07e7 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -54,6 +54,8 @@ "." @punctuation.delimiter ";" @punctuation.delimiter +(enumerator) @type.enum.variant + (string_literal) @string (system_lib_string) @string diff --git a/runtime/queries/rust/highlights.scm b/runtime/queries/rust/highlights.scm index b72216f6..5e469e67 100644 --- a/runtime/queries/rust/highlights.scm +++ b/runtime/queries/rust/highlights.scm @@ -1,213 +1,336 @@ -; Identifier conventions +; ------- +; Tree-Sitter doesn't allow overrides in regards to captures, +; though it is possible to affect the child node of a captured +; node. Thus, the approach here is to flip the order so that +; overrides are unnecessary. +; ------- -; Assume all-caps names are constants -((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]+$'")) -; Assume other uppercase names are enum constructors -((identifier) @constructor - (#match? @constructor "^[A-Z]")) +; ------- +; Types +; ------- -; Assume that uppercase names in paths are types -(mod_item - name: (identifier) @namespace) -(scoped_identifier - path: (identifier) @namespace) -(scoped_identifier - (scoped_identifier - name: (identifier) @namespace)) -(scoped_type_identifier - path: (identifier) @namespace) -(scoped_type_identifier - (scoped_identifier - name: (identifier) @namespace)) +; --- +; Primitives +; --- -((scoped_identifier - path: (identifier) @type) - (#match? @type "^[A-Z]")) -((scoped_identifier - path: (scoped_identifier - name: (identifier) @type)) - (#match? @type "^[A-Z]")) +(escape_sequence) @escape +(primitive_type) @type.builtin +(boolean_literal) @constant.builtin +[ + (integer_literal) + (float_literal) +] @number +[ + (char_literal) + (string_literal) + (raw_string_literal) +] @string +[ + (line_comment) + (block_comment) +] @comment -; Namespaces +; --- +; Extraneous +; --- -(crate) @namespace -(extern_crate_declaration - (crate) - name: (identifier) @namespace) -(scoped_use_list - path: (identifier) @namespace) -(scoped_use_list - path: (scoped_identifier - (identifier) @namespace)) -(use_list (scoped_identifier (identifier) @namespace . (_))) +(self) @variable.builtin +(enum_variant (identifier) @type.enum.variant) -; Function calls +(field_initializer + (field_identifier) @property) +(shorthand_field_initializer) @variable +(shorthand_field_identifier) @variable -(call_expression - function: (identifier) @function) -(call_expression - function: (field_expression - field: (field_identifier) @function.method)) -(call_expression - function: (scoped_identifier - "::" - name: (identifier) @function)) +(lifetime + "'" @label + (identifier) @label) +(loop_label + (identifier) @type) -(generic_function - function: (identifier) @function) -(generic_function - function: (scoped_identifier - name: (identifier) @function)) -(generic_function - function: (field_expression - field: (field_identifier) @function.method)) +; --- +; Punctuation +; --- -(macro_invocation - macro: (identifier) @function.macro - "!" @function.macro) -(macro_invocation - macro: (scoped_identifier - (identifier) @function.macro .)) +[ + "::" + "." + ";" +] @punctuation.delimiter -; (metavariable) @variable -(metavariable) @function.macro +[ + "(" + ")" + "[" + "]" +] @punctuation.bracket +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) -"$" @function.macro +; --- +; Parameters +; --- -; Function definitions +(parameter + pattern: (identifier) @variable.parameter) +(closure_parameters + (identifier) @variable.parameter) -(function_item (identifier) @function) -(function_signature_item (identifier) @function) -; Other identifiers -(type_identifier) @type -(primitive_type) @type.builtin -(field_identifier) @property +; ------- +; Keywords +; ------- -(line_comment) @comment -(block_comment) @comment +(for_expression + "for" @keyword.control) +((identifier) @keyword.control + (#match? @keyword.control "^yield$")) +[ + "while" + "loop" + "in" + "break" + "continue" -"(" @punctuation.bracket -")" @punctuation.bracket -"[" @punctuation.bracket -"]" @punctuation.bracket + "match" + "if" + "else" + "return" + + "await" +] @keyword.control + +[ + (crate) + (super) + "as" + "use" + "pub" + "mod" + "extern" + + "fn" + "struct" + "enum" + "impl" + "where" + "trait" + "for" + + "type" + "union" + "unsafe" + "default" + "macro_rules!" + + "let" + "ref" + "move" + + "dyn" + "static" + "const" + "async" +] @keyword -(type_arguments - "<" @punctuation.bracket - ">" @punctuation.bracket) -(type_parameters - "<" @punctuation.bracket - ">" @punctuation.bracket) - -"::" @punctuation.delimiter -"." @punctuation.delimiter -";" @punctuation.delimiter - -(parameter (identifier) @variable.parameter) -(closure_parameters (_) @variable.parameter) - -(lifetime (identifier) @label) - -"async" @keyword -"break" @keyword -"const" @keyword -"continue" @keyword -(crate) @keyword -"default" @keyword -"dyn" @keyword -"else" @keyword -"enum" @keyword -"extern" @keyword -"fn" @keyword -"for" @keyword -"if" @keyword -"impl" @keyword -"in" @keyword -"let" @keyword -"let" @keyword -"loop" @keyword -"macro_rules!" @keyword -"match" @keyword -"mod" @keyword -"move" @keyword -"pub" @keyword -"ref" @keyword -"return" @keyword -"static" @keyword -"struct" @keyword -"trait" @keyword -"type" @keyword -"union" @keyword -"unsafe" @keyword -"use" @keyword -"where" @keyword -"while" @keyword (mutable_specifier) @keyword.mut -(use_list (self) @keyword) -(scoped_use_list (self) @keyword) -(scoped_identifier (self) @keyword) -(super) @keyword -"as" @keyword -(self) @variable.builtin -[ -(char_literal) -(string_literal) -(raw_string_literal) -] @string -(boolean_literal) @constant.builtin -(integer_literal) @number -(float_literal) @number +; ------- +; Guess Other Types +; ------- -(escape_sequence) @escape +((identifier) @constant + (#match? @constant "^[A-Z][A-Z\\d_]+$")) + +; --- +; PascalCase identifiers in call_expressions (e.g. `Ok()`) +; are assumed to be enum constructors. +; --- + +(call_expression + function: [ + ((identifier) @type.variant + (#match? @type.variant "^[A-Z]")) + (scoped_identifier + name: ((identifier) @type.variant + (#match? @type.variant "^[A-Z]"))) + ]) + +; --- +; Assume that types in match arms are enums and not +; tuple structs. Same for `if let` expressions. +; --- + +(match_pattern + (scoped_identifier + name: (identifier) @constructor)) +(tuple_struct_pattern + type: [ + ((identifier) @constructor) + (scoped_identifier + name: (identifier) @constructor) + ]) +(struct_pattern + type: [ + ((type_identifier) @constructor) + (scoped_type_identifier + name: (type_identifier) @constructor) + ]) + +; --- +; Other PascalCase identifiers are assumed to be structs. +; --- +((identifier) @type + (#match? @type "^[A-Z]")) + + + +; ------- +; Functions +; ------- + +(call_expression + function: [ + ((identifier) @function) + (scoped_identifier + name: (identifier) @function) + (field_expression + field: (field_identifier) @function) + ]) +(generic_function + function: [ + ((identifier) @function) + (scoped_identifier + name: (identifier) @function) + (field_expression + field: (field_identifier) @function.method) + ]) + +(function_item + name: (identifier) @function) + +; --- +; Macros +; --- + +(meta_item + (identifier) @attribute) (attribute_item) @attribute (inner_attribute_item) @attribute +(macro_definition + name: (identifier) @function.macro) +(macro_invocation + macro: [ + ((identifier) @function.macro) + (scoped_identifier + name: (identifier) @function.macro) + ] + "!" @function.macro) + +(metavariable) @variable.parameter +(fragment_specifier) @variable.parameter + + + +; ------- +; Operators +; ------- + [ -"*" -"'" -"->" -"=>" -"<=" -"=" -"==" -"!" -"!=" -"%" -"%=" -"&" -"&=" -"&&" -"|" -"|=" -"||" -"^" -"^=" -"*" -"*=" -"-" -"-=" -"+" -"+=" -"/" -"/=" -">" -"<" -">=" -">>" -"<<" -">>=" -"@" -".." -"..=" -"'" + "*" + "'" + "->" + "=>" + "<=" + "=" + "==" + "!" + "!=" + "%" + "%=" + "&" + "&=" + "&&" + "|" + "|=" + "||" + "^" + "^=" + "*" + "*=" + "-" + "-=" + "+" + "+=" + "/" + "/=" + ">" + "<" + ">=" + ">>" + "<<" + ">>=" + "@" + ".." + "..=" + "'" ] @operator + + +; ------- +; Paths +; ------- + +(use_declaration + argument: (identifier) @namespace) +(use_wildcard + (identifier) @namespace) +(extern_crate_declaration + name: (identifier) @namespace) +(mod_item + name: (identifier) @namespace) +(scoped_use_list + path: (identifier)? @namespace) +(use_list + (identifier) @namespace) +(use_as_clause + path: (identifier)? @namespace + alias: (identifier) @namespace) + +; --- +; Remaining Paths +; --- + +(scoped_identifier + path: (identifier)? @namespace + name: (identifier) @namespace) +(scoped_type_identifier + path: (identifier) @namespace) + + + +; ------- +; Remaining Identifiers +; ------- + "?" @special + +(type_identifier) @type +(identifier) @variable +(field_identifier) @variable diff --git a/runtime/themes/dark_plus.toml b/runtime/themes/dark_plus.toml new file mode 100644 index 00000000..82cc6289 --- /dev/null +++ b/runtime/themes/dark_plus.toml @@ -0,0 +1,80 @@ +# Author: Shafkath Shuhan <shafkathshuhannyc@gmail.com> + +"namespace" = { fg = "type" } +"module" = { fg = "type" } +"type" = { fg = "type" } +"type.builtin" = { fg = "type" } + +"keyword" = { fg = "keyword" } +"keyword.directive" = { fg = "keyword" } +"function.macro" = { fg = "keyword" } +"variable.builtin" = { fg = "keyword" } +"label" = { fg = "keyword" } +"constant.builtin" = { fg = "keyword" } + +"punctuation" = { fg = "text" } +"punctuation.delimiter" = { fg = "text" } + +"keyword.control" = { fg = "special" } +"special" = { fg = "text" } +"operator" = { fg = "text" } + +"variable" = { fg = "variable" } +"variable.parameter" = { fg = "variable" } +"property" = { fg = "variable" } + +"attribute" = { fg = "fn_declaration" } +"function" = { fg = "fn_declaration" } +"function.builtin" = { fg = "fn_declaration" } + +"comment" = { fg = "#6A9955" } + +"constant" = { fg = "constant" } +"type.enum.variant" = { fg = "constant" } +"constructor" = { fg = "constant" } + +"string" = { fg = "#ce9178" } +"number" = { fg = "#b5cea8" } +"escape" = { fg = "#d7ba7d" } + +"ui.background" = { fg = "#d4d4d4", bg = "#1e1e1e" } + +"ui.help" = { bg = "widget" } +"ui.popup" = { bg = "widget" } +"ui.window" = { bg = "widget" } +"ui.menu.selected" = { bg = "widget" } + +"ui.cursor" = { fg = "cursor", modifiers = ["reversed"] } +"ui.cursor.primary" = { fg = "cursor", modifiers = ["reversed"] } +"ui.cursor.match" = { fg = "cursor", modifiers = ['underlined'] } + +"ui.selection" = { bg = "#3a3d41" } +"ui.selection.primary" = { bg = "#add6ff26" } + +"ui.linenr" = { fg = "#858585" } +"ui.linenr.selected" = { fg = "#c6c6c6" } + +"ui.statusline" = { fg = "#ffffff", bg = "#007acc" } +"ui.statusline.inactive" = { fg = "#ffffff", bg = "#007acc" } + +"ui.text" = { fg = "text", bg = "background" } +"ui.text.focus" = { fg = "#ffffff" } + +"warning" = { fg = "#cca700" } +"error" = { fg = "#f48771" } +"info" = { fg = "#75beff" } +"hint" = { fg = "#eeeeeeb3" } + +[palette] +type = "#4EC9B0" +keyword = "#569CD6" +regex = "#CE9178" +special = "#C586C0" +variable = "#9CDCFE" +fn_declaration = "#DCDCAA" +constant = "#4FC1FF" + +background = "#1e1e1e" +text = "#d4d4d4" +cursor = "#a6a6a6" +widget = "#252526" |