mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
runtime(python): Highlight f-string replacement fields in Python
Highlight f-string replacement fields, including - Comments - Debugging flags - Conversion fields - Format specifications - Delimiters Syntax inside fields will be addressed in a separate commit. related: #10734 related: #14033 closes: #17784 Signed-off-by: Rob B <github@0x7e.net> Signed-off-by: Zvezdan Petkovic <zpetkovic@acm.org> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
48b7eb1ceb
commit
a94a0555d9
@@ -99,6 +99,69 @@ and fields {1}, {2} and {1
|
||||
+
|
||||
2}"""
|
||||
|
||||
# F-string replacement fields
|
||||
test = f"String is {
|
||||
"one plus "
|
||||
"two plus "
|
||||
"three"}"
|
||||
test = f"Number is {
|
||||
1 +
|
||||
2 +
|
||||
3}"
|
||||
test = f"abc{a # This is a comment }
|
||||
+ 1}"
|
||||
test = f"def{a # So is this :
|
||||
+ 2}"
|
||||
test = f"ghi{a # And this "
|
||||
+ 3}"
|
||||
test = f"He said his name is {name!r}."
|
||||
test = f"He said his name is {repr(name)}."
|
||||
test = f"result: {value:{width}}"
|
||||
test = f"result: {value:{width}.{precision}}"
|
||||
test = f"result: {value:{width:d}.{precision!s}}"
|
||||
test = f"result: {value:{options}{width}{grouping}{precision}{type}}"
|
||||
test = f"{number:#0x}"
|
||||
test = f"{number:+#0x}"
|
||||
test = f"{number:<+#0x}"
|
||||
test = f"{number: <+#0x}"
|
||||
test = f"{number:<#0x}"
|
||||
test = f"{number: <#0x}"
|
||||
test = f"{string=}"
|
||||
test = f"{string=!r}"
|
||||
test = f"{string=:20}"
|
||||
test = f"{string=!r:20}"
|
||||
test = f"{string = }"
|
||||
test = f"{string = !r}"
|
||||
test = f"{string = :20}"
|
||||
test = f"{string = !r:20}"
|
||||
test = f"abc {a["x"]} def"
|
||||
test = f"List contains:\n{"\n".join(a)}"
|
||||
test = f"Today's date is {datetime.now()}"
|
||||
test = f"Today's formatted date is {datetime.now():%Y-%m-%d %H:%M:%S}"
|
||||
test = f"Date is {datetime.datetime(2010, 7, 4, 12, 15, 58)}"
|
||||
test = f"Formatted date is {datetime.datetime(2010, 7, 4, 12, 15, 58):%Y-%m-%d %H:%M:%S}"
|
||||
test = f"Lambda returns {(lambda x: x**2)}"
|
||||
test = f"Zero padded lambda returns {(lambda x: x**2):09}"
|
||||
test = f"Space padded lambda returns {(lambda x: x**2):{width}}"
|
||||
test = f"List copy is {items[:]}"
|
||||
test = f"List slice is {items[1:]}"
|
||||
test = f"List slice is {items[:9]}"
|
||||
test = f"List elements are {items[:2:]}"
|
||||
test = f"Padded list copy is {items[:]:99}"
|
||||
test = f"Left-aligned list slice is {items[1:]:<99}"
|
||||
test = f"Right aligned list slice is {items[:9]:>99}"
|
||||
test = f"Center-aligned list elements are {items[:2:]:^99}"
|
||||
test = f"Expression is {x == 1}"
|
||||
test = f"Expression is {x != 1}"
|
||||
test = f"Expression is {(x := 1)}"
|
||||
test = f"Debug expression is {x == 1=}"
|
||||
test = f"Debug expression is {x != 1=}"
|
||||
test = f"Debug expression is {(x := 1)=}"
|
||||
test = f"List comprehension returns { [x**2 for x in range(10)] }"
|
||||
test = f"Padded list comprehension returns { [x**2 for x in range(10)] :99}"
|
||||
test = f"Dict comprehension returns { {x: x**2 for x in range(10)} }"
|
||||
test = f"Padded dict comprehension returns { {x: x**2 for x in range(10)} :99}"
|
||||
|
||||
# Bytes
|
||||
test = b'Bytes with escapes \' and \" and \t'
|
||||
test = B"Bytes with escapes \040 and \xFF"
|
||||
|
Reference in New Issue
Block a user