feat(cmake): update cmake parser, adapt highlight.scm, and add indents.scm

This commit is contained in:
Uy Ha 2023-06-28 15:19:58 +00:00 committed by Christian Clason
parent f04f137acb
commit e68ad094cd
3 changed files with 93 additions and 44 deletions

View file

@ -48,7 +48,7 @@
"revision": "6e41628e9d18b19caea1cb1d72aae4ccff5bdfe9"
},
"cmake": {
"revision": "aafadc0d657faa99e483a4f2c70dbe64491b1802"
"revision": "3dfc596025431b21e839d392c171f6f97c2a4258"
},
"comment": {
"revision": "c9a7e2df7cac2dfb730f766a4f343308f84ff346"

View file

@ -1,6 +1,8 @@
(normal_command
(identifier)
(argument (unquoted_argument)) @constant
(argument_list
(argument (unquoted_argument)) @constant
)
(#lua-match? @constant "^[%u@][%u%d_]+$")
)
@ -55,32 +57,40 @@
(function_command
(function)
. (argument) @function
(argument)* @parameter
(argument_list
. (argument) @function
(argument)* @parameter
)
)
(macro_command
(macro)
. (argument) @function.macro
(argument)* @parameter
(argument_list
. (argument) @function.macro
(argument)* @parameter
)
)
(block_def
(block_command
(block) @function.builtin
(argument (unquoted_argument) @constant)
(argument_list
(argument (unquoted_argument) @constant)
)
(#any-of? @constant "SCOPE_FOR" "POLICIES" "VARIABLES" "PROPAGATE")
)
(endblock_command (endblock) @function.builtin)
)
;
((argument) @boolean
(#match? @boolean "\\c^(1|on|yes|true|y|0|off|no|false|n|ignore|notfound|.*-notfound)$")
)
;
(if_command
(if)
(argument) @keyword.operator
(argument_list
(argument) @keyword.operator
)
(#any-of? @keyword.operator "NOT" "AND" "OR"
"COMMAND" "POLICY" "TARGET" "TEST" "DEFINED" "IN_LIST"
"EXISTS" "IS_NEWER_THAN" "IS_DIRECTORY" "IS_SYMLINK" "IS_ABSOLUTE"
@ -92,7 +102,9 @@
)
(elseif_command
(elseif)
(argument) @keyword.operator
(argument_list
(argument) @keyword.operator
)
(#any-of? @keyword.operator "NOT" "AND" "OR"
"COMMAND" "POLICY" "TARGET" "TEST" "DEFINED" "IN_LIST"
"EXISTS" "IS_NEWER_THAN" "IS_DIRECTORY" "IS_SYMLINK" "IS_ABSOLUTE"
@ -110,77 +122,93 @@
(normal_command
(identifier) @_function
. (argument) @variable
(argument_list
. (argument) @variable
)
(#match? @_function "\\c^set$")
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^set$")
. (argument)
(
(argument_list
. (argument)
(
(argument) @_cache @storageclass
.
(argument) @_type @type
(#any-of? @_cache "CACHE")
(#any-of? @_type "BOOL" "FILEPATH" "PATH" "STRING" "INTERNAL")
)
)
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^unset$")
. (argument)
(argument) @storageclass
(#any-of? @storageclass "CACHE" "PARENT_SCOPE")
(argument_list
. (argument)
(argument) @storageclass
(#any-of? @storageclass "CACHE" "PARENT_SCOPE")
)
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^list$")
. (argument) @constant
(#any-of? @constant "LENGTH" "GET" "JOIN" "SUBLIST" "FIND")
. (argument) @variable
(argument) @variable .
(argument_list
. (argument) @constant
(#any-of? @constant "LENGTH" "GET" "JOIN" "SUBLIST" "FIND")
. (argument) @variable
(argument) @variable .
)
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^list$")
. (argument) @constant
. (argument) @variable
(#any-of? @constant "APPEND" "FILTER" "INSERT"
"POP_BACK" "POP_FRONT" "PREPEND"
"REMOVE_ITEM" "REMOVE_AT" "REMOVE_DUPLICATES"
"REVERSE" "SORT")
(argument_list
. (argument) @constant
. (argument) @variable
(#any-of? @constant "APPEND" "FILTER" "INSERT"
"POP_BACK" "POP_FRONT" "PREPEND"
"REMOVE_ITEM" "REMOVE_AT" "REMOVE_DUPLICATES"
"REVERSE" "SORT")
)
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^list$")
. (argument) @_transform @constant
. (argument) @variable
. (argument) @_action @constant
(#eq? @_transform "TRANSFORM")
(#any-of? @_action "APPEND" "PREPEND" "TOUPPER" "TOLOWER" "STRIP" "GENEX_STRIP" "REPLACE")
(argument_list
. (argument) @_transform @constant
. (argument) @variable
. (argument) @_action @constant
(#eq? @_transform "TRANSFORM")
(#any-of? @_action "APPEND" "PREPEND" "TOUPPER" "TOLOWER" "STRIP" "GENEX_STRIP" "REPLACE")
)
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^list$")
. (argument) @_transform @constant
. (argument) @variable
. (argument) @_action @constant
. (argument)? @_selector @constant
(#eq? @_transform "TRANSFORM")
(#any-of? @_action "APPEND" "PREPEND" "TOUPPER" "TOLOWER" "STRIP" "GENEX_STRIP" "REPLACE")
(#any-of? @_selector "AT" "FOR" "REGEX")
(argument_list
. (argument) @_transform @constant
. (argument) @variable
. (argument) @_action @constant
. (argument)? @_selector @constant
(#eq? @_transform "TRANSFORM")
(#any-of? @_action "APPEND" "PREPEND" "TOUPPER" "TOLOWER" "STRIP" "GENEX_STRIP" "REPLACE")
(#any-of? @_selector "AT" "FOR" "REGEX")
)
)
(normal_command
(identifier) @_function
(#match? @_function "\\c^list$")
. (argument) @_transform @constant
(argument) @constant .
(argument) @variable
(#eq? @_transform "TRANSFORM")
(#eq? @constant "OUTPUT_VARIABLE")
(argument_list
. (argument) @_transform @constant
(argument) @constant .
(argument) @variable
(#eq? @_transform "TRANSFORM")
(#eq? @constant "OUTPUT_VARIABLE")
)
)
(escape_sequence) @string.escape

21
queries/cmake/indents.scm Normal file
View file

@ -0,0 +1,21 @@
[
(normal_command)
(if_condition)
(foreach_loop)
(while_loop)
(function_def)
(macro_def)
(block_def)
] @indent.begin
[
(elseif_command)
(elseif_command)
(endif_command)
(endforeach_command)
(endfunction_command)
(endmacro_command)
(endblock_command)
] @indent.branch
(normal_command ")" @indent.branch)