summaryrefslogtreecommitdiff
path: root/kde-frameworks/syntax-highlighting/files/syntax-highlighting-5.85.0-python-add-yield-from-keyword.patch
blob: ba1ae38355e84596ed7048f1a57a251de970d039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From 439f8cbfe0b5d1f931c2233d1790e1280170c24c Mon Sep 17 00:00:00 2001
From: Jan Paul Batrina <jpmbatrina01@gmail.com>
Date: Sat, 28 Aug 2021 21:27:41 +0800
Subject: [PATCH] Python: Add "yield from" keyword

BUG: 441540
---
 autotests/folding/test.py.fold   |  9 +++++++++
 autotests/html/test.py.dark.html |  9 +++++++++
 autotests/html/test.py.html      |  9 +++++++++
 autotests/input/test.py          |  9 +++++++++
 autotests/reference/test.py.ref  |  9 +++++++++
 data/syntax/python.xml           | 17 +++++++++++++++--
 6 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/autotests/folding/test.py.fold b/autotests/folding/test.py.fold
index 7bbf054c..5e7a3ba8 100644
--- a/autotests/folding/test.py.fold
+++ b/autotests/folding/test.py.fold
@@ -118,6 +118,15 @@ match<beginfold id='2'>(</beginfold id='2'>command.split<beginfold id='2'>(</beg
     case <beginfold id='5'>[</beginfold id='5'>"quit"<endfold id='5'>]</endfold id='5'>:
         print<beginfold id='2'>(</beginfold id='2'>"Goodbye!"<endfold id='2'>)</endfold id='2'>
 
+def func1<beginfold id='2'>(</beginfold id='2'><endfold id='2'>)</endfold id='2'>:
+    yield 1
+    yield  from <beginfold id='5'>[</beginfold id='5'>func<beginfold id='2'>(</beginfold id='2'><endfold id='2'>)</endfold id='2'>, 1, 2, "3"<endfold id='5'>]</endfold id='5'>
+    # invalid, "from" no longer part of "yield from"
+    yield, from 1
+
+async def func2<beginfold id='2'>(</beginfold id='2'><endfold id='2'>)</endfold id='2'>:
+    await asyncio.sleep<beginfold id='2'>(</beginfold id='2'>1<endfold id='2'>)</endfold id='2'>
+
 "\\\\\\\\\\ENSURE THAT THIS AND THE FOLLOWING LINES ARE AT THE <endfold id='6'>END</endfold id='6'> OF THE FILE\\\\\\\\\\ \
 "
 </indentfold>a = 'otherwise all succeeding lines will be
diff --git a/autotests/html/test.py.dark.html b/autotests/html/test.py.dark.html
index 23718b11..1d6c1dd2 100644
--- a/autotests/html/test.py.dark.html
+++ b/autotests/html/test.py.dark.html
@@ -124,6 +124,15 @@ match(command.split())
     <span style="color:#fdbc4b;font-weight:bold;">case</span> [<span style="color:#f44f4f;">&quot;quit&quot;</span>]:
         <span style="color:#7f8c8d;">print</span>(<span style="color:#f44f4f;">&quot;Goodbye!&quot;</span>)
 
+<span style="font-weight:bold;">def</span> func1():
+    <span style="color:#fdbc4b;font-weight:bold;">yield</span> <span style="color:#f67400;">1</span>
+    <span style="color:#fdbc4b;font-weight:bold;">yield</span>  <span style="color:#fdbc4b;font-weight:bold;">from</span> [func(), <span style="color:#f67400;">1</span>, <span style="color:#f67400;">2</span>, <span style="color:#f44f4f;">&quot;3&quot;</span>]
+    <span style="color:#7a7c7d;"># invalid, &quot;from&quot; no longer part of &quot;yield from&quot;</span>
+    <span style="color:#fdbc4b;font-weight:bold;">yield</span>, <span style="color:#27ae60;">from</span> <span style="color:#f67400;">1</span>
+
+<span style="color:#fdbc4b;font-weight:bold;">async</span> <span style="font-weight:bold;">def</span> func2():
+    <span style="color:#fdbc4b;font-weight:bold;">await</span> asyncio.sleep(<span style="color:#f67400;">1</span>)
+
 <span style="color:#7a7c7d;">&quot;</span><span style="color:#3daee9;">\\\\\\\\\\</span><span style="color:#7a7c7d;">ENSURE THAT THIS AND THE FOLLOWING LINES ARE AT THE </span><span style="color:#2980b9;background-color:#153042;">END</span><span style="color:#7a7c7d;"> OF THE FILE</span><span style="color:#3daee9;">\\\\\\\\\\</span><span style="color:#7a7c7d;"> </span><span style="color:#3daee9;">\</span>
 <span style="color:#7a7c7d;">&quot;</span>
 a <span style="color:#3f8058;">=</span> <span style="color:#f44f4f;">'otherwise all succeeding lines will be</span>
diff --git a/autotests/html/test.py.html b/autotests/html/test.py.html
index 55cfefb0..4d7a2709 100644
--- a/autotests/html/test.py.html
+++ b/autotests/html/test.py.html
@@ -124,6 +124,15 @@ match(command.split())
     <span style="font-weight:bold;">case</span> [<span style="color:#bf0303;">&quot;quit&quot;</span>]:
         <span style="color:#644a9b;font-weight:bold;">print</span>(<span style="color:#bf0303;">&quot;Goodbye!&quot;</span>)
 
+<span style="font-weight:bold;">def</span> func1():
+    <span style="font-weight:bold;">yield</span> <span style="color:#b08000;">1</span>
+    <span style="font-weight:bold;">yield</span>  <span style="font-weight:bold;">from</span> [func(), <span style="color:#b08000;">1</span>, <span style="color:#b08000;">2</span>, <span style="color:#bf0303;">&quot;3&quot;</span>]
+    <span style="color:#898887;"># invalid, &quot;from&quot; no longer part of &quot;yield from&quot;</span>
+    <span style="font-weight:bold;">yield</span>, <span style="color:#ff5500;">from</span> <span style="color:#b08000;">1</span>
+
+<span style="font-weight:bold;">async</span> <span style="font-weight:bold;">def</span> func2():
+    <span style="font-weight:bold;">await</span> asyncio.sleep(<span style="color:#b08000;">1</span>)
+
 <span style="color:#898887;">&quot;</span><span style="color:#924c9d;">\\\\\\\\\\</span><span style="color:#898887;">ENSURE THAT THIS AND THE FOLLOWING LINES ARE AT THE </span><span style="color:#0057ae;background-color:#e0e9f8;">END</span><span style="color:#898887;"> OF THE FILE</span><span style="color:#924c9d;">\\\\\\\\\\</span><span style="color:#898887;"> </span><span style="color:#924c9d;">\</span>
 <span style="color:#898887;">&quot;</span>
 a <span style="color:#ca60ca;">=</span> <span style="color:#bf0303;">'otherwise all succeeding lines will be</span>
diff --git a/autotests/input/test.py b/autotests/input/test.py
index 3eb8378d..d91db578 100644
--- a/autotests/input/test.py
+++ b/autotests/input/test.py
@@ -118,6 +118,15 @@ match(command.split()):
     case ["quit"]:
         print("Goodbye!")
 
+def func1():
+    yield 1
+    yield  from [func(), 1, 2, "3"]
+    # invalid, "from" no longer part of "yield from"
+    yield, from 1
+
+async def func2():
+    await asyncio.sleep(1)
+
 "\\\\\\\\\\ENSURE THAT THIS AND THE FOLLOWING LINES ARE AT THE END OF THE FILE\\\\\\\\\\ \
 "
 a = 'otherwise all succeeding lines will be
diff --git a/autotests/reference/test.py.ref b/autotests/reference/test.py.ref
index 9c5bdb54..1742da2b 100644
--- a/autotests/reference/test.py.ref
+++ b/autotests/reference/test.py.ref
@@ -118,6 +118,15 @@
 <Normal Text>    </Normal Text><Flow Control Keyword>case</Flow Control Keyword><Normal Text> [</Normal Text><String>"quit"</String><Normal Text>]:</Normal Text><br/>
 <Normal Text>        </Normal Text><Builtin Function>print</Builtin Function><Normal Text>(</Normal Text><String>"Goodbye!"</String><Normal Text>)</Normal Text><br/>
 <Normal Text></Normal Text><br/>
+<Definition Keyword>def</Definition Keyword><Normal Text> func1():</Normal Text><br/>
+<Normal Text>    </Normal Text><Flow Control Keyword>yield</Flow Control Keyword><Normal Text> </Normal Text><Int>1</Int><br/>
+<Normal Text>    </Normal Text><Flow Control Keyword>yield</Flow Control Keyword><Normal Text>  </Normal Text><Flow Control Keyword>from</Flow Control Keyword><Normal Text> [func(), </Normal Text><Int>1</Int><Normal Text>, </Normal Text><Int>2</Int><Normal Text>, </Normal Text><String>"3"</String><Normal Text>]</Normal Text><br/>
+<Normal Text>    </Normal Text><Comment># invalid, "from" no longer part of "yield from"</Comment><br/>
+<Normal Text>    </Normal Text><Flow Control Keyword>yield</Flow Control Keyword><Normal Text>, </Normal Text><Import>from</Import><Normal Text> </Normal Text><Int>1</Int><br/>
+<Normal Text></Normal Text><br/>
+<Flow Control Keyword>async</Flow Control Keyword><Normal Text> </Normal Text><Definition Keyword>def</Definition Keyword><Normal Text> func2():</Normal Text><br/>
+<Normal Text>    </Normal Text><Flow Control Keyword>await</Flow Control Keyword><Normal Text> asyncio.sleep(</Normal Text><Int>1</Int><Normal Text>)</Normal Text><br/>
+<Normal Text></Normal Text><br/>
 <Comment>"</Comment><String Char>\\\\\\\\\\</String Char><Comment>ENSURE THAT THIS AND THE FOLLOWING LINES ARE AT THE </Comment><Region Marker>END</Region Marker><Comment> OF THE FILE</Comment><String Char>\\\\\\\\\\</String Char><Comment> </Comment><String Char>\</String Char><br/>
 <Comment>"</Comment><br/>
 <Normal Text>a </Normal Text><Operator>=</Operator><Normal Text> </Normal Text><String>'otherwise all succeeding lines will be</String><br/>
diff --git a/data/syntax/python.xml b/data/syntax/python.xml
index 7143bf30..676872f0 100644
--- a/data/syntax/python.xml
+++ b/data/syntax/python.xml
@@ -52,7 +52,7 @@
 <!-- v2.07 add support for %prog and co, see bug 142832 -->
 <!-- v2.08 add missing overloaders, new Python 3 statements, builtins, and keywords -->
 <!-- v2.29 recognize escape sequenzes correctly -->
-<language name="Python" version="21" style="python" indenter="python" kateversion="5.0" section="Scripts" extensions="*.py;*.pyw;SConstruct;SConscript;*.FCMacro" mimetype="application/x-python;text/x-python;text/x-python3" casesensitive="1" author="Michael Bueker" license="">
+<language name="Python" version="22" style="python" indenter="python" kateversion="5.0" section="Scripts" extensions="*.py;*.pyw;SConstruct;SConscript;*.FCMacro" mimetype="application/x-python;text/x-python;text/x-python3" casesensitive="1" author="Michael Bueker" license="">
 	<highlighting>
 		<list name="import">
 			<item>import</item>
@@ -90,10 +90,17 @@
 			<item>try</item>
 			<item>while</item>
 			<item>with</item>
-			<item>yield</item>
 			<item>async</item>
 			<item>await</item>
 		</list>
+		<list name="flow_yield">
+			<item>yield</item>
+			<!--
+				"yield from" added here as a keyword for autocompletion. The actual handling
+				is in context="yield" so that we won't need to add space as a weakDeliminator.
+			-->
+			<item>yield from</item>
+		</list>
 		<list name="patternmatching">
 			<item>match</item>
 			<item>case</item>
@@ -380,6 +387,7 @@
 				<keyword attribute="Definition Keyword" String="defs" context="#stay"/>
 				<keyword attribute="Operator Keyword" String="operators" context="#stay"/>
 				<keyword attribute="Flow Control Keyword" String="flow" context="#stay"/>
+				<keyword attribute="Flow Control Keyword" String="flow_yield" context="yield"/>
 				<keyword attribute="Flow Control Keyword" String="patternmatching" context="Pattern Matching" lookAhead="1" firstNonSpace="1"/>
 				<keyword attribute="Builtin Function" String="builtinfuncs" context="#stay"/>
 				<keyword attribute="Special Variable" String="specialvars" context="#stay"/>
@@ -428,6 +436,11 @@
 				<RegExpr attribute="Error" String="[\w\d]+" context="#pop#pop"/>
 			</context>
 
+			<context name="yield" attribute="Flow Control Keyword" lineEndContext="#pop" fallthrough="1" fallthroughContext="#pop">
+				<DetectSpaces attribute="Normal Text" context="#stay"/>
+				<WordDetect attribute="Flow Control Keyword" context="#pop" String="from"/>
+			</context>
+
 			<context name="Pattern Matching" attribute="Flow Control Keyword" lineEndContext="#pop">
 				<!--
 					Python 3.10: https://docs.python.org/3.10/reference/compound_stmts.html#the-match-statement
-- 
GitLab