filetype: python

detect:
    filename: "\\.py(3)?$"
    header: "^#!.*/(env +)?python(3)?$"

rules:
    # built-in objects
    - constant: "\\b(Ellipsis|None|self|cls|True|False)\\b"
      # built-in attributes
    - constant: "\\b(__bases__|__builtin__|__class__|__debug__|__dict__|__doc__|__file__|__members__|__methods__|__name__|__self__)\\b"
      # built-in functions
    - identifier: "\\b(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dir|divmod|eval|exec|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|max|min|next|nonlocal|oct|open|ord|pow|print|repr|round|setattr|sorted|sum|vars|__import__)\\b"
      # special method names
    - identifier: "\\b__(abs|add|and|call|cmp|coerce|complex|concat|contains|delattr|delitem|delslice|del|dict|divmod|div|float|getattr|getitem|getslice|hash|hex|iadd|iand|iconcat|ifloordiv|ilshift|imatmul|imod|imul|init|int|invert|inv|ior|ipow|irshift|isub|iter|itruediv|ixor|len|long|lshift|mod|mul|neg|next|nonzero|oct|or|pos|pow|radd|rand|rcmp|rdivmod|rdiv|repeat|repr|rlshift|rmod|rmul|ror|rpow|rrshift|rshift|rsub|rxor|setattr|setitem|setslice|str|sub|xor)__\\b"
      # types
    - type: "\\b(bool|bytearray|bytes|classmethod|complex|dict|enumerate|filter|float|frozenset|int|list|map|memoryview|object|property|range|reversed|set|slice|staticmethod|str|super|tuple|type|zip)\\b"
      # definitions
    - identifier: "def [a-zA-Z_0-9]+"
      # keywords
    - statement: "\\b(and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|raise|return|try|while|with|yield)\\b"
      # decorators
    - brightgreen: "@.*[(]"
      # operators
    - symbol.operator: "([~^.:;,+*|=!\\%@]|<|>|/|-|&)"
      # parentheses
    - symbol.brackets: "([(){}]|\\[|\\])"
      # numbers
    - constant.number: "\\b[0-9](_?[0-9])*(\\.([0-9](_?[0-9])*)?)?(e[0-9](_?[0-9])*)?\\b" # decimal
    - constant.number: "\\b0b(_?[01])+\\b"     # bin
    - constant.number: "\\b0o(_?[0-7])+\\b"    # oct
    - constant.number: "\\b0x(_?[0-9a-fA-F])+\\b" # hex

    - constant.string:
        start: "\"\"\""
        end: "\"\"\""
        rules: []

    - constant.string:
        start: "'''"
        end: "'''"
        rules: []

    - constant.string:
        start: "\""
        end: "(\"|$)"
        skip: "\\\\."
        rules:
            - constant.specialChar: "\\\\."

    - constant.string:
        start: "'"
        end: "('|$)"
        skip: "\\\\."
        rules:
            - constant.specialChar: "\\\\."

    - comment:
        start: "#"
        end: "$"
        rules:  # AKA Code tags (PEP 350)
            - todo: "(TODO|FIXME|HACK|BUG|NOTE|FAQ|MNEMONIC|REQ|RFE|IDEA|PORT|\\?\\?\\?|!!!|GLOSS|SEE|TODOC|STAT|RVD|CRED):?"
