From 3fb14431627ad3b5985505174a0fbe15d4dc6fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Plagborg=20Bak=20S=C3=B8rensen?= <57013304+kpbaks@users.noreply.github.com> Date: Mon, 18 Aug 2025 15:24:38 +0200 Subject: [PATCH] feat(python): add regex injection to functions in the std `re` module (#14254) --- runtime/queries/python/injections.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runtime/queries/python/injections.scm b/runtime/queries/python/injections.scm index 321c90ad..19a22c39 100644 --- a/runtime/queries/python/injections.scm +++ b/runtime/queries/python/injections.scm @@ -1,2 +1,14 @@ ((comment) @injection.content (#set! injection.language "comment")) + +; Match all 9 functions in the `re` module from the standard library that +; that takes a regex pattern as first argument. +; https://docs.python.org/3/library/re.html#functions +(call + function: (attribute + object: (identifier) @_module (#eq? @_module "re") + attribute: (identifier) @_function (#any-of? @_function "compile" "search" "match" "fullmatch" "sub" "subn" "findall" "finditer" "split")) + arguments: (argument_list + . (string + (string_content) @injection.content)) + (#set! injection.language "regex")) -- 2.51.2