| 353 | p = _parser.SubPattern(s, [(BRANCH, (None, p))]) |
| 354 | self.scanner = _compiler.compile(p) |
| 355 | def scan(self, string): |
| 356 | result = [] |
| 357 | append = result.append |
| 358 | match = self.scanner.scanner(string).match |
| 359 | i = 0 |
| 360 | while True: |
| 361 | m = match() |
| 362 | if not m: |
| 363 | break |
| 364 | j = m.end() |
| 365 | if i == j: |
| 366 | break |
| 367 | action = self.lexicon[m.lastindex-1][1] |
| 368 | if callable(action): |
| 369 | self.match = m |
| 370 | action = action(self, m.group()) |
| 371 | if action is not None: |
| 372 | append(action) |
| 373 | i = j |
| 374 | return result, string[i:] |