PageRenderTime 65ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/emacs.d/elpa/dumb-jump-20220524.2122/dumb-jump.el

https://github.com/mbezjak/dotfiles
Emacs Lisp | 1073 lines | 782 code | 204 blank | 87 comment | 20 complexity | f98fc3de8e5a8c9ad2bef2af51e61a58 MD5 | raw file
  1. ;;; dumb-jump.el --- Jump to definition for 50+ languages without configuration -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015-2021 jack angers
  3. ;; Author: jack angers and contributors
  4. ;; Url: https://github.com/jacktasia/dumb-jump
  5. ;; Package-Version: 20220524.2122
  6. ;; Package-Commit: 1dd583011f4025b1b8c75fd785691851b6c5dfa3
  7. ;; Version: 0.5.4
  8. ;; Package-Requires: ((emacs "24.3") (s "1.11.0") (dash "2.9.0") (popup "0.5.3"))
  9. ;; Keywords: programming
  10. ;; Dumb Jump is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 3, or (at your option)
  13. ;; any later version.
  14. ;;
  15. ;; Dumb Jump is distributed in the hope that it will be useful, but WITHOUT
  16. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. ;; License for more details.
  19. ;;
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with Dumb Jump. If not, see http://www.gnu.org/licenses.
  22. ;;; Commentary:
  23. ;; Dumb Jump is an Emacs "jump to definition" package with support for 50+ programming languages that favors
  24. ;; "just working" over speed or accuracy. This means minimal -- and ideally zero -- configuration with absolutely
  25. ;; no stored indexes (TAGS) or persistent background processes.
  26. ;;
  27. ;; Dumb Jump provides a xref-based interface for jumping to
  28. ;; definitions. It is based on tools such as grep, the silver searcher
  29. ;; (https://geoff.greer.fm/ag/), ripgrep
  30. ;; (https://github.com/BurntSushi/ripgrep) or git-grep
  31. ;; (https://git-scm.com/docs/git-grep).
  32. ;;
  33. ;; To enable Dumb Jump, add the following to your initialisation file:
  34. ;;
  35. ;; (add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
  36. ;;
  37. ;; Now pressing M-. on an identifier should open a buffer at the place
  38. ;; where it is defined, or a list of candidates if uncertain. This
  39. ;; list can be navigated using M-g M-n (next-error) and M-g M-p
  40. ;; (previous-error).
  41. ;;; Code:
  42. (unless (require 'xref nil :noerror)
  43. (require 'etags))
  44. (require 's)
  45. (require 'dash)
  46. (require 'popup)
  47. (require 'cl-generic nil :noerror)
  48. (require 'cl-lib)
  49. (defgroup dumb-jump nil
  50. "Easily jump to project function and variable definitions"
  51. :group 'tools
  52. :group 'convenience)
  53. ;;;###autoload
  54. (defvar dumb-jump-mode-map
  55. (let ((map (make-sparse-keymap)))
  56. (define-key map (kbd "C-M-g") 'dumb-jump-go)
  57. (define-key map (kbd "C-M-p") 'dumb-jump-back)
  58. (define-key map (kbd "C-M-q") 'dumb-jump-quick-look)
  59. map))
  60. (defcustom dumb-jump-window
  61. 'current
  62. "Which window to use when jumping. Valid options are 'current (default) or 'other."
  63. :group 'dumb-jump
  64. :type '(choice (const :tag "Current window" current)
  65. (const :tag "Other window" other)))
  66. (defcustom dumb-jump-use-visible-window
  67. t
  68. "When true will jump in a visible window if that window already has the file open."
  69. :group 'dumb-jump
  70. :type 'boolean)
  71. (defcustom dumb-jump-selector
  72. 'popup
  73. "Which selector to use when there is multiple choices. `ivy` and `helm' are also supported."
  74. :group 'dumb-jump
  75. :type '(choice (const :tag "Popup" popup)
  76. (const :tag "Helm" helm)
  77. (const :tag "Ivy" ivy)
  78. (const :tag "Completing Read" completing-read)))
  79. (defcustom dumb-jump-ivy-jump-to-selected-function
  80. #'dumb-jump-ivy-jump-to-selected
  81. "Prompts user for a choice using ivy then dumb-jump to that choice."
  82. :group 'dumb-jump
  83. :type 'function)
  84. (defcustom dumb-jump-prefer-searcher
  85. nil
  86. "The preferred searcher to use 'ag, 'rg, 'git-grep, 'gnu-grep,or 'grep.
  87. If nil then the most optimal searcher will be chosen at runtime."
  88. :group 'dumb-jump
  89. :type '(choice (const :tag "Best Available" nil)
  90. (const :tag "ag" ag)
  91. (const :tag "rg" rg)
  92. (const :tag "grep" gnu-grep)
  93. (const :tag "git grep" git-grep)
  94. (const :tag "git grep + ag" git-grep-plus-ag)))
  95. (defcustom dumb-jump-force-searcher
  96. nil
  97. "Forcibly use searcher: 'ag, 'rg, 'git-grep, 'gnu-grep, or 'grep.
  98. Set to nil to not force anything and use `dumb-jump-prefer-searcher'
  99. or most optimal searcher."
  100. :group 'dumb-jump
  101. :type '(choice (const :tag "Best Available" nil)
  102. (const :tag "ag" ag)
  103. (const :tag "rg" rg)
  104. (const :tag "grep" gnu-grep)
  105. (const :tag "git grep" git-grep)
  106. (const :tag "git grep + ag" git-grep-plus-ag)))
  107. (defcustom dumb-jump-grep-prefix
  108. "LANG=C"
  109. "Prefix to grep command. Seemingly makes it faster for pure text."
  110. :group 'dumb-jump
  111. :type 'string)
  112. (defcustom dumb-jump-grep-cmd
  113. "grep"
  114. "The path to grep. By default assumes it is in path."
  115. :group 'dumb-jump
  116. :type 'string)
  117. (defcustom dumb-jump-ag-cmd
  118. "ag"
  119. "The the path to the silver searcher. By default assumes it is in path. If not found fallbacks to grep."
  120. :group 'dumb-jump
  121. :type 'string)
  122. (defcustom dumb-jump-rg-cmd
  123. "rg"
  124. "The the path to ripgrep. By default assumes it is in path. If not found fallbacks to grep."
  125. :group 'dumb-jump
  126. :type 'string)
  127. (defcustom dumb-jump-git-grep-cmd
  128. "git grep"
  129. "The the path to git grep. By default assumes it is in path. If not found fallbacks to grep."
  130. :group 'dumb-jump
  131. :type 'string)
  132. (defcustom dumb-jump-ag-word-boundary
  133. "(?![a-zA-Z0-9\\?\\*-])"
  134. "`\\b` thinks `-` is a word boundary. When this matters use `\\j` instead and ag will use this value."
  135. :group 'dumb-jump
  136. :type 'string)
  137. (defcustom dumb-jump-rg-word-boundary
  138. "($|[^a-zA-Z0-9\\?\\*-])"
  139. "`\\b` thinks `-` is a word boundary. When this matters use `\\j` instead and rg will use this value."
  140. :group 'dumb-jump
  141. :type 'string)
  142. (defcustom dumb-jump-git-grep-word-boundary
  143. "($|[^a-zA-Z0-9\\?\\*-])"
  144. "`\\b` thinks `-` is a word boundary. When this matters use `\\j` instead and git grep will use this value."
  145. :group 'dumb-jump
  146. :type 'string)
  147. (defcustom dumb-jump-grep-word-boundary
  148. "($|[^a-zA-Z0-9\\?\\*-])"
  149. "`\\b` thinks `-` is a word boundary. When this matters use `\\j` instead and grep will use this value."
  150. :group 'dumb-jump
  151. :type 'string)
  152. (defcustom dumb-jump-fallback-regex
  153. "\\bJJJ\\j"
  154. "When dumb-jump-fallback-search is t use this regex. Defaults to boundary search of symbol under point."
  155. :group 'dumb-jump
  156. :type 'string)
  157. (defcustom dumb-jump-fallback-search
  158. t
  159. "If nothing is found with normal search fallback to searching the fallback regex."
  160. :group 'dumb-jump
  161. :type 'boolean)
  162. (defcustom dumb-jump-force-grep
  163. nil
  164. "When t will use grep even if ag is available."
  165. :group 'dumb-jump
  166. :type 'boolean)
  167. (defcustom dumb-jump-zgrep-cmd
  168. "zgrep"
  169. "The path to grep to use for gzipped files. By default assumes it is in path."
  170. :group 'dumb-jump
  171. :type 'string)
  172. (defcustom dumb-jump-grep-args "-REn"
  173. "Grep command args [R]ecursive, [E]xtended regexes, and show line [n]umbers."
  174. :group 'dumb-jump
  175. :type 'string)
  176. (defcustom dumb-jump-gnu-grep-args "-rEn"
  177. "Grep command args [r]ecursive and [E]xtended regexes, and show line [n]umbers."
  178. :group 'dumb-jump
  179. :type 'string)
  180. (defcustom dumb-jump-max-find-time
  181. 2
  182. "Number of seconds a grep/find command can take before being warned to use ag and config."
  183. :group 'dumb-jump
  184. :type 'integer)
  185. (defcustom dumb-jump-functions-only
  186. nil
  187. "Should we only jump to functions?"
  188. :group 'dumb-jump
  189. :type 'boolean)
  190. (defcustom dumb-jump-quiet
  191. nil
  192. "If non-nil Dumb Jump will not log anything to *Messages*."
  193. :group 'dumb-jump
  194. :type 'boolean)
  195. (defcustom dumb-jump-ignore-context
  196. nil
  197. "If non-nil Dumb Jump will ignore the context of point when jumping."
  198. :group 'dumb-jump
  199. :type 'boolean)
  200. (defcustom dumb-jump-git-grep-search-untracked
  201. t
  202. "If non-nil Dumb Jump will also search untracked files when using searcher git-grep."
  203. :group 'dumb-jump
  204. :type 'boolean)
  205. (defcustom dumb-jump-git-grep-search-args
  206. ""
  207. "Appends the passed arguments to the git-grep search function. Default: \"\""
  208. :group 'dumb-jump
  209. :type 'string)
  210. (defcustom dumb-jump-ag-search-args
  211. ""
  212. "Appends the passed arguments to the ag search function. Default: \"\""
  213. :group 'dumb-jump
  214. :type 'string)
  215. (defcustom dumb-jump-rg-search-args
  216. "--pcre2"
  217. "Appends the passed arguments to the rg search function. Default: \"--pcre2\""
  218. :group 'dumb-jump
  219. :type 'string)
  220. (defcustom dumb-jump-find-rules
  221. '((:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "elisp"
  222. :regex "\\\((defun|cl-defun)\\s+JJJ\\j"
  223. ;; \\j usage see `dumb-jump-ag-word-boundary`
  224. :tests ("(defun test (blah)" "(defun test\n" "(cl-defun test (blah)" "(cl-defun test\n")
  225. :not ("(defun test-asdf (blah)" "(defun test-blah\n" "(cl-defun test-asdf (blah)"
  226. "(cl-defun test-blah\n" "(defun tester (blah)" "(defun test? (blah)" "(defun test- (blah)"))
  227. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "elisp"
  228. :regex "\\\(defvar\\b\\s*JJJ\\j"
  229. :tests ("(defvar test " "(defvar test\n")
  230. :not ("(defvar tester" "(defvar test?" "(defvar test-"))
  231. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "elisp"
  232. :regex "\\\(defcustom\\b\\s*JJJ\\j"
  233. :tests ("(defcustom test " "(defcustom test\n")
  234. :not ("(defcustom tester" "(defcustom test?" "(defcustom test-"))
  235. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "elisp"
  236. :regex "\\\(setq\\b\\s*JJJ\\j" :tests ("(setq test 123)")
  237. :not ("setq test-blah 123)" "(setq tester" "(setq test?" "(setq test-"))
  238. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "elisp"
  239. :regex "\\\(JJJ\\s+" :tests ("(let ((test 123)))") :not ("(let ((test-2 123)))"))
  240. ;; variable in method signature
  241. (:type "variable" :supports ("ag" "rg" "git-grep") :language "elisp"
  242. :regex "\\((defun|cl-defun)\\s*.+\\\(?\\s*JJJ\\j\\s*\\\)?"
  243. :tests ("(defun blah (test)" "(defun blah (test blah)" "(defun (blah test)")
  244. :not ("(defun blah (test-1)" "(defun blah (test-2 blah)" "(defun (blah test-3)"))
  245. ;; common lisp
  246. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
  247. :regex "\\\(defun\\s+JJJ\\j"
  248. ;; \\j usage see `dumb-jump-ag-word-boundary`
  249. :tests ("(defun test (blah)" "(defun test\n")
  250. :not ("(defun test-asdf (blah)" "(defun test-blah\n"
  251. "(defun tester (blah)" "(defun test? (blah)" "(defun test- (blah)"))
  252. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
  253. :regex "\\\(defparameter\\b\\s*JJJ\\j"
  254. :tests ("(defparameter test " "(defparameter test\n")
  255. :not ("(defparameter tester" "(defparameter test?" "(defparameter test-"))
  256. ;; racket
  257. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  258. :regex "\\\(define\\s+\\(\\s*JJJ\\j"
  259. :tests ("(define (test blah)" "(define (test\n")
  260. :not ("(define test blah" "(define (test-asdf blah)" "(define test (lambda (blah"))
  261. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  262. :regex "\\\(define\\s+JJJ\\s*\\\(\\s*lambda"
  263. :tests ("(define test (lambda (blah" "(define test (lambda\n")
  264. :not ("(define test blah" "(define test-asdf (lambda (blah)" "(define (test)" "(define (test blah) (lambda (foo"))
  265. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  266. :regex "\\\(let\\s+JJJ\\s*(\\\(|\\\[)*"
  267. :tests ("(let test ((blah foo) (bar bas))" "(let test\n" "(let test [(foo")
  268. :not ("(let ((test blah"))
  269. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  270. :regex "\\\(define\\s+JJJ\\j"
  271. :tests ("(define test " "(define test\n")
  272. :not ("(define (test"))
  273. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  274. :regex "(\\\(|\\\[)\\s*JJJ\\s+"
  275. :tests ("(let ((test 'foo" "(let [(test 'foo" "(let [(test 'foo" "(let [[test 'foo" "(let ((blah 'foo) (test 'bar)")
  276. :not ("{test foo"))
  277. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  278. :regex "\\\(lambda\\s+\\\(?[^\(\)]*\\s*JJJ\\j\\s*\\\)?"
  279. :tests ("(lambda (test)" "(lambda (foo test)" "(lambda test (foo)")
  280. :not ("(lambda () test"))
  281. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  282. :regex "\\\(define\\s+\\\([^\(\)]+\\s*JJJ\\j\\s*\\\)?"
  283. :tests ("(define (foo test)" "(define (foo test bar)")
  284. :not ("(define foo test" "(define (test foo" "(define (test)"))
  285. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
  286. :regex "\\(struct\\s+JJJ\\j"
  287. :tests ("(struct test (a b)"))
  288. ;; scheme
  289. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  290. :regex "\\\(define\\s+\\(\\s*JJJ\\j"
  291. :tests ("(define (test blah)" "(define (test\n")
  292. :not ("(define test blah" "(define (test-asdf blah)" "(define test (lambda (blah"))
  293. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  294. :regex "\\\(define\\s+JJJ\\s*\\\(\\s*lambda"
  295. :tests ("(define test (lambda (blah" "(define test (lambda\n")
  296. :not ("(define test blah" "(define test-asdf (lambda (blah)" "(define (test)" "(define (test blah) (lambda (foo"))
  297. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  298. :regex "\\\(let\\s+JJJ\\s*(\\\(|\\\[)*"
  299. :tests ("(let test ((blah foo) (bar bas))" "(let test\n" "(let test [(foo")
  300. :not ("(let ((test blah"))
  301. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  302. :regex "\\\(define\\s+JJJ\\j"
  303. :tests ("(define test " "(define test\n")
  304. :not ("(define (test"))
  305. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  306. :regex "(\\\(|\\\[)\\s*JJJ\\s+"
  307. :tests ("(let ((test 'foo" "(let [(test 'foo" "(let [(test 'foo" "(let [[test 'foo" "(let ((blah 'foo) (test 'bar)")
  308. :not ("{test foo"))
  309. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  310. :regex "\\\(lambda\\s+\\\(?[^\(\)]*\\s*JJJ\\j\\s*\\\)?"
  311. :tests ("(lambda (test)" "(lambda (foo test)" "(lambda test (foo)")
  312. :not ("(lambda () test"))
  313. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scheme"
  314. :regex "\\\(define\\s+\\\([^\(\)]+\\s*JJJ\\j\\s*\\\)?"
  315. :tests ("(define (foo test)" "(define (foo test bar)")
  316. :not ("(define foo test" "(define (test foo" "(define (test)"))
  317. ;; c++
  318. (:type "function" :supports ("ag" "rg" "git-grep") :language "c++"
  319. :regex "\\bJJJ(\\s|\\))*\\((\\w|[,&*.<>:]|\\s)*(\\))\\s*(const|->|\\{|$)|typedef\\s+(\\w|[(*]|\\s)+JJJ(\\)|\\s)*\\("
  320. :tests ("int test(){" "my_struct (*test)(int a, int b){" "auto MyClass::test ( Builder::Builder& reference, ) -> decltype( builder.func() ) {" "int test( int *random_argument) const {" "test::test() {" "typedef int (*test)(int);")
  321. :not ("return test();)" "int test(a, b);" "if( test() ) {" "else test();"))
  322. ;; (:type "variable" :supports ("grep") :language "c++"
  323. ;; :regex "(\\b\\w+|[,>])([*&]|\\s)+JJJ\\s*(\\[([0-9]|\\s)*\\])*\\s*([=,){;]|:\\s*[0-9])|#define\\s+JJJ\\b"
  324. ;; :tests ("int test=2;" "char *test;" "int x = 1, test = 2" "int test[20];" "#define test" "unsigned int test:2;"))
  325. (:type "variable" :supports ("ag" "rg") :language "c++"
  326. :regex "\\b(?!(class\\b|struct\\b|return\\b|else\\b|delete\\b))(\\w+|[,>])([*&]|\\s)+JJJ\\s*(\\[(\\d|\\s)*\\])*\\s*([=,(){;]|:\\s*\\d)|#define\\s+JJJ\\b"
  327. :tests ("int test=2;" "char *test;" "int x = 1, test = 2" "int test[20];" "#define test" "typedef int test;" "unsigned int test:2")
  328. :not ("return test;" "#define NOT test" "else test=2;"))
  329. (:type "type" :supports ("ag" "rg" "git-grep") :language "c++"
  330. :regex "\\b(class|struct|enum|union)\\b\\s*JJJ\\b\\s*(final\\s*)?(:((\\s*\\w+\\s*::)*\\s*\\w*\\s*<?(\\s*\\w+\\s*::)*\\w+>?\\s*,*)+)?((\\{|$))|}\\s*JJJ\\b\\s*;"
  331. :tests ("typedef struct test {" "enum test {" "} test;" "union test {" "class test final: public Parent1, private Parent2{" "class test : public std::vector<int> {")
  332. :not("union test var;" "struct test function() {"))
  333. ;; clojure
  334. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  335. :regex "\\(def\\s+JJJ\\j"
  336. :tests ("(def test (foo)"))
  337. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  338. :regex "\\(defn-?\\s+JJJ\\j"
  339. :tests ("(defn test [foo]" "(defn- test [foo]")
  340. :not ("(defn test? [foo]" "(defn- test? [foo]"))
  341. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  342. :regex "\\(defmacro\\s+JJJ\\j"
  343. :tests ("(defmacro test [foo]"))
  344. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  345. :regex "\\(deftask\\s+JJJ\\j"
  346. :tests ("(deftask test [foo]"))
  347. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  348. :regex "\\(deftype\\s+JJJ\\j"
  349. :tests ("(deftype test [foo]"))
  350. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  351. :regex "\\(defmulti\\s+JJJ\\j"
  352. :tests ("(defmulti test fn"))
  353. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  354. :regex "\\(defmethod\\s+JJJ\\j"
  355. :tests ("(defmethod test type"))
  356. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  357. :regex "\\(definterface\\s+JJJ\\j"
  358. :tests ("(definterface test (foo)"))
  359. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  360. :regex "\\(defprotocol\\s+JJJ\\j"
  361. :tests ("(defprotocol test (foo)"))
  362. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "clojure"
  363. :regex "\\(defrecord\\s+JJJ\\j"
  364. :tests ("(defrecord test [foo]"))
  365. ;; coffeescript
  366. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "coffeescript"
  367. :regex "^\\s*JJJ\\s*[=:].*[-=]>"
  368. :tests ("test = () =>" "test= =>" "test = ->" "test=()->"
  369. "test : () =>" "test: =>" "test : ->" "test:()->")
  370. :not ("# test = =>" "test = 1"))
  371. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "coffeescript"
  372. :regex "^\\s*JJJ\\s*[:=][^:=-][^>]+$"
  373. :tests ("test = $" "test : [" "test = {" "test = a")
  374. :not ("test::a" "test: =>" "test == 1" "# test = 1"))
  375. (:type "class" :supports ("ag" "grep" "rg" "git-grep") :language "coffeescript"
  376. :regex "^\\s*\\bclass\\s+JJJ"
  377. :tests ("class test" "class test extends")
  378. :not ("# class"))
  379. ;; obj-c
  380. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "objc"
  381. :regex "\\\)\\s*JJJ(:|\\b|\\s)"
  382. :tests ("- (void)test" "- (void)test:(UIAlertView *)alertView")
  383. :not ("- (void)testnot" "- (void)testnot:(UIAlertView *)alertView"))
  384. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "objc"
  385. :regex "\\b\\*?JJJ\\s*=[^=\\n]+"
  386. :tests ("NSString *test = @\"asdf\"")
  387. :not ("NSString *testnot = @\"asdf\"" "NSString *nottest = @\"asdf\""))
  388. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "objc"
  389. :regex "(@interface|@protocol|@implementation)\\b\\s*JJJ\\b\\s*"
  390. :tests ("@interface test: UIWindow")
  391. :not ("@interface testnon: UIWindow"))
  392. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "objc"
  393. :regex "typedef\\b\\s+(NS_OPTIONS|NS_ENUM)\\b\\([^,]+?,\\s*JJJ\\b\\s*"
  394. :tests ("typedef NS_ENUM(NSUInteger, test)")
  395. :not ("typedef NS_ENUMD(NSUInteger, test)"))
  396. ;; swift
  397. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "swift"
  398. :regex "(let|var)\\s*JJJ\\s*(=|:)[^=:\\n]+"
  399. :tests ("let test = 1234" "var test = 1234" "private lazy var test: UITapGestureRecognizer")
  400. :not ("if test == 1234:"))
  401. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "swift"
  402. :regex "func\\s+JJJ\\b\\s*(<[^>]*>)?\\s*\\("
  403. :tests ("func test(asdf)" "func test()" "func test<Value: Protocol>()")
  404. :not ("func testnot(asdf)" "func testnot()"))
  405. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "swift"
  406. :regex "(class|struct|protocol|enum)\\s+JJJ\\b\\s*?"
  407. :tests ("struct test" "struct test: Codable" "struct test<Value: Codable>"
  408. "class test:" "class test: UIWindow" "class test<Value: Codable>")
  409. :not ("class testnot:" "class testnot(object):" "struct testnot(object)"))
  410. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "swift"
  411. :regex "(typealias)\\s+JJJ\\b\\s*?="
  412. :tests ("typealias test =")
  413. :not ("typealias testnot"))
  414. ;; c#
  415. (:type "function" :supports ("ag" "rg") :language "csharp"
  416. :regex "^\\s*(?:[\\w\\[\\]]+\\s+){1,3}JJJ\\s*\\\("
  417. :tests ("int test()" "int test(param)" "static int test()" "static int test(param)"
  418. "public static MyType test()" "private virtual SomeType test(param)" "static int test()")
  419. :not ("test()" "testnot()" "blah = new test()"))
  420. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "csharp"
  421. :regex "\\s*\\bJJJ\\s*=[^=\\n)]+" :tests ("int test = 1234") :not ("if test == 1234:" "int nottest = 44"))
  422. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "csharp"
  423. :regex "(class|interface)\\s*JJJ\\b"
  424. :tests ("class test:" "public class test : IReadableChannel, I")
  425. :not ("class testnot:" "public class testnot : IReadableChannel, I"))
  426. ;; java (literally the same regexes as c#, but different tests)
  427. (:type "function" :supports ("ag" "rg") :language "java"
  428. :regex "^\\s*(?:[\\w\\[\\]]+\\s+){1,3}JJJ\\s*\\\("
  429. :tests ("int test()" "int test(param)" "static int test()" "static int test(param)"
  430. "public static MyType test()" "private virtual SomeType test(param)" "static int test()"
  431. "private foo[] test()")
  432. :not ("test()" "testnot()" "blah = new test()" "foo bar = test()"))
  433. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "java"
  434. :regex "\\s*\\bJJJ\\s*=[^=\\n)]+" :tests ("int test = 1234") :not ("if test == 1234:" "int nottest = 44"))
  435. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "java"
  436. :regex "(class|interface)\\s*JJJ\\b"
  437. :tests ("class test:" "public class test implements Something")
  438. :not ("class testnot:" "public class testnot implements Something"))
  439. ;; vala (again just like c#, exactly the same..)
  440. (:type "function" :supports ("ag" "rg") :language "vala"
  441. :regex "^\\s*(?:[\\w\\[\\]]+\\s+){1,3}JJJ\\s*\\\("
  442. :tests ("int test()" "int test(param)" "static int test()" "static int test(param)"
  443. "public static MyType test()" "private virtual SomeType test(param)" "static int test()")
  444. :not ("test()" "testnot()" "blah = new test()"))
  445. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "vala"
  446. :regex "\\s*\\bJJJ\\s*=[^=\\n)]+" :tests ("int test = 1234") :not ("if test == 1234:" "int nottest = 44"))
  447. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "vala"
  448. :regex "(class|interface)\\s*JJJ\\b"
  449. :tests ("class test:" "public class test : IReadableChannel, I")
  450. :not ("class testnot:" "public class testnot : IReadableChannel, I"))
  451. ;; coq
  452. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  453. :regex "\\s*Variable\\s+JJJ\\b"
  454. :tests ("Variable test")
  455. :not ("Variable testx"))
  456. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  457. :regex "\\s*Inductive\\s+JJJ\\b"
  458. :tests ("Inductive test")
  459. :not ("Inductive testx"))
  460. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  461. :regex "\\s*Lemma\\s+JJJ\\b"
  462. :tests ("Lemma test")
  463. :not ("Lemma testx"))
  464. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  465. :regex "\\s*Definition\\s+JJJ\\b"
  466. :tests ("Definition test")
  467. :not ("Definition testx"))
  468. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  469. :regex "\\s*Hypothesis\\s+JJJ\\b"
  470. :tests ("Hypothesis test")
  471. :not ("Hypothesis testx"))
  472. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  473. :regex "\\s*Theorm\\s+JJJ\\b"
  474. :tests ("Theorm test")
  475. :not ("Theorm testx"))
  476. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  477. :regex "\\s*Fixpoint\\s+JJJ\\b"
  478. :tests ("Fixpoint test")
  479. :not ("Fixpoint testx"))
  480. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  481. :regex "\\s*Module\\s+JJJ\\b"
  482. :tests ("Module test")
  483. :not ("Module testx"))
  484. (:type "function" :supports ("ag" "rg" "git-grep") :language "coq"
  485. :regex "\\s*CoInductive\\s+JJJ\\b"
  486. :tests ("CoInductive test")
  487. :not ("CoInductive testx"))
  488. ;; python
  489. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "python"
  490. :regex "\\s*\\bJJJ\\s*=[^=\\n]+"
  491. :tests ("test = 1234")
  492. :not ("if test == 1234:" "_test = 1234"))
  493. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "python"
  494. :regex "def\\s*JJJ\\b\\s*\\\("
  495. :tests ("\tdef test(asdf)" "def test()")
  496. :not ("\tdef testnot(asdf)" "def testnot()"))
  497. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "python"
  498. :regex "class\\s*JJJ\\b\\s*\\\(?"
  499. :tests ("class test(object):" "class test:")
  500. :not ("class testnot:" "class testnot(object):"))
  501. ;; matlab
  502. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "matlab"
  503. :regex "^\\s*\\bJJJ\\s*=[^=\\n]+"
  504. :tests ("test = 1234")
  505. :not ("for test = 1:2:" "_test = 1234"))
  506. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "matlab"
  507. :regex "^\\s*function\\s*[^=]+\\s*=\\s*JJJ\\b"
  508. :tests ("\tfunction y = test(asdf)" "function x = test()" "function [x, losses] = test(A, y, lambda, method, qtile)")
  509. :not ("\tfunction testnot(asdf)" "function testnot()"))
  510. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "matlab"
  511. :regex "^\\s*classdef\\s*JJJ\\b\\s*"
  512. :tests ("classdef test")
  513. :not ("classdef testnot"))
  514. ;; nim
  515. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "nim"
  516. :regex "(const|let|var)\\s*JJJ\\*?\\s*(=|:)[^=:\\n]+"
  517. :tests ("let test = 1234" "var test = 1234" "var test: Stat" "const test = 1234" "const test* = 1234")
  518. :not ("if test == 1234:"))
  519. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "nim"
  520. :regex "(proc|func|macro|template)\\s*`?JJJ`?\\b\\*?\\s*\\\("
  521. :tests ("\tproc test(asdf)" "proc test()" "func test()" "macro test()" "template test()" "proc test*()")
  522. :not ("\tproc testnot(asdf)" "proc testnot()"))
  523. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "nim"
  524. :regex "type\\s*JJJ\\b\\*?\\s*(\\{[^}]+\\})?\\s*=\\s*\\w+"
  525. :tests ("type test = object" "type test {.pure.} = enum" "type test* = ref object")
  526. :not ("type testnot = object"))
  527. ;; nix
  528. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "nix"
  529. :regex "\\b\\s*JJJ\\s*=[^=;]+"
  530. :tests ("test = 1234;" "test = 123;" "test=123")
  531. :not ("testNot = 1234;" "Nottest = 1234;" "AtestNot = 1234;"))
  532. ;; ruby
  533. (:type "variable" :supports ("ag" "rg" "git-grep") :language "ruby"
  534. :regex "^\\s*((\\w+[.])*\\w+,\\s*)*JJJ(,\\s*(\\w+[.])*\\w+)*\\s*=([^=>~]|$)"
  535. :tests ("test = 1234" "self.foo, test, bar = args")
  536. :not ("if test == 1234" "foo_test = 1234"))
  537. (:type "function" :supports ("ag" "rg" "git-grep") :language "ruby"
  538. :regex "(^|[^\\w.])((private|public|protected)\\s+)?def\\s+(\\w+(::|[.]))*JJJ($|[^\\w|:])"
  539. :tests ("def test(foo)" "def test()" "def test foo" "def test; end"
  540. "def self.test()" "def MODULE::test()" "private def test")
  541. :not ("def test_foo"))
  542. (:type "function" :supports ("ag" "rg" "git-grep") :language "ruby"
  543. :regex "(^|\\W)define(_singleton|_instance)?_method(\\s|[(])\\s*:JJJ($|[^\\w|:])"
  544. :tests ("define_method(:test, &body)"
  545. "mod.define_instance_method(:test) { body }"))
  546. (:type "type" :supports ("ag" "rg" "git-grep") :language "ruby"
  547. :regex "(^|[^\\w.])class\\s+(\\w*::)*JJJ($|[^\\w|:])"
  548. :tests ("class test" "class Foo::test"))
  549. (:type "type" :supports ("ag" "rg" "git-grep") :language "ruby"
  550. :regex "(^|[^\\w.])module\\s+(\\w*::)*JJJ($|[^\\w|:])"
  551. :tests ("module test" "module Foo::test"))
  552. (:type "function" :supports ("ag" "rg" "git-grep") :language "ruby"
  553. :regex "(^|\\W)alias(_method)?\\W+JJJ(\\W|$)"
  554. :tests ("alias test some_method"
  555. "alias_method :test, :some_method"
  556. "alias_method 'test' 'some_method'"
  557. "some_class.send(:alias_method, :test, :some_method)")
  558. :not ("alias some_method test"
  559. "alias_method :some_method, :test"
  560. "alias test_foo test"))
  561. ;; Groovy
  562. (:type "variable" :supports ("ag" "rg" "git-grep") :language "groovy"
  563. :regex "^\\s*((\\w+[.])*\\w+,\\s*)*JJJ(,\\s*(\\w+[.])*\\w+)*\\s*=([^=>~]|$)"
  564. :tests ("test = 1234" "self.foo, test, bar = args")
  565. :not ("if test == 1234" "foo_test = 1234"))
  566. (:type "function" :supports ("ag" "rg" "git-grep") :language "groovy"
  567. :regex "(^|[^\\w.])((private|public)\\s+)?def\\s+(\\w+(::|[.]))*JJJ($|[^\\w|:])"
  568. :tests ("def test(foo)" "def test()" "def test foo" "def test; end"
  569. "def self.test()" "def MODULE::test()" "private def test")
  570. :not ("def test_foo"))
  571. (:type "type" :supports ("ag" "rg" "git-grep") :language "groovy"
  572. :regex "(^|[^\\w.])class\\s+(\\w*::)*JJJ($|[^\\w|:])"
  573. :tests ("class test" "class Foo::test"))
  574. ;; crystal
  575. (:type "variable" :supports ("ag" "rg" "git-grep") :language "crystal"
  576. :regex "^\\s*((\\w+[.])*\\w+,\\s*)*JJJ(,\\s*(\\w+[.])*\\w+)*\\s*=([^=>~]|$)"
  577. :tests ("test = 1234" "self.foo, test, bar = args")
  578. :not ("if test == 1234" "foo_test = 1234"))
  579. (:type "function" :supports ("ag" "rg" "git-grep") :language "crystal"
  580. :regex "(^|[^\\w.])((private|public|protected)\\s+)?def\\s+(\\w+(::|[.]))*JJJ($|[^\\w|:])"
  581. :tests ("def test(foo)" "def test()" "def test foo" "def test; end"
  582. "def self.test()" "def MODULE::test()" "private def test")
  583. :not ("def test_foo"))
  584. (:type "type" :supports ("ag" "rg" "git-grep") :language "crystal"
  585. :regex "(^|[^\\w.])class\\s+(\\w*::)*JJJ($|[^\\w|:])"
  586. :tests ("class test" "class Foo::test"))
  587. (:type "type" :supports ("ag" "rg" "git-grep") :language "crystal"
  588. :regex "(^|[^\\w.])module\\s+(\\w*::)*JJJ($|[^\\w|:])"
  589. :tests ("module test" "module Foo::test"))
  590. (:type "type" :supports ("ag" "rg" "git-grep") :language "crystal"
  591. :regex "(^|[^\\w.])struct\\s+(\\w*::)*JJJ($|[^\\w|:])"
  592. :tests ("struct test" "struct Foo::test"))
  593. (:type "type" :supports ("ag" "rg" "git-grep") :language "crystal"
  594. :regex "(^|[^\\w.])alias\\s+(\\w*::)*JJJ($|[^\\w|:])"
  595. :tests ("alias test" "alias Foo::test"))
  596. ;; scad
  597. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scad"
  598. :regex "\\s*\\bJJJ\\s*=[^=\\n]+" :tests ("test = 1234") :not ("if test == 1234 {"))
  599. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "scad"
  600. :regex "function\\s*JJJ\\s*\\\("
  601. :tests ("function test()" "function test ()"))
  602. (:type "module" :supports ("ag" "grep" "rg" "git-grep") :language "scad"
  603. :regex "module\\s*JJJ\\s*\\\("
  604. :tests ("module test()" "module test ()"))
  605. ;; scala
  606. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  607. :regex "\\bval\\s*JJJ\\s*=[^=\\n]+" :tests ("val test = 1234") :not ("case test => 1234"))
  608. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  609. :regex "\\bvar\\s*JJJ\\s*=[^=\\n]+" :tests ("var test = 1234") :not ("case test => 1234"))
  610. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  611. :regex "\\btype\\s*JJJ\\s*=[^=\\n]+" :tests ("type test = 1234") :not ("case test => 1234"))
  612. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  613. :regex "\\bdef\\s*JJJ\\s*\\\("
  614. :tests ("def test(asdf)" "def test()"))
  615. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  616. :regex "class\\s*JJJ\\s*\\\(?"
  617. :tests ("class test(object)"))
  618. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  619. :regex "trait\\s*JJJ\\s*\\\(?"
  620. :tests ("trait test(object)"))
  621. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "scala"
  622. :regex "object\\s*JJJ\\s*\\\(?"
  623. :tests ("object test(object)"))
  624. ;; solidity
  625. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "solidity"
  626. :regex "function\\s*JJJ\\s*\\\("
  627. :tests ("function test() internal" "function test (uint x, address y)" "function test() external"))
  628. (:type "modifier" :supports ("ag" "grep" "rg" "git-grep") :language "solidity"
  629. :regex "modifier\\s*JJJ\\s*\\\("
  630. :tests ("modifier test()" "modifier test ()"))
  631. (:type "event" :supports ("ag" "grep" "rg" "git-grep") :language "solidity"
  632. :regex "event\\s*JJJ\\s*\\\("
  633. :tests ("event test();" "event test (uint indexed x)" "event test(uint x, address y)"))
  634. (:type "error" :supports ("ag" "grep" "rg" "git-grep") :language "solidity"
  635. :regex "error\\s*JJJ\\s*\\\("
  636. :tests ("error test();" "error test (uint x)" "error test(uint x, address y)"))
  637. ;; R
  638. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "r"
  639. :regex "\\bJJJ\\s*=[^=><]" :tests ("test = 1234") :not ("if (test == 1234)"))
  640. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "r"
  641. :regex "\\bJJJ\\s*<-\\s*function\\b"
  642. :tests ("test <- function" "test <- function(")
  643. :not ("test <- functionX"))
  644. ;; perl
  645. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "perl"
  646. :regex "sub\\s*JJJ\\s*(\\{|\\()"
  647. :tests ("sub test{" "sub test {" "sub test(" "sub test ("))
  648. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "perl"
  649. :regex "JJJ\\s*=\\s*"
  650. :tests ("$test = 1234"))
  651. ;; Tcl
  652. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "tcl"
  653. :regex "proc\\s+JJJ\\s*\\{"
  654. :tests ("proc test{" "proc test {"))
  655. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "tcl"
  656. :regex "set\\s+JJJ"
  657. :tests ("set test 1234"))
  658. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "tcl"
  659. :regex "(variable|global)\\s+JJJ"
  660. :tests ("variable test" "global test"))
  661. ;; shell
  662. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "shell"
  663. :regex "function\\s*JJJ\\s*"
  664. :tests ("function test{" "function test {" "function test () {")
  665. :not ("function nottest {"))
  666. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "shell"
  667. :regex "JJJ\\\(\\\)\\s*\\{"
  668. :tests ("test() {")
  669. :not ("testx() {"))
  670. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "shell"
  671. :regex "\\bJJJ\\s*=\\s*"
  672. :tests ("test = 1234") :not ("blahtest = 1234"))
  673. ;; php
  674. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  675. :regex "function\\s*JJJ\\s*\\\("
  676. :tests ("function test()" "function test ()"))
  677. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  678. :regex "\\*\\s@method\\s+[^ \t]+\\s+JJJ\\("
  679. :tests ("/** @method string|false test($a)" " * @method bool test()"))
  680. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  681. :regex "(\\s|->|\\$|::)JJJ\\s*=\\s*"
  682. :tests ("$test = 1234" "$foo->test = 1234"))
  683. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  684. :regex "\\*\\s@property(-read|-write)?\\s+([^ \t]+\\s+)&?\\$JJJ(\\s+|$)"
  685. :tests ("/** @property string $test" "/** @property string $test description for $test property" " * @property-read bool|bool $test" " * @property-write \\ArrayObject<string,resource[]> $test"))
  686. (:type "trait" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  687. :regex "trait\\s*JJJ\\s*\\\{"
  688. :tests ("trait test{" "trait test {"))
  689. (:type "interface" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  690. :regex "interface\\s*JJJ\\s*\\\{"
  691. :tests ("interface test{" "interface test {"))
  692. (:type "class" :supports ("ag" "grep" "rg" "git-grep") :language "php"
  693. :regex "class\\s*JJJ\\s*(extends|implements|\\\{)"
  694. :tests ("class test{" "class test {" "class test extends foo" "class test implements foo"))
  695. ;; dart
  696. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "dart"
  697. :regex "\\bJJJ\\s*\\([^()]*\\)\\s*[{]"
  698. :tests ("test(foo) {" "test (foo){" "test(foo){"))
  699. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "dart"
  700. :regex "class\\s*JJJ\\s*[\\\(\\\{]"
  701. :tests ("class test(object) {" "class test{"))
  702. ;; faust
  703. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "faust"
  704. :regex "\\bJJJ\(\\\(.+\\\)\)*\\s*="
  705. :tests ("test = osc + 0.5;" "test(freq) = osc(freq) + 0.5;"))
  706. ;; fennel
  707. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "fennel"
  708. :regex "\\((local|var)\\s+JJJ\\j"
  709. :tests ("(local test (foo)"
  710. "(var test (foo)"))
  711. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "fennel"
  712. :regex "\\(fn\\s+JJJ\\j"
  713. :tests ("(fn test [foo]")
  714. :not ("(fn test? [foo]"))
  715. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "fennel"
  716. :regex "\\(macro\\s+JJJ\\j"
  717. :tests ("(macro test [foo]"))
  718. ;; fortran
  719. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "fortran"
  720. :regex "\\s*\\bJJJ\\s*=[^=\\n]+"
  721. :tests ("test = 1234")
  722. :not ("if (test == 1234)"))
  723. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "fortran"
  724. :regex "\\b(function|subroutine|FUNCTION|SUBROUTINE)\\s+JJJ\\b\\s*\\\("
  725. :tests ("function test (foo)" "integer function test(foo)"
  726. "subroutine test (foo, bar)" "FUNCTION test (foo)"
  727. "INTEGER FUNCTION test(foo)" "SUBROUTINE test (foo, bar)")
  728. :not ("end function test" "end subroutine test" "END FUNCTION test"
  729. "END SUBROUTINE test"))
  730. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "fortran"
  731. :regex "^\\s*(interface|INTERFACE)\\s+JJJ\\b"
  732. :tests ("interface test" "INTERFACE test")
  733. :not ("interface test2" "end interface test" "INTERFACE test2"
  734. "END INTERFACE test"))
  735. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "fortran"
  736. :regex "^\\s*(module|MODULE)\\s+JJJ\\s*"
  737. :tests ("module test" "MODULE test")
  738. :not ("end module test" "END MODULE test"))
  739. ;; go
  740. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "go"
  741. :regex "\\s*\\bJJJ\\s*=[^=\\n]+" :tests ("test = 1234") :not ("if test == 1234 {"))
  742. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "go"
  743. :regex "\\s*\\bJJJ\\s*:=\\s*" :tests ("test := 1234"))
  744. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "go"
  745. :regex "func\\s+\\\([^\\\)]*\\\)\\s+JJJ\\s*\\\("
  746. :tests ("func (s *blah) test(filename string) string {"))
  747. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "go"
  748. :regex "func\\s+JJJ\\s*\\\("
  749. :tests ("func test(url string) (string, error)"))
  750. (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "go"
  751. :regex "type\\s+JJJ\\s+struct\\s+\\\{"
  752. :tests ("type test struct {"))
  753. ;; javascript extended
  754. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  755. :regex "(service|factory)\\\(['\"]JJJ['\"]" :tags ("angular")
  756. :tests ("module.factory('test', [\"$rootScope\", function($rootScope) {"))
  757. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  758. :regex "\\bJJJ\\s*[=:]\\s*\\\([^\\\)]*\\\)\\s+=>" :tags ("es6")
  759. :tests ("const test = (foo) => " "test: (foo) => {" " test: (foo) => {"))
  760. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  761. :regex "\\bJJJ\\s*\\([^()]*\\)\\s*[{]" :tags ("es6")
  762. :tests ("test(foo) {" "test (foo){" "test(foo){")
  763. :not ("test = blah.then(function(){"))
  764. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript" :tags ("es6")
  765. :regex "class\\s*JJJ\\s*[\\\(\\\{]"
  766. :tests ("class test(object) {" "class test{"))
  767. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript" :tags ("es6")
  768. :regex "class\\s*JJJ\\s+extends"
  769. :tests ("class test extends Component{"))
  770. ;; javascript
  771. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  772. :regex "\\s*\\bJJJ\\s*=[^=\\n]+" :tests ("test = 1234" "const test = props =>") :not ("if (test === 1234)"))
  773. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  774. :regex "\\bfunction\\b[^\\(]*\\\(\\s*[^\\)]*\\bJJJ\\b\\s*,?\\s*\\\)?"
  775. :tests ("function (test)" "function (test, blah)" "function somefunc(test, blah) {" "function(blah, test)")
  776. :not ("function (testLen)" "function (test1, blah)" "function somefunc(testFirst, blah) {" "function(blah, testLast)"
  777. "function (Lentest)" "function (blahtest, blah)" "function somefunc(Firsttest, blah) {" "function(blah, Lasttest)"))
  778. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  779. :regex "function\\s*JJJ\\s*\\\("
  780. :tests ("function test()" "function test ()"))
  781. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  782. :regex "\\bJJJ\\s*:\\s*function\\s*\\\("
  783. :tests ("test: function()"))
  784. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "javascript"
  785. :regex "\\bJJJ\\s*=\\s*function\\s*\\\("
  786. :tests ("test = function()"))
  787. ;; hcl terraform
  788. (:type "block" :supports ("ag" "grep" "rg" "git-grep") :language "hcl"
  789. :regex "(variable|output|module)\\s*\"JJJ\"\\s*\\\{"
  790. :tests ("variable \"test\" {"
  791. "output \"test\" {"
  792. "module \"test\" {"))
  793. (:type "block" :supports ("ag" "grep" "rg" "git-grep") :language "hcl"
  794. :regex "(data|resource)\\s*\"\\w+\"\\s*\"JJJ\"\\s*\\\{"
  795. :tests ("data \"openstack_images_image_v2\" \"test\" {"
  796. "resource \"google_compute_instance\" \"test\" {"))
  797. ;; typescript
  798. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  799. :regex "(service|factory)\\\(['\"]JJJ['\"]" :tags ("angular")
  800. :tests ("module.factory('test', [\"$rootScope\", function($rootScope) {"))
  801. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  802. :regex "\\bJJJ\\s*[=:]\\s*\\\([^\\\)]*\\\)\\s+=>"
  803. :tests ("const test = (foo) => " "test: (foo) => {" " test: (foo) => {"))
  804. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  805. :regex "\\bJJJ\\s*\\([^()]*\\)\\s*[{]"
  806. :tests ("test(foo) {" "test (foo){" "test(foo){")
  807. :not ("test = blah.then(function(){"))
  808. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  809. :regex "class\\s*JJJ\\s*[\\\(\\\{]"
  810. :tests ("class test{"))
  811. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  812. :regex "class\\s*JJJ\\s+extends"
  813. :tests ("class test extends Component{"))
  814. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  815. :regex "function\\s*JJJ\\s*\\\("
  816. :tests ("function test()" "function test ()"))
  817. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  818. :regex "\\bJJJ\\s*:\\s*function\\s*\\\("
  819. :tests ("test: function()"))
  820. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  821. :regex "\\bJJJ\\s*=\\s*function\\s*\\\("
  822. :tests ("test = function()"))
  823. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  824. :regex "\\s*\\bJJJ\\s*=[^=\\n]+" :tests ("test = 1234" "const test = props =>") :not ("if (test === 1234)"))
  825. (:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "typescript"
  826. :regex "\\bfunction\\b[^\\(]*\\\(\\s*[^\\)]*\\bJJJ\\b\\s*,?\\s*\\\)?"
  827. :tests ("function (test)" "function (test, blah)" "function somefunc(test, blah) {" "function(blah, test)")
  828. :not ("function (testLen)" "function (test1, blah)" "function somefunc(testFirst, blah) {" "function(blah, testLast)"
  829. "function (Lentest)" "function (blahtest, blah)" "function somefunc(Firsttest, blah) {" "function(blah, Lasttest)"))
  830. ;; julia
  831. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "julia"
  832. :regex "(@noinline|@inline)?\\s*function\\s*JJJ(\\{[^\\}]*\\})?\\("
  833. :tests ("function test()" "@inline function test()"
  834. "function test{T}(h)"))
  835. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "julia"
  836. :regex "(@noinline|@inline)?JJJ(\\{[^\\}]*\\})?\\([^\\)]*\\)\s*="
  837. :tests ("test(a)=1" "test(a,b)=1*8"
  838. "@noinline test()=1" "test{T}(x)=x"))
  839. (:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "julia"
  840. :regex "macro\\s*JJJ\\("
  841. :tests ("macro test(a)=1" " macro test(a,b)=1*8"))
  842. (:type "variable" :supports ("ag" "rg") :language "julia"
  843. :regex "const\\s+JJJ\\b"
  844. :tests ("const test = "))
  845. (:type "type" :supports ("ag" "rg") :language "julia"
  846. :regex "(mutable)?\\s*struct\\s*JJJ"
  847. :tests ("struct test"))
  848. (:type "type" :supports ("ag" "rg") :language "julia"
  849. :regex "(type|immutable|abstract)\\s*JJJ"
  850. :tests ("type test" "immutable test" "abstract test <:Testable" ))
  851. ;; haskell
  852. (:type "module" :supports ("ag") :language "haskell"
  853. :regex "^module\\s+JJJ\\s+"
  854. :tests ("module Test (exportA, exportB) where"))
  855. ; TODO Doesn't support any '=' in arguments. E.g. 'foo A{a = b,..} = bar'.
  856. (:type "top level function" :supports ("ag") :language "haskell"
  857. :regex "^\\bJJJ(?!(\\s+::))\\s+((.|\\s)*?)=\\s+"
  858. :tests ("test n = n * 2"
  859. "test X{..} (Y a b c) \n bcd \n =\n x * y"
  860. "test ab cd e@Datatype {..} (Another thing, inTheRow) = \n undefined"
  861. "test = runRealBasedMode @ext @ctx identity identity"
  862. "test unwrap wrap nr@Naoeu {..} (Action action, specSpecs) = \n undefined")
  863. :not ("nottest n = n * 2"
  864. "let testnot x y = x * y" "test $ y z" "let test a o = mda"
  865. "test :: Sometype -> AnotherType aoeu kek = undefined"))
  866. (:type "type-like" :supports ("ag") :language "haskell"
  867. :regex "^\\s*((data(\\s+family)?)|(newtype)|(type(\\s+family)?))\\s+JJJ\\s+"
  868. :tests ("newtype Test a = Something { b :: Kek }"
  869. "data Test a b = Somecase a | Otherca