lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

syntax_test_python.py (52057B)


      1 # SYNTAX TEST "Packages/Python/Python.sublime-syntax"
      2 # <- source.python comment.line.number-sign punctuation.definition.comment
      3 
      4 r"""This is a syntax test file.
      5 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation
      6 #^^^ punctuation.definition.comment.begin
      7 # <- storage.type.string
      8 
      9 And this right here, where we're writing in, is a docstring.
     10 """
     11 
     12 ur"""Raw docstring \"""
     13 # <- storage.type.string.python
     14 # ^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.python
     15 #                   ^^^ punctuation.definition.comment.end.python
     16 
     17 """Normal docstring \""""
     18 # ^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.python
     19 #                   ^^ constant.character.escape.python
     20 #                     ^^^ punctuation.definition.comment.end.python
     21 
     22 debug = False
     23 """
     24 This is a variable docstring, as supported by sphinx and epydoc
     25 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation
     26 """
     27 
     28 
     29 ##################
     30 # Imports
     31 ##################
     32 
     33 import sys # comment
     34 #^^^^^ keyword.control.import
     35 #          ^ comment
     36 from os import path, chdir # comment
     37 #^^^ keyword.control.import.from
     38 #       ^^^^^^ keyword.control.import
     39 #                  ^ punctuation.separator.import-list
     40 #                          ^ comment
     41 from . import module
     42 #    ^ keyword.control.import.relative.python
     43 #      ^^^^^^ keyword.control.import
     44 from .import module  # yes, this is actually legit
     45 #    ^ keyword.control.import.relative.python
     46 #     ^^^^^^ keyword.control.import.python
     47 from collections.abc import Iterable
     48 #                    ^^^^^^ keyword.control.import
     49 from a.b.c.else import module
     50 #          ^^^^ invalid.illegal.name.python
     51 #               ^^^^^^ keyword.control.import
     52 from .while import module
     53 #     ^^^^^ invalid.illegal.name.python
     54 #           ^^^^^^ keyword.control.import
     55 from .index import module
     56 #     ^^^^^ - invalid
     57 from \
     58     os \
     59     import \
     60     path
     61 #   ^^^^ meta.statement.import
     62 from sys import (version, # comment
     63 #^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.import
     64 #               ^ punctuation.section.import-list.begin
     65 #                         ^ comment
     66                  version_info, . ) # comment
     67 #                ^^^^^^^^^^^^^ meta.statement.import
     68 #                              ^ invalid.illegal.name.import
     69 #                                ^ punctuation.section.import-list.end
     70 #                                  ^ comment
     71 import path from os
     72 #           ^^^^ invalid.illegal.name
     73 from .sub import *
     74 #                ^ constant.language.import-all.python
     75 import a as b
     76 #        ^^ keyword.control.import.as.python
     77 from a import b as c, d as e
     78 #               ^^ keyword.control.import.as.python
     79 #                       ^^ keyword.control.import.as.python
     80 from a import (b as c)
     81 #                ^^ keyword.control.import.as.python
     82 
     83 import re; re.compile(r'')
     84 #        ^^^^^^^^^^^^^^^^^ - meta.statement.import
     85 #        ^ punctuation.terminator.statement
     86 
     87 from unicode.__init__ . 123 import unicode as unicode
     88 #    ^^^^^^^^^^^^^^^^^^^^^^ meta.import-source.python meta.import-path.python
     89 #    ^^^^^^^ meta.import-name.python - support
     90 #           ^ punctuation.accessor.dot.python
     91 #            ^^^^^^^^ meta.import-name.python - support
     92 #                     ^^^^^ invalid.illegal.name.python
     93 #                                  ^^^^^^^ support.type.python
     94 #                                             ^^^^^^^ support.type.python
     95 
     96 import .str
     97 #      ^ invalid.illegal.unexpected-relative-import.python
     98 #       ^^^ support.type.python
     99 
    100 import str
    101 #      ^^^ support.type.python
    102 
    103 
    104 ##################
    105 # Identifiers
    106 ##################
    107 
    108 identifier
    109 #^^^^^^^^^ meta.qualified-name meta.generic-name
    110 
    111 class
    112 #^^^^ storage.type.class keyword.declaration.class.python
    113 def
    114 #^^ storage.type.function keyword.declaration.function.python
    115 
    116 # async and await are still recognized as valid identifiers unless in an "async" block
    117 async
    118 #^^^^ - invalid.illegal.name
    119 
    120 __all__
    121 #^^^^^^ meta.qualified-name support.variable.magic - meta.generic-name
    122 __file__
    123 #^^^^^^^ support.variable.magic
    124 __missing__
    125 #^^^^^^^^^^ support.function.magic
    126 __bool__ abc.__nonzero__
    127 #^^^^^^^ support.function.magic
    128 #            ^^^^^^^^^^^ support.function.magic
    129 
    130 TypeError module.TypeError
    131 #^^^^^^^^ support.type.exception
    132 #                ^^^^^^^^^ - support
    133 
    134 open.open.open
    135 #    ^^^^^^^^^ - support
    136 
    137 ... Ellipsis __debug__
    138 #^^ constant.language.python
    139 #   ^^^^^^^^ constant.language.python
    140 #            ^^^^^^^^^ constant.language.python
    141 
    142 CONSTANT._13_
    143 #^^^^^^^ meta.qualified-name.python variable.other.constant.python
    144 #        ^^^^ - variable.other.constant
    145 
    146  _A_B A1
    147 #^^^^ - variable.other.constant
    148 #     ^^ - variable.other.constant
    149 
    150 some.NO
    151 #    ^^ meta.qualified-name.python variable.other.constant.python
    152 
    153 NO_SWEAT NO AA1
    154 # <- meta.qualified-name.python variable.other.constant.python
    155 #        ^^ variable.other.constant
    156 #           ^^^ variable.other.constant
    157 
    158 _ self
    159 # <- variable.language.python
    160 # ^^^^ variable.language.python
    161 
    162 
    163 ##################
    164 # Function Calls
    165 ##################
    166 
    167 identifier()
    168 #^^^^^^^^^^^ meta.function-call
    169 #^^^^^^^^^ meta.qualified-name variable.function
    170 #         ^ punctuation.section.arguments.begin
    171 #          ^ punctuation.section.arguments.end
    172 
    173 IDENTIFIER()
    174 #^^^^^^^^^ meta.qualified-name variable.function - variable.other.constant
    175 
    176 dotted . identifier(12, True)
    177 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call - meta.function-call meta.function-call
    178 #                  ^^^^^^^^^^ meta.function-call.arguments
    179 #^^^^^^^^^^^^^^^^^^ meta.qualified-name
    180 #^^^^^^ - variable.function
    181 #      ^ punctuation.accessor.dot
    182 #        ^^^^^^^^^^ variable.function
    183 
    184 open.__new__(12, \
    185 #^^^^^^^^^^^^^^^^^^^^^ meta.function-call
    186 #^^^ support.function.builtin
    187 #   ^ punctuation.accessor.dot
    188 #    ^^^^^^^ variable.function support.function.magic
    189 #                ^ punctuation.separator.continuation.line.python
    190              True)
    191 
    192 TypeError()
    193 #^^^^^^^^ support.type.exception
    194 #
    195 module.TypeError()
    196 #^^^^^^^^^^^^^^^ meta.function-call
    197 #      ^^^^^^^^^ variable.function - support
    198 
    199 open.open.open()
    200 #^^^ support.function.builtin
    201 #   ^ punctuation.accessor.dot
    202 #    ^^^^^^^^^ - support
    203 #         ^^^^ variable.function
    204 
    205 call(2**10, *range(10), **dict(), * *{}, ***a)
    206 #     ^^ keyword.operator.arithmetic
    207 #           ^ keyword.operator.unpacking.sequence.python
    208 #                       ^^ keyword.operator.unpacking.mapping.python
    209 #                                 ^ keyword.operator.unpacking.sequence.python
    210 #                                   ^ - keyword.operator.unpacking
    211 #                                        ^^^ invalid.illegal.syntax.python
    212 
    213 if p.type not in ('NUMBER', 'INTEGER'):
    214 #             ^^ keyword.operator - meta.function-call invalid
    215 
    216 call(from='no', from_='yes')
    217 #^^^^^^^^^^^^^^ meta.function-call
    218 #    ^^^^ invalid.illegal.name
    219 #        ^ keyword.operator.assignment
    220 #         ^^^^ string
    221 
    222 ##################
    223 # Expressions
    224 ##################
    225 
    226 def _():
    227     yield from
    228 #   ^^^^^ keyword.control.flow.yield
    229 #         ^^^^ keyword.control.flow.yield-from
    230 
    231     yield fromsomething
    232 #         ^^^^ - keyword
    233 
    234     a if b else c
    235 #     ^^ keyword.control.conditional.if
    236 #          ^^^^ keyword.control.conditional.else
    237 
    238     c = lambda: pass
    239 #       ^^^^^^^^^^^^ meta.function.inline
    240 #       ^^^^^^ storage.type.function.inline keyword.declaration.function.inline.python
    241 #             ^ punctuation.section.function.begin
    242 #               ^^^^ invalid.illegal.name.python
    243 
    244     _(lambda x, y: 10)
    245 #     ^^^^^^^^^^^^^^^ meta.function.inline
    246 #     ^^^^^^ keyword.declaration.function.inline.python
    247 #           ^^^^^ meta.function.inline.parameters
    248 #            ^ variable.parameter
    249 #             ^ punctuation.separator.parameters
    250 #               ^ variable.parameter
    251 #                  ^^ constant.numeric
    252 
    253     lambda \
    254         a, \
    255         b=2: True
    256 #       ^^^^^^^^^ meta.function.inline
    257 #        ^ keyword.operator.assignment
    258 #          ^ punctuation.section.function.begin
    259 #           ^^^^^ meta.function.inline.body
    260 #            ^^^^ constant.language.python
    261 
    262     lambda as, in=2: 0
    263 #          ^^ invalid.illegal.name
    264 #              ^^ invalid.illegal.name
    265 
    266     lambda *a, **kwa, ab*, * *: (a, kwa)
    267 #          ^ keyword.operator.unpacking.sequence.python
    268 #           ^ variable.parameter.python
    269 #                ^^^ variable.parameter.python
    270 #              ^^ keyword.operator.unpacking.mapping.python
    271 #                       ^ invalid.illegal.expected-parameter.python
    272 #                            ^ invalid.illegal.expected-parameter.python
    273 
    274     lambda x
    275 #   ^^^^^^ storage.type.function.inline keyword.declaration.function.inline.python
    276 
    277     lambda (x, y): 0
    278 #   ^^^^^^^^^^^^^^^^ meta.function.inline
    279 #         ^^^^^^^^ meta.function.inline.parameters.python
    280 #                 ^^ meta.function.inline.body.python
    281 #          ^^^^^^ meta.group.python
    282 #          ^ punctuation.section.group.begin.python
    283 #           ^ variable.parameter.python
    284 #            ^ punctuation.separator.parameters.python
    285 #              ^ variable.parameter.python
    286 #               ^ punctuation.section.group.end.python
    287 #                ^ punctuation.section.function.begin.python
    288     lambda (
    289 #   ^^^^^^^^^ meta.function.inline.python
    290 #         ^^^ meta.function.inline.parameters.python
    291 #          ^^ meta.group.python
    292 #          ^ punctuation.section.group.begin.python
    293         x,
    294 #      ^^^^ meta.function.inline.parameters.python meta.group.python
    295 #       ^ variable.parameter.python
    296 #        ^ punctuation.separator.parameters.python
    297         y
    298 #      ^^^^ meta.function.inline.parameters.python meta.group.python
    299 #       ^ variable.parameter.python
    300     ):
    301 #^^^^ meta.function.inline.parameters.python meta.group.python
    302 #   ^ punctuation.section.group.end.python
    303 #    ^ punctuation.section.function.begin.python
    304         pass
    305 #       ^^^^ keyword.control.flow.pass.python
    306 
    307     ( 3 - 6 \
    308 #   ^^^^^^^^^ meta.group.python
    309 #   ^ punctuation.section.group.begin.python
    310 #     ^ constant.numeric.integer.decimal.python
    311 #       ^ keyword.operator.arithmetic.python
    312 #         ^ constant.numeric.integer.decimal.python
    313 #           ^ punctuation.separator.continuation.line.python
    314      )
    315 #^^^^^ meta.group.python
    316 
    317 ##################
    318 # Compound expressions
    319 ##################
    320 
    321 myobj.method().attribute
    322 #^^^^^^^^^^^^^ meta.function-call
    323 #    ^ punctuation.accessor.dot
    324 #     ^^^^^^ variable.function
    325 #             ^ punctuation.accessor.dot
    326 
    327 'foo'. upper()
    328 #    ^^^^^^^^^ meta.function-call
    329 #    ^ punctuation.accessor.dot
    330 #      ^^^^^ variable.function
    331 
    332 func()(1, 2)
    333 # <- meta.function-call
    334 #^^^^^^^^^^^ meta.function-call
    335 #^^^^^^^^^^^ - meta.function-call meta.function-call
    336 
    337 myobj[1](True)
    338 #^^^^^^^ meta.item-access
    339 #    ^ punctuation.section.brackets.begin - meta.item-access.arguments
    340 #     ^ meta.item-access.arguments
    341 #      ^ punctuation.section.brackets.end - meta.item-access.arguments
    342 #       ^^^^^^ meta.function-call
    343 
    344 myobj[1][2](0)
    345 #^^^^^^^^^^ meta.item-access
    346 #    ^ punctuation.section.brackets.begin - meta.item-access.arguments
    347 #     ^ meta.item-access.arguments
    348 #      ^ punctuation.section.brackets.end - meta.item-access.arguments
    349 #       ^ punctuation.section.brackets.begin - meta.item-access.arguments
    350 #        ^ meta.item-access.arguments
    351 #         ^ punctuation.section.brackets.end - meta.item-access.arguments
    352 #          ^^^ meta.function-call
    353 
    354 range(20)[10:2:-2]
    355 #           ^ punctuation.separator.slice
    356 #             ^ punctuation.separator.slice
    357 
    358 "string"[12]
    359 #       ^^^^ meta.item-access - meta.structure
    360 
    361 "string".upper()
    362 #       ^^^^^^^^ meta.function-call
    363 
    364 (i for i in range(10))[5]
    365 #                     ^^^ meta.item-access - meta.structure
    366 
    367 [1, 2, 3][2]
    368 #^^^^^^^^ meta.sequence
    369 #        ^^^ meta.item-access - meta.structure
    370 
    371 {True: False}.get(True)
    372 #            ^^^^^^^^^^ meta.function-call
    373 
    374 1[12]
    375 #^^^^ - meta.item-access
    376 
    377 
    378 ##################
    379 # print & exec
    380 ##################
    381 
    382 def _():
    383     print (file=None)
    384 #   ^^^^^ support.function.builtin - keyword
    385     print . __class__
    386 #   ^^^^^ support.function.builtin - keyword
    387     print "keyword"
    388 #   ^^^^^ keyword.other.print
    389     print __init__
    390 #   ^^^^^ keyword.other.print
    391 #
    392     exec 123
    393 #   ^^^^ keyword
    394     exec ("print('ok')")
    395 #   ^^^^ support.function.builtin - keyword
    396     callback(print , print
    397 #            ^^^^^ - keyword
    398 #                  ^ punctuation.separator.arguments
    399 #                    ^^^^^ - keyword
    400              , print)
    401 #              ^^^^^ - keyword
    402 
    403     some \
    404       print \
    405 #     ^^^^^ keyword.other.print
    406 
    407     func(
    408         print
    409 #       ^^^^^ support.function.builtin - keyword
    410     )
    411 
    412     print
    413 #   ^^^^^ keyword.other.print
    414 
    415 
    416 ##################
    417 # Block statements
    418 ##################
    419 def _():
    420     for
    421 #   ^^^ keyword.control.loop.for
    422     b = c in d
    423 #         ^^ keyword.operator.logical - keyword.control.loop.for.in
    424 
    425     for \
    426         a \
    427         in \
    428         b:
    429 #       ^^ meta.statement.loop.for
    430 #        ^ punctuation.section.block.loop.for.python
    431 
    432     async for i in myfunc():
    433 #   ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.loop.for
    434 #   ^^^^^ storage.modifier.async
    435 #         ^^^ keyword.control.loop.for
    436 #               ^^ keyword.control.loop.for.in
    437 #                          ^ punctuation.section.block.loop.for
    438         pass
    439 
    440     for i:
    441 #        ^ invalid.illegal.missing-in
    442 
    443     a for b in c:  # TODO make this invalid (for not at beginning of line)
    444 
    445 
    446     something as nothing:
    447 #             ^^ invalid.illegal.name
    448 
    449     with \
    450         open() \
    451         as \
    452         x:
    453 #       ^^ meta.statement.with
    454 
    455     with open(), open() as x, open() as y:
    456 #   ^^^^ keyword.control.flow.with
    457 #        ^^^^ support.function
    458 #              ^ punctuation.separator.with-resources
    459 #                       ^^ keyword.control.flow.with.as
    460 #                           ^ punctuation.separator.with-resources
    461 #                             ^^^^ support.function
    462 #                                    ^^ keyword.control.flow.with.as
    463 
    464     with captured() as (out, err):
    465 #   ^^^^ keyword.control.flow.with
    466 #        ^^^^^^^^ variable.function
    467 #                ^ punctuation.section.arguments.begin
    468 #                 ^ punctuation.section.arguments.end
    469 #                   ^^ keyword.control.flow.with.as
    470 #                      ^ punctuation.section.group.begin
    471 #                       ^^^ meta.generic-name
    472 #                          ^ punctuation.separator.tuple
    473 #                            ^^^ meta.generic-name
    474 #                               ^ punctuation.section.group.end
    475 #                                ^ punctuation.section.block.with
    476 
    477     with captured() \
    478     as (
    479 #      ^ punctuation.section.group.begin
    480         out,
    481 #       ^^^ meta.generic-name
    482 #          ^ punctuation.separator.tuple
    483         err
    484 #       ^^^ meta.generic-name
    485     ):
    486 #   ^ punctuation.section.group.end
    487 #    ^ punctuation.section.block.with
    488 
    489     with captured() as [out, err]:
    490 #   ^^^^ keyword.control.flow.with
    491 #        ^^^^^^^^ variable.function
    492 #                ^ punctuation.section.arguments.begin
    493 #                 ^ punctuation.section.arguments.end
    494 #                   ^^ keyword.control.flow.with.as
    495 #                      ^ punctuation.section.sequence.begin
    496 #                       ^^^ meta.generic-name
    497 #                          ^ punctuation.separator.sequence
    498 #                            ^^^ meta.generic-name
    499 #                               ^ punctuation.section.sequence.end
    500 #                                ^ punctuation.section.block.with
    501 
    502     with captured() \
    503     as [
    504 #      ^ punctuation.section.sequence.begin
    505         out,
    506 #       ^^^ meta.generic-name
    507 #          ^ punctuation.separator.sequence
    508         err
    509 #       ^^^ meta.generic-name
    510     ]:
    511 #   ^ punctuation.section.sequence.end
    512 #    ^ punctuation.section.block.with
    513 
    514     async with context_manager() as c:
    515 #   ^^^^^ storage.modifier.async
    516 #         ^^^^ keyword.control.flow.with
    517 #                                ^^ keyword.control.flow.with.as
    518 #                                    ^ punctuation.section.block.with
    519         await something()
    520 #       ^^^^^ keyword.other.await
    521 
    522     assert foo == bar
    523 #   ^^^^^^ keyword.control.flow.assert.python
    524 
    525     try:
    526 #   ^^^^ meta.statement.exception.try.python
    527 #   ^^^ keyword.control.exception.try.python
    528 #      ^ punctuation.section.block.exception.try.python
    529         raise
    530 #       ^^^^^ meta.statement.raise.python keyword.control.flow.raise.python
    531     except Exception as x:
    532 #   ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.exception.catch.python - meta.statement.exception.catch.python meta.statement.exception.catch.python
    533 #   ^^^^^^ keyword.control.exception.catch.python
    534 #          ^^^^^^^^^ support.type.exception.python
    535 #                    ^^ keyword.control.exception.catch.as.python
    536 #                       ^ meta.generic-name.python
    537 #                        ^ punctuation.section.block.exception.catch.python
    538         pass
    539     finally :
    540 #   ^^^^^^^^^ meta.statement.exception.finally.python
    541 #   ^^^^^^^ keyword.control.exception.finally.python
    542 #           ^ punctuation.section.block.exception.finally.python
    543     try_except_raise:
    544 #   ^^^ - keyword
    545 
    546     while (
    547 #   ^^^^^^^^ meta.statement.loop.while.python
    548 #   ^^^^^ keyword.control.loop.while.python
    549 #         ^ meta.statement.loop.while.python meta.group.python punctuation.section.group.begin.python
    550         a is b
    551 #       ^^^^^^ meta.statement.loop.while.python
    552 #         ^^ keyword.operator.logical.python
    553     ):
    554 #    ^ meta.statement.loop.while.python punctuation.section.block.loop.while.python
    555         sleep()
    556         if a:
    557             break
    558 #           ^^^^^ keyword.control.flow.break.python
    559         elif b:
    560             continue
    561 #           ^^^^^^^^ keyword.control.flow.continue.python
    562 
    563     if 213 is 231:
    564 #   ^^^^^^^^^^^^^^ meta.statement.conditional.if.python
    565 #   ^^ keyword.control.conditional.if.python
    566 #      ^^^ constant.numeric.integer.decimal.python
    567 #          ^^ keyword.operator.logical.python
    568 #                ^ punctuation.section.block.conditional.if.python
    569         pass
    570     elif:
    571 #   ^^^^^ meta.statement.conditional.elseif.python
    572 #       ^ punctuation.section.block.conditional.elseif.python
    573         pass
    574     elif False :
    575 #   ^^^^^^^^^^^^ meta.statement.conditional.elseif.python
    576 #        ^^^^^ constant.language
    577 #              ^ punctuation.section.block.conditional.elseif.python
    578         pass
    579     else  :
    580 #   ^^^^^^^ meta.statement.conditional.else.python
    581 #         ^ punctuation.section.block.conditional.else.python
    582         pass
    583 
    584     if \
    585         True:
    586 #       ^^^^^ meta.statement.conditional.if.python
    587 #       ^^^^ constant.language.python
    588 #           ^ punctuation.section.block.conditional.if.python
    589 #
    590 
    591     # verify that keywords also work when they are bare (useful when typing)
    592     for
    593 #   ^^^ keyword.control.loop.for.python
    594     with
    595 #   ^^^^ keyword.control.flow.with.python
    596     if
    597 #   ^^ keyword.control.conditional.if.python
    598     finally
    599 #   ^^^^^^^ keyword.control.exception.finally.python
    600     else
    601 #   ^^^^ keyword.control.conditional.else.python
    602     while
    603 #   ^^^^^ keyword.control.loop.while.python
    604     return
    605 #   ^^^^^^ keyword.control.flow.return.python
    606     raise
    607 #   ^^^^^ keyword.control.flow.raise.python
    608 
    609 
    610 ##################
    611 # Function definitions
    612 ##################
    613 
    614 def abc():
    615     global from, for, variable, .
    616 #   ^^^^^^ storage.modifier.global
    617 #          ^^^^ invalid.illegal.name
    618 #                ^^^ invalid.illegal.name
    619 #                               ^ invalid.illegal.name.storage
    620 
    621 
    622 def my_func(param1, # Multi-line function definition
    623 #                 ^ punctuation.separator.parameters
    624 #                   ^ comment.line.number-sign
    625     # This is defaulted
    626 #   ^ comment.line.number-sign
    627     param2='#1' \
    628 #               ^ punctuation.separator.continuation.line.python
    629 ):
    630 # <- punctuation.section.parameters.end
    631     print('Hi!')
    632 
    633 
    634 def func(from='me'):
    635 #        ^^^^ invalid.illegal.name
    636     pass
    637 
    638 def type_annotations(param1: int, param2: MyType, param3: max(2, 3), param4: "string" = "default") -> int:
    639 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function
    640 #                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters
    641 #                                                                                                  ^^^^^^ meta.function.annotation.return
    642 #                   ^ - meta.function meta.function.parameters
    643 #                    ^^^^^^ variable.parameter
    644 #                          ^^^^^ meta.function.parameters.annotation
    645 #                          ^ punctuation.separator.annotation
    646 #                            ^^^ support.type
    647 #                               ^ punctuation.separator.parameters
    648 #                                 ^^^^^^ variable.parameter
    649 #                                       ^ punctuation.separator.annotation
    650 #                                               ^ punctuation.separator.parameters
    651 #                                                 ^^^^^^ variable.parameter
    652 #                                                       ^ punctuation.separator.annotation
    653 #                                                         ^^^^^^^^^ meta.function-call
    654 #                                                            ^ punctuation.section.arguments.begin
    655 #                                                             ^ constant.numeric
    656 #                                                                ^ constant.numeric
    657 #                                                                 ^ punctuation.section.arguments.end
    658 #                                                                  ^ punctuation.separator.parameters
    659 #                                                                    ^^^^^^ variable.parameter
    660 #                                                                          ^ punctuation.separator.annotation
    661 #                                                                            ^^^^^^^^ string.quoted.double
    662 #                                                                                     ^^^^^^^^^^^ meta.function.parameters.default-value
    663 #                                                                                     ^ keyword.operator.assignment
    664 #                                                                                       ^^^^^^^^^ string.quoted.double
    665 #                                                                                                ^ punctuation.section.parameters.end
    666 #                                                                                                  ^^ punctuation.separator.annotation
    667 #                                                                                                     ^^^ support.type
    668 #                                                                                                        ^ punctuation.section.function.begin
    669     pass
    670 
    671 
    672 async def coroutine(param1):
    673 #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function
    674 #                  ^^^^^^^^ meta.function.parameters - meta.function meta.function
    675 # <- storage.modifier.async
    676 #     ^ storage.type
    677 #         ^ entity.name.function
    678    pass
    679 
    680 def func(*args, other_arg=2**10, **kwargs):
    681 #        ^ keyword.operator.unpacking.sequence.python
    682 #                          ^^ keyword.operator.arithmetic.python
    683 #                                ^^ keyword.operator.unpacking.mapping.python
    684     pass
    685 
    686 def func(
    687     *args,
    688 #   ^ keyword.operator.unpacking.sequence
    689     other_arg=2**10,
    690 #              ^^ keyword.operator.arithmetic
    691     **kwargs
    692 #   ^^ keyword.operator.unpacking.mapping
    693 ):
    694     pass
    695 
    696 def func(args, (x, y)=(0,0)):
    697 #       ^^^^^^^^^^^^^ meta.function.parameters.python
    698 #                    ^^^^^^ meta.function.parameters.default-value.python
    699 #                          ^ meta.function.parameters.python
    700 #              ^^^^^^ meta.group.python
    701 #                    ^ - meta.group.python
    702 #                     ^^^^^ meta.sequence.tuple.python
    703 #                          ^ - meta.group.python
    704 #       ^ punctuation.section.parameters.begin.python
    705 #            ^ punctuation.separator.parameters.python
    706 #              ^ punctuation.section.group.begin.python
    707 #               ^ variable.parameter.python
    708 #                ^ punctuation.separator.parameters.python
    709 #                  ^ variable.parameter.python
    710 #                   ^ punctuation.section.group.end.python
    711 #                    ^ keyword.operator.assignment.python
    712 #                     ^ punctuation.section.sequence.begin.python
    713 #                      ^ constant.numeric.integer.decimal.python
    714 #                       ^ punctuation.separator.sequence.python
    715 #                        ^ constant.numeric.integer.decimal.python
    716 #                         ^ punctuation.section.sequence.end.python
    717 #                          ^ punctuation.section.parameters.end.python
    718     pass
    719 
    720 def foo(arg: int = 0, (x: float, y=20) = (0.0, "default")):
    721 #                     ^^^^^^^^^^^^^^^^ meta.group.python
    722 #                                     ^^^ - meta.group.python
    723 #                                        ^^^^^^^^^^^^^^^^ meta.sequence.tuple.python
    724 #                     ^ punctuation.section.group.begin.python
    725 #                      ^ variable.parameter.python
    726 #                       ^^^^^^^ invalid.illegal.annotation.python
    727 #                              ^ punctuation.separator.parameters.python
    728 #                                ^ variable.parameter.python
    729 #                                 ^^^ invalid.illegal.default-value.python
    730 #                                    ^ punctuation.section.group.end.python
    731 #                                      ^ keyword.operator.assignment.python
    732 #                                        ^ punctuation.section.sequence.begin.python
    733 #                                                       ^ punctuation.section.sequence.end.python
    734     pass
    735 
    736 def name(p1, p2=None, /, p_or_kw=None, *, kw): pass
    737 #                     ^ storage.modifier.positional-args-only.python
    738 #                      ^ punctuation.separator.parameters.python
    739 #                                      ^ keyword.operator.unpacking.sequence.python
    740 def name(p1, p2, /): pass
    741 #                ^ storage.modifier.positional-args-only.python
    742 #                 ^ punctuation.section.parameters.end.python
    743 
    744 
    745 ##################
    746 # Class definitions
    747 ##################
    748 
    749 class MyClass():
    750 #^^^^^^^^^^^^^^^ meta.class
    751 #            ^^ meta.class.inheritance
    752 #              ^ punctuation.section.class.begin
    753     def my_func(self, param1, # Multi-line function definition
    754 #                             ^ comment.line.number-sign
    755         # This is defaulted
    756 #       ^ comment.line.number-sign
    757         param2='#1'):
    758 #                  ^ punctuation.section.parameters.end
    759         print('Hi!')
    760 
    761 
    762 class UnicødeIdentifier():
    763 #     ^^^^^^^^^^^^^^^^^ entity.name.class
    764     def résumé():
    765 #       ^^^^^^ entity.name.function
    766         """
    767 #       ^^^ punctuation.definition.comment.begin
    768         A function-level docstring
    769 #       ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.python
    770         """
    771 #       ^^^ punctuation.definition.comment.end
    772 
    773         yield from range(100)
    774 #       ^^^^^ keyword.control.flow
    775 #            ^ - keyword
    776 #             ^^^^ keyword.control.flow
    777 
    778 
    779 class MyClass(Inherited, \
    780 #     ^^^^^^^ entity.name.class
    781 #             ^^^^^^^^^ entity.other.inherited-class
    782 #                      ^ punctuation.separator.inheritance
    783 #                        ^ punctuation.separator.continuation.line.python
    784               module . Inherited2, metaclass=ABCMeta):
    785 #             ^^^^^^^^^^^^^^^^^^^ entity.other.inherited-class
    786 #                    ^ punctuation.accessor.dot
    787 #                                ^ punctuation.separator.inheritance
    788 #                                  ^^^^^^^^^ variable.parameter.class-inheritance
    789 #                                           ^ keyword.operator.assignment
    790     ur'''
    791 #   ^^ storage.type.string
    792     This is a test of docstrings
    793     '''
    794 #   ^^^ comment.block.documentation.python
    795     pass
    796 
    797 
    798 class Unterminated(Inherited:
    799 #                           ^ invalid.illegal
    800 
    801 
    802 ##################
    803 # Decorators
    804 ##################
    805 
    806 @ normal . decorator
    807 # <- meta.annotation punctuation.definition.annotation
    808 #^^^^^^^^^^^^^^^^^^^ meta.annotation
    809 # ^^^^^^^^^^^^^^^^^^ meta.qualified-name
    810 # ^^^^^^ meta.generic-name - variable.annotation
    811 #          ^^^^^^^^^ variable.annotation
    812 #        ^ punctuation.accessor.dot - variable
    813 #                   ^ - meta.annotation
    814 class Class():
    815 
    816     @functools.wraps(method, 12, kwarg=None)# comment
    817 #^^^ - meta.annotation
    818 #   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation - meta.annotation meta.annotation
    819 #                    ^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.arguments
    820 #   ^ punctuation.definition.annotation
    821 #    ^^^^^^^^^^^^^^^^ meta.annotation.function
    822 #    ^^^^^^^^^^^^^^^ meta.qualified-name
    823 #    ^^^^^^^^^ meta.generic-name - variable.annotation
    824 #             ^ punctuation.accessor.dot
    825 #              ^^^^^ variable.annotation.function meta.generic-name
    826 #                   ^ punctuation.section.arguments.begin
    827 #                          ^ punctuation.separator.arguments
    828 #                            ^^ constant.numeric
    829 #                                ^^^^^ variable.parameter
    830 #                                     ^ keyword.operator
    831 #                                      ^^^^ constant.language
    832 #                              ^ punctuation.separator.arguments
    833 #                                          ^ meta.annotation.function punctuation.section.arguments.end
    834 #                                           ^^^^^^^^^ comment - meta.annotation
    835     def wrapper(self):
    836         return self.__class__(method)
    837 
    838     @deco #comment
    839 #^^^ - meta.annotation
    840 #   ^^^^^ meta.annotation
    841 #    ^^^^ meta.qualified-name variable.annotation
    842 #        ^^ - meta.annotation
    843 #         ^^^^^^^^ comment
    844 
    845     @staticmethod
    846 #   ^^^^^^^^^^^^^ meta.annotation
    847 #    ^^^^^^^^^^^^ variable.annotation support.function.builtin
    848 #                ^ - meta.annotation
    849 
    850     @not_a.staticmethod
    851 #   ^^^^^^^^^^^^^^^^^^^ meta.annotation
    852 #          ^^^^^^^^^^^^ variable.annotation - support
    853 #         ^ punctuation.accessor.dot
    854 
    855     @not_a.__init__()
    856 #   ^^^^^^^^^^^^^^^ meta.annotation
    857 #          ^^^^^^^^ variable.annotation support.function.magic
    858 #         ^ punctuation.accessor.dot
    859 
    860     @deco[4]
    861 #        ^ invalid.illegal.character
    862 
    863     @deco \
    864         . rator
    865 #       ^^^^^^^ meta.annotation
    866 #       ^ punctuation.accessor.dot
    867 
    868     @ deco \
    869         . rator()
    870 #       ^^^^^^^^^ meta.annotation.function
    871 #         ^^^^^ variable.annotation.function
    872 
    873     @ deco \
    874 #     ^^^^ meta.qualified-name meta.generic-name - variable.annotation
    875 #          ^ punctuation.separator.continuation.line
    876 
    877     @deco \
    878 
    879     def f(): pass
    880 #   ^^^ storage.type.function keyword.declaration.function.python - meta.decorator
    881 
    882 
    883 class AClass:
    884     # `def` immediately after a line-continued string within a class
    885     x =  "Type help() for interactive help, " \
    886          "or help(object) for help about object."
    887     def __call__(self, *args, **kwds):
    888 #   ^^^ - invalid.illegal
    889         pass
    890 
    891 
    892 ##################
    893 # Collection literals and generators
    894 ##################
    895 
    896 mytuple = ("this", 'is', 4, tuple)
    897 #         ^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.tuple.python
    898 #         ^ punctuation.section.sequence.begin
    899 #          ^^^^^^ string.quoted.double
    900 #                ^ punctuation.separator.sequence
    901 #                  ^^^^ string.quoted.single
    902 #                      ^ punctuation.separator.sequence
    903 #                        ^ constant.numeric
    904 #                         ^ punctuation.separator.sequence
    905 #                           ^^^^^ support.type
    906 #                                ^ punctuation.section.sequence.end
    907 
    908 also_a_tuple = ()[-1]
    909 #              ^^ meta.sequence.tuple.empty.python
    910 #                ^^^^ meta.item-access
    911 
    912 not_a_tuple = (a = 2, b += 3)
    913 #             ^^^^^^^^^^^^^^^ - meta.sequence
    914 #                ^ - keyword
    915 #                        ^ - keyword
    916 
    917 just_a_group = (1)
    918 #              ^^^ meta.group.python
    919 
    920 mylist = []
    921 #        ^^ meta.sequence.list.empty.python
    922 #        ^ punctuation.section.sequence.begin
    923 #         ^ punctuation.section.sequence.end
    924 
    925 mylist = [1, "testing", ["sublist", True]]
    926 #        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence
    927 #        ^ punctuation.section.sequence.begin
    928 #         ^ constant.numeric
    929 #          ^ punctuation.separator.sequence
    930 #            ^^^^^^^^^ string.quoted.double
    931 #                     ^ punctuation.separator
    932 #                       ^^^^^^^^^^^^^^^^^ meta.sequence meta.sequence
    933 #                       ^ punctuation.section.sequence.begin
    934 #                        ^^^^^^^^^ string.quoted.double
    935 #                                 ^ punctuation.separator.sequence
    936 #                                   ^^^^ constant.language
    937 #                                       ^ punctuation.section.sequence.end
    938 #                                        ^ punctuation.section.sequence.end
    939 
    940 mydict = {}
    941 #        ^^ meta.mapping.empty.python
    942 #        ^ punctuation.section.mapping.begin
    943 #         ^ punctuation.section.mapping.end
    944 
    945 key2 = "my_key"
    946 mydict = {"key": True, key2: (1, 2, [-1, -2]), ,}
    947 #        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping
    948 #        ^ punctuation.section.mapping.begin
    949 #         ^^^^^ meta.mapping.key.python string.quoted.double
    950 #              ^ punctuation.separator.mapping.key-value
    951 #                ^^^^ meta.mapping.value.python constant.language
    952 #                    ^ punctuation.separator.mapping
    953 #                      ^^^^ meta.mapping.key.python meta.qualified-name
    954 #                          ^ punctuation.separator.mapping
    955 #                            ^^^^^^^^^^^^^^^^ meta.sequence.tuple
    956 #                            ^ punctuation.section.sequence.begin
    957 #                             ^ constant.numeric
    958 #                                ^ constant.numeric
    959 #                                   ^^^^^^^^ meta.sequence.list
    960 #                                      ^ punctuation.separator.sequence
    961 #                                           ^ punctuation.section.sequence.end
    962 #                                            ^ punctuation.separator.mapping.python
    963 #                                              ^ invalid.illegal.expected-colon.python
    964 #                                               ^ punctuation.section.mapping.end - meta.mapping.key
    965 
    966 mydict = { 'a' : xform, 'b' : form, 'c' : frm }
    967 #                                 ^ meta.mapping.python punctuation.separator.mapping.python
    968 #                                       ^ punctuation.separator.mapping.key-value.python
    969 
    970 myset = {"key", True, key2, [-1], {}:1}
    971 #       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.set
    972 #       ^ punctuation.section.set.begin.python
    973 #        ^^^^^ string.quoted.double
    974 #             ^ punctuation.separator.set
    975 #               ^^^^ constant.language
    976 #                   ^ punctuation.separator.set
    977 #                         ^ punctuation.separator.set
    978 #                           ^^^^ meta.sequence
    979 #                             ^ constant.numeric
    980 #                               ^ punctuation.separator.set
    981 #                                 ^^ meta.mapping.empty.python
    982 #                                   ^ invalid.illegal.colon-inside-set.python
    983 #                                     ^ punctuation.section.set.end.python
    984 
    985 mapping_or_set = {
    986 #                ^ meta.mapping-or-set.python punctuation.section.mapping-or-set.begin.python
    987     1: True
    988 #   ^ meta.mapping.key.python constant.numeric.integer.decimal.python
    989 #    ^ punctuation.separator.mapping.key-value.python
    990 }
    991 # <- meta.mapping.python punctuation.section.mapping.end.python
    992 
    993 complex_mapping = {(): "value"}
    994 #                 ^^^ meta.mapping-or-set.python
    995 #                    ^^^^^^^^^^ meta.mapping - meta.mapping-or-set
    996 
    997 more_complex_mapping = {**{1: 1}, 2: 2}
    998 #                      ^ meta.mapping.python
    999 #                               ^ meta.mapping.python punctuation.separator.mapping.python
   1000 #                                  ^ meta.mapping.python punctuation.separator.mapping.key-value.python
   1001 
   1002 more_complex_set = {
   1003 #                  ^ meta.mapping-or-set.python
   1004     *{1}, 2: 2}
   1005 #   ^ meta.set.python
   1006 #       ^ meta.set.python punctuation.separator.set.python
   1007 #          ^ meta.set.python invalid.illegal.colon-inside-set.python
   1008 
   1009 generator = (i for i in range(100))
   1010 #           ^^^^^^^^^^^^^^^^^^^^^^^ meta.group
   1011 #              ^^^^^^^^ meta.expression.generator
   1012 #              ^^^ keyword.control.loop.for.generator
   1013 #                    ^^ keyword.control.loop.for.in
   1014 list_ = [i for i in range(100)]
   1015 #       ^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence
   1016 #          ^^^^^^^^ meta.expression.generator
   1017 #          ^^^ keyword.control.loop.for.generator
   1018 #                ^^ keyword.control.loop.for.in
   1019 set_ = {i for i in range(100)}
   1020 #      ^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping-or-set
   1021 #         ^^^^^^^^ meta.expression.generator
   1022 #         ^^^ keyword.control.loop.for.generator
   1023 #               ^^ keyword.control.loop.for.in
   1024 dict_ = {i: i for i in range(100)}
   1025 #       ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping
   1026 #        ^ meta.mapping.key.python
   1027 #         ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.mapping.key.python
   1028 #           ^ meta.mapping.value.python
   1029 #            ^^^^^^^^^^^^^^^^^^^^^ - meta.mapping.value
   1030 #             ^^^^^^^^ meta.expression.generator
   1031 #             ^^^ keyword.control.loop.for.generator
   1032 #                   ^^ keyword.control.loop.for.in
   1033 list_ = [i for i in range(100) if i > 0 else -1]
   1034 #       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence
   1035 #          ^^^^^^^^ meta.expression.generator
   1036 #                              ^^ keyword.control.conditional.if
   1037 #                                       ^^^^ keyword.control.conditional.else
   1038 
   1039 list2_ = [i in range(10) for i in range(100) if i in range(5, 15)]
   1040 #           ^^ keyword.operator.logical
   1041 #                              ^^ keyword.control.loop.for.in
   1042 #                                                 ^^ keyword.operator.logical
   1043 
   1044 generator = ((k1, k2, v) for ((k1, k2), v) in xs)
   1045 #           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.python
   1046 #            ^^^^^^^^^^^ meta.sequence.tuple.python
   1047 #           ^ punctuation.section.group.begin.python
   1048 #            ^ punctuation.section.sequence.begin.python
   1049 #                      ^ punctuation.section.sequence.end.python
   1050 #                            ^^ punctuation.section.target-list.begin.python
   1051 #                                    ^ punctuation.section.target-list.end.python
   1052 #                                        ^ punctuation.section.target-list.end.python
   1053 #                                               ^ punctuation.section.group.end.python
   1054 
   1055 list_ = [(k1, k2, v) for ((k1, k2), v) in xs]
   1056 #       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.list.python
   1057 #        ^^^^^^^^^^^ meta.sequence.tuple.python
   1058 #                   ^ - meta.sequence.tuple.python - meta.expression.generator.python
   1059 #       ^ punctuation.section.sequence.begin.python
   1060 #        ^ punctuation.section.sequence.begin.python
   1061 #                  ^ punctuation.section.sequence.end.python
   1062 #                        ^^ punctuation.section.target-list.begin.python
   1063 #                                ^ punctuation.section.target-list.end.python
   1064 #                                    ^ punctuation.section.target-list.end.python
   1065 #                                           ^ punctuation.section.sequence.end.python
   1066 
   1067 dict_ = {k1: (k2, v) for ((k1, k2), v) in xs}
   1068 #       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping
   1069 #       ^ punctuation.section.mapping.begin.python
   1070 #            ^^^^^^^ meta.sequence.tuple.python
   1071 #            ^ punctuation.section.sequence.begin.python
   1072 #                  ^ punctuation.section.sequence.end.python
   1073 #                        ^^ punctuation.section.target-list.begin.python
   1074 #                                ^ punctuation.section.target-list.end.python
   1075 #                                    ^ punctuation.section.target-list.end.python
   1076 #                                           ^ punctuation.section.mapping.end.python
   1077 
   1078 list(i for i in generator)
   1079 #      ^^^^^^^^ meta.expression.generator
   1080 list((i for i in generator), 123)
   1081 #       ^^^^^^^^ meta.expression.generator
   1082 #                         ^^^^^^^ - meta.expression.generator
   1083 #                          ^ punctuation.separator.arguments
   1084 
   1085 _ = [m
   1086      for cls in self.__class__.mro()
   1087 #    ^^^ keyword.control.loop.for.generator
   1088 #            ^^ keyword.control.loop.for.in
   1089      for m in cls.__dict__]
   1090 #    ^^^ keyword.control.loop.for.generator
   1091 #          ^^ keyword.control.loop.for.in
   1092 
   1093 result = [i async for i in aiter() if i % 2]
   1094 #           ^^^^^ storage.modifier.async
   1095 result = [await fun() for fun in funcs]
   1096 #         ^^^^^ keyword.other.await.python
   1097 
   1098 
   1099 t = (*tuple(), *[1, 2], 3*1)
   1100 #   ^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.tuple.python
   1101 #    ^ keyword.operator.arithmetic.python
   1102 #     ^^^^^ support.type.python
   1103 #              ^ keyword.operator.unpacking.sequence.python
   1104 #                        ^ keyword.operator.arithmetic.python
   1105 
   1106 l = [1 * 2, 2**10, *result]
   1107 #      ^ keyword.operator.arithmetic.python
   1108 #            ^^ keyword.operator.arithmetic.python
   1109 #                  ^ keyword.operator.unpacking.sequence.python
   1110 
   1111 l = [*l]
   1112 #    ^ keyword.operator.unpacking.sequence.python
   1113 
   1114 d = {1: 3**4, **dict_}
   1115 #        ^^ keyword.operator.arithmetic.python
   1116 #             ^^ keyword.operator.unpacking.mapping.python
   1117 
   1118 d = {**d, **dict()}
   1119 #   ^^^^^^^^^^^^^^^ meta.mapping.python
   1120 #    ^^^ - meta.mapping.key
   1121 #    ^^ keyword.operator.unpacking.mapping.python
   1122 #      ^ meta.qualified-name.python
   1123 #       ^ punctuation.separator.mapping.python
   1124 #         ^^^^^^^^ - meta.mapping.key
   1125 #         ^^ keyword.operator.unpacking.mapping.python
   1126 #           ^^^^ support.type.python
   1127 
   1128 s = {*d, *set()}
   1129 #   ^^^^^^^^^^^^ meta.set.python
   1130 #    ^ keyword.operator.unpacking.sequence.python
   1131 #     ^ meta.qualified-name.python
   1132 #      ^ punctuation.separator.set.python
   1133 #        ^ keyword.operator.unpacking.sequence.python
   1134 #         ^^^ support.type.python
   1135 
   1136 generator = (
   1137     i
   1138     for
   1139 #   ^^^ keyword.control.loop.for.generator
   1140     i
   1141     in
   1142 #   ^^ keyword.control.loop.for.in
   1143     range(100)
   1144 )
   1145 
   1146 
   1147 ##################
   1148 # Exception handling
   1149 ##################
   1150 
   1151 except Exception:
   1152 #^^^^^^^^^^^^^^^^ meta.statement.exception.catch
   1153 #^^^^^ keyword.control.exception.catch
   1154 #      ^^^^^^^^^ support.type.exception
   1155 #               ^ punctuation.section.block
   1156 except (KeyError, NameError) as e:
   1157 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.exception.catch
   1158 #^^^^^ keyword.control.exception.catch
   1159 #       ^^^^^^^^ support.type.exception
   1160 #               ^ punctuation.separator.target-list
   1161 #                 ^^^^^^^^^ support.type.exception
   1162 #                            ^^ keyword.control.exception.catch.as
   1163 #                                ^ punctuation.section.block
   1164 except \
   1165     StopIteration \
   1166     as \
   1167     err:
   1168 #   ^^^^ meta.statement.exception.catch
   1169 
   1170 except StopIteration
   1171     as
   1172 #   ^^ invalid.illegal.name - meta.statement.exception.catch
   1173 
   1174 except
   1175 #^^^^^ keyword.control.exception.catch
   1176 
   1177 raise
   1178 #^^^^ meta.statement.raise keyword.control.flow.raise
   1179 raise Ellipsis
   1180 #^^^^^^^^^^^^^ meta.statement.raise
   1181 #^^^^ keyword.control.flow.raise
   1182 #     ^^^^^^^^ constant.language
   1183 raise KeyError() from z
   1184 #^^^^^^^^^^^^^^^^^^^^^^ meta.statement.raise
   1185 #^^^^ keyword.control.flow.raise
   1186 #     ^^^^^^^^ support.type.exception
   1187 #                ^^^^ keyword.control.flow.raise.from
   1188 
   1189 
   1190 
   1191 ##################
   1192 # Stray braces
   1193 ##################
   1194 
   1195 )
   1196 # <- invalid.illegal.stray.brace.round
   1197 ]
   1198 # <- invalid.illegal.stray.brace.square
   1199 }
   1200 # <- invalid.illegal.stray.brace.curly
   1201 
   1202 
   1203 
   1204 ##################
   1205 # Integral numbers
   1206 ##################
   1207 
   1208 decimal = 1234567890 + 9876543210L + -1 + -42L * 0000
   1209 #         ^^^^^^^^^^ constant.numeric.integer.decimal.python
   1210 #                      ^^^^^^^^^^^ constant.numeric.integer.decimal.python
   1211 #                                ^ storage.type.numeric.python
   1212 #                                    ^ keyword.operator.arithmetic.python - constant.numeric
   1213 #                                         ^ keyword.operator.arithmetic.python - constant.numeric
   1214 #                                            ^ storage.type.numeric.python
   1215 #                                                ^^^^ constant.numeric.integer
   1216 
   1217 floating = 0.1 - .1 * 10e-20 - 0.0e2 % 2.
   1218 #          ^^^ constant.numeric.float.decimal.python
   1219 #                ^ punctuation.separator.decimal.python
   1220 #                ^^ constant.numeric.float.decimal.python
   1221 #                     ^^^^^^ constant.numeric.float.decimal.python
   1222 #                               ^ punctuation.separator.decimal.python
   1223 #                              ^^^^^ constant.numeric.float.decimal.python
   1224 #                                      ^^ constant.numeric.float.decimal.python
   1225 #                                       ^ punctuation.separator.decimal.python
   1226 
   1227 binary = 0b1010011 | 0b0110110L
   1228 #        ^^^^^^^^^ constant.numeric.integer.binary.python
   1229 #        ^^ punctuation.definition.numeric.base.python
   1230 #                    ^^^^^^^^^^ constant.numeric.integer.binary.python
   1231 #                    ^^ punctuation.definition.numeric.base.python
   1232 #                             ^ storage.type.numeric.python
   1233 
   1234 octal = 0o755 ^ 0o644L
   1235 #       ^^^^^ constant.numeric.integer.octal.python
   1236 #       ^^ punctuation.definition.numeric.base.python
   1237 #                    ^ storage.type.numeric.python
   1238 #               ^^^^^^ constant.numeric.integer.octal.python
   1239 #               ^^ punctuation.definition.numeric.base.python
   1240 
   1241 old_style_octal = 010 + 007 - 012345670L
   1242 #                 ^^^ constant.numeric.integer.octal.python
   1243 #                 ^ punctuation.definition.numeric.base.python
   1244 #                       ^^^ constant.numeric.integer.octal.python
   1245 #                       ^ punctuation.definition.numeric.base.python
   1246 #                             ^^^^^^^^^^ constant.numeric.integer.octal.python
   1247 #                             ^ punctuation.definition.numeric.base.python
   1248 #                                      ^ storage.type.numeric.python
   1249 
   1250 hexadecimal = 0x100af - 0XDEADF00L
   1251 #             ^^^^^^^ constant.numeric.integer.hexadecimal.python
   1252 #             ^^ punctuation.definition.numeric.base.python
   1253 #                       ^^^^^^^^^^ constant.numeric.integer.hexadecimal.python
   1254 #                       ^^ punctuation.definition.numeric.base.python
   1255 #                                ^ storage.type.numeric.python
   1256 
   1257 unintuitive = 0B101 + 0O101 + 10l
   1258 #             ^^^^^ constant.numeric.integer.binary.python
   1259 #             ^^ punctuation.definition.numeric.base.python
   1260 #                     ^^^^^ constant.numeric.integer.octal.python
   1261 #                     ^^ punctuation.definition.numeric.base.python
   1262 #                             ^^^ constant.numeric.integer.decimal.python
   1263 #                               ^ storage.type.numeric.python
   1264 
   1265 illegal = 1LL << 08 | 0b010203 | 0xAbraCadabra
   1266 #           ^ - constant.numeric
   1267 #                 ^ - constant.numeric
   1268 #                          ^^^ - constant.numeric
   1269 #                                    ^^^^^^^^^ - constant.numeric
   1270 
   1271 amount = 10_000_000.0_2e2_0 + .e2 + 2_2._2
   1272 #        ^^^^^^^^^^^^^^^^^^ constant.numeric.float.decimal.python
   1273 #                  ^ punctuation.separator.decimal.python
   1274 #                             ^^^ - constant
   1275 #                                       ^^ - constant
   1276 
   1277 very_complex = 23_2.2e2_0J + 2_1j
   1278 #              ^^^^^^^^^^^ constant.numeric.imaginary.decimal.python
   1279 #                  ^ punctuation.separator.decimal.python
   1280 #                            ^^^^ constant.numeric.imaginary.decimal.python
   1281 #                        ^ storage.type.numeric.python
   1282 #                               ^ storage.type.numeric.python
   1283 
   1284 addr = 0xCAFE_F00D
   1285 #      ^^^^^^^^^^^ constant.numeric
   1286 #      ^^ punctuation.definition.numeric.base.python
   1287 
   1288 flags = 0b_0011_1111_0100_1110 | 0b_1 & 0b_0_
   1289 #       ^^^^^^^^^^^^^^^^^^^^^^ constant.numeric
   1290 #       ^^ punctuation.definition.numeric.base.python
   1291 #                                ^^^^ constant.numeric.integer.binary.python
   1292 #                                           ^ - constant
   1293 
   1294 octoct = 0o_2 ^ 0o_
   1295 #        ^^^^ constant.numeric.integer.octal.python
   1296 #               ^^^ - constant
   1297 
   1298 ##################
   1299 # Operators
   1300 ##################
   1301 
   1302 # This is to test the difference between the assignment operator (=) and
   1303 # the comparison operator (==)
   1304 foo = bar()
   1305 #   ^ keyword.operator.assignment.python
   1306 foo == bar()
   1307 #   ^^ keyword.operator.comparison.python
   1308 #
   1309 foo <<= bar
   1310 #   ^^^ keyword.operator.assignment.augmented.python
   1311 
   1312 matrix @ multiplication
   1313 #      ^ keyword.operator.matrix.python
   1314 
   1315 a @= b
   1316 # ^^ keyword.operator.assignment.augmented.python
   1317 
   1318 
   1319 ##################
   1320 # Context "Fail Early"
   1321 ##################
   1322 
   1323 # Pop contexts gracefully
   1324 def func(unclosed, parameters: if else
   1325     pass
   1326 #   ^^^^ invalid.illegal.name
   1327 
   1328 # The following function should be matched as normal
   1329 # despite the above definition not being closed correctly
   1330 def another_func():
   1331 #^^ -invalid
   1332     pass
   1333 
   1334 
   1335 x = [
   1336 for x in y:
   1337     break
   1338 #   ^^^^^ invalid.illegal.name
   1339 #        ^ - meta.sequence
   1340 
   1341 
   1342 with open(x) as y:
   1343 #^^^ -invalid
   1344 #            ^^ - invalid
   1345 
   1346 ]
   1347 #<- invalid.illegal.stray.brace.square
   1348 
   1349 class Class(object
   1350     def __init__(self):
   1351 #   ^^^ invalid.illegal.name
   1352 #      ^ - meta.class
   1353 
   1354 # "Hang on, I'm still typing"
   1355 
   1356 foo.'bar'
   1357 # ^^^^^^^ - invalid
   1358 
   1359 foo.bar(baz., True)
   1360 #       ^^^^^ - invalid
   1361 
   1362 ##################
   1363 # Variable annotations
   1364 ##################
   1365 
   1366 primes: List[int] = []
   1367 #     ^ punctuation.separator.annotation.variable.python
   1368 #                 ^ keyword.operator.assignment
   1369 
   1370 captain: str  # Note: no initial value!
   1371 #      ^ punctuation.separator.annotation.variable.python
   1372 
   1373 class Starship:
   1374     stats: ClassVar[Dict[str, int]] = {}
   1375 #        ^ punctuation.separator.annotation.variable.python
   1376 #                                   ^ keyword.operator.assignment
   1377 
   1378 
   1379 ##################
   1380 # Assignment Expressions
   1381 ##################
   1382 
   1383 # Examples from https://www.python.org/dev/peps/pep-0572/
   1384 
   1385 y := f(x)
   1386 # ^^ invalid.illegal.not-allowed-here.python
   1387 
   1388 (y := f(x))
   1389 #  ^^ keyword.operator.assignment.inline.python
   1390 
   1391 y0 = y1 := f(x)
   1392 #       ^^ invalid.illegal.not-allowed-here.python
   1393 
   1394 y0 = (y1 := f(x))
   1395 #        ^^ keyword.operator.assignment.inline.python
   1396 
   1397 foo(x=(y := f(x)))
   1398 #        ^^ keyword.operator.assignment.inline.python
   1399 
   1400 if (match := pattern.search(data)) is not None:
   1401 #         ^^ keyword.operator.assignment.inline.python
   1402     pass
   1403 
   1404 if tz := self._tzstr():
   1405 #     ^^ keyword.operator.assignment.inline.python
   1406     s += tz
   1407 
   1408 while chunk := file.read(8192):
   1409 #           ^^ keyword.operator.assignment.inline.python
   1410     process(chunk)
   1411 
   1412 [y := f(x), y**2, y**3]
   1413 #  ^^ keyword.operator.assignment.inline.python
   1414 
   1415 filtered_data = [y for x in data if (y := f(x)) is not None]
   1416 #                                      ^^ keyword.operator.assignment.inline.python
   1417 
   1418 def foo(answer=(p := 42)):
   1419 #                 ^^ keyword.operator.assignment.inline.python
   1420 
   1421 lambda: (x := 1)
   1422 #          ^^ keyword.operator.assignment.inline.python
   1423 
   1424 lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid
   1425 #               ^^ keyword.operator.assignment.inline.python
   1426 
   1427 f'{(x:=10)}'
   1428 #    ^^ keyword.operator.assignment.inline.python
   1429 
   1430 f'{x:=10}'
   1431 #   ^^ - keyword.operator.assignment.inline.python
   1432 
   1433 
   1434 if any(len(longline := line) >= 100 for line in lines):
   1435 #                   ^^ keyword.operator.assignment.inline.python
   1436     print("Extremely long line:", longline)
   1437 
   1438 # These are all invalid. We could let linters handle them,
   1439 # but these weren't hard to implement.
   1440 def foo(x: y:=f(x)) -> a:=None: pass
   1441 #           ^^ invalid.illegal.not-allowed-here.python
   1442 #                       ^^ invalid.illegal.not-allowed-here.python
   1443 foo(x = y := f(x), y=x:=2)
   1444 #         ^^ invalid.illegal.not-allowed-here.python
   1445 #                     ^^ invalid.illegal.not-allowed-here.python
   1446 {a := 1: 2}
   1447 #  ^^ invalid.illegal.not-allowed-here.python
   1448 {1, b := 2}
   1449 #     ^^ invalid.illegal.not-allowed-here.python
   1450 [1][x:=0]
   1451 #    ^^ invalid.illegal.not-allowed-here.python
   1452 def foo(answer = p := 42):  pass
   1453 #                  ^^ invalid.illegal.not-allowed-here.python
   1454 (lambda: x := 1)
   1455 #          ^^ invalid.illegal.not-allowed-here.python
   1456 
   1457 
   1458 # <- - meta
   1459 # ensure we're not leaking a context