Commit a1d84ae
Syntax-highlight
The REPL highlights soft keywords only in contexts recognized by `is_soft_keyword_used()` in Lib/_pyrepl/utils.py, which knew about `match`, `case`, `type`, and `lazy` but not `perchance`. Add patterns for both forms: the expression form highlights when the previous token can end an expression (name, number, string, closing bracket, `...`, or a constant keyword) and the next token can start one, via a new `_starts_expression()` helper; the statement form highlights at line start. Identifier uses (`perchance = 5`, `f(perchance=3)`, `perchance.method()`) stay uncolored, and in `x = perchance perchance 0` only the second occurrence — the operator — is highlighted.
Also relax the `bracket_level == 0` gate for `perchance` alone: the other soft keywords can only start statements and thus cannot legally appear inside brackets, but the perchance expression form is most at home there, e.g. `[int(v) perchance None for v in vs]`.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>perchance in the new REPL1 parent eeeb42c commit a1d84ae
1 file changed
Lines changed: 41 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
| |||
247 | 250 | | |
248 | 251 | | |
249 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
250 | 265 | | |
251 | 266 | | |
252 | 267 | | |
| |||
299 | 314 | | |
300 | 315 | | |
301 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
302 | 342 | | |
303 | 343 | | |
304 | 344 | | |
| |||
0 commit comments