Skip to content

Commit

Permalink
add new name categories and other improvements
Browse files Browse the repository at this point in the history
+ add regex, token, rule, and grammar categories for Perl 6
+ allow '::' in identifiers in certain positions
+ add appropriate regexes for the new categories
+ add new categories to the menu list
+ add new categories to the Perl 6 test file
  • Loading branch information
tbrowder committed Jun 13, 2018
1 parent 4867c6d commit cc28223
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
59 changes: 57 additions & 2 deletions perl6-imenu.el
Expand Up @@ -17,8 +17,11 @@
;; Regex definitions:
(defvar perl6-name-regex
(concat
"[_[:alpha:]]" ; mandatory leading character
"\\(?:[-']?[[:alpha:]]\\|[_[:alnum:]]\\)*" ; rest of the name allowing embedded hyphens or single quotes
"[_[:alpha:]]" ; mandatory leading character
"\\(?:[-']?[[:alpha:]]" ; rest of the name allowing embedded hyphens or single quotes or '::'
"\\|[_[:alnum:]]"
"\\|\\:\\:[_[:alnum:]]"
"\\)*"
))

(defvar nqp-name-regex
Expand Down Expand Up @@ -68,9 +71,61 @@
"\\)" ; end of capture group 1
))

(defvar perl6-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
perl6-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))

(defvar perl6-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
perl6-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))

(defvar perl6-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
perl6-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))

(defvar perl6-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
perl6-name-regex
"\\|"
nqp-name-regex
"\\)" ; end of capture group 1
))

(defvar perl6-imenu-generic-expression
`(
;; the names are in reverse desired order since they are evaluated here last first
("Rules" ,perl6-rules-regex 1)
("Tokens" ,perl6-tokens-regex 1)
("Regexes" ,perl6-regexes-regex 1)
("Grammars" ,perl6-grammars-regex 1)
("Classes" ,perl6-classes-regex 1)
("Variables" ,perl6-vars-regex 1)
("Subs/Methods" ,perl6-subs-regex 1)
Expand Down
10 changes: 9 additions & 1 deletion test/test-imenu.p6
@@ -1,6 +1,7 @@
# file: test-imenu.p6

# Perl 6 syntax file for testing perl6-mode with imenu support, which is located at:
# Perl 6 syntax file for testing perl6-mode with imenu support, which
# is located at:
#
# https://github.com/tbrowder/perl6-mode [branch: "my-branch"]

Expand All @@ -20,6 +21,13 @@ multi c() {}
proto xx() {}
multi method !z-private() {}

my $F::B;

class My-class1 {}
class My-class2{
class doit () {}

token one {}
regex two {}
rule three {}
grammar G::T {}

0 comments on commit cc28223

Please sign in to comment.