Skip to content

Instantly share code, notes, and snippets.

@Bike
Created September 28, 2023 13:28
Show Gist options
  • Save Bike/5c9e1b091efd31bdc51070b498eeb7f5 to your computer and use it in GitHub Desktop.
Save Bike/5c9e1b091efd31bdc51070b498eeb7f5 to your computer and use it in GitHub Desktop.
regex-based who-whatevers search
;;; example use:
;;; (who-regex:who-calls "^MAP.*")
;;; => ((MAPCAR (SWANK::APPLICABLE-METHODS-KEYWORDS . #<SPI>)
;;; (SWANK::ENCODE-ARGLIST . #<SPI>)
;;; ...)
;;; (MAPHASH (SWANK::HASH-TABLE-TO-ALIST . #<SPI>) ...)
;;; ...)
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :cl-ppcre))
(defpackage #:who-regex
(:use #:cl)
(:local-nicknames (#:e #:ext) (#:re #:cl-ppcre))
(:export #:who-calls #:who-binds #:who-references #:who-sets
#:who-macroexpands #:who-specializes-directly))
(in-package #:who-regex)
(defun who-whats (regex searcher)
(let ((result nil)
(regex (cl-ppcre:create-scanner regex)))
(do-all-symbols (s result)
(when (re:scan regex (symbol-name s))
(let ((sub (funcall searcher s)))
(when sub
(push (cons s sub) result)))))))
(macrolet ((def (name)
`(defun ,name (regex)
(who-whats regex #',(intern (symbol-name name) "E")))))
(def who-calls)
(def who-binds)
(def who-references)
(def who-sets)
(def who-macroexpands)
(def who-specializes-directly))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment