@@ -159,8 +159,13 @@ it is the character that will terminate the string, or t if the string should be
159
159
(and (boundp 'poly-php-html-mode )
160
160
(symbol-value 'poly-php-html-mode )))
161
161
162
- (defun php-create-regexp-for-method (visibility )
163
- " Make a regular expression for methods with the given VISIBILITY.
162
+ (defconst php-beginning-of-defun-regexp
163
+ " ^\\ s-*\\ (?:\\ (?:abstract\\ |final\\ |private\\ |protected\\ |public\\ |static\\ )\\ s-+\\ )*function\\ s-+&?\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*("
164
+ " Regular expression for a PHP function." )
165
+
166
+ (eval-when-compile
167
+ (defun php-create-regexp-for-method (&optional visibility )
168
+ " Make a regular expression for methods with the given VISIBILITY.
164
169
165
170
VISIBILITY must be a string that names the visibility for a PHP
166
171
method, e.g. 'public'. The parameter VISIBILITY can itself also
@@ -170,61 +175,71 @@ The regular expression this function returns will check for other
170
175
keywords that can appear in method signatures, e.g. 'final' and
171
176
'static'. The regular expression will have one capture group
172
177
which will be the name of the method."
173
- (concat
174
- ; ; Initial space with possible 'abstract' or 'final' keywords
175
- " ^\\ s-*\\ (?:\\ (?:abstract\\ |final\\ )\\ s-+\\ )?"
176
- ; ; 'static' keyword may come either before or after visibility
177
- " \\ (?:" visibility " \\ (?:\\ s-+static\\ )?\\ |\\ (?:static\\ s-+\\ )?" visibility " \\ )\\ s-+"
178
- ; ; Make sure 'function' comes next with some space after
179
- " function\\ s-+"
180
- ; ; Capture the name as the first group and the regexp and make sure
181
- ; ; by the end we see the opening parenthesis for the parameters.
182
- " \\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*(" ))
183
-
184
- (defun php-create-regexp-for-classlike (type )
185
- " Accepts a `TYPE' of a 'classlike' object as a string, such as
178
+ (rx-form `(: line-start
179
+ (* (syntax whitespace))
180
+ ,@(if visibility
181
+ `((* (or " abstract" " final" " static" )
182
+ (+ (syntax whitespace)))
183
+ (or ,@visibility )
184
+ (+ (syntax whitespace))
185
+ (* (or " abstract" " final" " static" )
186
+ (+ (syntax whitespace))))
187
+ '((* (* (or " abstract" " final" " static"
188
+ " private" " protected" " public" ))
189
+ (+ (syntax whitespace)))))
190
+ " function"
191
+ (+ (syntax whitespace))
192
+ (group (+ (or (syntax word) (syntax symbol))))
193
+ (* (syntax whitespace))
194
+ " (" )))
195
+
196
+ (defun php-create-regexp-for-classlike (type )
197
+ " Accepts a `TYPE' of a 'classlike' object as a string, such as
186
198
'class' or 'interface', and returns a regexp as a string which
187
199
can be used to match against definitions for that classlike."
188
- (concat
189
- ; ; First see if 'abstract' or 'final' appear, although really these
190
- ; ; are not valid for all values of `type' that the function
191
- ; ; accepts.
192
- " ^\\ s-*\\ (?:\\ (?:abstract\\ |final\\ )\\ s-+\\ )?"
193
- ; ; The classlike type
194
- type
195
- ; ; Its name, which is the first captured group in the regexp. We
196
- ; ; allow backslashes in the name to handle namespaces, but again
197
- ; ; this is not necessarily correct for all values of `type' .
198
- " \\ s-+\\ (\\ (?:\\ sw\\ |\\\\\\ |\\ s_\\ )+\\ )" ))
199
-
200
- (defvar php-imenu-generic-expression
201
- `((" Namespaces"
202
- ,(php-create-regexp-for-classlike " namespace" ) 1 )
203
- (" Classes"
204
- ,(php-create-regexp-for-classlike " class" ) 1 )
205
- (" Interfaces"
206
- ,(php-create-regexp-for-classlike " interface" ) 1 )
207
- (" Traits"
208
- ,(php-create-regexp-for-classlike " trait" ) 1 )
209
- (" All Methods"
210
- ,(php-create-regexp-for-method " \\ (?:\\ sw\\ |\\ s_\\ )+" ) 1 )
211
- (" Private Methods"
212
- ,(php-create-regexp-for-method " private" ) 1 )
213
- (" Protected Methods"
214
- ,(php-create-regexp-for-method " protected" ) 1 )
215
- (" Public Methods"
216
- ,(php-create-regexp-for-method " public" ) 1 )
217
- (" Anonymous Functions"
218
- " \\ <\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*=\\ s-*function\\ s-*(" 1 )
219
- (" Named Functions"
220
- " ^\\ s-*function\\ s-+\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*(" 1 ))
200
+ (concat
201
+ ; ; First see if 'abstract' or 'final' appear, although really these
202
+ ; ; are not valid for all values of `type' that the function
203
+ ; ; accepts.
204
+ " ^\\ s-*\\ (?:\\ (?:abstract\\ |final\\ )\\ s-+\\ )?"
205
+ ; ; The classlike type
206
+ type
207
+ ; ; Its name, which is the first captured group in the regexp. We
208
+ ; ; allow backslashes in the name to handle namespaces, but again
209
+ ; ; this is not necessarily correct for all values of `type' .
210
+ " \\ s-+\\ (\\ (?:\\ sw\\ |\\\\\\ |\\ s_\\ )+\\ )" )))
211
+
212
+ (defconst php-imenu-generic-expression
213
+ (eval-when-compile
214
+ `((" Namespaces"
215
+ ,(php-create-regexp-for-classlike " namespace" ) 1 )
216
+ (" Classes"
217
+ ,(php-create-regexp-for-classlike " class" ) 1 )
218
+ (" Interfaces"
219
+ ,(php-create-regexp-for-classlike " interface" ) 1 )
220
+ (" Traits"
221
+ ,(php-create-regexp-for-classlike " trait" ) 1 )
222
+ (" All Methods"
223
+ ,(php-create-regexp-for-method) 1 )
224
+ (" Private Methods"
225
+ ,(php-create-regexp-for-method '(" private" )) 1 )
226
+ (" Protected Methods"
227
+ ,(php-create-regexp-for-method '(" protected" )) 1 )
228
+ (" Public Methods"
229
+ ,(php-create-regexp-for-method '(" public" )) 1 )
230
+ (" Anonymous Functions"
231
+ " \\ <\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*=\\ s-*f\\ (unctio\\ )?n\\ s-*(" 1 )
232
+ (" Named Functions"
233
+ " ^\\ s-*function\\ s-+\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*(" 1 )))
221
234
" Imenu generic expression for PHP Mode. See `imenu-generic-expression' ." )
222
235
223
- (defvar php--re-namespace-pattern
224
- (php-create-regexp-for-classlike " namespace" ))
236
+ (defconst php--re-namespace-pattern
237
+ (eval-when-compile
238
+ (php-create-regexp-for-classlike " namespace" )))
225
239
226
- (defvar php--re-classlike-pattern
227
- (php-create-regexp-for-classlike (regexp-opt '(" class" " interface" " trait" ))))
240
+ (defconst php--re-classlike-pattern
241
+ (eval-when-compile
242
+ (php-create-regexp-for-classlike (regexp-opt '(" class" " interface" " trait" )))))
228
243
229
244
(defun php-get-current-element (re-pattern )
230
245
" Return backward matched element by RE-PATTERN."
0 commit comments