83
83
CRE
84
84
end ).
85
85
86
- -define (RE_FUNCTIONS , ? COMPILE (" ^([a-z][a-zA-Z0-9_@]*)\\ s*\\ (" )).
87
- -define (RE_TYPESPECS , ? COMPILE (" ^-\\ s*(type|opaque)\\ s*([a-zA-Z0-9_@]*)\\ b" )).
88
- -define (RE_DEFINES , ? COMPILE (" ^-\\ s*(record|define)\\ s*\\ (\\ s*([a-zA-Z0-9_@]*)\\ b" )).
86
+ -define (RE_FUNCTIONS , ? COMPILE (" ^([a-z][a-zA-Z0-9_@]*)\\ s*\\ (" )).
87
+ -define (RE_TYPESPECS1 , ? COMPILE (" ^-\\ s*(type|opaque)\\ s*([a-zA-Z0-9_@]+)\\ b" )).
88
+ -define (RE_TYPESPECS2 , ? COMPILE (" ^-\\ s*(type|opaque)\\ s*'([^ \\ t']+)'" )).
89
+ -define (RE_DEFINES1 , ? COMPILE (" ^-\\ s*(record|define)\\ s*\\ (\\ s*([a-zA-Z0-9_@]+)\\ b" )).
90
+ -define (RE_DEFINES2 , ? COMPILE (" ^-\\ s*(record|define)\\ s*\\ (\\ s*'([^ \\ t']+)'" )).
89
91
90
92
-define (DEFAULT_PATH , " ." ).
91
93
@@ -287,28 +289,44 @@ add_tags_from_file(File, Tags) ->
287
289
ok = scan_tags (Contents , {Tags , File , ModName }).
288
290
289
291
scan_tags (Contents , {Tags , File , ModName }) ->
290
- case re :run (Contents , ? RE_FUNCTIONS , [{capture , all , binary }, global ]) of
291
- nomatch ->
292
- ok ;
293
- {match , Matches1 } ->
294
- [ add_func_tags (Tags , File , ModName , FuncName )
295
- || [_ , FuncName ] <- Matches1 ]
296
- end ,
297
- case re :run (Contents , ? RE_TYPESPECS , [{capture , all , binary }, global ]) of
298
- nomatch ->
299
- ok ;
300
- {match , Matches2 } ->
301
- [ add_type_tags (Tags , File , ModName , Attr , TypeName )
302
- || [_ , Attr , TypeName ] <- Matches2 ]
303
- end ,
304
- case re :run (Contents , ? RE_DEFINES , [{capture , all , binary }, global ]) of
292
+ scan_tags_core (
293
+ Contents , ? RE_FUNCTIONS ,
294
+ fun ([_ , FuncName ]) ->
295
+ add_func_tags (Tags , File , ModName , FuncName )
296
+ end ),
297
+ scan_tags_core (
298
+ Contents , ? RE_TYPESPECS1 ,
299
+ fun ([_ , Attr , TypeName ]) ->
300
+ InnerPattern = [TypeName , " \\ >" ],
301
+ add_type_tags (Tags , File , ModName , Attr , TypeName , InnerPattern )
302
+ end ),
303
+ scan_tags_core (
304
+ Contents , ? RE_TYPESPECS2 ,
305
+ fun ([_ , Attr , TypeName ]) ->
306
+ InnerPattern = [$' , TypeName , $' ],
307
+ add_type_tags (Tags , File , ModName , Attr , TypeName , InnerPattern )
308
+ end ),
309
+ scan_tags_core (
310
+ Contents , ? RE_DEFINES1 ,
311
+ fun ([_ , Attr , Name ]) ->
312
+ InnerPattern = [Name , " \\ >" ],
313
+ add_record_or_macro_tag (Tags , File , Attr , Name , InnerPattern )
314
+ end ),
315
+ scan_tags_core (
316
+ Contents , ? RE_DEFINES2 ,
317
+ fun ([_ , Attr , Name ]) ->
318
+ InnerPattern = [$' , Name , $' ],
319
+ add_record_or_macro_tag (Tags , File , Attr , Name , InnerPattern )
320
+ end ),
321
+ ok .
322
+
323
+ scan_tags_core (Contents , Pattern , Fun ) ->
324
+ case re :run (Contents , Pattern , [{capture , all , binary }, global ]) of
305
325
nomatch ->
306
326
ok ;
307
- {match , Matches3 } ->
308
- [ add_record_or_macro_tag (Tags , File , Attr , Name )
309
- || [_ , Attr , Name ] <- Matches3 ]
310
- end ,
311
- ok .
327
+ {match , Matches } ->
328
+ lists :foreach (Fun , Matches )
329
+ end .
312
330
313
331
% %%=============================================================================
314
332
% %% Add specific tags
@@ -344,11 +362,11 @@ add_func_tags(Tags, File, ModName, FuncName) ->
344
362
add_tag (Tags , FuncName , File , [" /^" , FuncName , " \\ >/" ], local , $f ).
345
363
346
364
% File contains the type ModName:Type; add this information to Tags.
347
- add_type_tags (Tags , File , ModName , Attribute , TypeName ) ->
365
+ add_type_tags (Tags , File , ModName , Attribute , TypeName , InnerPattern ) ->
348
366
349
367
log (" Type definition found: ~s~n " , [TypeName ]),
350
368
351
- Pattern = [" /^-\\ s\\ *" , Attribute , " \\ s\\ *" , TypeName , " \\ >/ " ],
369
+ Pattern = [" /^-\\ s\\ *" , Attribute , " \\ s\\ *" , InnerPattern , $/ ],
352
370
353
371
% Global entry:
354
372
% mymod:mytype <tab> ./mymod.erl <tab> /^-type\s\*mytype\>/
@@ -363,7 +381,7 @@ add_type_tags(Tags, File, ModName, Attribute, TypeName) ->
363
381
add_tag (Tags , TypeName , File , Pattern , local , $t ).
364
382
365
383
% File contains a macro or record called Name; add this information to Tags.
366
- add_record_or_macro_tag (Tags , File , Attribute , Name ) ->
384
+ add_record_or_macro_tag (Tags , File , Attribute , Name , InnerPattern ) ->
367
385
368
386
{Kind , Prefix } =
369
387
case Attribute of
@@ -388,15 +406,15 @@ add_record_or_macro_tag(Tags, File, Attribute, Name) ->
388
406
% mymac ./mymod.erl /^-define\s\*\<mymac\>/;" m file:
389
407
% mymac ./myhrl.hrl /^-define\s\*\<mymac\>/;" m
390
408
add_tag (Tags , Name , File ,
391
- [" /^-\\ s\\ *" , Attribute , " \\ s\\ *(\\ s\\ *" , Name , " \\ > /" ],
409
+ [" /^-\\ s\\ *" , Attribute , " \\ s\\ *(\\ s\\ *" , InnerPattern , " /" ],
392
410
Scope , Kind ),
393
411
394
412
% #myrec ./mymod.erl /^-record\s\*\<myrec\>/;" r file:
395
413
% #myrec ./myhrl.hrl /^-record\s\*\<myrec\>/;" r
396
414
% ?mymac ./mymod.erl /^-define\s\*\<mymac\>/;" m file:
397
415
% ?mymac ./myhrl.hrl /^-define\s\*\<mymac\>/;" m
398
416
add_tag (Tags , [Prefix |Name ], File ,
399
- [" /^-\\ s\\ *" , Attribute , " \\ s\\ *(\\ s\\ *" , Name , " \\ > /" ],
417
+ [" /^-\\ s\\ *" , Attribute , " \\ s\\ *(\\ s\\ *" , InnerPattern , " /" ],
400
418
Scope , Kind ).
401
419
402
420
add_tag (Tags , Tag , File , TagAddress , Scope , Kind ) ->
0 commit comments