mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
fix(python): regex injection not working for concatenated strings (#8197)
Co-authored-by: Riley Bruins <ribru17@hotmail.com>
This commit is contained in:
parent
98fe644cb3
commit
c53bb10a71
7 changed files with 83 additions and 3 deletions
|
|
@ -417,11 +417,19 @@
|
|||
function: (attribute
|
||||
object: (identifier) @_re)
|
||||
arguments: (argument_list
|
||||
.
|
||||
(string
|
||||
(string_content) @string.regexp))
|
||||
(#eq? @_re "re"))
|
||||
|
||||
(call
|
||||
function: (attribute
|
||||
object: (identifier) @_re)
|
||||
arguments: (argument_list
|
||||
(concatenated_string
|
||||
(string
|
||||
(string_content) @string.regexp)))
|
||||
(#eq? @_re "re"))
|
||||
|
||||
; Decorators
|
||||
((decorator
|
||||
"@" @attribute)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,24 @@
|
|||
function: (attribute
|
||||
object: (identifier) @_re)
|
||||
arguments: (argument_list
|
||||
.
|
||||
(string
|
||||
(string_content) @injection.content))
|
||||
(#eq? @_re "re")
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
(call
|
||||
function: (attribute
|
||||
object: (identifier) @_re)
|
||||
arguments: (argument_list
|
||||
(concatenated_string
|
||||
[
|
||||
(string
|
||||
(string_content) @injection.content)
|
||||
(comment)
|
||||
]+))
|
||||
(#eq? @_re "re")
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
((binary_operator
|
||||
left: (string
|
||||
(string_content) @injection.content)
|
||||
|
|
|
|||
|
|
@ -1 +1,8 @@
|
|||
; inherits: python
|
||||
((binary_operator
|
||||
left: (string
|
||||
(string_content) @injection.content)
|
||||
operator: "%")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
|
|
|||
19
tests/query/highlights/python/regex.py
Normal file
19
tests/query/highlights/python/regex.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import re
|
||||
|
||||
re_test = re.compile(r"^(?P<year>\d{4}) (?P<day>\d) \w\s{,3}$")
|
||||
# ^ @string.regexp
|
||||
re_test = re.compile(
|
||||
# comment
|
||||
# ^ @comment
|
||||
r"^(?P<year>\d{4}){1}"
|
||||
# ^ @string.regexp
|
||||
# comment
|
||||
# ^ @comment
|
||||
r"(?P<day>\d) \w\s{,3}"
|
||||
# ^ @string.regexp
|
||||
# comment
|
||||
# ^ @comment
|
||||
)
|
||||
# interpolation
|
||||
print("foo %s bar %d" % ("arg1", 2))
|
||||
# ^ @character
|
||||
11
tests/query/highlights/starlark/test.bzl
Normal file
11
tests/query/highlights/starlark/test.bzl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# split
|
||||
# ^ @comment
|
||||
assert_eq('foo bar'.split(' '), ['foo', 'bar'])
|
||||
# ^ @keyword
|
||||
# ^ @punctuation.bracket
|
||||
# ^ @string
|
||||
# ^ @punctuation.delimiter
|
||||
assert_eq('foo bar foo'.rsplit(' ', 1), ['foo bar', 'foo'])
|
||||
# ^ @number
|
||||
assert_eq("foo %s bar %d" % ("arg1", 2), "foo arg1 bar 2")
|
||||
# ^ @character
|
||||
18
tests/query/injections/python/test.py
Normal file
18
tests/query/injections/python/test.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import re
|
||||
|
||||
re_test = re.compile(r"^(?P<year>\d{4}) (?P<day>\d) \w\s{,3}$")
|
||||
# ^ @regex
|
||||
re_test = re.compile(
|
||||
# comment
|
||||
# ^ @comment
|
||||
r"^(?P<year>\d{4}) "
|
||||
# comment
|
||||
# ^ @comment
|
||||
r"(?P<day>\d) \w\s{,3}$"
|
||||
# ^ @regex
|
||||
# comment
|
||||
# comment
|
||||
# ^ @comment
|
||||
)
|
||||
print("foo %s bar %d" % ("arg1", 2))
|
||||
# ^ @printf
|
||||
5
tests/query/injections/starlark/test.bzl
Normal file
5
tests/query/injections/starlark/test.bzl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# split
|
||||
# ^ @comment
|
||||
assert_eq('foo bar'.split(' '), ['foo', 'bar'])
|
||||
assert_eq("foo %s bar %d" % ("arg1", 2), "foo arg1 bar 2")
|
||||
# ^ @printf
|
||||
Loading…
Add table
Add a link
Reference in a new issue