Replace any alternate token by its original counterpart. In order to comply with the google rule stating that unary operators should never be followed by a space, an exception is made for the 'not' and 'compl' alternate tokens. For these, any trailing space is removed during the con
(line)
| 2075 | |
| 2076 | |
| 2077 | def ReplaceAlternateTokens(line): |
| 2078 | """Replace any alternate token by its original counterpart. |
| 2079 | |
| 2080 | In order to comply with the google rule stating that unary operators should |
| 2081 | never be followed by a space, an exception is made for the 'not' and 'compl' |
| 2082 | alternate tokens. For these, any trailing space is removed during the |
| 2083 | conversion. |
| 2084 | |
| 2085 | Args: |
| 2086 | line: The line being processed. |
| 2087 | |
| 2088 | Returns: |
| 2089 | The line with alternate tokens replaced. |
| 2090 | """ |
| 2091 | for match in _ALT_TOKEN_REPLACEMENT_PATTERN.finditer(line): |
| 2092 | token = _ALT_TOKEN_REPLACEMENT[match.group(2)] |
| 2093 | tail = "" if match.group(2) in ["not", "compl"] and match.group(3) == " " else r"\3" |
| 2094 | line = re.sub(match.re, rf"\1{token}{tail}", line, count=1) |
| 2095 | return line |
| 2096 | |
| 2097 | |
| 2098 | class CleansedLines: |