-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathraku-imenu.el
148 lines (132 loc) · 4.74 KB
/
raku-imenu.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
;;; raku-imenu.el --- Imenu support Raku -*- lexical-binding: t; -*-
;; Imenu functions and variables are defined here.
;; Definition of "identifiers" (names) from
;; https://docs.raku.org/language/syntax#Identifiers
;;
;; Identifiers are a grammatical building block that occur in several
;; places. An identifier is a primitive name, and must start with an
;; alphabetic character (or an underscore), followed by zero or more
;; word characters (alphabetic, underscore or number). You can also
;; embed dashes - or single quotes ' in the middle, but not two in a
;; row, and only if followed immediately by an alphabetic character.
;;
;; For NQP names, no embedded hyphens or single quotes are allowed.
;; Regex definitions:
(defvar raku-name-regex
(concat
"[_[:alpha:]]" ; mandatory leading character
"\\(?:[-']?[[:alpha:]]" ; rest of the name allowing embedded hyphens or single quotes or '::'
"\\|[_[:alnum:]]"
"\\|\\:\\:[_[:alnum:]]"
"\\)*"
))
(defvar nqp-name-regex
(concat
"[_[:alpha:]]" ; mandatory leading character
"[_[:alnum:]]*" ; rest of the name (stricter than Raku name)
))
(defvar raku-vars-regex
(concat
"^\\s-*" ; leading ws allowed
"\\(?:my\\|our\\|state\\)\\s-+" ; scope of var, followed by mandatory ws
"\\(" ; start capture group 1 for the var name
"\\(?:\\$\\|@\\|%\\)" ; sigil for type of var
"\\(?:" ; start shy group for choice of one type name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end shy group
"\\)" ; end of capture group 1
))
(defvar raku-subs-regex
(concat
"^\\s-*" ; leading ws allowed
"\\(?:my\\s-+\\|our\\s-+\\)?" ; optional specific scope followed by at least one space
; must have one of the five type identifiers
; followed by at least one space:
"\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\|proto\\)\\s-+"
"\\!?" ; optional private marker
"\\(" ; start capture group 1 for the sub name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))
(defvar raku-classes-regex
(concat
"^\\s-*" ; leading ws allowed
; must have one of the four type identifiers followed by at least one space:
"class\\s-+"
"\\(" ; start capture group 1 of the class name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))
(defvar raku-regexes-regex
(concat
"^\\s-*" ; leading ws allowed
; must have an identifier followed by at least one space:
"regex\\s-+"
"\\(" ; start capture group 1 of the regex name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))
(defvar raku-tokens-regex
(concat
"^\\s-*" ; leading ws allowed
; must have an identifier followed by at least one space:
"token\\s-+"
"\\(" ; start capture group 1 of the regex name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))
(defvar raku-rules-regex
(concat
"^\\s-*" ; leading ws allowed
; must have an identifier followed by at least one space:
"rule\\s-+"
"\\(" ; start capture group 1 of the regex name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))
(defvar raku-grammars-regex
(concat
"^\\s-*" ; leading ws allowed
; must have an identifier followed by at least one space:
"grammar\\s-+"
"\\(" ; start capture group 1 of the regex name
raku-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))
(defvar raku-imenu-generic-expression
`(
;; the names are in reverse desired order since they are evaluated here last first
("Rules" ,raku-rules-regex 1)
("Tokens" ,raku-tokens-regex 1)
("Regexes" ,raku-regexes-regex 1)
("Grammars" ,raku-grammars-regex 1)
("Classes" ,raku-classes-regex 1)
("Variables" ,raku-vars-regex 1)
("Subs/Methods" ,raku-subs-regex 1)
)
"Define interesting points in the Raku buffer for `imenu'.
This is used to set `imenu-generic-expression' when Raku mode is
entered. Subsequent changes to `raku-imenu-generic-expression' will
not affect existing Raku buffers because imenu-generic-expression is
a local variable.")
;;===========================
(provide 'raku-imenu)
;; Local Variables:
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; raku-imenu.el ends here