Find the line numbers of non-continuation lines. As quickly as humanly possible , find the line numbers (0- based) of the non-continuation lines. Creates self.{goodlines, continuation}.
(self)
| 195 | self.code = self.code[lo:] |
| 196 | |
| 197 | def _study1(self): |
| 198 | """Find the line numbers of non-continuation lines. |
| 199 | |
| 200 | As quickly as humanly possible <wink>, find the line numbers (0- |
| 201 | based) of the non-continuation lines. |
| 202 | Creates self.{goodlines, continuation}. |
| 203 | """ |
| 204 | if self.study_level >= 1: |
| 205 | return |
| 206 | self.study_level = 1 |
| 207 | |
| 208 | # Map all uninteresting characters to "x", all open brackets |
| 209 | # to "(", all close brackets to ")", then collapse runs of |
| 210 | # uninteresting characters. This can cut the number of chars |
| 211 | # by a factor of 10-40, and so greatly speed the following loop. |
| 212 | code = self.code |
| 213 | code = code.translate(trans) |
| 214 | code = code.replace('xxxxxxxx', 'x') |
| 215 | code = code.replace('xxxx', 'x') |
| 216 | code = code.replace('xx', 'x') |
| 217 | code = code.replace('xx', 'x') |
| 218 | code = code.replace('\nx', '\n') |
| 219 | # Replacing x\n with \n would be incorrect because |
| 220 | # x may be preceded by a backslash. |
| 221 | |
| 222 | # March over the squashed version of the program, accumulating |
| 223 | # the line numbers of non-continued stmts, and determining |
| 224 | # whether & why the last stmt is a continuation. |
| 225 | continuation = C_NONE |
| 226 | level = lno = 0 # level is nesting level; lno is line number |
| 227 | self.goodlines = goodlines = [0] |
| 228 | push_good = goodlines.append |
| 229 | i, n = 0, len(code) |
| 230 | while i < n: |
| 231 | ch = code[i] |
| 232 | i = i+1 |
| 233 | |
| 234 | # cases are checked in decreasing order of frequency |
| 235 | if ch == 'x': |
| 236 | continue |
| 237 | |
| 238 | if ch == '\n': |
| 239 | lno = lno + 1 |
| 240 | if level == 0: |
| 241 | push_good(lno) |
| 242 | # else we're in an unclosed bracket structure |
| 243 | continue |
| 244 | |
| 245 | if ch == '(': |
| 246 | level = level + 1 |
| 247 | continue |
| 248 | |
| 249 | if ch == ')': |
| 250 | if level: |
| 251 | level = level - 1 |
| 252 | # else the program is invalid, but we can't complain |
| 253 | continue |
| 254 |
no test coverage detected