diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 9f1ae209..3984af08 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -167,6 +167,7 @@ | log | ✓ | | | | | | | lpf | ✓ | | | | | | | lua | ✓ | ✓ | ✓ | | ✓ | `lua-language-server` | +| lua-format-string | ✓ | | | | | | | luap | ✓ | | | | | | | luau | ✓ | ✓ | ✓ | | | `luau-lsp` | | mail | ✓ | ✓ | | | | | diff --git a/languages.toml b/languages.toml index 43d2408c..96405c12 100644 --- a/languages.toml +++ b/languages.toml @@ -1534,6 +1534,16 @@ injection-regex = "luap" name = "luap" source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-luap", rev = "c134aaec6acf4fa95fe4aa0dc9aba3eacdbbe55a" } +[[language]] +name = "lua-format-string" +scope = "source.lua-format-string" +file-types = [] +injection-regex = "lua-format-string" + +[[grammar]] +name = "lua-format-string" +source = { git = "https://codeberg.org/kpbaks/tree-sitter-lua-format-string", rev = "b667c8cab109df307e1b4d56b0b43f5c4a353533" } + [[grammar]] name = "teal" source = { git = "https://github.com/euclidianAce/tree-sitter-teal", rev = "3db655924b2ff1c54fdf6371b5425ea6b5dccefe" } diff --git a/runtime/queries/lua-format-string/highlights.scm b/runtime/queries/lua-format-string/highlights.scm new file mode 100644 index 00000000..02bd09a0 --- /dev/null +++ b/runtime/queries/lua-format-string/highlights.scm @@ -0,0 +1,13 @@ +(escaped_percent_sign) @constant.character.escape + +(flag) @constant.builtin + +(text) @string + +(width) @constant.numeric.integer +(precision) @constant.numeric.float + +(conversion_specifier) @type + +"." @punctuation.delimiter +"%" @punctuation.special diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 8f8c174a..e8303477 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -27,3 +27,26 @@ content: (string_content) @injection.content (#set! injection.language "luap") (#set! injection.include-children)))) + +; string.format("format string", ...) +((function_call + name: (dot_index_expression + table: (identifier) @_table + field: (identifier) @_function) + arguments: (arguments + . + (string + content: (string_content) @injection.content))) + (#eq? @_table "string") + (#eq? @_function "format") + (#set! injection.language "lua-format-string")) + +; ("format"):format(...) +((function_call + name: (method_index_expression + table: (parenthesized_expression + (string + content: (string_content) @injection.content)) + method: (identifier) @_function)) + (#eq? @_function "format") + (#set! injection.language "lua-format-string")) diff --git a/runtime/queries/luau/injections.scm b/runtime/queries/luau/injections.scm index 86d4196e..3311f44c 100644 --- a/runtime/queries/luau/injections.scm +++ b/runtime/queries/luau/injections.scm @@ -24,3 +24,22 @@ (string) @injection.content) (#any-of? @_method "find" "format" "match" "gmatch" "gsub") (#set! injection.language "luap")) + +; string.format("format string", ...) +((call_stmt + invoked: (var + table_name: (name) @_table + (key + field_name: (name) @_function)) + (arglist + . (string) @injection.content)) + (#eq? @_table "string") + (#eq? @_function "format") + (#set! injection.language "lua-format-string")) + +; ("format"):format(...) +((call_stmt + method_table: (exp_wrap (string) @injection.content) + method_name: (name) @_function) + (#eq? @_function "format") + (#set! injection.language "lua-format-string"))