From a1e204af633f8f30db041901b1597adbd084461d Mon Sep 17 00:00:00 2001 From: Sean O'Rourke Date: Mon, 14 Mar 2011 20:17:53 -0600 Subject: [PATCH] Regex debug toy. --- sepia-re.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 sepia-re.el diff --git a/sepia-re.el b/sepia-re.el new file mode 100644 index 0000000..39a00ae --- /dev/null +++ b/sepia-re.el @@ -0,0 +1,35 @@ +(define-derived-mode sepia-regex-mode text-mode "RE" + "Mode for looking at 'use re \"debug\"' output." + (view-mode 1) + (font-lock-add-keywords + 'sepia-regex-mode + '(("^\\(Compiling REx\\|Guessing start of match\\|Matching REx\\|Freeing REx:\\)" . font-lock-keyword-face) + ("^Match .*" . font-lock-warning-face) + ;; ("^Matches word.*" . font-lock-keyword-face) + ;; ("^Matching stclass.* against.*" . font-lock-keyword-face) + ("^ +\\([0-9]+\\)[: ]" 1 font-lock-constant-face) + ("^ *[0-9]+ <\\([^>]*\\)>" 1 font-lock-string-face) + ("^ *[0-9]+ <[^>]*> <\\([^>]*\\)>" 1 font-lock-string-face) + ("^ *[0-9]+.*?\\(|.*\\)" 1 font-lock-comment-face) + ) + 'set) + (modify-syntax-entry ?\" "\"") + (font-lock-fontify-buffer) + (toggle-truncate-lines 1)) + +(defun sepia-test-regex (pat str) + (interactive "Smatch pattern: \nSAgainst string: \n") + "Show the debug output for compiling `pat' and matching against `str'. + +XXX: this doesn't work, because I can't figure out how to +redirect the debug output to a file." + (with-current-buffer (get-buffer-create "*sepia-regex*") + (let ((inhibit-read-only t)) + (erase-buffer) + (shell-command (format "perl -Mre=debug -e 'q#%s# =~ m/%s/'" str pat) + (current-buffer)) + ;; (insert (sepia-eval-raw + ;; (format "do { use re 'debug'; qq#%s# =~ m#%s# }" str pat))) + ) + (sepia-regex-mode) + (pop-to-buffer (current-buffer)))) -- 2.11.4.GIT