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 <stsewd@proton.me>

* fix(python): only highlight string content itself as regex

---------

Co-authored-by: Santos Gallegos <stsewd@proton.me>
This commit is contained in:
Riley Bruins 2023-11-20 08:26:18 -08:00 committed by GitHub
parent 3da5cfb4a2
commit 1610b1aafb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -346,3 +346,11 @@
;; https://docs.python.org/3/library/stdtypes.html ;; https://docs.python.org/3/library/stdtypes.html
"bool" "int" "float" "complex" "list" "tuple" "range" "str" "bool" "int" "float" "complex" "list" "tuple" "range" "str"
"bytes" "bytearray" "memoryview" "set" "frozenset" "dict" "type" "object")) "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"))

View file

@ -1,10 +1,9 @@
(call (call
function: (attribute function: (attribute
object: (identifier) @_re) object: (identifier) @_re)
arguments: (argument_list (string arguments: (argument_list . (string
(string_content) @injection.content) @_string) (string_content) @injection.content))
(#eq? @_re "re") (#eq? @_re "re")
(#lua-match? @_string "^r.*")
(#set! injection.language "regex")) (#set! injection.language "regex"))
((comment) @injection.content ((comment) @injection.content