| 453 | ) |
| 454 | |
| 455 | def _replaceTokenMatch(self, line, linenr, filename): |
| 456 | for func in ('Match', 'simpleMatch'): |
| 457 | is_simplematch = func == 'simpleMatch' |
| 458 | pattern_start = 0 |
| 459 | while True: |
| 460 | # skip comments |
| 461 | if line.strip().startswith('//'): |
| 462 | break |
| 463 | |
| 464 | pos1 = line.find('Token::' + func + '(', pattern_start) |
| 465 | if pos1 == -1: |
| 466 | break |
| 467 | |
| 468 | res = self.parseMatch(line, pos1) |
| 469 | if res is None: |
| 470 | break |
| 471 | |
| 472 | # assert that Token::Match has either 2 or 3 arguments |
| 473 | assert(len(res) == 3 or len(res) == 4) |
| 474 | |
| 475 | end_pos = len(res[0]) |
| 476 | tok = res[1] |
| 477 | raw_pattern = res[2] |
| 478 | varId = None |
| 479 | if len(res) == 4: |
| 480 | varId = res[3] |
| 481 | |
| 482 | pattern_start = pos1 + end_pos |
| 483 | res = re.match(r'\s*"((?:.|\\")*?)"\s*$', raw_pattern) |
| 484 | if res is None: |
| 485 | if self._showSkipped: |
| 486 | print(filename + ":" + str(linenr) + " skipping match pattern:" + raw_pattern) |
| 487 | continue # Non-const pattern - bailout |
| 488 | |
| 489 | pattern = res.group(1) |
| 490 | orig_len = len(line) |
| 491 | line = self._replaceSpecificTokenMatch( |
| 492 | is_simplematch, |
| 493 | line, |
| 494 | pos1, |
| 495 | end_pos, |
| 496 | pattern, |
| 497 | tok, |
| 498 | varId) |
| 499 | pattern_start += len(line) - orig_len |
| 500 | |
| 501 | return line |
| 502 | |
| 503 | @staticmethod |
| 504 | def _compileVerifyTokenFindMatch( |