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