From 18fadcfd4b88bd084ff227734ce8fe2a0b14d240 Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Wed, 2 Dec 2020 21:27:25 +0100 Subject: add readme and more correct highlight captures --- queries/kotlin/highlights.scm | 108 +++++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 37 deletions(-) (limited to 'queries') diff --git a/queries/kotlin/highlights.scm b/queries/kotlin/highlights.scm index 60ab279a..e896b74a 100644 --- a/queries/kotlin/highlights.scm +++ b/queries/kotlin/highlights.scm @@ -1,18 +1,19 @@ -;;; Kotlin +;;; Kotlin ;; Issues ; mapOf with type definition AND multiple entries are not highligted correctly. Issue in parser. Eg. ; a = mapOf(AA.value to AA.value, AA.value to AA.value) +;; parser does not recognice `in` and `downto` in `for (i in 5..1) print(i)` -(function_modifier) @type - -;; String +;; Strings (line_string_literal) @string (multi_line_string_literal) @string -(line_string_literal (interpolated_identifier)) @string -(line_string_literal (interpolated_expression (line_string_literal))) @string +; Interpolated +(interpolated_identifier) @none +(interpolated_expression) @none + ;; Constants ; Assume all-caps names are constants @@ -20,17 +21,24 @@ (#vim-match? @constant "^[A-Z][A-Z_]+")) -;; Variables -(class_parameter (simple_identifier) @variable.builtin) +;; Variables/fields +; field in data classes etc. +(class_parameter (simple_identifier) @field) +; field in normal classes +(property_declaration (variable_declaration (simple_identifier) @field)) +; accessed field in blocks. `logger` in `logger.info("")` +(statements (call_expression (navigation_expression (simple_identifier) @field))) -; Class level -(property_declaration (variable_declaration (simple_identifier) @variable.builtin)) +(statements (navigation_expression (simple_identifier) @field)) -(statements (call_expression (navigation_expression (simple_identifier) @variable.builtin))) +(call_expression (navigation_expression (simple_identifier) @field)) -(directly_assignable_expression (navigation_expression (simple_identifier) @variable.builtin)) +; TODO check if this is needed +(directly_assignable_expression (navigation_expression (simple_identifier) @string)) +; `variable` in `variable = car.doors` +(directly_assignable_expression (simple_identifier) @field) -(directly_assignable_expression (simple_identifier) @variable.builtin) +(lambda_parameters) @field ; TODO not supported yet @@ -41,44 +49,55 @@ ;; Property access syntax -; TODO -; a = get().value etc -(assignment (navigation_expression (navigation_suffix) @type )) -; val a = A.get().value etc -(property_declaration (navigation_expression (navigation_suffix) @type )) -; value in `mapOf(A.value to B.value)` etc. -(infix_expression (navigation_expression (navigation_suffix) @type )) +; `value` in `a = get().value` +(assignment (navigation_expression (navigation_suffix) @property )) +; `value` in `val a = A.get().value` +(property_declaration (navigation_expression (navigation_suffix) @property )) +; `value` in `mapOf(A.value to B.value)` +(infix_expression (navigation_expression (navigation_suffix) @property )) ; java in `Car::class.java` -(value_argument (navigation_expression (navigation_suffix) @type )) - - -;; Interpolated - -(interpolated_identifier) @type -(interpolated_expression) @type +(value_argument (navigation_expression (navigation_suffix) @method )) ;; Builtin functions -((simple_identifier) @function.builtin - (#vim-match? @function.builtin "(^let$|^listOf$|^mapOf$|^map$)")) - +;; TODO add more functions +((simple_identifier) @function.macro + (#vim-match? @function.macro "(^let$|^listOf$|^mapOf$|^map$|^downto$)")) +;; TODO add more functions ((simple_identifier) @function.builtin - (#vim-match? @function.builtin "^to$")) + (#vim-match? @function.builtin "(^print$|^println$)")) -(modifiers (annotation (user_type (type_identifier)))) @attribute +((simple_identifier) @keyword.operator + (#vim-match? @keyword.operator "^to$")) -(annotation) @attribute +;; Numbers (integer_literal) @number +;; Booleans (boolean_literal) @boolean +;; Annotations +(annotation (single_annotation) @annotation) + +;; Types +; TODO more type definitions +(variable_declaration (user_type (type_identifier) @type)) +(callable_reference (type_identifier) @type) + ;; it -(indexing_expression (simple_identifier) @type - (#vim-match? @type "^it$")) +(indexing_expression (simple_identifier) @variable.builtin + (#vim-match? @variable.builtin "^it$")) + + +;; Keyword operators + +[ +"in" +] @keyword.operator ;; Keywords @@ -99,6 +118,7 @@ "companion" "return" "constructor" + "throw" ] @keyword ; const does not work @@ -112,6 +132,13 @@ ] @conditional +;; Loops +[ +"for" +"while" +] @repeat + + ;; Includes "import" @include @@ -121,11 +148,18 @@ ;; Punctuation [ +"::" ";" "." "," ] @punctuation.delimiter +[ +"$" +"${" +"}" +] @none + [ "[" "]" @@ -137,8 +171,6 @@ [ "$" -"${" -"}" ] @punctuation.special ;; Comments @@ -159,4 +191,6 @@ "*" ] @operator +; TODO parameter + (ERROR) @error -- cgit v1.2.3