aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2013-04-15 14:32:20 +0000
committerAlan Mackenzie2013-04-15 14:32:20 +0000
commit85c9ab6469de468202fee8d17b63258b00bc76d3 (patch)
treef92f029b6958c934d76730b0f50882ba6d9b1631
parentdbde58a60313a2bccb24f6b928a7ef2950086f25 (diff)
downloademacs-85c9ab6469de468202fee8d17b63258b00bc76d3.tar.gz
emacs-85c9ab6469de468202fee8d17b63258b00bc76d3.zip
Reformulate java imenu-generic-expression.
The old expression contained ill formed regexps. * progmodes/cc-menus.el (cc-imenu-java-ellipsis-regexp) (cc-imenu-java-type-spec-regexp, cc-imenu-java-comment-regexp) (cc-imenu-java-method-arg-regexp): New defconsts. (cc-imenu-java-build-type-args-regex): New defun. (cc-imenu-java-generic-expression): Fixed, to remove "ambiguous" handling of spaces in the regexp.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/progmodes/cc-menus.el159
2 files changed, 133 insertions, 38 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2231d96a757..d367ddb36f8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12013-04-15 Filipp Gunbin <fgunbin@fastmail.fm>
2
3 Reformulate java imenu-generic-expression.
4 The old expression contained ill formed regexps.
5
6 * progmodes/cc-menus.el (cc-imenu-java-ellipsis-regexp)
7 (cc-imenu-java-type-spec-regexp, cc-imenu-java-comment-regexp)
8 (cc-imenu-java-method-arg-regexp): New defconsts.
9 (cc-imenu-java-build-type-args-regex): New defun.
10 (cc-imenu-java-generic-expression): Fixed, to remove "ambiguous"
11 handling of spaces in the regexp.
12
12013-03-15 Agustín Martín Domingo <agustin.martin@hispalinux.es> 132013-03-15 Agustín Martín Domingo <agustin.martin@hispalinux.es>
2 14
3 * textmodes/ispell.el (ispell-command-loop): Remove 15 * textmodes/ispell.el (ispell-command-loop): Remove
diff --git a/lisp/progmodes/cc-menus.el b/lisp/progmodes/cc-menus.el
index a06eaf566d8..067a4df13dd 100644
--- a/lisp/progmodes/cc-menus.el
+++ b/lisp/progmodes/cc-menus.el
@@ -161,49 +161,132 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
161 cc-imenu-c++-generic-expression 161 cc-imenu-c++-generic-expression
162 "Imenu generic expression for C mode. See `imenu-generic-expression'.") 162 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
163 163
164(defvar cc-imenu-java-generic-expression 164
165;; Auxiliary regexps for Java try to match their trailing whitespace where
166;; appropriate, but _not_ starting whitespace.
167
168(defconst cc-imenu-java-ellipsis-regexp
169 (concat
170 "\\.\\{3\\}"
171 "[ \t\n\r]*"))
172
173(defun cc-imenu-java-build-type-args-regex (depth)
174 "Builds regexp for type arguments list with DEPTH allowed
175nested angle brackets constructs."
176 (if (> depth 0)
177 (concat "<"
178 "[][.," c-alnum "_? \t\n\r]+"
179 (if (> depth 1)
180 "\\(")
181 (cc-imenu-java-build-type-args-regex (1- depth))
182 (if (> depth 1)
183 (concat "[][.," c-alnum "_? \t\n\r]*"
184 "\\)*"))
185 ">")))
186
187(defconst cc-imenu-java-type-spec-regexp
188 (concat
189 ;; zero or more identifiers followed by a dot
190 "\\("
191 "[" c-alpha "_][" c-alnum "_]*\\."
192 "\\)*"
193 ;; a single mandatory identifier without a dot
194 "[" c-alpha "_][" c-alnum "_]*"
195 ;; then choice:
196 "\\("
197 ;; (option 1) type arguments list which _may_ be followed with brackets
198 ;; and/or spaces, then optional variable arity
199 "[ \t\n\r]*"
200 (cc-imenu-java-build-type-args-regex 3)
201 "[][ \t\n\r]*"
202 "\\(" cc-imenu-java-ellipsis-regexp "\\)?"
203 "\\|"
204 ;; (option 2) just brackets and/or spaces (there should be at least one),
205 ;; then optional variable arity
206 "[][ \t\n\r]+"
207 "\\(" cc-imenu-java-ellipsis-regexp "\\)?"
208 "\\|"
209 ;; (option 3) just variable arity
210 cc-imenu-java-ellipsis-regexp
211 "\\)"))
212
213(defconst cc-imenu-java-comment-regexp
214 (concat
215 "/"
216 "\\("
217 ;; a traditional comment
218 "\\*"
219 "\\("
220 "[^*]"
221 "\\|"
222 "\\*+[^/*]"
223 "\\)*"
224 "\\*+/"
225 "\\|"
226 ;; an end-of-line comment
227 "/[^\n\r]*[\n\r]"
228 "\\)"
229 "[ \t\n\r]*"
230 ))
231
232;; Comments are allowed before the argument, after any of the
233;; modifiers and after the identifier.
234(defconst cc-imenu-java-method-arg-regexp
235 (concat
236 "\\(" cc-imenu-java-comment-regexp "\\)*"
237 ;; optional modifiers
238 "\\("
239 ;; a modifier is either an annotation or "final"
240 "\\("
241 "@[" c-alpha "_]"
242 "[" c-alnum "._]*"
243 ;; TODO support element-value pairs!
244 "\\|"
245 "final"
246 "\\)"
247 ;; a modifier ends with comments and/or ws
248 "\\("
249 "\\(" cc-imenu-java-comment-regexp "\\)+"
250 "\\|"
251 "[ \t\n\r]+"
252 "\\(" cc-imenu-java-comment-regexp "\\)*"
253 "\\)"
254 "\\)*"
255 ;; type spec
256 cc-imenu-java-type-spec-regexp
257 ;; identifier
258 "[" c-alpha "_]"
259 "[" c-alnum "_]*"
260 ;; optional comments and/or ws
261 "[ \t\n\r]*"
262 "\\(" cc-imenu-java-comment-regexp "\\)*"
263 ))
264
265(defconst cc-imenu-java-generic-expression
165 `((nil 266 `((nil
166 ,(concat 267 ,(concat
167 "[" c-alpha "_][\]\[." c-alnum "_<> ]+[ \t\n\r]+" ; type spec 268 cc-imenu-java-type-spec-regexp
168 "\\([" c-alpha "_][" c-alnum "_]*\\)" ; method name 269 "\\(" ; method name which gets captured
270 ; into index
271 "[" c-alpha "_]"
272 "[" c-alnum "_]*"
273 "\\)"
169 "[ \t\n\r]*" 274 "[ \t\n\r]*"
170 ;; An argument list htat is either empty or contains any number 275 ;; An argument list that contains zero or more arguments.
171 ;; of arguments. An argument is any number of annotations 276 (concat
172 ;; followed by a type spec followed by a word. A word is an 277 "("
173 ;; identifier. A type spec is an identifier, possibly followed 278 "[ \t\n\r]*"
174 ;; by < typespec > possibly followed by []. 279 "\\("
175 (concat "(" 280 "\\(" cc-imenu-java-method-arg-regexp ",[ \t\n\r]*\\)*"
176 "\\(" 281 cc-imenu-java-method-arg-regexp
177 "[ \t\n\r]*" 282 "\\)?"
178 "\\(" 283 ")"
179 "@" 284 "[.,_" c-alnum " \t\n\r]*" ; throws etc.
180 "[" c-alpha "_]" 285 "{"
181 "[" c-alnum "._]""*" 286 )) 7))
182 "[ \t\n\r]+"
183 "\\)*"
184 "\\("
185 "[" c-alpha "_]"
186 "[\]\[" c-alnum "_.]*"
187 "\\("
188
189 "<"
190 "[ \t\n\r]*"
191 "[\]\[.," c-alnum "_<> \t\n\r]*"
192 ">"
193 "\\)?"
194 "\\(\\[\\]\\)?"
195 "[ \t\n\r]+"
196 "\\)"
197 "[" c-alpha "_]"
198 "[" c-alnum "_]*"
199 "[ \t\n\r,]*"
200 "\\)*"
201 ")"
202 "[.," c-alnum " \t\n\r]*"
203 "{"
204 )) 1))
205 "Imenu generic expression for Java mode. See `imenu-generic-expression'.") 287 "Imenu generic expression for Java mode. See `imenu-generic-expression'.")
206 288
289
207;; Internal variables 290;; Internal variables
208(defvar cc-imenu-objc-generic-expression-noreturn-index nil) 291(defvar cc-imenu-objc-generic-expression-noreturn-index nil)
209(defvar cc-imenu-objc-generic-expression-general-func-index nil) 292(defvar cc-imenu-objc-generic-expression-general-func-index nil)