From 0b5f0d606a060c9bcf062a983c760a0f9c4bab19 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 28 Jan 2024 14:48:57 -0500 Subject: [PATCH 01/22] Reverse syntax highlighting query precedence ordering --- helix-core/src/syntax.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 8fda29352..6b52ee40a 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -2475,15 +2475,17 @@ fn next(&mut self) -> Option { } } - // Once a highlighting pattern is found for the current node, skip over - // any later highlighting patterns that also match this node. Captures + // Use the last capture found for the current node, skipping over any + // highlight patterns that also match this node. Captures // for a given node are ordered by pattern index, so these subsequent // captures are guaranteed to be for highlighting, not injections or // local variables. while let Some((next_match, next_capture_index)) = captures.peek() { let next_capture = next_match.captures[*next_capture_index]; if next_capture.node == capture.node { - captures.next(); + match_.remove(); + capture = next_capture; + match_ = captures.next().unwrap().0; } else { break; } From c75179d92118fee46b10c4d2bdd7186d67f82bab Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 28 Jan 2024 14:49:18 -0500 Subject: [PATCH 02/22] WIP: Reverse highlight queries --- runtime/queries/erlang/highlights.scm | 85 +++++++++++++-------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/runtime/queries/erlang/highlights.scm b/runtime/queries/erlang/highlights.scm index f09f61042..041fb021b 100644 --- a/runtime/queries/erlang/highlights.scm +++ b/runtime/queries/erlang/highlights.scm @@ -1,3 +1,45 @@ +; Comments +(tripledot) @comment.discard + +[(comment) (line_comment) (shebang)] @comment + +; Basic types +(variable) @variable +((atom) @constant.builtin.boolean + (#match? @constant.builtin.boolean "^(true|false)$")) +(atom) @string.special.symbol +[(string) (sigil)] @string +(character) @constant.character +(escape_sequence) @constant.character.escape + +(integer) @constant.numeric.integer +(float) @constant.numeric.float + +; Punctuation +["," "." "-" ";"] @punctuation.delimiter +["(" ")" "#" "{" "}" "[" "]" "<<" ">>"] @punctuation.bracket + +; Operators +(binary_operator + left: (atom) @function + operator: "/" + right: (integer) @constant.numeric.integer) + +((binary_operator operator: _ @keyword.operator) + (#match? @keyword.operator "^\\w+$")) +((unary_operator operator: _ @keyword.operator) + (#match? @keyword.operator "^\\w+$")) + +(binary_operator operator: _ @operator) +(unary_operator operator: _ @operator) +["/" ":" "->"] @operator + + +; Keywords +(attribute name: (atom) @keyword) + +["case" "fun" "if" "of" "when" "end" "receive" "try" "catch" "after" "begin" "maybe"] @keyword + ; Attributes ; module declaration (attribute @@ -122,46 +164,3 @@ (record field: (atom) @variable.other.member) (record name: (atom) @type) - -; Keywords -(attribute name: (atom) @keyword) - -["case" "fun" "if" "of" "when" "end" "receive" "try" "catch" "after" "begin" "maybe"] @keyword - -; Operators -(binary_operator - left: (atom) @function - operator: "/" - right: (integer) @constant.numeric.integer) - -((binary_operator operator: _ @keyword.operator) - (#match? @keyword.operator "^\\w+$")) -((unary_operator operator: _ @keyword.operator) - (#match? @keyword.operator "^\\w+$")) - -(binary_operator operator: _ @operator) -(unary_operator operator: _ @operator) -["/" ":" "->"] @operator - -; Comments -(tripledot) @comment.discard - -[(comment) (line_comment) (shebang)] @comment - -; Basic types -(variable) @variable -((atom) @constant.builtin.boolean - (#match? @constant.builtin.boolean "^(true|false)$")) -(atom) @string.special.symbol -[(string) (sigil)] @string -(character) @constant.character -(escape_sequence) @constant.character.escape - -(integer) @constant.numeric.integer -(float) @constant.numeric.float - -; Punctuation -["," "." "-" ";"] @punctuation.delimiter -["(" ")" "#" "{" "}" "[" "]" "<<" ">>"] @punctuation.bracket - -; (ERROR) @error From 96688a5915a5eff963a195dedbe0f4f5b2130dcc Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Mon, 29 Jan 2024 07:13:40 +0200 Subject: [PATCH 03/22] Update PureScript highlight queries in light of reversing queries precedence order This commit adapts PureScript highlight queries to match upcoming changes in Helix which will make queries matching order go from more to general to more specific, the opposite of previous order. --- runtime/queries/purescript/highlights.scm | 67 +++++++++++------------ 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/runtime/queries/purescript/highlights.scm b/runtime/queries/purescript/highlights.scm index b7868e6e7..314fb3132 100644 --- a/runtime/queries/purescript/highlights.scm +++ b/runtime/queries/purescript/highlights.scm @@ -1,19 +1,3 @@ -; ---------------------------------------------------------------------------- -; Record fields would need to come before literal strings in order to be captured correctly - - (record_accessor - field: [ (variable) - (string) - (triple_quote_string) - ] @variable.other.member) - - (exp_record_access - field: [ (variable) - (string) - (triple_quote_string) - ] @variable.other.member) - - ; ---------------------------------------------------------------------------- ; Literals and comments @@ -21,6 +5,7 @@ (exp_negation) @constant.numeric.integer (exp_literal (number)) @constant.numeric.float (char) @constant.character + [ (string) (triple_quote_string) @@ -28,7 +13,6 @@ (comment) @comment - ; ---------------------------------------------------------------------------- ; Punctuation @@ -41,18 +25,19 @@ "]" ] @punctuation.bracket - [ - (comma) - ";" - ] @punctuation.delimiter + (comma) @punctuation.delimiter +; ---------------------------------------------------------------------------- +; Types + + (type) @type + + (constructor) @constructor ; ---------------------------------------------------------------------------- ; Keywords, operators, includes - ; This needs to come before the other "else" in - ; order to be highlighted correctly - (class_instance "else" @keyword) + (module) @namespace [ "if" @@ -95,7 +80,6 @@ ] @operator (qualified_module (module) @constructor) - (module) @namespace (qualified_type (module) @namespace) (qualified_variable (module) @namespace) (import (module) @namespace) @@ -122,6 +106,11 @@ "infixr" ] @keyword + ; NOTE + ; Needs to come after the other `else` in + ; order to be highlighted correctly + (class_instance "else" @keyword) + (type_role_declaration "role" @keyword role: (type_role) @keyword) @@ -131,10 +120,27 @@ ; ---------------------------------------------------------------------------- ; Functions and variables + (variable) @variable + (row_field (field_name) @variable.other.member) (record_field (field_name) @variable.other.member) (record_field (field_pun) @variable.other.member) + ; NOTE + ; Record fields must come after literal strings and + ; plain variables in order to be highlighted correctly + (record_accessor + field: [ (variable) + (string) + (triple_quote_string) + ] @variable.other.member) + + (exp_record_access + field: [ (variable) + (string) + (triple_quote_string) + ] @variable.other.member) + (signature name: (variable) @type) (function name: (variable) @function) (class_instance (instance_name) @function) @@ -151,14 +157,5 @@ (exp_ticked (exp_name (variable) @operator)) (exp_ticked (exp_name (qualified_variable (variable) @operator))) - (variable) @variable - - ("@" @namespace) ; "as" pattern operator, e.g. x@Constructor - -; ---------------------------------------------------------------------------- -; Types - - (type) @type - - (constructor) @constructor + (patterns (pat_as "@" @namespace)) From 132d38844407cc52a626c2b7a0c8a969c152d0c1 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Tue, 30 Jan 2024 04:22:49 +0200 Subject: [PATCH 04/22] Update Haskell highlight queries in light of reversing precedence ordering --- runtime/queries/haskell/highlights.scm | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/runtime/queries/haskell/highlights.scm b/runtime/queries/haskell/highlights.scm index 3d416de8d..e880cc1e8 100644 --- a/runtime/queries/haskell/highlights.scm +++ b/runtime/queries/haskell/highlights.scm @@ -1,17 +1,3 @@ -;; ---------------------------------------------------------------------------- -;; Literals and comments - -(integer) @constant.numeric.integer -(exp_negation) @constant.numeric.integer -(exp_literal (float)) @constant.numeric.float -(char) @constant.character -(string) @string - -(con_unit) @constant.builtin ; unit, as in () - -(comment) @comment - - ;; ---------------------------------------------------------------------------- ;; Punctuation @@ -30,6 +16,20 @@ ] @punctuation.delimiter +;; ---------------------------------------------------------------------------- +;; Literals and comments + +(integer) @constant.numeric.integer +(exp_negation) @constant.numeric.integer +(exp_literal (float)) @constant.numeric.float +(char) @constant.character +(string) @string + +(comment) @comment + +(con_unit [ "(" ")" ] @constant.builtin) ; unit, as in () + + ;; ---------------------------------------------------------------------------- ;; Keywords, operators, includes @@ -103,6 +103,8 @@ ;; ---------------------------------------------------------------------------- ;; Functions and variables +(variable) @variable + (signature name: (variable) @type) (function name: (variable) @function @@ -117,7 +119,6 @@ (exp_apply . (exp_name (variable) @function)) (exp_apply . (exp_name (qualified_variable (variable) @function))) -(variable) @variable (pat_wildcard) @variable ;; ---------------------------------------------------------------------------- From 0364f7c87912c292e84ca60b2ab54ed7ae8f7602 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:07:15 +0200 Subject: [PATCH 05/22] Reverse Nix highlights queries --- runtime/queries/nix/highlights.scm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/queries/nix/highlights.scm b/runtime/queries/nix/highlights.scm index 4633e1786..a733d6a64 100644 --- a/runtime/queries/nix/highlights.scm +++ b/runtime/queries/nix/highlights.scm @@ -17,6 +17,18 @@ "with" ] @keyword +(variable_expression name: (identifier) @variable) + +(select_expression + attrpath: (attrpath attr: (identifier)) @variable.other.member) + +(apply_expression + function: [ + (variable_expression name: (identifier) @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @function .))]) + ((identifier) @variable.builtin (#match? @variable.builtin "^(__currentSystem|__currentTime|__nixPath|__nixVersion|__storeDir|builtins)$") (#is-not? local)) @@ -59,28 +71,16 @@ name: (identifier) @variable.parameter "?"? @punctuation.delimiter) -(select_expression - attrpath: (attrpath attr: (identifier)) @variable.other.member) - (interpolation "${" @punctuation.special "}" @punctuation.special) @embedded -(apply_expression - function: [ - (variable_expression name: (identifier) @function) - (select_expression - attrpath: (attrpath - attr: (identifier) @function .))]) - (unary_expression operator: _ @operator) (binary_expression operator: _ @operator) -(variable_expression name: (identifier) @variable) - (binding attrpath: (attrpath attr: (identifier)) @variable.other.member) @@ -109,4 +109,4 @@ "]" "{" "}" -] @punctuation.bracket \ No newline at end of file +] @punctuation.bracket From 951b454a3351704c675e98ab17212fff86a1f2d3 Mon Sep 17 00:00:00 2001 From: Iorvethe <58810330+Iorvethe@users.noreply.github.com> Date: Fri, 17 May 2024 13:24:49 +0200 Subject: [PATCH 06/22] Update tree-sitter-julia (#10031) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update julia parser to latest version, along with: - updating the queries, - pulling changes from `nvim-treesitter`’s queries (as the maintainters of the parser update the queries there), - reversing the queries’ order to be compatible with upstream. --- languages.toml | 2 +- runtime/queries/julia/folds.scm | 21 +- runtime/queries/julia/highlights.scm | 527 ++++++++++++++++++--------- runtime/queries/julia/indents.scm | 30 +- runtime/queries/julia/injections.scm | 12 +- runtime/queries/julia/locals.scm | 95 ++++- 6 files changed, 484 insertions(+), 203 deletions(-) diff --git a/languages.toml b/languages.toml index 8776947a8..ae05f5923 100644 --- a/languages.toml +++ b/languages.toml @@ -1115,7 +1115,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "julia" -source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "8fb38abff74652c4faddbf04d2d5bbbc6b4bae25" } +source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "e84f10db8eeb8b9807786bfc658808edaa1b4fa2" } [[language]] name = "java" diff --git a/runtime/queries/julia/folds.scm b/runtime/queries/julia/folds.scm index 91eede5f6..91a26c0c9 100644 --- a/runtime/queries/julia/folds.scm +++ b/runtime/queries/julia/folds.scm @@ -1,11 +1,14 @@ [ - (module_definition) - (struct_definition) - (macro_definition) - (function_definition) - (compound_expression) ; begin blocks - (let_statement) - (if_statement) - (for_statement) - (while_statement) + (module_definition) + (struct_definition) + (macro_definition) + (function_definition) + (if_statement) + (try_statement) + (for_statement) + (while_statement) + (let_statement) + (quote_statement) + (do_clause) + (compound_statement) ; begin block ] @fold diff --git a/runtime/queries/julia/highlights.scm b/runtime/queries/julia/highlights.scm index 013f50632..805310fdd 100644 --- a/runtime/queries/julia/highlights.scm +++ b/runtime/queries/julia/highlights.scm @@ -1,39 +1,48 @@ -; ---------- -; Primitives -; ---------- +; ------------ +; Variables identifiers +; ------------ -[ - (line_comment) - (block_comment) -] @comment +(identifier) @variable +; Remaining identifiers that start with capital letters should be types (PascalCase) ( - ((identifier) @constant.builtin) - (#match? @constant.builtin "^(nothing|missing|undef)$")) - -[ - (true) - (false) -] @constant.builtin.boolean - -(integer_literal) @constant.numeric.integer -(float_literal) @constant.numeric.float + (identifier) @type + (match? @type "^[A-Z]")) +; SCREAMING_SNAKE_CASE ( - ((identifier) @constant.numeric.float) - (#match? @constant.numeric.float "^((Inf|NaN)(16|32|64)?)$")) + (identifier) @constant + (match? @constant "^[A-Z][A-Z0-9_]*$")) -(character_literal) @constant.character -(escape_sequence) @constant.character.escape +(const_statement + (assignment + . (identifier) @constant)) -(string_literal) @string - -(prefixed_string_literal - prefix: (identifier) @function.macro) @string +; Field expressions are either module content or struct fields. +; Module types and constants should already be captured, so this +; assumes the remaining identifiers to be struct fields. +(field_expression + (_) + (identifier) @variable.other.member) (quote_expression - (identifier) @string.special.symbol) - + ":" @string.special.symbol + [ + (identifier) + (operator) + ] @string.special.symbol) + +; ------ +; Macros +; ------ + +(macro_definition + name: (identifier) @function.macro) + +(macro_identifier + "@" @function.macro + (identifier) @function.macro) + ; ------------------- ; Modules and Imports ; ------------------- @@ -50,49 +59,6 @@ (scoped_identifier (identifier) @namespace) -; ----- -; Types -; ----- - -(abstract_definition - name: (identifier) @type) - -(primitive_definition - name: (identifier) @type) - -(struct_definition - name: (identifier) @type) - -(struct_definition - . (_) - (identifier) @variable.other.member) - -(struct_definition - . (_) - (typed_expression - . (identifier) @variable.other.member)) - -(type_parameter_list - (identifier) @type) - -(constrained_type_parameter - (identifier) @type) - -(subtype_clause - (identifier) @type) - -(typed_expression - (identifier) @type . ) - -(parameterized_identifier - (identifier) @type) - -(type_argument_list - (identifier) @type) - -(where_clause - (identifier) @type) - ; ------------------- ; Function definition ; ------------------- @@ -119,22 +85,6 @@ ; prevent constructors (PascalCase) to be highlighted as functions (#match? @function "^[^A-Z]")) -(parameter_list - (identifier) @variable.parameter) - -(typed_parameter - (identifier) @variable.parameter - (identifier)? @type) - -(optional_parameter - . (identifier) @variable.parameter) - -(slurp_parameter - (identifier) @variable.parameter) - -(function_expression - . (identifier) @variable.parameter) - ; --------------- ; Functions calls ; --------------- @@ -145,93 +95,294 @@ ; prevent constructors (PascalCase) to be highlighted as functions (#match? @function "^[^A-Z]")) -( - (broadcast_call_expression - (identifier) @function) - (#match? @function "^[^A-Z]")) - ( (call_expression (field_expression (identifier) @function .)) (#match? @function "^[^A-Z]")) +( + (broadcast_call_expression + (identifier) @function) + (#match? @function "^[^A-Z]")) + ( (broadcast_call_expression (field_expression (identifier) @function .)) (#match? @function "^[^A-Z]")) -; ------ -; Macros -; ------ -(macro_definition - name: (identifier) @function.macro) +; ------------------- +; Functions builtins +; ------------------- + +((identifier) @function.builtin + (#any-of? @function.builtin + "_abstracttype" "_apply_iterate" "_apply_pure" "_call_in_world" "_call_in_world_total" + "_call_latest" "_equiv_typedef" "_expr" "_primitivetype" "_setsuper!" "_structtype" "_typebody!" + "_typevar" "applicable" "apply_type" "arrayref" "arrayset" "arraysize" "const_arrayref" + "donotdelete" "fieldtype" "get_binding_type" "getfield" "ifelse" "invoke" "isa" "isdefined" + "modifyfield!" "nfields" "replacefield!" "set_binding_type!" "setfield!" "sizeof" "svec" + "swapfield!" "throw" "tuple" "typeassert" "typeof")) + +; ----------- +; Parameters +; ----------- + +(parameter_list + (identifier) @variable.parameter) + +(optional_parameter + . (identifier) @variable.parameter) + +(slurp_parameter + (identifier) @variable.parameter) + +(typed_parameter + parameter: (identifier)? @variable.parameter + type: (_) @type) + +(function_expression + . (identifier) @variable.parameter) ; Single parameter arrow functions + +; ----- +; Types +; ----- + +; Definitions +(abstract_definition + name: (identifier) @type.definition) @keyword + +(primitive_definition + name: (identifier) @type.definition) @keyword + +(struct_definition + name: (identifier) @type) + +(struct_definition + . (_) + (identifier) @variable.other.member) + +(struct_definition + . (_) + (typed_expression + . (identifier) @variable.other.member)) + +(type_clause + [ + (identifier) @type + (field_expression + (identifier) @type .) + ]) + +; Annotations +(parametrized_type_expression + (_) @type + (curly_expression + (_) @type)) + +(type_parameter_list + (identifier) @type) + +(typed_expression + (identifier) @type . ) + +(function_definition + return_type: (identifier) @type) + +(short_function_definition + return_type: (identifier) @type) + +(where_clause + (identifier) @type) + +(where_clause + (curly_expression + (_) @type)) + +; --------- +; Builtins +; --------- + +; This list was generated with: +; +; istype(x) = typeof(x) === DataType || typeof(x) === UnionAll +; get_types(m) = filter(x -> istype(Base.eval(m, x)), names(m)) +; type_names = sort(union(get_types(Core), get_types(Base))) +; +((identifier) @type.builtin + (#any-of? @type.builtin + "AbstractArray" "AbstractChannel" "AbstractChar" "AbstractDict" "AbstractDisplay" + "AbstractFloat" "AbstractIrrational" "AbstractLock" "AbstractMatch" "AbstractMatrix" + "AbstractPattern" "AbstractRange" "AbstractSet" "AbstractSlices" "AbstractString" + "AbstractUnitRange" "AbstractVecOrMat" "AbstractVector" "Any" "ArgumentError" "Array" + "AssertionError" "Atomic" "BigFloat" "BigInt" "BitArray" "BitMatrix" "BitSet" "BitVector" "Bool" + "BoundsError" "By" "CanonicalIndexError" "CapturedException" "CartesianIndex" "CartesianIndices" + "Cchar" "Cdouble" "Cfloat" "Channel" "Char" "Cint" "Cintmax_t" "Clong" "Clonglong" "Cmd" "Colon" + "ColumnSlices" "Complex" "ComplexF16" "ComplexF32" "ComplexF64" "ComposedFunction" + "CompositeException" "ConcurrencyViolationError" "Condition" "Cptrdiff_t" "Cshort" "Csize_t" + "Cssize_t" "Cstring" "Cuchar" "Cuint" "Cuintmax_t" "Culong" "Culonglong" "Cushort" "Cvoid" + "Cwchar_t" "Cwstring" "DataType" "DenseArray" "DenseMatrix" "DenseVecOrMat" "DenseVector" "Dict" + "DimensionMismatch" "Dims" "DivideError" "DomainError" "EOFError" "Enum" "ErrorException" + "Exception" "ExponentialBackOff" "Expr" "Float16" "Float32" "Float64" "Function" "GlobalRef" + "HTML" "IO" "IOBuffer" "IOContext" "IOStream" "IdDict" "IndexCartesian" "IndexLinear" + "IndexStyle" "InexactError" "InitError" "Int" "Int128" "Int16" "Int32" "Int64" "Int8" "Integer" + "InterruptException" "InvalidStateException" "Irrational" "KeyError" "LazyString" "LinRange" + "LineNumberNode" "LinearIndices" "LoadError" "Lt" "MIME" "Matrix" "Method" "MethodError" + "Missing" "MissingException" "Module" "NTuple" "NamedTuple" "Nothing" "Number" "Ordering" + "OrdinalRange" "OutOfMemoryError" "OverflowError" "Pair" "ParseError" "PartialQuickSort" "Perm" + "PermutedDimsArray" "Pipe" "ProcessFailedException" "Ptr" "QuoteNode" "Rational" "RawFD" + "ReadOnlyMemoryError" "Real" "ReentrantLock" "Ref" "Regex" "RegexMatch" "Returns" + "ReverseOrdering" "RoundingMode" "RowSlices" "SegmentationFault" "Set" "Signed" "Slices" "Some" + "SpinLock" "StackFrame" "StackOverflowError" "StackTrace" "Stateful" "StepRange" "StepRangeLen" + "StridedArray" "StridedMatrix" "StridedVecOrMat" "StridedVector" "String" "StringIndexError" + "SubArray" "SubString" "SubstitutionString" "Symbol" "SystemError" "Task" "TaskFailedException" + "Text" "TextDisplay" "Timer" "Tmstruct" "Tuple" "Type" "TypeError" "TypeVar" "UInt" "UInt128" + "UInt16" "UInt32" "UInt64" "UInt8" "UndefInitializer" "UndefKeywordError" "UndefRefError" + "UndefVarError" "Union" "UnionAll" "UnitRange" "Unsigned" "Val" "VecElement" "VecOrMat" "Vector" + "VersionNumber" "WeakKeyDict" "WeakRef")) + +((identifier) @variable.builtin + (#any-of? @variable.builtin "begin" "end") + (#has-ancestor? @variable.builtin index_expression)) + +((identifier) @variable.builtin + (#any-of? @variable.builtin "begin" "end") + (#has-ancestor? @variable.builtin range_expression)) -(macro_identifier - "@" @function.macro - (identifier) @function.macro) ; -------- ; Keywords ; -------- -(function_definition - ["function" "end"] @keyword.function) +[ + "global" + "local" +] @keyword + +(compound_statement + [ + "begin" + "end" + ] @keyword) + +(quote_statement + [ + "quote" + "end" + ] @keyword) + +(let_statement + [ + "let" + "end" + ] @keyword) (if_statement - ["if" "end"] @keyword.control.conditional) -(elseif_clause - ["elseif"] @keyword.control.conditional) -(else_clause - ["else"] @keyword.control.conditional) -(ternary_expression - ["?" ":"] @keyword.control.conditional) + [ + "if" + "end" + ] @keyword.control.conditional) -(for_statement - ["for" "end"] @keyword.control.repeat) -(while_statement - ["while" "end"] @keyword.control.repeat) -(break_statement) @keyword.control.repeat -(continue_statement) @keyword.control.repeat -(for_binding - "in" @keyword.control.repeat) -(for_clause - "for" @keyword.control.repeat) +(elseif_clause + "elseif" @keyword.control.conditional) + +(else_clause + "else" @keyword.control.conditional) + +(if_clause + "if" @keyword.control.conditional) ; `if` clause in comprehensions + +(ternary_expression + [ + "?" + ":" + ] @keyword.control.conditional) (try_statement - ["try" "end" ] @keyword.control.exception) + [ + "try" + "end" + ] @keyword.control.exception) + (finally_clause "finally" @keyword.control.exception) + (catch_clause "catch" @keyword.control.exception) -[ - "export" - "import" - "using" -] @keyword.control.import +(for_statement + [ + "for" + "end" + ] @keyword.control.repeat) + +(while_statement + [ + "while" + "end" + ] @keyword.control.repeat) + +(for_clause + "for" @keyword.control.repeat) + +[ + (break_statement) + (continue_statement) +] @keyword.control.repeat + +(module_definition + [ + "module" + "baremodule" + "end" + ] @keyword.control.import) + +(import_statement + [ + "import" + "using" + ] @keyword.control.import) + +(import_alias + "as" @keyword.control.import) + +(export_statement + "export" @keyword.control.import) + +(selected_import + ":" @punctuation.delimiter) + +(struct_definition + [ + "struct" + "end" + ] @keyword) + +(macro_definition + [ + "macro" + "end" + ] @keyword) + +(function_definition + [ + "function" + "end" + ] @keyword.function) + +(do_clause + [ + "do" + "end" + ] @keyword.function) + +(return_statement + "return" @keyword.control.return) [ - "abstract" - "baremodule" - "begin" "const" - "do" - "end" - "let" - "macro" - "module" "mutable" - "primitive" - "quote" - "return" - "struct" - "type" - "where" -] @keyword - -; TODO: fix this -((identifier) @keyword (#match? @keyword "global|local")) +] @keyword.storage.modifier ; --------- ; Operators @@ -239,14 +390,34 @@ [ (operator) - "::" - "<:" - ":" - "=>" - "..." - "$" + "=" + "∈" ] @operator +(adjoint_expression + "'" @operator) + +(range_expression + ":" @operator) + +((operator) @keyword.operator + (#any-of? @keyword.operator "in" "isa")) + +(for_binding + "in" @keyword.operator) + +(where_clause + "where" @keyword.operator) + +(where_expression + "where" @keyword.operator) + +(binary_expression + (_) + (operator) @operator + (identifier) @function + (#any-of? @operator "|>" ".|>")) + ; ------------ ; Punctuations ; ------------ @@ -255,40 +426,58 @@ "." "," ";" + "::" + "->" ] @punctuation.delimiter +"..." @punctuation.special + [ - "[" - "]" "(" ")" + "[" + "]" "{" "}" ] @punctuation.bracket -; --------------------- -; Remaining identifiers -; --------------------- +; --------- +; Literals +; --------- -(const_statement - (variable_declaration - . (identifier) @constant)) +(boolean_literal) @constant.builtin.boolean + +(integer_literal) @constant.numeric.integer + +(float_literal) @constant.numeric.float -; SCREAMING_SNAKE_CASE ( - (identifier) @constant - (#match? @constant "^[A-Z][A-Z0-9_]*$")) + ((identifier) @constant.numeric.float) + (#match? @constant.numeric.float "^((Inf|NaN)(16|32|64)?)$")) -; remaining identifiers that start with capital letters should be types (PascalCase) ( - (identifier) @type - (#match? @type "^[A-Z]")) + ((identifier) @constant.builtin) + (#match? @constant.builtin "^(nothing|missing|undef)$")) -; Field expressions are either module content or struct fields. -; Module types and constants should already be captured, so this -; assumes the remaining identifiers to be struct fields. -(field_expression - (_) - (identifier) @variable.other.member) +(character_literal) @constant.character -(identifier) @variable +(escape_sequence) @constant.character.escape + +(string_literal) @string + +(prefixed_string_literal + prefix: (identifier) @function.macro) @string + +(command_literal) @string + +(prefixed_command_literal + prefix: (identifier) @function.macro) @string + +; --------- +; Comments +; --------- + +[ + (line_comment) + (block_comment) +] @comment diff --git a/runtime/queries/julia/indents.scm b/runtime/queries/julia/indents.scm index 08f55aa7f..d73201771 100644 --- a/runtime/queries/julia/indents.scm +++ b/runtime/queries/julia/indents.scm @@ -2,15 +2,39 @@ (struct_definition) (macro_definition) (function_definition) - (compound_expression) - (let_statement) + (compound_statement) (if_statement) + (try_statement) (for_statement) (while_statement) + (let_statement) + (quote_statement) (do_clause) - (parameter_list) + (assignment) + (for_binding) + (call_expression) + (parenthesized_expression) + (tuple_expression) + (comprehension_expression) + (matrix_expression) + (vector_expression) ] @indent [ "end" + ")" + "]" + "}" ] @outdent + +(argument_list + . (_) @anchor + (#set! "scope" "tail")) @align + +(parameter_list + . (_) @anchor + (#set! "scope" "tail")) @align + +(curly_expression + . (_) @anchor + (#set! "scope" "tail")) @align diff --git a/runtime/queries/julia/injections.scm b/runtime/queries/julia/injections.scm index fd174a4a0..3b80163f8 100644 --- a/runtime/queries/julia/injections.scm +++ b/runtime/queries/julia/injections.scm @@ -9,7 +9,8 @@ (primitive_definition) (abstract_definition) (struct_definition) - (assignment_expression) + (short_function_definition) + (assignment) (const_statement) ]) (#set! injection.language "markdown")) @@ -21,10 +22,17 @@ ] @injection.content (#set! injection.language "comment")) +( + [ + (command_literal) + (prefixed_command_literal) + ] @injection.content + (#set! injection.language "sh")) + ( (prefixed_string_literal prefix: (identifier) @function.macro) @injection.content - (#eq? @function.macro "re") + (#eq? @function.macro "r") (#set! injection.language "regex")) ( diff --git a/runtime/queries/julia/locals.scm b/runtime/queries/julia/locals.scm index 70b31e509..bbf72c0e2 100644 --- a/runtime/queries/julia/locals.scm +++ b/runtime/queries/julia/locals.scm @@ -2,43 +2,100 @@ ; Definitions ; ----------- -; Imports -(import_statement +; Variables +(assignment (identifier) @local.definition) - + +(assignment + (tuple_expression + (identifier) @local.definition)) + ; Constants (const_statement - (variable_declaration + (assignment . (identifier) @local.definition)) +; let/const bindings +(let_binding + (identifier) @local.definition) + +(let_binding + (tuple_expression + (identifier) @local.definition)) + +; For bindings +(for_binding + (identifier) @local.definition) + +(for_binding + (tuple_expression + (identifier) @local.definition)) + +; Types +(struct_definition + name: (identifier) @local.definition) + +(abstract_definition + name: (identifier) @local.definition) + +(abstract_definition + name: (identifier) @local.definition) + +(type_parameter_list + (identifier) @local.definition) + +; Module imports +(import_statement + (identifier) @local.definition) + ; Parameters (parameter_list (identifier) @local.definition) -(typed_parameter - . (identifier) @local.definition) - -(optional_parameter . +(optional_parameter + . (identifier) @local.definition) (slurp_parameter (identifier) @local.definition) -(function_expression - . (identifier) @local.definition) - -; ------ -; Scopes -; ------ +(typed_parameter + parameter: (identifier) @local.definition + (_)) -[ - (function_definition) - (short_function_definition) - (macro_definition) -] @local.scope +; Single parameter arrow function +(function_expression + . + (identifier) @local.definition) + +; Function/macro definitions +(function_definition + name: (identifier) @local.definition) @local.scope + +(short_function_definition + name: (identifier) @local.definition) @local.scope + +(macro_definition + name: (identifier) @local.definition) @local.scope ; ---------- ; References ; ---------- (identifier) @local.reference + +; ------ +; Scopes +; ------ + +[ + (for_statement) + (while_statement) + (try_statement) + (catch_clause) + (finally_clause) + (let_statement) + (quote_statement) + (do_clause) +] @local.scope + From bd9cfbb61d1ad3ce8ad144ad9e6d04cfc1fad473 Mon Sep 17 00:00:00 2001 From: Iorvethe <58810330+Iorvethe@users.noreply.github.com> Date: Sun, 19 May 2024 11:29:53 +0200 Subject: [PATCH 07/22] Fix `#match?` predicates in julia queries (#10793) --- runtime/queries/julia/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/queries/julia/highlights.scm b/runtime/queries/julia/highlights.scm index 805310fdd..7072640ff 100644 --- a/runtime/queries/julia/highlights.scm +++ b/runtime/queries/julia/highlights.scm @@ -7,12 +7,12 @@ ; Remaining identifiers that start with capital letters should be types (PascalCase) ( (identifier) @type - (match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ; SCREAMING_SNAKE_CASE ( (identifier) @constant - (match? @constant "^[A-Z][A-Z0-9_]*$")) + (#match? @constant "^[A-Z][A-Z0-9_]*$")) (const_statement (assignment From 974303e20016f1c0230f756b29e79703bcc247b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 03:40:30 +0900 Subject: [PATCH 08/22] queries: Tweak capnp --- runtime/queries/capnp/highlights.scm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/queries/capnp/highlights.scm b/runtime/queries/capnp/highlights.scm index 27ddf8e2d..34b023be0 100644 --- a/runtime/queries/capnp/highlights.scm +++ b/runtime/queries/capnp/highlights.scm @@ -1,7 +1,9 @@ ; Preproc -(unique_id) @keyword.directive -(top_level_annotation_body) @keyword.directive +[ + (unique_id) + (top_level_annotation_body) +] @keyword.directive ; Includes @@ -9,6 +11,7 @@ "import" "$import" "embed" + "using" ] @keyword.control.import (import_path) @string @@ -84,10 +87,10 @@ "union" ] @keyword.storage.type +"extends" @keyword + [ - "extends" "namespace" - "using" (annotation_target) ] @special From 44605c4dceb4c917e1f919dff337f39073696283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 03:40:42 +0900 Subject: [PATCH 09/22] queries: Reorder scheme --- runtime/queries/scheme/highlights.scm | 89 +++++++++++++-------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/runtime/queries/scheme/highlights.scm b/runtime/queries/scheme/highlights.scm index c7050847f..a0c15a121 100644 --- a/runtime/queries/scheme/highlights.scm +++ b/runtime/queries/scheme/highlights.scm @@ -10,32 +10,28 @@ (block_comment) @comment.block (directive) @keyword.directive -; operators +; variables -((symbol) @operator - (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) +((symbol) @variable.builtin + (#eq? @variable.builtin "...")) -; keywords +((symbol) @variable.builtin + (#eq? @variable.builtin ".")) + +(symbol) @variable + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket + +(quote "'") @operator +(unquote_splicing ",@") @operator +(unquote ",") @operator +(quasiquote "`") @operator + +; procedure (list . - ((symbol) @keyword.conditional - (#match? @keyword.conditional "^(if|cond|case|when|unless)$" - ))) - -(list - . - (symbol) @keyword - (#match? @keyword - "^(define-syntax|let\\*|lambda|λ|case|=>|quote-splicing|unquote-splicing|set!|let|letrec|letrec-syntax|let-values|let\\*-values|do|else|define|cond|syntax-rules|unquote|begin|quote|let-syntax|and|if|quasiquote|letrec|delay|or|when|unless|identifier-syntax|assert|library|export|import|rename|only|except|prefix)$" - )) - -(list - . - (symbol) @function.builtin - (#match? @function.builtin - "^(caar|cadr|call-with-input-file|call-with-output-file|cdar|cddr|list|open-input-file|open-output-file|with-input-from-file|with-output-to-file|\\*|\\+|-|/|<|<=|=|>|>=|abs|acos|angle|append|apply|asin|assoc|assq|assv|atan|boolean\\?|caaaar|caaadr|caaar|caadar|caaddr|caadr|cadaar|cadadr|cadar|caddar|cadddr|caddr|call-with-current-continuation|call-with-values|car|cdaaar|cdaadr|cdaar|cdadar|cdaddr|cdadr|cddaar|cddadr|cddar|cdddar|cddddr|cdddr|cdr|ceiling|char->integer|char-alphabetic\\?|char-ci<=\\?|char-ci<\\?|char-ci=\\?|char-ci>=\\?|char-ci>\\?|char-downcase|char-lower-case\\?|char-numeric\\?|char-ready\\?|char-upcase|char-upper-case\\?|char-whitespace\\?|char<=\\?|char<\\?|char=\\?|char>=\\?|char>\\?|char\\?|close-input-port|close-output-port|complex\\?|cons|cos|current-error-port|current-input-port|current-output-port|denominator|display|dynamic-wind|eof-object\\?|eq\\?|equal\\?|eqv\\?|eval|even\\?|exact->inexact|exact\\?|exp|expt|floor|flush-output|for-each|force|gcd|imag-part|inexact->exact|inexact\\?|input-port\\?|integer->char|integer\\?|interaction-environment|lcm|length|list->string|list->vector|list-ref|list-tail|list\\?|load|log|magnitude|make-polar|make-rectangular|make-string|make-vector|map|max|member|memq|memv|min|modulo|negative\\?|newline|not|null-environment|null\\?|number->string|number\\?|numerator|odd\\?|output-port\\?|pair\\?|peek-char|positive\\?|procedure\\?|quotient|rational\\?|rationalize|read|read-char|real-part|real\\?|remainder|reverse|round|scheme-report-environment|set-car!|set-cdr!|sin|sqrt|string|string->list|string->number|string->symbol|string-append|string-ci<=\\?|string-ci<\\?|string-ci=\\?|string-ci>=\\?|string-ci>\\?|string-copy|string-fill!|string-length|string-ref|string-set!|string<=\\?|string<\\?|string=\\?|string>=\\?|string>\\?|string\\?|substring|symbol->string|symbol\\?|tan|transcript-off|transcript-on|truncate|values|vector|vector->list|vector-fill!|vector-length|vector-ref|vector-set!|vector\\?|write|write-char|zero\\?)$" - )) + (symbol) @function) ; special forms @@ -62,12 +58,10 @@ (#match? @_f "^(let|let\\*|let-syntax|let-values|let\\*-values|letrec|letrec\\*|letrec-syntax)$")) -; quote +; operators -(list - . - (symbol) @_f - (#eq? @_f "quote")) @string.symbol +((symbol) @operator + (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) ; library @@ -79,26 +73,31 @@ (#eq? @_lib "library")) -; procedure +; quote + +(list + . + (symbol) @_f + (#eq? @_f "quote")) @string.symbol + +; keywords (list . - (symbol) @function) - -;; variables - -((symbol) @variable.builtin - (#eq? @variable.builtin "...")) - -((symbol) @variable.builtin - (#eq? @variable.builtin ".")) - -(symbol) @variable - -["(" ")" "[" "]" "{" "}"] @punctuation.bracket - -(quote "'") @operator -(unquote_splicing ",@") @operator -(unquote ",") @operator -(quasiquote "`") @operator + ((symbol) @keyword.conditional + (#match? @keyword.conditional "^(if|cond|case|when|unless)$" + ))) + +(list + . + (symbol) @keyword + (#match? @keyword + "^(define-syntax|let\\*|lambda|λ|case|=>|quote-splicing|unquote-splicing|set!|let|letrec|letrec-syntax|let-values|let\\*-values|do|else|define|cond|syntax-rules|unquote|begin|quote|let-syntax|and|if|quasiquote|letrec|delay|or|when|unless|identifier-syntax|assert|library|export|import|rename|only|except|prefix)$" + )) +(list + . + (symbol) @function.builtin + (#match? @function.builtin + "^(caar|cadr|call-with-input-file|call-with-output-file|cdar|cddr|list|open-input-file|open-output-file|with-input-from-file|with-output-to-file|\\*|\\+|-|/|<|<=|=|>|>=|abs|acos|angle|append|apply|asin|assoc|assq|assv|atan|boolean\\?|caaaar|caaadr|caaar|caadar|caaddr|caadr|cadaar|cadadr|cadar|caddar|cadddr|caddr|call-with-current-continuation|call-with-values|car|cdaaar|cdaadr|cdaar|cdadar|cdaddr|cdadr|cddaar|cddadr|cddar|cdddar|cddddr|cdddr|cdr|ceiling|char->integer|char-alphabetic\\?|char-ci<=\\?|char-ci<\\?|char-ci=\\?|char-ci>=\\?|char-ci>\\?|char-downcase|char-lower-case\\?|char-numeric\\?|char-ready\\?|char-upcase|char-upper-case\\?|char-whitespace\\?|char<=\\?|char<\\?|char=\\?|char>=\\?|char>\\?|char\\?|close-input-port|close-output-port|complex\\?|cons|cos|current-error-port|current-input-port|current-output-port|denominator|display|dynamic-wind|eof-object\\?|eq\\?|equal\\?|eqv\\?|eval|even\\?|exact->inexact|exact\\?|exp|expt|floor|flush-output|for-each|force|gcd|imag-part|inexact->exact|inexact\\?|input-port\\?|integer->char|integer\\?|interaction-environment|lcm|length|list->string|list->vector|list-ref|list-tail|list\\?|load|log|magnitude|make-polar|make-rectangular|make-string|make-vector|map|max|member|memq|memv|min|modulo|negative\\?|newline|not|null-environment|null\\?|number->string|number\\?|numerator|odd\\?|output-port\\?|pair\\?|peek-char|positive\\?|procedure\\?|quotient|rational\\?|rationalize|read|read-char|real-part|real\\?|remainder|reverse|round|scheme-report-environment|set-car!|set-cdr!|sin|sqrt|string|string->list|string->number|string->symbol|string-append|string-ci<=\\?|string-ci<\\?|string-ci=\\?|string-ci>=\\?|string-ci>\\?|string-copy|string-fill!|string-length|string-ref|string-set!|string<=\\?|string<\\?|string=\\?|string>=\\?|string>\\?|string\\?|substring|symbol->string|symbol\\?|tan|transcript-off|transcript-on|truncate|values|vector|vector->list|vector-fill!|vector-length|vector-ref|vector-set!|vector\\?|write|write-char|zero\\?)$" + )) From de0618186c026515b549ca56a92429620fe589b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 03:43:27 +0900 Subject: [PATCH 10/22] queries: Update cel --- runtime/queries/cel/highlights.scm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/runtime/queries/cel/highlights.scm b/runtime/queries/cel/highlights.scm index ab3bae5a5..737707522 100644 --- a/runtime/queries/cel/highlights.scm +++ b/runtime/queries/cel/highlights.scm @@ -22,16 +22,10 @@ "in" ] @keyword -; Function calls - -(call_expression - function: (identifier) @function) - -(member_call_expression - function: (identifier) @function) - ; Identifiers +(identifier) @variable.other.member + (select_expression operand: (identifier) @type) @@ -39,7 +33,13 @@ operand: (select_expression member: (identifier) @type)) -(identifier) @variable.other.member +; Function calls + +(call_expression + function: (identifier) @function) + +(member_call_expression + function: (identifier) @function) ; Literals From 0fbfc0cc8d398233779e9e0dbff50e5b9a76c215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 03:46:27 +0900 Subject: [PATCH 11/22] queries: Update vhs --- runtime/queries/vhs/highlights.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/queries/vhs/highlights.scm b/runtime/queries/vhs/highlights.scm index a7e1af301..5e53584b8 100644 --- a/runtime/queries/vhs/highlights.scm +++ b/runtime/queries/vhs/highlights.scm @@ -40,6 +40,7 @@ (float) @constant.numeric.float (integer) @constant.numeric.integer (comment) @comment -[(path) (string) (json)] @string.special.path +[(string) (json)] @string.special.path +(path) @string.special.path (time) @string.special.symbol (boolean) @constant.builtin.boolean From aad5f6a5e266d0a1a737e568dfbbeb287fdec964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 03:54:43 +0900 Subject: [PATCH 12/22] queries: Update ld, strace --- runtime/queries/ld/highlights.scm | 4 ++-- runtime/queries/strace/highlights.scm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/queries/ld/highlights.scm b/runtime/queries/ld/highlights.scm index e0c9dd1e1..c4ba0bb15 100644 --- a/runtime/queries/ld/highlights.scm +++ b/runtime/queries/ld/highlights.scm @@ -1,11 +1,11 @@ ; Identifiers +[(NAME) (SYMBOLNAME)] @variable + (section . (NAME) @namespace) -[(NAME) (SYMBOLNAME)] @variable - ; Operators [ diff --git a/runtime/queries/strace/highlights.scm b/runtime/queries/strace/highlights.scm index 4f54cb3e9..82ba70688 100644 --- a/runtime/queries/strace/highlights.scm +++ b/runtime/queries/strace/highlights.scm @@ -1,4 +1,4 @@ -(syscall) @function +(syscall) @function.builtin (integer) @constant.numeric (pointer) @constant.numeric (value) @label From c6645d4d8f911acad79f3e62959d82b639ed1e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 03:59:25 +0900 Subject: [PATCH 13/22] queries: Update janet --- runtime/queries/janet/highlights.scm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/queries/janet/highlights.scm b/runtime/queries/janet/highlights.scm index 133559439..94e4cdce1 100644 --- a/runtime/queries/janet/highlights.scm +++ b/runtime/queries/janet/highlights.scm @@ -10,12 +10,15 @@ (num_lit) @constant.numeric -[(bool_lit) (nil_lit)] @constant.builtin +(bool_lit) @constant.builtin.boolean +(nil_lit) @constant.builtin (comment) @comment -((sym_lit) @variable - (#match? @variable "^\\*.+\\*$")) +(sym_lit) @variable + +((sym_lit) @variable.builtin + (#match? @variable.builtin "^\\*.+\\*$")) (short_fn_lit . @@ -57,8 +60,6 @@ . (sym_lit) @function) -(sym_lit) @variable - ["{" "@{" "}" "[" "@[" "]" "(" "@(" ")"] @punctuation.bracket From bbdebe9d720f68b9e658c5d80c35294243e2f573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 19:12:25 +0900 Subject: [PATCH 14/22] queries: Reverse go queries --- runtime/queries/go/highlights.scm | 63 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/runtime/queries/go/highlights.scm b/runtime/queries/go/highlights.scm index 7dc20e69c..0f9be0483 100644 --- a/runtime/queries/go/highlights.scm +++ b/runtime/queries/go/highlights.scm @@ -1,8 +1,34 @@ -; Function calls -(call_expression - function: (identifier) @function.builtin - (#match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)$")) +; Identifiers + +(field_identifier) @variable.other.member + +(identifier) @variable + +(package_identifier) @namespace + +(parameter_declaration (identifier) @variable.parameter) +(variadic_parameter_declaration (identifier) @variable.parameter) + +(const_spec + name: (identifier) @constant) + +(type_spec + name: (type_identifier) @constructor) + +(keyed_element (literal_element (identifier) @variable.other.member)) +(field_declaration + name: (field_identifier) @variable.other.member) + +(parameter_declaration (identifier) @variable.parameter) +(variadic_parameter_declaration (identifier) @variable.parameter) + +(label_name) @label + +(const_spec + name: (identifier) @constant) + +; Function calls (call_expression function: (identifier) @function) @@ -11,9 +37,14 @@ function: (selector_expression field: (field_identifier) @function.method)) +(call_expression + function: (identifier) @function.builtin + (#match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)$")) ; Types +(type_identifier) @type + (type_parameter_list (parameter_declaration name: (identifier) @type.parameter)) @@ -21,8 +52,6 @@ ((type_identifier) @type.builtin (#match? @type.builtin "^(any|bool|byte|comparable|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$")) -(type_identifier) @type - ; Function definitions (function_declaration @@ -34,28 +63,6 @@ (method_spec name: (field_identifier) @function.method) -; Identifiers - -(const_spec - name: (identifier) @constant) - -(parameter_declaration (identifier) @variable.parameter) -(variadic_parameter_declaration (identifier) @variable.parameter) - -(type_spec - name: (type_identifier) @constructor) -(field_identifier) @variable.other.member -(keyed_element (literal_element (identifier) @variable.other.member)) -(identifier) @variable -(package_identifier) @namespace - -(parameter_declaration (identifier) @variable.parameter) -(variadic_parameter_declaration (identifier) @variable.parameter) - -(label_name) @label - -(const_spec - name: (identifier) @constant) ; Operators From 67baa536ecde837484d99fda892ed5f230882abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 19:32:54 +0900 Subject: [PATCH 15/22] queries: Update docker, dot --- runtime/queries/dockerfile/highlights.scm | 12 ++++++++++++ runtime/queries/dot/highlights.scm | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/runtime/queries/dockerfile/highlights.scm b/runtime/queries/dockerfile/highlights.scm index cdbf807c2..ba23ea0eb 100644 --- a/runtime/queries/dockerfile/highlights.scm +++ b/runtime/queries/dockerfile/highlights.scm @@ -37,6 +37,15 @@ (double_quoted_string) @string +[ + (heredoc_marker) + (heredoc_end) +] @label + +((heredoc_block + (heredoc_line) @string) + (#set! "priority" 90)) + (expansion [ "$" @@ -52,3 +61,6 @@ (param) (mount_param) ] @constant + +(expose_instruction + (expose_port) @constant.numeric.integer) diff --git a/runtime/queries/dot/highlights.scm b/runtime/queries/dot/highlights.scm index 6ad64d287..eefb81f9c 100644 --- a/runtime/queries/dot/highlights.scm +++ b/runtime/queries/dot/highlights.scm @@ -1,3 +1,5 @@ +(identifier) @variable + (keyword) @keyword (string_literal) @string (number_literal) @constant.numeric @@ -33,11 +35,9 @@ (identifier) @constant) ) -[ - (comment) - (preproc) -] @comment +(comment) @comment + +(preproc) @keyword.directive (ERROR) @error -(identifier) @variable From 29b4a2f042d97bb5ade37df332589982f30155c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 19:36:05 +0900 Subject: [PATCH 16/22] queries: Update ron --- runtime/queries/ron/highlights.scm | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/runtime/queries/ron/highlights.scm b/runtime/queries/ron/highlights.scm index 1061d559a..fe0545cd8 100644 --- a/runtime/queries/ron/highlights.scm +++ b/runtime/queries/ron/highlights.scm @@ -1,3 +1,11 @@ +; Structs +;------------ + +(enum_variant) @type.enum.variant +(struct_entry (_) @variable.other.member ":") +(struct_name (identifier)) @type +(unit_struct) @type.builtin + ; Literals ;------------ @@ -7,16 +15,6 @@ (float) @constant.numeric.float (char) @constant.character -; Structs -;------------ - -(enum_variant) @type.enum.variant -(struct_entry (_) @variable.other.member ":") -(struct_name (identifier)) @type - - - - ; Comments ;------------ @@ -37,6 +35,7 @@ "{" @punctuation.bracket "}" @punctuation.bracket +"-" @operator ; Special ;------------ From 1231429028c0ea5de3254b3bd959cb1ca93a199a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 19:48:25 +0900 Subject: [PATCH 17/22] queries: Update cue --- runtime/queries/cue/highlights.scm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/runtime/queries/cue/highlights.scm b/runtime/queries/cue/highlights.scm index aef016e8b..52523b210 100644 --- a/runtime/queries/cue/highlights.scm +++ b/runtime/queries/cue/highlights.scm @@ -1,6 +1,6 @@ (package_clause "package" @keyword.control.import) -(package_identifier) @variable +(package_identifier) @namespace (import_declaration "import" @keyword.control.import) @@ -25,7 +25,7 @@ "/" ] @operator -(unary_expression "*" @operator.default) +(unary_expression "*" @operator) (unary_expression "=~" @operator.regexp) @@ -95,16 +95,24 @@ (interpolation "\\(" @punctuation.bracket (_) ")" @punctuation.bracket) @variable.other.member -(field (label (identifier) @variable.other.member)) +(identifier) @variable + +; Types +(primitive_type) @type.builtin ( (identifier) @keyword.storage.type (#match? @keyword.storage.type "^#") ) +[ + (slice_type) + (pointer_type) +] @type ; In attributes + + +(field (label (identifier) @variable.other.member)) + (field (label alias: (identifier) @label)) -(let_clause left: (identifier) @label) - - -(attribute (identifier) @tag) +(attribute (identifier) @attribute) From b7656e007971afdfdff3cd33fefb70bdfac738e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 21 May 2024 03:43:57 +0900 Subject: [PATCH 18/22] queries: bash, devicetree, yaml --- runtime/queries/bash/highlights.scm | 7 +++++-- runtime/queries/devicetree/highlights.scm | 4 ++-- runtime/queries/yaml/highlights.scm | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm index 1aa35aa7c..67d5f7cb9 100644 --- a/runtime/queries/bash/highlights.scm +++ b/runtime/queries/bash/highlights.scm @@ -7,7 +7,10 @@ (command_name) @function -(variable_name) @variable.other.member +(variable_name) @variable + +((variable_name) @constant + (#match? @constant "^[A-Z][A-Z_0-9]*$")) [ "if" @@ -51,7 +54,7 @@ (command_substitution) (process_substitution) (expansion) -]@embedded +] @embedded [ "$" diff --git a/runtime/queries/devicetree/highlights.scm b/runtime/queries/devicetree/highlights.scm index d27c79e4a..b9b29fe20 100644 --- a/runtime/queries/devicetree/highlights.scm +++ b/runtime/queries/devicetree/highlights.scm @@ -51,14 +51,14 @@ (integer_literal) @constant.numeric.integer +(identifier) @variable + (call_expression function: (identifier) @function) (labeled_item label: (identifier) @label) -(identifier) @variable - (unit_address) @tag (reference) @constant diff --git a/runtime/queries/yaml/highlights.scm b/runtime/queries/yaml/highlights.scm index e4fed27a9..6d58e4459 100644 --- a/runtime/queries/yaml/highlights.scm +++ b/runtime/queries/yaml/highlights.scm @@ -1,13 +1,3 @@ -(block_mapping_pair - key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @variable.other.member)) -(block_mapping_pair - key: (flow_node (plain_scalar (string_scalar) @variable.other.member))) - -(flow_mapping - (_ key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @variable.other.member))) -(flow_mapping - (_ key: (flow_node (plain_scalar (string_scalar) @variable.other.member)))) - (boolean_scalar) @constant.builtin.boolean (null_scalar) @constant.builtin (double_quote_scalar) @string @@ -24,6 +14,16 @@ (yaml_directive) @keyword (ERROR) @error +(block_mapping_pair + key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @variable.other.member)) +(block_mapping_pair + key: (flow_node (plain_scalar (string_scalar) @variable.other.member))) + +(flow_mapping + (_ key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @variable.other.member))) +(flow_mapping + (_ key: (flow_node (plain_scalar (string_scalar) @variable.other.member)))) + [ "," "-" From b13999952fbf811ffee0b24c0111c7317c90af78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Wed, 22 May 2024 01:06:08 +0900 Subject: [PATCH 19/22] queries: update more grammars --- runtime/queries/awk/highlights.scm | 9 +++++---- runtime/queries/bash/highlights.scm | 3 +++ runtime/queries/c/highlights.scm | 23 ++++++++++++----------- runtime/queries/clojure/highlights.scm | 16 ++++++++-------- runtime/queries/cpp/highlights.scm | 4 ++-- runtime/queries/java/highlights.scm | 4 ++-- runtime/queries/move/highlights.scm | 7 ++++--- runtime/queries/openscad/highlights.scm | 5 +++-- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/runtime/queries/awk/highlights.scm b/runtime/queries/awk/highlights.scm index 34d660ad5..7254b1305 100644 --- a/runtime/queries/awk/highlights.scm +++ b/runtime/queries/awk/highlights.scm @@ -109,14 +109,15 @@ (number) @constant.numeric (string) @string -(func_call name: (identifier) @function) -(func_def name: (identifier) @function) - -(field_ref (_) @variable) [ (identifier) (field_ref) ] @variable +(func_call name: (identifier) @function) +(func_def name: (identifier) @function) + +(field_ref (_) @variable) + (ns_qualified_name "::" @operator) (ns_qualified_name (namespace) @namespace) diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm index 67d5f7cb9..731106448 100644 --- a/runtime/queries/bash/highlights.scm +++ b/runtime/queries/bash/highlights.scm @@ -46,6 +46,9 @@ (comment) @comment +((word) @constant.builtin.boolean + (#any-of? @constant.builtin.boolean "true" "false")) + (function_definition name: (word) @function) (file_descriptor) @constant.numeric.integer diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 07915f4e3..e48e45ab5 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,3 +1,9 @@ + +(identifier) @variable + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z\\d_]*$")) + "sizeof" @keyword [ @@ -109,6 +115,12 @@ (char_literal) @constant.character (escape_sequence) @constant.character.escape +(field_identifier) @variable.other.member +(statement_identifier) @label +(type_identifier) @type +(primitive_type) @type.builtin +(sized_type_specifier) @type.builtin + (call_expression function: (identifier) @function) (call_expression @@ -128,15 +140,4 @@ (attribute name: (identifier) @attribute) -(field_identifier) @variable.other.member -(statement_identifier) @label -(type_identifier) @type -(primitive_type) @type.builtin -(sized_type_specifier) @type.builtin - -((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]*$")) - -(identifier) @variable - (comment) @comment diff --git a/runtime/queries/clojure/highlights.scm b/runtime/queries/clojure/highlights.scm index 1441ea97d..8155e6e3b 100644 --- a/runtime/queries/clojure/highlights.scm +++ b/runtime/queries/clojure/highlights.scm @@ -10,6 +10,14 @@ (comment) @comment +;; other symbols +(sym_lit) @variable + +;; other calls +(list_lit + . + (sym_lit) @function) + ;; metadata experiment (meta_lit marker: "^" @punctuation) @@ -61,20 +69,12 @@ ((sym_lit) @operator (#match? @operator "^%")) -;; other calls -(list_lit - . - (sym_lit) @function) - ;; interop-ish (list_lit . (sym_lit) @function.method (#match? @function.method "^\\.")) -;; other symbols -(sym_lit) @variable - ;; quote (quoting_lit) @constant.character.escape diff --git a/runtime/queries/cpp/highlights.scm b/runtime/queries/cpp/highlights.scm index c1d14a0b1..b168b3306 100644 --- a/runtime/queries/cpp/highlights.scm +++ b/runtime/queries/cpp/highlights.scm @@ -1,3 +1,5 @@ +; inherits: c + ; Functions ; These casts are parsed as function calls, but are not. @@ -132,5 +134,3 @@ ; Strings (raw_string_literal) @string - -; inherits: c diff --git a/runtime/queries/java/highlights.scm b/runtime/queries/java/highlights.scm index ae99a33ab..1f5da9c60 100644 --- a/runtime/queries/java/highlights.scm +++ b/runtime/queries/java/highlights.scm @@ -1,3 +1,5 @@ +(identifier) @variable + ; Methods (method_declaration @@ -54,8 +56,6 @@ ((identifier) @constant (#match? @constant "^_*[A-Z][A-Z\\d_]+$")) -(identifier) @variable - (this) @variable.builtin ; Literals diff --git a/runtime/queries/move/highlights.scm b/runtime/queries/move/highlights.scm index 86a79dc22..bf607e1f2 100644 --- a/runtime/queries/move/highlights.scm +++ b/runtime/queries/move/highlights.scm @@ -23,12 +23,16 @@ (borrow_expression "&" @keyword.storage.modifier.ref) (borrow_expression "&mut" @keyword.storage.modifier.mut) +(identifier) @variable + (constant_identifier) @constant ((identifier) @constant (#match? @constant "^[A-Z][A-Z\\d_]*$")) (function_identifier) @function +(primitive_type) @type.builtin + (struct_identifier) @type (pack_expression access: (module_access @@ -152,6 +156,3 @@ "with" ] @keyword -(primitive_type) @type.buildin - -(identifier) @variable diff --git a/runtime/queries/openscad/highlights.scm b/runtime/queries/openscad/highlights.scm index c06738e85..90d5ac59d 100644 --- a/runtime/queries/openscad/highlights.scm +++ b/runtime/queries/openscad/highlights.scm @@ -3,13 +3,14 @@ (boolean) @constant.builtin.boolean (include_path) @string.special.path +(identifier) @variable + (parameters_declaration (identifier) @variable.parameter) (function_declaration name: (identifier) @function) (function_call function: (identifier) @function) (module_call name: (identifier) @function) -(identifier) @variable (special_variable) @variable.builtin [ @@ -60,4 +61,4 @@ "." ] @punctuation.delimiter -(comment) @comment \ No newline at end of file +(comment) @comment From 8caba39b05d7bb08242a1afe8a585c367ed4ed4d Mon Sep 17 00:00:00 2001 From: gabydd Date: Mon, 15 Jul 2024 23:30:53 -0400 Subject: [PATCH 20/22] queries: update zig --- runtime/queries/zig/highlights.scm | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/runtime/queries/zig/highlights.scm b/runtime/queries/zig/highlights.scm index d6b1f95a2..56480e040 100644 --- a/runtime/queries/zig/highlights.scm +++ b/runtime/queries/zig/highlights.scm @@ -7,6 +7,18 @@ (line_comment) ] @comment.line +[ + variable: (IDENTIFIER) + variable_type_function: (IDENTIFIER) +] @variable + +parameter: (IDENTIFIER) @variable.parameter + +[ + field_member: (IDENTIFIER) + field_access: (IDENTIFIER) +] @variable.other.member + ;; assume TitleCase is a type ( [ @@ -36,6 +48,13 @@ (#match? @constant "^[A-Z][A-Z_0-9]+$") ) +[ + function_call: (IDENTIFIER) + function: (IDENTIFIER) +] @function + +exception: "!" @keyword.control.exception + ;; _ ( (IDENTIFIER) @variable.builtin @@ -45,25 +64,6 @@ ;; C Pointers [*c]T (PtrTypeStart "c" @variable.builtin) -[ - variable: (IDENTIFIER) - variable_type_function: (IDENTIFIER) -] @variable - -parameter: (IDENTIFIER) @variable.parameter - -[ - field_member: (IDENTIFIER) - field_access: (IDENTIFIER) -] @variable.other.member - -[ - function_call: (IDENTIFIER) - function: (IDENTIFIER) -] @function - -exception: "!" @keyword.control.exception - field_constant: (IDENTIFIER) @constant (BUILTINIDENTIFIER) @function.builtin From 400a1930ad915f90001b806cf502a1ad4cef28a3 Mon Sep 17 00:00:00 2001 From: gabydd Date: Tue, 16 Jul 2024 00:59:48 -0400 Subject: [PATCH 21/22] grammars: update ron and dockerfile --- languages.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/languages.toml b/languages.toml index ae05f5923..00c0a68d6 100644 --- a/languages.toml +++ b/languages.toml @@ -1604,7 +1604,7 @@ language-servers = [ "docker-langserver" ] [[grammar]] name = "dockerfile" -source = { git = "https://github.com/camdencheek/tree-sitter-dockerfile", rev = "8ee3a0f7587b2bd8c45c8cb7d28bd414604aec62" } +source = { git = "https://github.com/camdencheek/tree-sitter-dockerfile", rev = "868e44ce378deb68aac902a9db68ff82d2299dd0" } [[language]] name = "docker-compose" @@ -1864,7 +1864,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "ron" -source = { git = "https://github.com/zee-editor/tree-sitter-ron", rev = "7762d709a0f7c1f9e269d0125a2e8a7a69006146" } +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-ron", rev = "78938553b93075e638035f624973083451b29055" } [[language]] name = "robot" From f3a46c8751eb31f26c85be3762429d83f2d87b73 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 3 Oct 2024 13:02:48 -0400 Subject: [PATCH 22/22] Update cue parser and queries Queries ported from nvim-treesitter --- languages.toml | 2 +- runtime/queries/cue/highlights.scm | 193 +++++++++++++++++------------ 2 files changed, 116 insertions(+), 79 deletions(-) diff --git a/languages.toml b/languages.toml index 00c0a68d6..7e600c6be 100644 --- a/languages.toml +++ b/languages.toml @@ -2351,7 +2351,7 @@ formatter = { command = "cue", args = ["fmt", "-"] } [[grammar]] name = "cue" -source = { git = "https://github.com/eonpatapon/tree-sitter-cue", rev = "61843e3beebf19417e4fede4e8be4df1084317ad" } +source = { git = "https://github.com/eonpatapon/tree-sitter-cue", rev = "8a5f273bfa281c66354da562f2307c2d394b6c81" } [[language]] name = "slint" diff --git a/runtime/queries/cue/highlights.scm b/runtime/queries/cue/highlights.scm index 52523b210..4168036b5 100644 --- a/runtime/queries/cue/highlights.scm +++ b/runtime/queries/cue/highlights.scm @@ -1,12 +1,46 @@ -(package_clause "package" @keyword.control.import) +; Includes +[ + "package" + "import" +] @keyword.control.import +; Namespaces (package_identifier) @namespace -(import_declaration "import" @keyword.control.import) +(import_spec + [ + "." + "_" + ] @punctuation.special) [ - "!" + (attr_path) + (package_path) +] @string.special.url ; In attributes + +; Attributes +(attribute) @attribute + +; Conditionals +"if" @keyword.control.conditional + +; Repeats +"for" @keyword.control.repeat + +(for_clause + "_" @punctuation.special) + +; Keywords +"let" @keyword + +"in" @keyword.operator + +; Operators +[ + "+" + "-" "*" + "/" "|" "&" "||" @@ -19,100 +53,103 @@ ">=" "=~" "!~" - "+" - "-" - "*" - "/" + "!" + "=" ] @operator -(unary_expression "*" @operator) +; Fields & Properties +(field + (label + (identifier) @variable.other.member)) -(unary_expression "=~" @operator.regexp) +(selector_expression + (_) + (identifier) @variable.other.member) -(unary_expression "!~" @operator.regexp) +; Functions +(call_expression + function: (identifier) @function) -(binary_expression _ "&" @operator.unify _) +(call_expression + function: (selector_expression + (_) + (identifier) @function)) -(binary_expression _ "|" @operator.disjunct _) +(call_expression + function: (builtin_function) @function) -(builtin) @function.builtin - -(qualified_identifier) @function.builtin - -(let_clause "let" @keyword.storage.type) - -(for_clause "for" @keyword.control.repeat) -(for_clause "in" @keyword.control.repeat) - -(guard_clause "if" @keyword.control.conditional) - -(comment) @comment - -[ - (string_type) - (simple_string_lit) - (multiline_string_lit) - (bytes_type) - (simple_bytes_lit) - (multiline_bytes_lit) -] @string - -[ - (number_type) - (int_lit) - (int_type) - (uint_type) -] @constant.numeric.integer - -[ - (float_lit) - (float_type) -] @constant.numeric.float - -[ - (bool_type) - (true) - (false) -] @constant.builtin.boolean - -(null) @constant.builtin - -(ellipsis) @punctuation.bracket - -[ - "," - ":" -] @punctuation.delimiter - -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket - -(interpolation "\\(" @punctuation.bracket (_) ")" @punctuation.bracket) @variable.other.member +(builtin_function) @function.builtin +; Variables (identifier) @variable ; Types (primitive_type) @type.builtin -( - (identifier) @keyword.storage.type - (#match? @keyword.storage.type "^#") -) +((identifier) @type + (#match? @type "^_?#")) [ (slice_type) (pointer_type) ] @type ; In attributes +; Punctuation +[ + "," + ":" +] @punctuation.delimiter -(field (label (identifier) @variable.other.member)) +[ + "{" + "}" + "[" + "]" + "(" + ")" + "<" + ">" +] @punctuation.bracket -(field (label alias: (identifier) @label)) +[ + (ellipsis) + "?" +] @punctuation.special -(attribute (identifier) @attribute) +; Literals +(string) @string + +[ + (escape_char) + (escape_unicode) +] @constant.character.escape + +(number) @constant.numeric + +(float) @constant.numeric.float + +(si_unit + (float) + (_) @string.special.symbol) + +(boolean) @constant.builtin.boolean + +[ + (null) + (top) + (bottom) +] @constant.builtin + +; Interpolations +(interpolation + "\\(" @punctuation.special + (_) + ")" @punctuation.special) + +(interpolation + "\\(" + (identifier) @variable + ")") + +; Comments +(comment) @comment