Fetch tokens until specified token appeared. .. note:: This also handles parenthesis well.
(self, condition: Any)
| 167 | return self.current |
| 168 | |
| 169 | def fetch_until(self, condition: Any) -> list[Token]: |
| 170 | """Fetch tokens until specified token appeared. |
| 171 | |
| 172 | .. note:: This also handles parenthesis well. |
| 173 | """ |
| 174 | tokens = [] |
| 175 | while current := self.fetch_token(): |
| 176 | tokens.append(current) |
| 177 | if current == condition: |
| 178 | break |
| 179 | if current == [OP, '(']: |
| 180 | tokens += self.fetch_until([OP, ')']) |
| 181 | elif current == [OP, '{']: |
| 182 | tokens += self.fetch_until([OP, '}']) |
| 183 | elif current == [OP, '[']: |
| 184 | tokens += self.fetch_until([OP, ']']) |
| 185 | |
| 186 | return tokens |
| 187 | |
| 188 | |
| 189 | class AfterCommentParser(TokenProcessor): |
no test coverage detected