|
411 | 411 | (/= font-lock-end orig-end))
|
412 | 412 | ))
|
413 | 413 |
|
| 414 | +(defun rust-conditional-re-search-forward (regexp bound condition) |
| 415 | + ;; Search forward for regexp (with bound). If found, call condition and return the found |
| 416 | + ;; match only if it returns true. |
| 417 | + (let* (found |
| 418 | + found-ret-list |
| 419 | + (ret-list (save-excursion |
| 420 | + (while (and (not found) (re-search-forward regexp bound t)) |
| 421 | + (setq |
| 422 | + found-ret-list (list (point) (match-data)) |
| 423 | + found (save-match-data (save-excursion (ignore-errors (funcall condition))))) |
| 424 | + ;; If the condition filters out a match, need to search |
| 425 | + ;; again just after its beginning. This will allow |
| 426 | + ;; cases such as: |
| 427 | + ;; "bar" r"foo" |
| 428 | + ;; where the filtered out search (r" r") should not |
| 429 | + ;; prevent finding another one that begins in the middle |
| 430 | + ;; of it (r"foo") |
| 431 | + (when (not found) |
| 432 | + (goto-char (1+ (match-beginning 0)))) |
| 433 | + ) |
| 434 | + (when found found-ret-list)))) |
| 435 | + (when ret-list |
| 436 | + (goto-char (nth 0 ret-list)) |
| 437 | + (set-match-data (nth 1 ret-list)) |
| 438 | + (nth 0 ret-list)))) |
| 439 | + |
414 | 440 | (defun rust-look-for-raw-string (bound)
|
415 | 441 | ;; Find a raw string, but only if it's not in the middle of another string or
|
416 | 442 | ;; a comment
|
|
450 | 476 |
|
451 | 477 | ;; No "#"s - capture the ending quote (using a backref to group 3,
|
452 | 478 | ;; so that we can't match a quote if we had "#"s) as group 6
|
453 |
| - (group (backref 3)))))) |
454 |
| - ;; If it matches, it ends up with the starting character of the string |
455 |
| - ;; as group 1, any ending backslashes as group 4, and the ending |
456 |
| - ;; character as either group 5 or group 6. |
457 |
| - |
458 |
| - (ret-list (save-excursion |
459 |
| - (let* ((match-end (re-search-forward raw-str-regexp bound t)) |
460 |
| - (ret-list (and match-end (list match-end (match-beginning 0) (match-data) (point))))) |
461 |
| - (when (and ret-list |
462 |
| - (save-excursion |
463 |
| - (goto-char (nth 1 ret-list)) |
464 |
| - (not (rust-in-str-or-cmnt)))) |
465 |
| - ret-list))))) |
466 |
| - (when ret-list |
467 |
| - (goto-char (nth 3 ret-list)) |
468 |
| - (set-match-data (nth 2 ret-list)) |
469 |
| - (nth 0 ret-list)))) |
| 479 | + (group (backref 3)))) |
| 480 | + ;; If it matches, it ends up with the starting character of the string |
| 481 | + ;; as group 1, any ending backslashes as group 4, and the ending |
| 482 | + ;; character as either group 5 or group 6. |
| 483 | + ))) |
| 484 | + (rust-conditional-re-search-forward |
| 485 | + raw-str-regexp bound |
| 486 | + (lambda () (save-excursion |
| 487 | + (goto-char (match-beginning 0)) |
| 488 | + (not (rust-in-str-or-cmnt))))))) |
470 | 489 |
|
471 | 490 | (defvar rust-mode-font-lock-syntactic-keywords
|
472 | 491 | (append
|
|
0 commit comments