| 407 | p = _parser.SubPattern(s, [(BRANCH, (None, p))]) |
| 408 | self.scanner = _compiler.compile(p) |
| 409 | def scan(self, string): |
| 410 | result = [] |
| 411 | append = result.append |
| 412 | match = self.scanner.scanner(string).match |
| 413 | i = 0 |
| 414 | while True: |
| 415 | m = match() |
| 416 | if not m: |
| 417 | break |
| 418 | j = m.end() |
| 419 | if i == j: |
| 420 | break |
| 421 | action = self.lexicon[m.lastindex-1][1] |
| 422 | if callable(action): |
| 423 | self.match = m |
| 424 | action = action(self, m.group()) |
| 425 | if action is not None: |
| 426 | append(action) |
| 427 | i = j |
| 428 | return result, string[i:] |