Highlight arguments in a string.
(text: str, tokens: list[tuple[str, str]])
| 227 | arg_pattern = re.compile(r'(\s+)|(--?[^\s\'"]+)|("[^"]*"?|\'[^\']*\'?)|([^\s\'"]+)') |
| 228 | |
| 229 | def highlight_args(text: str, tokens: list[tuple[str, str]]) -> None: |
| 230 | """Highlight arguments in a string.""" |
| 231 | for m in arg_pattern.finditer(text): |
| 232 | space, flag, quoted, word = m.groups() |
| 233 | match_text = m.group(0) |
| 234 | |
| 235 | if space: |
| 236 | tokens.append(("", match_text)) |
| 237 | elif flag: |
| 238 | tokens.append((self.flag_color, match_text)) |
| 239 | elif (quoted or word) and match_text not in exclude_tokens: |
| 240 | tokens.append((self.argument_color, match_text)) |
| 241 | else: |
| 242 | tokens.append(("", match_text)) |
| 243 | |
| 244 | def get_line(lineno: int) -> list[tuple[str, str]]: |
| 245 | """Return the tokens for the given line number.""" |