(key: str, s: int)
| 116 | |
| 117 | |
| 118 | def _parse_single_key_sequence(key: str, s: int) -> tuple[list[str], int]: |
| 119 | ctrl = 0 |
| 120 | meta = 0 |
| 121 | ret = "" |
| 122 | while not ret and s < len(key): |
| 123 | if key[s] == "\\": |
| 124 | c = key[s + 1].lower() |
| 125 | if c in _escapes: |
| 126 | ret = _escapes[c] |
| 127 | s += 2 |
| 128 | elif c == "c": |
| 129 | if key[s + 2] != "-": |
| 130 | raise KeySpecError( |
| 131 | "\\C must be followed by `-' (char %d of %s)" |
| 132 | % (s + 2, repr(key)) |
| 133 | ) |
| 134 | if ctrl: |
| 135 | raise KeySpecError( |
| 136 | "doubled \\C- (char %d of %s)" % (s + 1, repr(key)) |
| 137 | ) |
| 138 | ctrl = 1 |
| 139 | s += 3 |
| 140 | elif c == "m": |
| 141 | if key[s + 2] != "-": |
| 142 | raise KeySpecError( |
| 143 | "\\M must be followed by `-' (char %d of %s)" |
| 144 | % (s + 2, repr(key)) |
| 145 | ) |
| 146 | if meta: |
| 147 | raise KeySpecError( |
| 148 | "doubled \\M- (char %d of %s)" % (s + 1, repr(key)) |
| 149 | ) |
| 150 | meta = 1 |
| 151 | s += 3 |
| 152 | elif c.isdigit(): |
| 153 | n = key[s + 1 : s + 4] |
| 154 | ret = chr(int(n, 8)) |
| 155 | s += 4 |
| 156 | elif c == "x": |
| 157 | n = key[s + 2 : s + 4] |
| 158 | ret = chr(int(n, 16)) |
| 159 | s += 4 |
| 160 | elif c == "<": |
| 161 | t = key.find(">", s) |
| 162 | if t == -1: |
| 163 | raise KeySpecError( |
| 164 | "unterminated \\< starting at char %d of %s" |
| 165 | % (s + 1, repr(key)) |
| 166 | ) |
| 167 | ret = key[s + 2 : t].lower() |
| 168 | if ret not in _keynames: |
| 169 | raise KeySpecError( |
| 170 | "unrecognised keyname `%s' at char %d of %s" |
| 171 | % (ret, s + 2, repr(key)) |
| 172 | ) |
| 173 | ret = _keynames[ret] |
| 174 | s = t + 1 |
| 175 | else: |
no test coverage detected
searching dependent graphs…