From 1610b1aafb9b7b3a7b54c853ed45c6cb1a3d0df2 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Mon, 20 Nov 2023 08:26:18 -0800 Subject: feat(python): `@string.regex` capture, injection improvements (#5697) * feat(python): `@string.regex` capture, injection improvements * fix(python): match regex only for first argument of re module * chore(python): remove unneeded capture Co-authored-by: Santos Gallegos * fix(python): only highlight string content itself as regex --------- Co-authored-by: Santos Gallegos --- queries/python/highlights.scm | 8 ++++++++ queries/python/injections.scm | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'queries') diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index de98dccbf..b09122dd9 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -346,3 +346,11 @@ ;; https://docs.python.org/3/library/stdtypes.html "bool" "int" "float" "complex" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview" "set" "frozenset" "dict" "type" "object")) + +;; Regex from the `re` module + +(call + function: (attribute + object: (identifier) @_re) + arguments: (argument_list . (string (string_content) @string.regex)) + (#eq? @_re "re")) diff --git a/queries/python/injections.scm b/queries/python/injections.scm index b836ea3f7..aa36a5af9 100644 --- a/queries/python/injections.scm +++ b/queries/python/injections.scm @@ -1,10 +1,9 @@ (call function: (attribute object: (identifier) @_re) - arguments: (argument_list (string - (string_content) @injection.content) @_string) + arguments: (argument_list . (string + (string_content) @injection.content)) (#eq? @_re "re") - (#lua-match? @_string "^r.*") (#set! injection.language "regex")) ((comment) @injection.content -- cgit v1.2.3-70-g09d2